mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch '1.3' of github.com:cakephp/cakephp1x into 1.3
Conflicts: cake/libs/folder.php
This commit is contained in:
parent
7459da2aff
commit
98749a5a2b
5 changed files with 92 additions and 27 deletions
|
@ -90,6 +90,12 @@ class ProjectTask extends Shell {
|
||||||
$this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php'));
|
$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);
|
$corePath = $this->corePath($path);
|
||||||
if ($corePath === true ) {
|
if ($corePath === true ) {
|
||||||
$this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', true), CAKE_CORE_INCLUDE_PATH));
|
$this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', true), CAKE_CORE_INCLUDE_PATH));
|
||||||
|
@ -215,6 +221,30 @@ class ProjectTask extends Shell {
|
||||||
return false;
|
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
|
* Generates and writes CAKE_CORE_INCLUDE_PATH
|
||||||
*
|
*
|
||||||
|
|
|
@ -696,12 +696,12 @@ class App extends Object {
|
||||||
$_this->{$type} = $default;
|
$_this->{$type} = $default;
|
||||||
|
|
||||||
if (!empty($paths[$type])) {
|
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)$paths[$type], $merge
|
||||||
))));
|
)));
|
||||||
$_this->{$type} = array_values($path);
|
$_this->{$type} = array_values($path);
|
||||||
} else {
|
} 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);
|
$_this->{$type} = array_values($path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -734,13 +734,16 @@ class App extends Object {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function core($type = null) {
|
function core($type = null) {
|
||||||
|
static $paths = false;
|
||||||
|
if ($paths === false) {
|
||||||
$paths = Cache::read('core_paths', '_cake_core_');
|
$paths = Cache::read('core_paths', '_cake_core_');
|
||||||
|
}
|
||||||
if (!$paths) {
|
if (!$paths) {
|
||||||
$paths = array();
|
$paths = array();
|
||||||
$openBasedir = ini_get('open_basedir');
|
$openBasedir = ini_get('open_basedir');
|
||||||
if ($openBasedir) {
|
if ($openBasedir) {
|
||||||
$all = explode(PATH_SEPARATOR, $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 {
|
} else {
|
||||||
$all = explode(PATH_SEPARATOR, ini_get('include_path'));
|
$all = explode(PATH_SEPARATOR, ini_get('include_path'));
|
||||||
$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))));
|
||||||
|
@ -925,8 +928,7 @@ class App extends Object {
|
||||||
$_this->__overload($type, $name . $ext['class'], $parent);
|
$_this->__overload($type, $name . $ext['class'], $parent);
|
||||||
|
|
||||||
if ($_this->return) {
|
if ($_this->return) {
|
||||||
$value = include $load;
|
return include($load);
|
||||||
return $value;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -967,8 +969,7 @@ class App extends Object {
|
||||||
$_this->__overload($type, $name . $ext['class'], $parent);
|
$_this->__overload($type, $name . $ext['class'], $parent);
|
||||||
|
|
||||||
if ($_this->return) {
|
if ($_this->return) {
|
||||||
$value = include $directory . $file;
|
return include($directory . $file);
|
||||||
return $value;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1001,6 +1002,8 @@ class App extends Object {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __find($file, $recursive = true) {
|
function __find($file, $recursive = true) {
|
||||||
|
static $appPath = false;
|
||||||
|
|
||||||
if (empty($this->search)) {
|
if (empty($this->search)) {
|
||||||
return null;
|
return null;
|
||||||
} elseif (is_string($this->search)) {
|
} elseif (is_string($this->search)) {
|
||||||
|
@ -1012,9 +1015,12 @@ class App extends Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->search as $path) {
|
foreach ($this->search as $path) {
|
||||||
|
if ($appPath === false) {
|
||||||
|
$appPath = rtrim(APP, DS);
|
||||||
|
}
|
||||||
$path = rtrim($path, DS);
|
$path = rtrim($path, DS);
|
||||||
|
|
||||||
if ($path === rtrim(APP, DS)) {
|
if ($path === $appPath) {
|
||||||
$recursive = false;
|
$recursive = false;
|
||||||
}
|
}
|
||||||
if ($recursive === false) {
|
if ($recursive === false) {
|
||||||
|
@ -1029,7 +1035,7 @@ class App extends Object {
|
||||||
require LIBS . 'folder.php';
|
require LIBS . 'folder.php';
|
||||||
}
|
}
|
||||||
$Folder =& new Folder();
|
$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);
|
sort($directories);
|
||||||
$this->__paths[$path] = $directories;
|
$this->__paths[$path] = $directories;
|
||||||
}
|
}
|
||||||
|
@ -1133,7 +1139,7 @@ class App extends Object {
|
||||||
*/
|
*/
|
||||||
function __settings($type, $plugin, $parent) {
|
function __settings($type, $plugin, $parent) {
|
||||||
if (!$parent) {
|
if (!$parent) {
|
||||||
return null;
|
return array('class' => null, 'suffix' => null, 'path' => null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
|
@ -1164,6 +1170,11 @@ class App extends Object {
|
||||||
}
|
}
|
||||||
return array('class' => $type, 'suffix' => null, 'path' => $path);
|
return array('class' => $type, 'suffix' => null, 'path' => $path);
|
||||||
break;
|
break;
|
||||||
|
case 'datasource':
|
||||||
|
if ($plugin) {
|
||||||
|
$path = $pluginPath . DS . 'models' . DS . 'datasources' . DS;
|
||||||
|
}
|
||||||
|
return array('class' => $type, 'suffix' => null, 'path' => $path);
|
||||||
case 'controller':
|
case 'controller':
|
||||||
App::import($type, 'AppController', false);
|
App::import($type, 'AppController', false);
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
|
@ -1226,8 +1237,9 @@ class App extends Object {
|
||||||
if ($type === 'core') {
|
if ($type === 'core') {
|
||||||
return App::core('libs');
|
return App::core('libs');
|
||||||
}
|
}
|
||||||
if ($paths = App::path($type .'s')) {
|
|
||||||
return $paths;
|
if (isset($this->{$type.'s'})) {
|
||||||
|
return $this->{$type.'s'};
|
||||||
}
|
}
|
||||||
return $paths;
|
return $paths;
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,7 +270,7 @@ class Folder extends Object {
|
||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function isAbsolute($path) {
|
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 @@ class Folder extends Object {
|
||||||
function tree($path, $exceptions = true, $type = null) {
|
function tree($path, $exceptions = true, $type = null) {
|
||||||
$original = $this->path;
|
$original = $this->path;
|
||||||
$path = rtrim($path, DS);
|
$path = rtrim($path, DS);
|
||||||
|
if (!$this->cd($path)) {
|
||||||
|
if ($type === null) {
|
||||||
|
return array(array(), array());
|
||||||
|
}
|
||||||
|
return array();
|
||||||
|
}
|
||||||
$this->__files = array();
|
$this->__files = array();
|
||||||
$this->__directories = array($path);
|
$this->__directories = array($this->realpath($path));
|
||||||
$directories = array();
|
$directories = array();
|
||||||
|
|
||||||
if ($hidden === false) {
|
if ($exceptions === false) {
|
||||||
$hidden = true;
|
$exceptions = true;
|
||||||
}
|
}
|
||||||
while (count($this->__directories)) {
|
while (!empty($this->__directories)) {
|
||||||
$dir = array_pop($this->__directories);
|
$dir = array_pop($this->__directories);
|
||||||
$this->__tree($dir, $exceptions);
|
$this->__tree($dir, $exceptions);
|
||||||
$directories[] = $dir;
|
$directories[] = $dir;
|
||||||
|
@ -451,16 +457,15 @@ class Folder extends Object {
|
||||||
* Private method to list directories and files in each directory
|
* Private method to list directories and files in each directory
|
||||||
*
|
*
|
||||||
* @param string $path The Path to read.
|
* @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
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __tree($path, $hidden) {
|
function __tree($path, $exceptions) {
|
||||||
if ($this->cd($path)) {
|
$this->path = $path;
|
||||||
list($dirs, $files) = $this->read(false, $hidden, true);
|
list($dirs, $files) = $this->read(false, $exceptions, true);
|
||||||
$this->__directories = array_merge($this->__directories, $dirs);
|
$this->__directories = array_merge($this->__directories, $dirs);
|
||||||
$this->__files = array_merge($this->__files, $files);
|
$this->__files = array_merge($this->__files, $files);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a directory structure recursively. Can be used to create
|
* Create a directory structure recursively. Can be used to create
|
||||||
|
|
|
@ -181,7 +181,7 @@ class ConnectionManager extends Object {
|
||||||
$conn = array_merge(array('plugin' => null, 'classname' => null, 'parent' => null), $conn);
|
$conn = array_merge(array('plugin' => null, 'classname' => null, 'parent' => null), $conn);
|
||||||
$class = "{$conn['plugin']}.{$conn['classname']}";
|
$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);
|
trigger_error(sprintf(__('ConnectionManager::loadDataSource - Unable to import DataSource class %s', true), $class), E_USER_ERROR);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,6 +173,24 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
|
$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.
|
* Test that index.php is generated correctly.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue