Skip to content
Permalink
Browse files

Core need some love.

1. Core/Plugin.php: load(): Don't declare $pluginPath in loop.
2. Standardize the code block of pr() and pj()
3. Simple structures use ternary instead of if/else
  • Loading branch information...
FrankFFFF committed Mar 28, 2015
1 parent 01c2c72 commit 08aef486d90ed5514ed29f72e7f052ee7ed74a95
@@ -59,13 +59,8 @@ public static function className($class, $type = '', $suffix = '')
}
list($plugin, $name) = pluginSplit($class);
if ($plugin) {
$base = $plugin;
} else {
$base = Configure::read('App.namespace');
}
$base = $plugin ?: Configure::read('App.namespace');
$base = str_replace('/', '\\', rtrim($base, '\\'));
$fullname = '\\' . str_replace('/', '\\', $type . '\\' . $name) . $suffix;
if (static::_classExistsInBase($fullname, $base)) {
@@ -166,11 +166,10 @@ public static function delete($var)
*/
public static function consume($var)
{
$simple = strpos($var, '.') === false;
if ($simple && !isset(static::$_values[$var])) {
return null;
}
if ($simple) {
if (strpos($var, '.') === false) {
if (!isset(static::$_values[$var])) {
return null;
}
$value = static::$_values[$var];
unset(static::$_values[$var]);
return $value;
@@ -144,7 +144,6 @@ protected function _configRead($key)
}
$return = $return[$k];
}
return $return;
@@ -168,11 +167,7 @@ protected function _configWrite($key, $value, $merge = false)
}
if ($merge) {
if (is_array($key)) {
$update = $key;
} else {
$update = [$key => $value];
}
$update = is_array($key) ? $key : [$key => $value];
if ($merge === 'shallow') {
$this->_config = array_merge($this->_config, Hash::expand($update));
} else {
@@ -136,8 +136,8 @@ public static function load($plugin, array $config = [])
if (empty($config['path'])) {
$paths = App::path('Plugin');
$pluginPath = str_replace('/', DS, $plugin);
foreach ($paths as $path) {
$pluginPath = str_replace('/', DS, $plugin);
if (is_dir($path . $pluginPath)) {
$config['path'] = $path . $pluginPath . DS;
break;
@@ -72,15 +72,18 @@ trait StaticConfigTrait
*/
public static function config($key, $config = null)
{
// Read config.
if ($config === null && is_string($key)) {
return isset(static::$_config[$key]) ? static::$_config[$key] : null;
}
if ($config === null && is_array($key)) {
foreach ($key as $name => $settings) {
static::config($name, $settings);
if ($config === null) {
// Read config.
if (is_string($key)) {
return isset(static::$_config[$key]) ? static::$_config[$key] : null;
}
if (is_array($key)) {
foreach ($key as $name => $settings) {
static::config($name, $settings);
}
return;
}
return;
}
if (isset(static::$_config[$key])) {
@@ -131,10 +131,12 @@ function namespaceSplit($class)
*/
function pr($var)
{
if (Configure::read('debug')) {
$template = PHP_SAPI !== 'cli' ? '<pre class="pr">%s</pre>' : "\n%s\n\n";
printf($template, trim(print_r($var, true)));
if (!Configure::read('debug')) {
return;
}
$template = PHP_SAPI !== 'cli' ? '<pre class="pr">%s</pre>' : "\n%s\n\n";
printf($template, trim(print_r($var, true)));
}
}
@@ -156,11 +158,9 @@ function pj($var)
if (!Configure::read('debug')) {
return;
}
if (PHP_SAPI === 'cli') {
printf("\n%s\n\n", trim(json_encode($var, JSON_PRETTY_PRINT)));
} elseif (Configure::read('debug')) {
printf('<pre class="pj">%s</pre>', trim(json_encode($var, JSON_PRETTY_PRINT)));
}
$template = PHP_SAPI !== 'cli' ? '<pre class="pj">%s</pre>' : "\n%s\n\n";
printf($template, trim(json_encode($var, JSON_PRETTY_PRINT)));
}
}

0 comments on commit 08aef48

Please sign in to comment.
You can’t perform that action at this time.