Browse Source

Merge pull request #6190 from Fieah/someLove

Core need some love.
Mark Story 11 years ago
parent
commit
b6ea2ca88c

+ 1 - 6
src/Core/App.php

@@ -59,13 +59,8 @@ class App
         }
 
         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)) {

+ 4 - 5
src/Core/Configure.php

@@ -166,11 +166,10 @@ class Configure
      */
     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;

+ 1 - 6
src/Core/InstanceConfigTrait.php

@@ -144,7 +144,6 @@ trait InstanceConfigTrait
             }
 
             $return = $return[$k];
-
         }
 
         return $return;
@@ -168,11 +167,7 @@ trait InstanceConfigTrait
         }
 
         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 {

+ 1 - 1
src/Core/Plugin.php

@@ -136,8 +136,8 @@ class Plugin
 
         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;

+ 11 - 8
src/Core/StaticConfigTrait.php

@@ -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])) {

+ 8 - 8
src/Core/functions.php

@@ -131,10 +131,12 @@ if (!function_exists('pr')) {
      */
     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 @@ if (!function_exists('pj')) {
         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)));
     }
 
 }