Skip to content

Commit

Permalink
Cleanup from review during documentation
Browse files Browse the repository at this point in the history
- Docblock tweaks, some visibility changes
- Move module aware helpers to Xmf\Module\Helper
- Dump Krumo add Kint
  • Loading branch information
geekwright committed Feb 27, 2016
1 parent 21cd6f9 commit 18b931d
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 147 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"require": {
"php": ">=5.3.7",
"mmucklo/krumo": "0.5.6",
"raveren/kint": "1.0.10",
"symfony/yaml": "2.4.*",
"ircmaxell/random-lib": "^1.1.0",
"firebase/php-jwt": "^3.0.0"
Expand Down
24 changes: 5 additions & 19 deletions src/Xmf/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,20 @@
* @link http://xoops.org
* @since 1.0
*/
class Debug
class Debug extends \Kint
{
/**
* Dump one or more variables
*
* @param mixed $var variable(s) to dump
* @param mixed $data variable(s) to dump
*
* @return void
*/
public static function dump($var)
public static function dump($data = NULL)
{
$args = func_get_args();

$config = array(
'skin' => array('selected' => 'stylish'),
'css' => array('url' => XOOPS_URL . '/include/krumo/'),
'display' => array(
'show_version' => false,
'show_call_info' => false,
'carriage_returns' => false,
),
'sorting' => array('sort_arrays' => false,),
);
\Krumo::setConfig($config);
foreach ($args as $var) {
$msg = \Krumo::dump($var, KRUMO_RETURN);
echo $msg;
}
parent::$theme = 'aante-light'; // options: 'original' (default), 'solarized', 'solarized-dark' and 'aante-light'
call_user_func_array('parent::dump', $args);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Xmf/Metagen.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public static function generateSeoTitle($title = '', $extension = '')
*
* @param string $haystack the string to summarize
* @param mixed $needles search term, array of search terms, or null
* @param int $length maximum length for the summary
* @param int $length maximum character length for the summary
*
* @return string a substring of haystack
*/
Expand Down
122 changes: 61 additions & 61 deletions src/Xmf/Module/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* Xmf\Module\Admin provides helpful methods for module administration
* uses.
*
* Xmf\Module\Admin also provides a method compatible subset of the
* Xoops 2.6 ModuleAdmin class for use in transition from 2.5 to 2.6
* Xmf\Module\Admin provides a method compatible subset of the Xoops\Module\Admin class
* (introduced in 2.6) and other convenience methods useful in transition
*
* @category Xmf\Module\Admin
* @package Xmf
Expand Down Expand Up @@ -51,15 +51,11 @@ protected function __construct()
/**
* Retrieve a module admin instance
*
* If we are on 2.6 this will be the a XoopsModuleAdmin instance.
* Older systems with the Frameworks based admin class will get
* an instance of this class which provides compatible methods
* built from the old Frameworks version.
* If we are on a next generation system this will be the a native Xoops\Module\Admin instance.
* Older systems with the Frameworks based admin class will get an instance of this class which
* provides compatible methods built from the old Frameworks version.
*
* **Always use this to get the ModuleAdmin instance if you use
* anything (even the static methods) of this class.**
*
* @return object a ModuleAdmin instance.
* @return object a ModuleAdmin or Xoops\Module\Admin instance.
*
* @since 1.0
*/
Expand All @@ -83,38 +79,6 @@ public static function getInstance()
return $instance;
}

/**
* Are we in a 2.6 environment?
*
* @return bool true if we are in a 2.6 environment
*/
protected static function is26()
{
return class_exists('\Xoops', false);
}

/**
* Get an appropriate imagePath for menu.php use.
*
* just to help with other admin things than ModuleAdmin
*
* not part of 2.6 module admin
*
* @param string $image icon name to prepend with path
*
* @return string true if we are in a 2.6 environment
*/
public static function menuIconPath($image)
{
if (static::is26()) {
return($image);
} else {
$path = '../../Frameworks/moduleclasses/icons/32/';

return($path . $image);
}
}

/**
* Add config line
*
Expand Down Expand Up @@ -295,18 +259,6 @@ public function renderAbout($logo_xoops = true)
return static::$ModuleAdmin->renderAbout(static::$paypal, $logo_xoops);
}

/**
* set paypal for 2.5 renderAbout
*
* @param string $paypal PayPal identifier for donate button
*
* @return void
*/
public static function setPaypal($paypal = '')
{
static::$paypal = $paypal;
}

/**
* Display about page
*
Expand Down Expand Up @@ -423,21 +375,55 @@ public function addConfigModuleVersion($moddir, $minversion)
return $return;
}

// not in regular ModuleAdmin
// the following not part of next generation Xoops\Module\Admin

/**
* Are we in a next generation environment?
*
* not part of next generation Xoops\Module\Admin
*
* @return bool true if we are in a post XOOPS 2.5.x environment
*/
protected static function isXng()
{
return class_exists('\Xoops', false);
}

/**
* Get an appropriate imagePath for menu.php use.
*
* just to help with other admin things than ModuleAdmin
*
* not part of next generation Xoops\Module\Admin
*
* @param string $image icon name to prepend with path
*
* @return string the icon path
*/
public static function menuIconPath($image)
{
if (static::isXng()) {
return($image);
} else {
$path = '../../Frameworks/moduleclasses/icons/32/';

return($path . $image);
}
}

/**
* Get an appropriate URL for system provided icons.
*
* Things which were in Frameworks in 2.5 are in media in 2.6,
* Things which were in Frameworks in 2.5 are in media in later versions,
* making it harder to use and rely on the standard icons.
*
* not part of 2.6, just a transition assist
* not part of next generation Xoops\Module\Admin
*
* @param string $name the image name to provide URL for, or blank
* to just get the URL path.
* to just get the URL path.
* @param string $size the icon size (directory). Valid values are
* 16, 32 or /. A '/' slash will simply set the
* path to the icon directory and append $image.
* 16, 32 or /. A '/' slash will simply set the
* path to the icon directory and append $image.
*
* @return string path to icons
*/
Expand All @@ -456,12 +442,26 @@ public static function iconUrl($name = '', $size = '32')
break;
}

if (static::is26()) {
if (static::isXng()) {
$path = '/media/xoops/images/icons/' . $path;
} else {
$path = '/Frameworks/moduleclasses/icons/' . $path;
}

return(XOOPS_URL . $path . $name);
}

/**
* set paypal for 2.5.x renderAbout
*
* not part of next generation Xoops\Module\Admin
*
* @param string $paypal PayPal identifier for donate button
*
* @return void
*/
public static function setPaypal($paypal = '')
{
static::$paypal = $paypal;
}
}
30 changes: 18 additions & 12 deletions src/Xmf/Module/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,35 @@
* @link http://xoops.org
* @since 1.0
*/
class Helper
class Helper extends GenericHelper
{
/**
* Get an instance to a module helper for a module directory
* Get an instance of a module helper for the module identified by $dirname
*
* @param string $dirname module directory
*
* @return bool|\Xoops\Module\Helper|GenericHelper
* @return \Xmf\Module\Helper|\Xoops\Module\Helper|false a Helper object of false on error
*/
public static function getHelper($dirname = 'system')
{
// if this is a 2.6 system turn everything over to the core
if (class_exists('Xoops', false)) {
return \Xoops\Module\Helper::getHelper($dirname);
}
static $instance = array();

// otherwise get a GenericHelper instance for dirname
$dirname = strtolower($dirname);
if (xoops_isActiveModule($dirname)) {
return GenericHelper::getInstance($dirname);

if (!isset($instance[$dirname])) {
$instance[$dirname] = false;

// if this is a 2.6 system turn everything over to the core
if (class_exists('Xoops', false)) {
$instance[$dirname] = \Xoops\Module\Helper::getHelper($dirname);
}

// otherwise get a GenericHelper instance for dirname
if (xoops_isActiveModule($dirname)) {
$instance[$dirname] = new static($dirname);
}
}

// not an active installed module
return false;
return $instance[$dirname];
}
}
24 changes: 7 additions & 17 deletions src/Xmf/Module/Helper/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Xmf\Module\Helper;

use Xmf\Module\Helper;

/**
* Xmf\Module\Helper\AbstractHelper defines the basis for various
* helpers that simplify routine module tasks.
Expand Down Expand Up @@ -43,16 +41,15 @@ abstract class AbstractHelper
* Instantiate a XoopsModule object for the helper to use.
* This occurs in one of three ways
* - if null is passed, use the current module
* - if a string is passed, use as dirname for a module
* - if an object is passed, use it as the module object
* - if a string is passed, use as dirname to load
*
* @param mixed $module string dirname | object XoopsModule
* @param string|null $dirname dirname
*/
public function __construct($module = null)
public function __construct($dirname = null)
{
$this->module = null;

if (empty($module)) {
if (empty($dirname)) {
// nothing specified, use current module
// check if we are running in 2.6
if (class_exists('Xoops', false)) {
Expand All @@ -63,17 +60,10 @@ public function __construct($module = null)
} else {
$this->module = $GLOBALS['xoopsModule'];
}
} elseif (is_scalar($module)) {
// dirname specified, get a module object
$helper = Helper::getHelper($module);
if ($helper) {
$this->module = $helper->getModule();
}
} else {
// assume a passed object is appropriate
if (is_object($module)) {
$this->module = $module;
}
// assume dirname specified, try to get a module object
$moduleHandler = xoops_getHandler('module');
$this->module = $moduleHandler->getByDirname($dirname);
}
if (is_object($this->module)) {
$this->init();
Expand Down
4 changes: 1 addition & 3 deletions src/Xmf/Module/Cache.php → src/Xmf/Module/Helper/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

namespace Xmf\Module;

use Xmf\Module\Helper\AbstractHelper;
namespace Xmf\Module\Helper;

/**
* Manage cache interaction in a module. Cache key will be prefixed
Expand Down
24 changes: 2 additions & 22 deletions src/Xmf/Module/Helper/GenericHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,6 @@ protected function __construct($dirname)
$this->dirname = $dirname;
}

/**
* Return instance of module Xmf\Module\GenericHelper for dirname
*
* @param string $dirname module directory name
*
* @return GenericHelper
*/
public static function getInstance($dirname)
{
static $instance = array();
if (!isset($instance[$dirname])) {
$instance[$dirname] = new static($dirname);
}

return $instance[$dirname];

}

/**
* get the module object
*
Expand All @@ -110,12 +92,12 @@ public function getModule()
* @return mixed string config item, array of config items,
* or null if config not found
*/
public function getConfig($name)
public function getConfig($name = null)
{
if ($this->configs == null) {
$this->initConfig();
}
if (!$name) {
if (empty($name)) {
$this->addLog("Getting all config");

return $this->configs;
Expand Down Expand Up @@ -279,8 +261,6 @@ public function addLog($log)
}
}

// these added to mimic 2.6 Xoops\Module\Helper\HelperAbstract

/**
* Is this the currently active module?
*
Expand Down
Loading

0 comments on commit 18b931d

Please sign in to comment.