Skip to content
Permalink
Browse files

Various Optimizations, thanks jrbasso. Closes #232

  • Loading branch information...
lorenzo committed Jan 24, 2010
1 parent ad496ce commit c2d19c2011d39867a34c3ffc45bd8090f36288fd
Showing with 44 additions and 33 deletions.
  1. +28 −14 cake/libs/configure.php
  2. +15 −18 cake/libs/folder.php
  3. +1 −1 cake/libs/model/connection_manager.php
@@ -696,12 +696,12 @@ function build($paths = array(), $reset = false) {
$_this->{$type} = $default;
if (!empty($paths[$type])) {
$path = array_flip(array_flip((array_merge(
$path = array_flip(array_flip(array_merge(
$_this->{$type}, (array)$paths[$type], $merge
))));
)));
$_this->{$type} = array_values($path);
} else {
$path = array_flip(array_flip((array_merge($_this->{$type}, $merge))));
$path = array_flip(array_flip(array_merge($_this->{$type}, $merge)));
$_this->{$type} = array_values($path);
}
}
@@ -734,13 +734,16 @@ function pluginPath($plugin) {
* @access public
*/
function core($type = null) {
$paths = Cache::read('core_paths', '_cake_core_');
static $paths = false;
if ($paths === false) {
$paths = Cache::read('core_paths', '_cake_core_');
}
if (!$paths) {
$paths = array();
$openBasedir = ini_get('open_basedir');
if ($openBasedir) {
$all = explode(PATH_SEPARATOR, $openBasedir);
$all = array_flip(array_flip((array_merge(array(CAKE_CORE_INCLUDE_PATH), $all))));
$all = array_flip(array_flip(array_merge(array(CAKE_CORE_INCLUDE_PATH), $all)));
} else {
$all = explode(PATH_SEPARATOR, ini_get('include_path'));
$all = array_flip(array_flip((array_merge(array(CAKE_CORE_INCLUDE_PATH), $all))));
@@ -925,8 +928,7 @@ function import($type = null, $name = null, $parent = true, $search = array(), $
$_this->__overload($type, $name . $ext['class'], $parent);
if ($_this->return) {
$value = include $load;
return $value;
return include($load);
}
return true;
} else {
@@ -967,8 +969,7 @@ function import($type = null, $name = null, $parent = true, $search = array(), $
$_this->__overload($type, $name . $ext['class'], $parent);
if ($_this->return) {
$value = include $directory . $file;
return $value;
return include($directory . $file);
}
return true;
}
@@ -1001,6 +1002,9 @@ function &getInstance() {
* @access private
*/
function __find($file, $recursive = true) {
static $appPath = false;
static $libsPath = false;
if (empty($this->search)) {
return null;
} elseif (is_string($this->search)) {
@@ -1012,9 +1016,13 @@ function __find($file, $recursive = true) {
}
foreach ($this->search as $path) {
if ($appPath === false) {
$appPath = rtrim(APP, DS);
$libsPath = rtrim(LIBS, DS);
}
$path = rtrim($path, DS);
if ($path === rtrim(APP, DS)) {
if ($path === $appPath || $path === $libsPath) {
$recursive = false;
}
if ($recursive === false) {
@@ -1029,7 +1037,7 @@ function __find($file, $recursive = true) {
require LIBS . 'folder.php';
}
$Folder =& new Folder();
$directories = $Folder->tree($path, array('.svn', 'tests', 'templates'), 'dir');
$directories = $Folder->tree($path, array('.svn', '.git', 'CVS', 'tests', 'templates'), 'dir');
sort($directories);
$this->__paths[$path] = $directories;
}
@@ -1133,7 +1141,7 @@ function __overload($type, $name, $parent) {
*/
function __settings($type, $plugin, $parent) {
if (!$parent) {
return null;
return array('class' => null, 'suffix' => null, 'path' => null);
}
if ($plugin) {
@@ -1164,6 +1172,11 @@ function __settings($type, $plugin, $parent) {
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'datasource':
if ($plugin) {
$path = $pluginPath . DS . 'models' . DS . 'datasources' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
case 'controller':
App::import($type, 'AppController', false);
if ($plugin) {
@@ -1226,8 +1239,9 @@ function __paths($type) {
if ($type === 'core') {
return App::core('libs');
}
if ($paths = App::path($type .'s')) {
return $paths;
if (isset($this->{$type.'s'})) {
return $this->{$type.'s'};
}
return $paths;
}
@@ -254,10 +254,7 @@ function _findRecursive($pattern, $sort = false) {
* @static
*/
function isWindowsPath($path) {
if (preg_match('/^[A-Z]:\\\\/i', $path)) {
return true;
}
return false;
return (bool)preg_match('/^[A-Z]:\\\\/i', $path);
}
/**
@@ -269,8 +266,7 @@ function isWindowsPath($path) {
* @static
*/
function isAbsolute($path) {
$match = preg_match('/^\\//', $path) || preg_match('/^[A-Z]:\\\\/i', $path);
return $match;
return !empty($path) && ($path[0] === '/' || preg_match('/^[A-Z]:\\\\/i', $path));
}
/**
@@ -356,11 +352,7 @@ function inPath($path = '', $reverse = false) {
} else {
$return = preg_match('/^(.*)' . preg_quote($current, '/') . '(.*)/', $dir);
}
if ($return == 1) {
return true;
} else {
return false;
}
return (bool)$return;
}
/**
@@ -427,14 +419,20 @@ function chmod($path, $mode = false, $recursive = true, $exceptions = array()) {
function tree($path, $exceptions = true, $type = null) {
$original = $this->path;
$path = rtrim($path, DS);
if (!$this->cd($path)) {
if ($type === null) {
return array(array(), array());
}
return array();
}
$this->__files = array();
$this->__directories = array($path);
$this->__directories = array($this->realpath($path));
$directories = array();
if ($exceptions === false) {
$exceptions = true;
}
while (count($this->__directories)) {
while (!empty($this->__directories)) {
$dir = array_pop($this->__directories);
$this->__tree($dir, $exceptions);
$directories[] = $dir;
@@ -459,11 +457,10 @@ function tree($path, $exceptions = true, $type = null) {
* @access private
*/
function __tree($path, $exceptions) {
if ($this->cd($path)) {
list($dirs, $files) = $this->read(false, $exceptions, true);
$this->__directories = array_merge($this->__directories, $dirs);
$this->__files = array_merge($this->__files, $files);
}
$this->path = $path;
list($dirs, $files) = $this->read(false, $exceptions, true);
$this->__directories = array_merge($this->__directories, $dirs);
$this->__files = array_merge($this->__files, $files);
}
/**
@@ -181,7 +181,7 @@ function loadDataSource($connName) {
$conn = array_merge(array('plugin' => null, 'classname' => null, 'parent' => null), $conn);
$class = "{$conn['plugin']}.{$conn['classname']}";
if (!App::import('Datasource', $class, false)) {
if (!App::import('Datasource', $class, !is_null($conn['plugin']))) {
trigger_error(sprintf(__('ConnectionManager::loadDataSource - Unable to import DataSource class %s', true), $class), E_USER_ERROR);
return null;
}

0 comments on commit c2d19c2

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