Permalink
Browse files

Merge branch '1.3' of github.com:cakephp/cakephp1x into 1.3

Conflicts:
	cake/libs/folder.php
  • Loading branch information...
1 parent 7459da2 commit 98749a5a2bd533e5c97ff5d885b9bd6c60da4e8a @markstory markstory committed Jan 25, 2010
@@ -90,6 +90,12 @@ function execute($project = null) {
$this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php'));
}
+ if ($this->securityCipherSeed($path) === true ) {
+ $this->out(__('Random seed created for \'Security.cipherSeed\'', true));
+ } else {
+ $this->err(sprintf(__('Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', true), CONFIGS . 'core.php'));
+ }
+
$corePath = $this->corePath($path);
if ($corePath === true ) {
$this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', true), CAKE_CORE_INCLUDE_PATH));
@@ -215,6 +221,30 @@ function securitySalt($path) {
return false;
}
+ /**
+ * Generates and writes 'Security.cipherSeed'
+ *
+ * @param string $path Project path
+ * @return boolean Success
+ * @access public
+ */
+ function securityCipherSeed($path) {
+ $File =& new File($path . 'config' . DS . 'core.php');
+ $contents = $File->read();
+ if (preg_match('/([\\t\\x20]*Configure::write\\(\\\'Security.cipherSeed\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
+ if (!class_exists('Security')) {
+ require LIBS . 'security.php';
+ }
+ $string = substr(bin2hex(Security::generateAuthKey()), 0, 30);
+ $result = str_replace($match[0], "\t" . 'Configure::write(\'Security.cipherSeed\', \''.$string.'\');', $contents);
+ if ($File->write($result)) {
+ return true;
+ }
+ return false;
+ }
+ return false;
+ }
+
/**
* Generates and writes CAKE_CORE_INCLUDE_PATH
*
@@ -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,8 @@ function &getInstance() {
* @access private
*/
function __find($file, $recursive = true) {
+ static $appPath = false;
+
if (empty($this->search)) {
return null;
} elseif (is_string($this->search)) {
@@ -1012,9 +1015,12 @@ function __find($file, $recursive = true) {
}
foreach ($this->search as $path) {
+ if ($appPath === false) {
+ $appPath = rtrim(APP, DS);
+ }
$path = rtrim($path, DS);
- if ($path === rtrim(APP, DS)) {
+ if ($path === $appPath) {
$recursive = false;
}
if ($recursive === false) {
@@ -1029,7 +1035,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 +1139,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 +1170,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 +1237,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;
}
View
@@ -270,7 +270,7 @@ function isWindowsPath($path) {
* @static
*/
function isAbsolute($path) {
- return (bool) (preg_match('/^\\//', $path) || preg_match('/^[A-Z]:\\\\/i', $path));
+ return !empty($path) && ($path[0] === '/' || preg_match('/^[A-Z]:\\\\/i', $path));
}
/**
@@ -423,14 +423,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 ($hidden === false) {
- $hidden = true;
+ if ($exceptions === false) {
+ $exceptions = true;
}
- while (count($this->__directories)) {
+ while (!empty($this->__directories)) {
$dir = array_pop($this->__directories);
$this->__tree($dir, $exceptions);
$directories[] = $dir;
@@ -451,15 +457,14 @@ function tree($path, $exceptions = true, $type = null) {
* Private method to list directories and files in each directory
*
* @param string $path The Path to read.
- * @param mixed $hidden Array of files to exclude from the read that will be performed.
+ * @param mixed $exceptions Array of files to exclude from the read that will be performed.
* @access private
*/
- function __tree($path, $hidden) {
- if ($this->cd($path)) {
- list($dirs, $files) = $this->read(false, $hidden, true);
- $this->__directories = array_merge($this->__directories, $dirs);
- $this->__files = array_merge($this->__files, $files);
- }
+ function __tree($path, $exceptions) {
+ $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;
}
@@ -173,6 +173,24 @@ function testSecuritySaltGeneration() {
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
}
+ /**
+ * test generation of Security.salt
+ *
+ * @return void
+ * @access public
+ */
+ function testSecurityCipherSeedGeneration() {
+ $this->_setupTestProject();
+
+ $path = $this->Task->path . 'bake_test_app' . DS;
+ $result = $this->Task->securityCipherSeed($path);
+ $this->assertTrue($result);
+
+ $file =& new File($path . 'config' . DS . 'core.php');
+ $contents = $file->read();
+ $this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
+ }
+
/**
* Test that index.php is generated correctly.
*

0 comments on commit 98749a5

Please sign in to comment.