Merge branch 'dispatcher-request' into 2.0

Conflicts:
	cake/libs/configure.php
	cake/tests/cases/libs/all_routing.test.php
	cake/tests/cases/libs/controller/controller.test.php
This commit is contained in:
mark_story 2010-11-15 22:42:54 -05:00
commit 66e6ec763e
18 changed files with 1601 additions and 1621 deletions

View file

@ -65,21 +65,16 @@
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
return;
} else {
require CAKE . 'dispatcher.php';
require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch();
$Dispatcher->dispatch(new CakeRequest(isset($_GET['url']) ? $_GET['url'] : null));
}

View file

@ -65,13 +65,8 @@ if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);

View file

@ -29,6 +29,7 @@ require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
require LIBS . 'exceptions.php';
require LIBS . 'object.php';
require LIBS . 'inflector.php';
require LIBS . 'app.php';
require LIBS . 'configure.php';
require LIBS . 'set.php';
require LIBS . 'cache.php';

View file

@ -65,21 +65,16 @@
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);
}
if (isset($_GET['url']) && $_GET['url'] === 'favicon.ico') {
return;
} else {
require CAKE . 'dispatcher.php';
require LIBS . 'dispatcher.php';
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch();
$Dispatcher->dispatch(new CakeRequest(isset($_GET['url']) ? $_GET['url'] : null));
}

View file

@ -65,13 +65,8 @@ if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS);
}
if (!defined('CORE_PATH')) {
if (function_exists('ini_set') && ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path'))) {
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
}
if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);

901
cake/libs/app.php Normal file
View file

@ -0,0 +1,901 @@
<?php
/**
* App class
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP(tm) v 1.2.0.6001
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* App is responsible for path managment, class location and class loading.
*
* ### Adding paths
*
* You can add paths to the search indexes App uses to find classes using `App::build()`. Adding
* additional controller paths for example would alter where CakePHP looks for controllers when you
* call App::import('Controller', 'Posts'); This allows you to split your application up across the filesystem.
*
* ### Inspecting loaded paths
*
* You can inspect the currently loaded paths using `App::path('controller')` for example to see loaded
* controller paths.
*
* ### Locating plugins and themes
*
* Plugins and Themes can be located with App as well. Using App::pluginPath('DebugKit') for example, will
* give you the full path to the DebugKit plugin. App::themePath('purple'), would give the full path to the
* `purple` theme.
*
* ### Inspecting known objects
*
* You can find out which objects App knows about using App::objects('controller') for example to find
* which application controllers App knows about.
*
* @link http://book.cakephp.org/view/933/The-App-Class
* @package cake
* @subpackage cake.cake.libs
*/
class App {
/**
* List of object types and their properties
*
* @var array
*/
public static $types = array(
'class' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'file' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'model' => array('suffix' => '.php', 'extends' => 'AppModel', 'core' => false),
'behavior' => array('suffix' => '.php', 'extends' => 'ModelBehavior', 'core' => true),
'controller' => array('suffix' => '_controller.php', 'extends' => 'AppController', 'core' => true),
'component' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'lib' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'view' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'helper' => array('suffix' => '.php', 'extends' => 'AppHelper', 'core' => true),
'vendor' => array('suffix' => '', 'extends' => null, 'core' => true),
'shell' => array('suffix' => '.php', 'extends' => 'Shell', 'core' => true),
'plugin' => array('suffix' => '', 'extends' => null, 'core' => true)
);
/**
* List of additional path(s) where model files reside.
*
* @var array
*/
public static $models = array();
/**
* List of additional path(s) where behavior files reside.
*
* @var array
*/
public static $behaviors = array();
/**
* List of additional path(s) where controller files reside.
*
* @var array
*/
public static $controllers = array();
/**
* List of additional path(s) where component files reside.
*
* @var array
*/
public static $components = array();
/**
* List of additional path(s) where datasource files reside.
*
* @var array
*/
public static $datasources = array();
/**
* List of additional path(s) where libs files reside.
*
* @var array
*/
public static $libs = array();
/**
* List of additional path(s) where view files reside.
*
* @var array
*/
public static $views = array();
/**
* List of additional path(s) where helper files reside.
*
* @var array
*/
public static $helpers = array();
/**
* List of additional path(s) where plugins reside.
*
* @var array
*/
public static $plugins = array();
/**
* List of additional path(s) where vendor packages reside.
*
* @var array
*/
public static $vendors = array();
/**
* List of additional path(s) where locale files reside.
*
* @var array
*/
public static $locales = array();
/**
* List of additional path(s) where console shell files reside.
*
* @var array
*/
public static $shells = array();
/**
* Paths to search for files.
*
* @var array
*/
public static $search = array();
/**
* Whether or not to return the file that is loaded.
*
* @var boolean
*/
public static $return = false;
/**
* Determines if $__maps and $__paths cache should be written.
*
* @var boolean
*/
private static $__cache = false;
/**
* Holds key/value pairs of $type => file path.
*
* @var array
*/
private static $__map = array();
/**
* Holds paths for deep searching of files.
*
* @var array
*/
private static $__paths = array();
/**
* Holds loaded files.
*
* @var array
*/
private static $__loaded = array();
/**
* Holds and key => value array of object types.
*
* @var array
*/
private static $__objects = array();
/**
* Used to read information stored path
*
* Usage:
*
* `App::path('models'); will return all paths for models`
*
* @param string $type type of path
* @return string array
*/
public static function path($type) {
if (!isset(self::${$type})) {
return array();
}
return self::${$type};
}
/**
* Build path references. Merges the supplied $paths
* with the base paths and the default core paths.
*
* @param array $paths paths defines in config/bootstrap.php
* @param boolean $reset true will set paths, false merges paths [default] false
* @return void
*/
public static function build($paths = array(), $reset = false) {
$defaults = array(
'models' => array(MODELS),
'behaviors' => array(BEHAVIORS),
'datasources' => array(MODELS . 'datasources'),
'controllers' => array(CONTROLLERS),
'components' => array(COMPONENTS),
'libs' => array(APPLIBS),
'views' => array(VIEWS),
'helpers' => array(HELPERS),
'locales' => array(APP . 'locale' . DS),
'shells' => array(
APP . 'console' . DS . 'shells' . DS,
APP . 'vendors' . DS . 'shells' . DS,
VENDORS . 'shells' . DS
),
'vendors' => array(APP . 'vendors' . DS, VENDORS),
'plugins' => array(APP . 'plugins' . DS)
);
if ($reset == true) {
foreach ($paths as $type => $new) {
self::${$type} = (array)$new;
}
return $paths;
}
$core = self::core();
$app = array('models' => true, 'controllers' => true, 'helpers' => true);
foreach ($defaults as $type => $default) {
$merge = array();
if (isset($app[$type])) {
$merge = array(APP);
}
if (isset($core[$type])) {
$merge = array_merge($merge, (array)$core[$type]);
}
if (empty(self::${$type}) || empty($paths)) {
self::${$type} = $default;
}
if (!empty($paths[$type])) {
$path = array_flip(array_flip(array_merge(
(array)$paths[$type], self::${$type}, $merge
)));
self::${$type} = array_values($path);
} else {
$path = array_flip(array_flip(array_merge(self::${$type}, $merge)));
self::${$type} = array_values($path);
}
}
}
/**
* Get the path that a plugin is on. Searches through the defined plugin paths.
*
* @param string $plugin CamelCased/lower_cased plugin name to find the path of.
* @return string full path to the plugin.
*/
public static function pluginPath($plugin) {
$pluginDir = Inflector::underscore($plugin);
for ($i = 0, $length = count(self::$plugins); $i < $length; $i++) {
if (is_dir(self::$plugins[$i] . $pluginDir)) {
return self::$plugins[$i] . $pluginDir . DS ;
}
}
return self::$plugins[0] . $pluginDir . DS;
}
/**
* Find the path that a theme is on. Search through the defined theme paths.
*
* @param string $theme lower_cased theme name to find the path of.
* @return string full path to the theme.
*/
public static function themePath($theme) {
$themeDir = 'themed' . DS . Inflector::underscore($theme);
for ($i = 0, $length = count(self::$views); $i < $length; $i++) {
if (is_dir(self::$views[$i] . $themeDir)) {
return self::$views[$i] . $themeDir . DS ;
}
}
return self::$views[0] . $themeDir . DS;
}
/**
* Returns a key/value list of all paths where core libs are found.
* Passing $type only returns the values for a given value of $key.
*
* @param string $type valid values are: 'model', 'behavior', 'controller', 'component',
* 'view', 'helper', 'datasource', 'libs', and 'cake'
* @return array numeric keyed array of core lib paths
*/
public static function core($type = null) {
static $paths = false;
if ($paths === false) {
$paths = Cache::read('core_paths', '_cake_core_');
}
if (!$paths) {
$paths = array();
$libs = dirname(__FILE__) . DS;
$cake = dirname($libs) . DS;
$path = dirname($cake) . DS;
$paths['cake'][] = $cake;
$paths['libs'][] = $libs;
$paths['models'][] = $libs . 'model' . DS;
$paths['datasources'][] = $libs . 'model' . DS . 'datasources' . DS;
$paths['behaviors'][] = $libs . 'model' . DS . 'behaviors' . DS;
$paths['controllers'][] = $libs . 'controller' . DS;
$paths['components'][] = $libs . 'controller' . DS . 'components' . DS;
$paths['views'][] = $libs . 'view' . DS;
$paths['helpers'][] = $libs . 'view' . DS . 'helpers' . DS;
$paths['plugins'][] = $path . 'plugins' . DS;
$paths['vendors'][] = $path . 'vendors' . DS;
$paths['shells'][] = $cake . 'console' . DS . 'shells' . DS;
// Provide BC path to vendors/shells
$paths['shells'][] = $path . 'vendors' . DS . 'shells' . DS;
Cache::write('core_paths', array_filter($paths), '_cake_core_');
}
if ($type && isset($paths[$type])) {
return $paths[$type];
}
return $paths;
}
/**
* Returns an array of objects of the given type.
*
* Example usage:
*
* `App::objects('plugin');` returns `array('DebugKit', 'Blog', 'User');`
*
* @param string $type Type of object, i.e. 'model', 'controller', 'helper', or 'plugin'
* @param mixed $path Optional Scan only the path given. If null, paths for the chosen
* type will be used.
* @param boolean $cache Set to false to rescan objects of the chosen type. Defaults to true.
* @return mixed Either false on incorrect / miss. Or an array of found objects.
*/
public static function objects($type, $path = null, $cache = true) {
$objects = array();
$extension = false;
$name = $type;
if ($type === 'file' && !$path) {
return false;
} elseif ($type === 'file') {
$extension = true;
$name = $type . str_replace(DS, '', $path);
}
if (empty(self::$__objects) && $cache === true) {
self::$__objects = Cache::read('object_map', '_cake_core_');
}
if (!isset(self::$__objects[$name]) || $cache !== true) {
$types = self::$types;
if (!isset($types[$type])) {
return false;
}
$objects = array();
if (empty($path)) {
$path = self::${"{$type}s"};
if (isset($types[$type]['core']) && $types[$type]['core'] === false) {
array_pop($path);
}
}
$items = array();
foreach ((array)$path as $dir) {
if ($dir != APP) {
$items = self::__list($dir, $types[$type]['suffix'], $extension);
$objects = array_merge($items, array_diff($objects, $items));
}
}
if ($type !== 'file') {
foreach ($objects as $key => $value) {
$objects[$key] = Inflector::camelize($value);
}
}
if ($cache === true) {
self::$__cache = true;
}
self::$__objects[$name] = $objects;
}
return self::$__objects[$name];
}
/**
* Allows you to modify the object listings that App maintains inside of it
* Useful for testing
*
* @param string $type Type of object listing you are changing
* @param array $values The values $type should be set to.
* @return void
*/
public static function setObjects($type, $values) {
self::$__objects[$type] = $values;
}
/**
* Finds classes based on $name or specific file(s) to search. Calling App::import() will
* not construct any classes contained in the files. It will only find and require() the file.
*
* @link http://book.cakephp.org/view/934/Using-App-import
* @param mixed $type The type of Class if passed as a string, or all params can be passed as
* an single array to $type,
* @param string $name Name of the Class or a unique name for the file
* @param mixed $parent boolean true if Class Parent should be searched, accepts key => value
* array('parent' => $parent ,'file' => $file, 'search' => $search, 'ext' => '$ext');
* $ext allows setting the extension of the file name
* based on Inflector::underscore($name) . ".$ext";
* @param array $search paths to search for files, array('path 1', 'path 2', 'path 3');
* @param string $file full name of the file to search for including extension
* @param boolean $return, return the loaded file, the file must have a return
* statement in it to work: return $variable;
* @return boolean true if Class is already in memory or if file is found and loaded, false if not
*/
public static function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) {
$plugin = $directory = null;
if (is_array($type)) {
extract($type, EXTR_OVERWRITE);
}
if (is_array($parent)) {
extract($parent, EXTR_OVERWRITE);
}
if ($name === null && $file === null) {
$name = $type;
$type = 'Core';
} elseif ($name === null) {
$type = 'File';
}
if (is_array($name)) {
foreach ($name as $class) {
$tempType = $type;
$plugin = null;
if (strpos($class, '.') !== false) {
$value = explode('.', $class);
$count = count($value);
if ($count > 2) {
$tempType = $value[0];
$plugin = $value[1] . '.';
$class = $value[2];
} elseif ($count === 2 && ($type === 'Core' || $type === 'File')) {
$tempType = $value[0];
$class = $value[1];
} else {
$plugin = $value[0] . '.';
$class = $value[1];
}
}
if (!App::import($tempType, $plugin . $class, $parent)) {
return false;
}
}
return true;
}
if ($name != null && strpos($name, '.') !== false) {
list($plugin, $name) = explode('.', $name);
$plugin = Inflector::camelize($plugin);
}
self::$return = $return;
if (isset($ext)) {
$file = Inflector::underscore($name) . ".{$ext}";
}
$ext = self::__settings($type, $plugin, $parent);
if ($name != null && !class_exists($name . $ext['class'])) {
if ($load = self::__mapped($name . $ext['class'], $type, $plugin)) {
if (self::__load($load)) {
self::__overload($type, $name . $ext['class'], $parent);
if (self::$return) {
return include($load);
}
return true;
} else {
self::__remove($name . $ext['class'], $type, $plugin);
self::$__cache = true;
}
}
if (!empty($search)) {
self::$search = $search;
} elseif ($plugin) {
self::$search = self::__paths('plugin');
} else {
self::$search = self::__paths($type);
}
$find = $file;
if ($find === null) {
$find = Inflector::underscore($name . $ext['suffix']).'.php';
if ($plugin) {
$paths = self::$search;
foreach ($paths as $key => $value) {
self::$search[$key] = $value . $ext['path'];
}
}
}
if (strtolower($type) !== 'vendor' && empty($search) && self::__load($file)) {
$directory = false;
} else {
$file = $find;
$directory = self::__find($find, true);
}
if ($directory !== null) {
self::$__cache = true;
self::__map($directory . $file, $name . $ext['class'], $type, $plugin);
self::__overload($type, $name . $ext['class'], $parent);
if (self::$return) {
return include($directory . $file);
}
return true;
}
return false;
}
return true;
}
/**
* Initializes the cache for App, registers a shutdown function.
*
* @return void
*/
public static function init() {
self::$__map = (array)Cache::read('file_map', '_cake_core_');
register_shutdown_function(array('App', 'shutdown'));
}
/**
* Locates the $file in $__paths, searches recursively.
*
* @param string $file full file name
* @param boolean $recursive search $__paths recursively
* @return mixed boolean on fail, $file directory path on success
*/
private static function __find($file, $recursive = true) {
static $appPath = false;
if (empty(self::$search)) {
return null;
} elseif (is_string(self::$search)) {
$this->search = array(self::$search);
}
if (empty(self::$__paths)) {
self::$__paths = Cache::read('dir_map', '_cake_core_');
}
foreach (self::$search as $path) {
if ($appPath === false) {
$appPath = rtrim(APP, DS);
}
$path = rtrim($path, DS);
if ($path === $appPath) {
$recursive = false;
}
if ($recursive === false) {
if (self::__load($path . DS . $file)) {
return $path . DS;
}
continue;
}
if (!isset(self::$__paths[$path])) {
if (!class_exists('Folder')) {
require LIBS . 'folder.php';
}
$Folder = new Folder();
$directories = $Folder->tree($path, array('.svn', '.git', 'CVS', 'tests', 'templates'), 'dir');
sort($directories);
self::$__paths[$path] = $directories;
}
foreach (self::$__paths[$path] as $directory) {
if (self::__load($directory . DS . $file)) {
return $directory . DS;
}
}
}
return null;
}
/**
* Attempts to load $file.
*
* @param string $file full path to file including file name
* @return boolean
* @access private
*/
private static function __load($file) {
if (empty($file)) {
return false;
}
if (!self::$return && isset(self::$__loaded[$file])) {
return true;
}
if (file_exists($file)) {
if (!self::$return) {
require($file);
self::$__loaded[$file] = true;
}
return true;
}
return false;
}
/**
* Maps the $name to the $file.
*
* @param string $file full path to file
* @param string $name unique name for this map
* @param string $type type object being mapped
* @param string $plugin camelized if object is from a plugin, the name of the plugin
* @return void
* @access private
*/
private static function __map($file, $name, $type, $plugin) {
if ($plugin) {
self::$__map['Plugin'][$plugin][$type][$name] = $file;
} else {
self::$__map[$type][$name] = $file;
}
}
/**
* Returns a file's complete path.
*
* @param string $name unique name
* @param string $type type object
* @param string $plugin camelized if object is from a plugin, the name of the plugin
* @return mixed, file path if found, false otherwise
* @access private
*/
private static function __mapped($name, $type, $plugin) {
if ($plugin) {
if (isset(self::$__map['Plugin'][$plugin][$type]) && isset(self::$__map['Plugin'][$plugin][$type][$name])) {
return self::$__map['Plugin'][$plugin][$type][$name];
}
return false;
}
if (isset(self::$__map[$type]) && isset(self::$__map[$type][$name])) {
return self::$__map[$type][$name];
}
return false;
}
/**
* Used to overload objects as needed.
*
* @param string $type Model or Helper
* @param string $name Class name to overload
* @access private
*/
private static function __overload($type, $name, $parent) {
}
/**
* Loads parent classes based on $type.
* Returns a prefix or suffix needed for loading files.
*
* @param string $type type of object
* @param string $plugin camelized name of plugin
* @param boolean $parent false will not attempt to load parent
* @return array
* @access private
*/
private static function __settings($type, $plugin, $parent) {
if (!$parent) {
return array('class' => null, 'suffix' => null, 'path' => null);
}
if ($plugin) {
$pluginPath = Inflector::underscore($plugin);
}
$path = null;
$load = strtolower($type);
switch ($load) {
case 'model':
if (!class_exists('Model')) {
require LIBS . 'model' . DS . 'model.php';
}
if (!class_exists('AppModel')) {
App::import($type, 'AppModel', false);
}
if ($plugin) {
if (!class_exists($plugin . 'AppModel')) {
App::import($type, $plugin . '.' . $plugin . 'AppModel', false, array(), $pluginPath . DS . $pluginPath . '_app_model.php');
}
$path = $pluginPath . DS . 'models' . DS;
}
return array('class' => null, 'suffix' => null, 'path' => $path);
break;
case 'behavior':
if ($plugin) {
$path = $pluginPath . DS . 'models' . DS . 'behaviors' . DS;
}
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) {
App::import($type, $plugin . '.' . $plugin . 'AppController', false, array(), $pluginPath . DS . $pluginPath . '_app_controller.php');
$path = $pluginPath . DS . 'controllers' . DS;
}
return array('class' => $type, 'suffix' => $type, 'path' => $path);
break;
case 'component':
App::import('Core', 'Component', false);
if ($plugin) {
$path = $pluginPath . DS . 'controllers' . DS . 'components' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'lib':
if ($plugin) {
$path = $pluginPath . DS . 'libs' . DS;
}
return array('class' => null, 'suffix' => null, 'path' => $path);
break;
case 'view':
App::import('View', 'View', false);
if ($plugin) {
$path = $pluginPath . DS . 'views' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'helper':
if (!class_exists('AppHelper')) {
App::import($type, 'AppHelper', false);
}
if ($plugin) {
$path = $pluginPath . DS . 'views' . DS . 'helpers' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'shell':
if (!class_exists('Shell')) {
App::import($type, 'Shell', false);
}
if ($plugin) {
$path = $pluginPath . DS . 'console' . DS . 'shells' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'vendor':
if ($plugin) {
$path = $pluginPath . DS . 'vendors' . DS;
}
return array('class' => null, 'suffix' => null, 'path' => $path);
break;
default:
$type = $suffix = $path = null;
break;
}
return array('class' => null, 'suffix' => null, 'path' => null);
}
/**
* Returns default search paths.
*
* @param string $type type of object to be searched
* @return array list of paths
*/
private static function __paths($type) {
$type = strtolower($type);
$paths = array();
if ($type === 'core') {
return App::core('libs');
}
if (isset(self::${$type . 's'})) {
return self::${$type . 's'};
}
return $paths;
}
/**
* Removes file location from map if the file has been deleted.
*
* @param string $name name of object
* @param string $type type of object
* @param string $plugin camelized name of plugin
* @return void
*/
private static function __remove($name, $type, $plugin) {
if ($plugin) {
unset(self::$__map['Plugin'][$plugin][$type][$name]);
} else {
unset(self::$__map[$type][$name]);
}
}
/**
* Returns an array of filenames of PHP files in the given directory.
*
* @param string $path Path to scan for files
* @param string $suffix if false, return only directories. if string, match and return files
* @return array List of directories or files in directory
*/
private static function __list($path, $suffix = false, $extension = false) {
if (!class_exists('Folder')) {
require LIBS . 'folder.php';
}
$items = array();
$Folder = new Folder($path);
$contents = $Folder->read(false, true);
if (is_array($contents)) {
if (!$suffix) {
return $contents[0];
} else {
foreach ($contents[1] as $item) {
if (substr($item, - strlen($suffix)) === $suffix) {
if ($extension) {
$items[] = $item;
} else {
$items[] = substr($item, 0, strlen($item) - strlen($suffix));
}
}
}
}
}
return $items;
}
/**
* Object destructor.
*
* Writes cache file if changes have been made to the $__map or $__paths
*
* @return void
*/
public static function shutdown() {
if (self::$__cache) {
$core = App::core('cake');
unset(self::$__paths[rtrim($core[0], DS)]);
Cache::write('dir_map', array_filter(self::$__paths), '_cake_core_');
Cache::write('file_map', array_filter(self::$__map), '_cake_core_');
Cache::write('object_map', self::$__objects, '_cake_core_');
}
}
}

View file

@ -1,6 +1,6 @@
<?php
/**
* App and Configure classes
* Configure class
*
* PHP 5
*
@ -19,7 +19,11 @@
*/
/**
* Configuration class (singleton). Used for managing runtime configuration information.
* Configuration class. Used for managing runtime configuration information.
*
* Provides features for reading and writing to the runtime configuration, as well
* as methods for loading additional configuration files or storing runtime configuration
* for future use.
*
* @package cake
* @subpackage cake.cake.libs
@ -42,14 +46,11 @@ class Configure {
* @return void
*/
public static function bootstrap($boot = true) {
if (!class_exists('Set')) {
require LIBS . 'set.php';
}
self::__loadBootstrap($boot);
}
/**
* Used to store a dynamic variable in the Configure instance.
* Used to store a dynamic variable in Configure.
*
* Usage:
* {{{
@ -129,7 +130,7 @@ class Configure {
}
/**
* Used to read information stored in the Configure instance. Currently its not
* Used to read information stored in Configure. Its not
* possible to store `null` values in Configure.
*
* Usage:
@ -176,7 +177,7 @@ class Configure {
}
/**
* Used to delete a variable from the Configure instance.
* Used to delete a variable from Configure.
*
* Usage:
* {{{
@ -200,6 +201,7 @@ class Configure {
/**
* Loads a file from app/config/configure_file.php.
*
* Config file variables should be formated like:
* `$config['name'] = 'value';`
* These will be used to create dynamic Configure vars. load() is also used to
@ -387,851 +389,3 @@ class Configure {
}
}
}
/**
* Class/file loader and path management.
*
* @link http://book.cakephp.org/view/933/The-App-Class
* @since CakePHP(tm) v 1.2.0.6001
* @package cake
* @subpackage cake.cake.libs
*/
class App {
/**
* List of object types and their properties
*
* @var array
*/
public static $types = array(
'class' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'file' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'model' => array('suffix' => '.php', 'extends' => 'AppModel', 'core' => false),
'behavior' => array('suffix' => '.php', 'extends' => 'ModelBehavior', 'core' => true),
'controller' => array('suffix' => '_controller.php', 'extends' => 'AppController', 'core' => true),
'component' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'lib' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'view' => array('suffix' => '.php', 'extends' => null, 'core' => true),
'helper' => array('suffix' => '.php', 'extends' => 'AppHelper', 'core' => true),
'vendor' => array('suffix' => '', 'extends' => null, 'core' => true),
'shell' => array('suffix' => '.php', 'extends' => 'Shell', 'core' => true),
'plugin' => array('suffix' => '', 'extends' => null, 'core' => true)
);
/**
* List of additional path(s) where model files reside.
*
* @var array
*/
public static $models = array();
/**
* List of additional path(s) where behavior files reside.
*
* @var array
*/
public static $behaviors = array();
/**
* List of additional path(s) where controller files reside.
*
* @var array
*/
public static $controllers = array();
/**
* List of additional path(s) where component files reside.
*
* @var array
*/
public static $components = array();
/**
* List of additional path(s) where datasource files reside.
*
* @var array
*/
public static $datasources = array();
/**
* List of additional path(s) where libs files reside.
*
* @var array
*/
public static $libs = array();
/**
* List of additional path(s) where view files reside.
*
* @var array
*/
public static $views = array();
/**
* List of additional path(s) where helper files reside.
*
* @var array
*/
public static $helpers = array();
/**
* List of additional path(s) where plugins reside.
*
* @var array
*/
public static $plugins = array();
/**
* List of additional path(s) where vendor packages reside.
*
* @var array
*/
public static $vendors = array();
/**
* List of additional path(s) where locale files reside.
*
* @var array
*/
public static $locales = array();
/**
* List of additional path(s) where console shell files reside.
*
* @var array
*/
public static $shells = array();
/**
* Paths to search for files.
*
* @var array
*/
public static $search = array();
/**
* Whether or not to return the file that is loaded.
*
* @var boolean
*/
public static $return = false;
/**
* Determines if $__maps and $__paths cache should be written.
*
* @var boolean
*/
private static $__cache = false;
/**
* Holds key/value pairs of $type => file path.
*
* @var array
*/
private static $__map = array();
/**
* Holds paths for deep searching of files.
*
* @var array
*/
private static $__paths = array();
/**
* Holds loaded files.
*
* @var array
*/
private static $__loaded = array();
/**
* Holds and key => value array of object types.
*
* @var array
*/
private static $__objects = array();
/**
* Used to read information stored path
*
* Usage:
*
* `App::path('models'); will return all paths for models`
*
* @param string $type type of path
* @return string array
*/
public static function path($type) {
if (!isset(self::${$type})) {
return array();
}
return self::${$type};
}
/**
* Build path references. Merges the supplied $paths
* with the base paths and the default core paths.
*
* @param array $paths paths defines in config/bootstrap.php
* @param boolean $reset true will set paths, false merges paths [default] false
* @return void
*/
public static function build($paths = array(), $reset = false) {
$defaults = array(
'models' => array(MODELS),
'behaviors' => array(BEHAVIORS),
'datasources' => array(MODELS . 'datasources'),
'controllers' => array(CONTROLLERS),
'components' => array(COMPONENTS),
'libs' => array(APPLIBS),
'views' => array(VIEWS),
'helpers' => array(HELPERS),
'locales' => array(APP . 'locale' . DS),
'shells' => array(
APP . 'console' . DS . 'shells' . DS,
APP . 'vendors' . DS . 'shells' . DS,
VENDORS . 'shells' . DS
),
'vendors' => array(APP . 'vendors' . DS, VENDORS),
'plugins' => array(APP . 'plugins' . DS)
);
if ($reset == true) {
foreach ($paths as $type => $new) {
self::${$type} = (array)$new;
}
return $paths;
}
$core = self::core();
$app = array('models' => true, 'controllers' => true, 'helpers' => true);
foreach ($defaults as $type => $default) {
$merge = array();
if (isset($app[$type])) {
$merge = array(APP);
}
if (isset($core[$type])) {
$merge = array_merge($merge, (array)$core[$type]);
}
if (empty(self::${$type}) || empty($paths)) {
self::${$type} = $default;
}
if (!empty($paths[$type])) {
$path = array_flip(array_flip(array_merge(
(array)$paths[$type], self::${$type}, $merge
)));
self::${$type} = array_values($path);
} else {
$path = array_flip(array_flip(array_merge(self::${$type}, $merge)));
self::${$type} = array_values($path);
}
}
}
/**
* Get the path that a plugin is on. Searches through the defined plugin paths.
*
* @param string $plugin CamelCased/lower_cased plugin name to find the path of.
* @return string full path to the plugin.
*/
public static function pluginPath($plugin) {
$pluginDir = Inflector::underscore($plugin);
for ($i = 0, $length = count(self::$plugins); $i < $length; $i++) {
if (is_dir(self::$plugins[$i] . $pluginDir)) {
return self::$plugins[$i] . $pluginDir . DS ;
}
}
return self::$plugins[0] . $pluginDir . DS;
}
/**
* Find the path that a theme is on. Search through the defined theme paths.
*
* @param string $theme lower_cased theme name to find the path of.
* @return string full path to the theme.
*/
public static function themePath($theme) {
$themeDir = 'themed' . DS . Inflector::underscore($theme);
for ($i = 0, $length = count(self::$views); $i < $length; $i++) {
if (is_dir(self::$views[$i] . $themeDir)) {
return self::$views[$i] . $themeDir . DS ;
}
}
return self::$views[0] . $themeDir . DS;
}
/**
* Returns a key/value list of all paths where core libs are found.
* Passing $type only returns the values for a given value of $key.
*
* @param string $type valid values are: 'model', 'behavior', 'controller', 'component',
* 'view', 'helper', 'datasource', 'libs', and 'cake'
* @return array numeric keyed array of core lib paths
*/
public static function core($type = null) {
static $paths = false;
if ($paths === false) {
$paths = Cache::read('core_paths', '_cake_core_');
}
if (!$paths) {
$paths = array();
$libs = dirname(__FILE__) . DS;
$cake = dirname($libs) . DS;
$path = dirname($cake) . DS;
$paths['cake'][] = $cake;
$paths['libs'][] = $libs;
$paths['models'][] = $libs . 'model' . DS;
$paths['datasources'][] = $libs . 'model' . DS . 'datasources' . DS;
$paths['behaviors'][] = $libs . 'model' . DS . 'behaviors' . DS;
$paths['controllers'][] = $libs . 'controller' . DS;
$paths['components'][] = $libs . 'controller' . DS . 'components' . DS;
$paths['views'][] = $libs . 'view' . DS;
$paths['helpers'][] = $libs . 'view' . DS . 'helpers' . DS;
$paths['plugins'][] = $path . 'plugins' . DS;
$paths['vendors'][] = $path . 'vendors' . DS;
$paths['shells'][] = $cake . 'console' . DS . 'shells' . DS;
// Provide BC path to vendors/shells
$paths['shells'][] = $path . 'vendors' . DS . 'shells' . DS;
Cache::write('core_paths', array_filter($paths), '_cake_core_');
}
if ($type && isset($paths[$type])) {
return $paths[$type];
}
return $paths;
}
/**
* Returns an array of objects of the given type.
*
* Example usage:
*
* `App::objects('plugin');` returns `array('DebugKit', 'Blog', 'User');`
*
* @param string $type Type of object, i.e. 'model', 'controller', 'helper', or 'plugin'
* @param mixed $path Optional Scan only the path given. If null, paths for the chosen
* type will be used.
* @param boolean $cache Set to false to rescan objects of the chosen type. Defaults to true.
* @return mixed Either false on incorrect / miss. Or an array of found objects.
*/
public static function objects($type, $path = null, $cache = true) {
$objects = array();
$extension = false;
$name = $type;
if ($type === 'file' && !$path) {
return false;
} elseif ($type === 'file') {
$extension = true;
$name = $type . str_replace(DS, '', $path);
}
if (empty(self::$__objects) && $cache === true) {
self::$__objects = Cache::read('object_map', '_cake_core_');
}
if (!isset(self::$__objects[$name]) || $cache !== true) {
$types = self::$types;
if (!isset($types[$type])) {
return false;
}
$objects = array();
if (empty($path)) {
$path = self::${"{$type}s"};
if (isset($types[$type]['core']) && $types[$type]['core'] === false) {
array_pop($path);
}
}
$items = array();
foreach ((array)$path as $dir) {
if ($dir != APP) {
$items = self::__list($dir, $types[$type]['suffix'], $extension);
$objects = array_merge($items, array_diff($objects, $items));
}
}
if ($type !== 'file') {
foreach ($objects as $key => $value) {
$objects[$key] = Inflector::camelize($value);
}
}
if ($cache === true) {
self::$__cache = true;
}
self::$__objects[$name] = $objects;
}
return self::$__objects[$name];
}
/**
* Allows you to modify the object listings that App maintains inside of it
* Useful for testing
*
* @param string $type Type of object listing you are changing
* @param array $values The values $type should be set to.
* @return void
*/
public static function setObjects($type, $values) {
self::$__objects[$type] = $values;
}
/**
* Finds classes based on $name or specific file(s) to search. Calling App::import() will
* not construct any classes contained in the files. It will only find and require() the file.
*
* @link http://book.cakephp.org/view/934/Using-App-import
* @param mixed $type The type of Class if passed as a string, or all params can be passed as
* an single array to $type,
* @param string $name Name of the Class or a unique name for the file
* @param mixed $parent boolean true if Class Parent should be searched, accepts key => value
* array('parent' => $parent ,'file' => $file, 'search' => $search, 'ext' => '$ext');
* $ext allows setting the extension of the file name
* based on Inflector::underscore($name) . ".$ext";
* @param array $search paths to search for files, array('path 1', 'path 2', 'path 3');
* @param string $file full name of the file to search for including extension
* @param boolean $return, return the loaded file, the file must have a return
* statement in it to work: return $variable;
* @return boolean true if Class is already in memory or if file is found and loaded, false if not
*/
public static function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) {
$plugin = $directory = null;
if (is_array($type)) {
extract($type, EXTR_OVERWRITE);
}
if (is_array($parent)) {
extract($parent, EXTR_OVERWRITE);
}
if ($name === null && $file === null) {
$name = $type;
$type = 'Core';
} elseif ($name === null) {
$type = 'File';
}
if (is_array($name)) {
foreach ($name as $class) {
$tempType = $type;
$plugin = null;
if (strpos($class, '.') !== false) {
$value = explode('.', $class);
$count = count($value);
if ($count > 2) {
$tempType = $value[0];
$plugin = $value[1] . '.';
$class = $value[2];
} elseif ($count === 2 && ($type === 'Core' || $type === 'File')) {
$tempType = $value[0];
$class = $value[1];
} else {
$plugin = $value[0] . '.';
$class = $value[1];
}
}
if (!App::import($tempType, $plugin . $class, $parent)) {
return false;
}
}
return true;
}
if ($name != null && strpos($name, '.') !== false) {
list($plugin, $name) = explode('.', $name);
$plugin = Inflector::camelize($plugin);
}
self::$return = $return;
if (isset($ext)) {
$file = Inflector::underscore($name) . ".{$ext}";
}
$ext = self::__settings($type, $plugin, $parent);
if ($name != null && !class_exists($name . $ext['class'])) {
if ($load = self::__mapped($name . $ext['class'], $type, $plugin)) {
if (self::__load($load)) {
if (self::$return) {
return include($load);
}
return true;
} else {
self::__remove($name . $ext['class'], $type, $plugin);
self::$__cache = true;
}
}
if (!empty($search)) {
self::$search = $search;
} elseif ($plugin) {
self::$search = self::__paths('plugin');
} else {
self::$search = self::__paths($type);
}
$find = $file;
if ($find === null) {
$find = Inflector::underscore($name . $ext['suffix']).'.php';
if ($plugin) {
$paths = self::$search;
foreach ($paths as $key => $value) {
self::$search[$key] = $value . $ext['path'];
}
}
}
if (strtolower($type) !== 'vendor' && empty($search) && self::__load($file)) {
$directory = false;
} else {
$file = $find;
$directory = self::__find($find, true);
}
if ($directory !== null) {
self::$__cache = true;
self::__map($directory . $file, $name . $ext['class'], $type, $plugin);
if (self::$return) {
return include($directory . $file);
}
return true;
}
return false;
}
return true;
}
/**
* Initializes the cache for App, registers a shutdown function.
*
* @return void
*/
public static function init() {
self::$__map = (array)Cache::read('file_map', '_cake_core_');
register_shutdown_function(array('App', 'shutdown'));
}
/**
* Locates the $file in $__paths, searches recursively.
*
* @param string $file full file name
* @param boolean $recursive search $__paths recursively
* @return mixed boolean on fail, $file directory path on success
*/
private static function __find($file, $recursive = true) {
static $appPath = false;
if (empty(self::$search)) {
return null;
} elseif (is_string(self::$search)) {
$this->search = array(self::$search);
}
if (empty(self::$__paths)) {
self::$__paths = Cache::read('dir_map', '_cake_core_');
}
foreach (self::$search as $path) {
if ($appPath === false) {
$appPath = rtrim(APP, DS);
}
$path = rtrim($path, DS);
if ($path === $appPath) {
$recursive = false;
}
if ($recursive === false) {
if (self::__load($path . DS . $file)) {
return $path . DS;
}
continue;
}
if (!isset(self::$__paths[$path])) {
if (!class_exists('Folder')) {
require LIBS . 'folder.php';
}
$Folder = new Folder();
$directories = $Folder->tree($path, array('.svn', '.git', 'CVS', 'tests', 'templates'), 'dir');
sort($directories);
self::$__paths[$path] = $directories;
}
foreach (self::$__paths[$path] as $directory) {
if (self::__load($directory . DS . $file)) {
return $directory . DS;
}
}
}
return null;
}
/**
* Attempts to load $file.
*
* @param string $file full path to file including file name
* @return boolean
* @access private
*/
private static function __load($file) {
if (empty($file)) {
return false;
}
if (!self::$return && isset(self::$__loaded[$file])) {
return true;
}
if (file_exists($file)) {
if (!self::$return) {
require($file);
self::$__loaded[$file] = true;
}
return true;
}
return false;
}
/**
* Maps the $name to the $file.
*
* @param string $file full path to file
* @param string $name unique name for this map
* @param string $type type object being mapped
* @param string $plugin camelized if object is from a plugin, the name of the plugin
* @return void
* @access private
*/
private static function __map($file, $name, $type, $plugin) {
if ($plugin) {
self::$__map['Plugin'][$plugin][$type][$name] = $file;
} else {
self::$__map[$type][$name] = $file;
}
}
/**
* Returns a file's complete path.
*
* @param string $name unique name
* @param string $type type object
* @param string $plugin camelized if object is from a plugin, the name of the plugin
* @return mixed, file path if found, false otherwise
* @access private
*/
private static function __mapped($name, $type, $plugin) {
if ($plugin) {
if (isset(self::$__map['Plugin'][$plugin][$type]) && isset(self::$__map['Plugin'][$plugin][$type][$name])) {
return self::$__map['Plugin'][$plugin][$type][$name];
}
return false;
}
if (isset(self::$__map[$type]) && isset(self::$__map[$type][$name])) {
return self::$__map[$type][$name];
}
return false;
}
/**
* Loads parent classes based on $type.
* Returns a prefix or suffix needed for loading files.
*
* @param string $type type of object
* @param string $plugin camelized name of plugin
* @param boolean $parent false will not attempt to load parent
* @return array
* @access private
*/
private static function __settings($type, $plugin, $parent) {
if (!$parent) {
return array('class' => null, 'suffix' => null, 'path' => null);
}
if ($plugin) {
$pluginPath = Inflector::underscore($plugin);
}
$path = null;
$load = strtolower($type);
switch ($load) {
case 'model':
if (!class_exists('Model')) {
require LIBS . 'model' . DS . 'model.php';
}
if (!class_exists('AppModel')) {
App::import($type, 'AppModel', false);
}
if ($plugin) {
if (!class_exists($plugin . 'AppModel')) {
App::import($type, $plugin . '.' . $plugin . 'AppModel', false, array(), $pluginPath . DS . $pluginPath . '_app_model.php');
}
$path = $pluginPath . DS . 'models' . DS;
}
return array('class' => null, 'suffix' => null, 'path' => $path);
break;
case 'behavior':
if ($plugin) {
$path = $pluginPath . DS . 'models' . DS . 'behaviors' . DS;
}
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) {
App::import($type, $plugin . '.' . $plugin . 'AppController', false, array(), $pluginPath . DS . $pluginPath . '_app_controller.php');
$path = $pluginPath . DS . 'controllers' . DS;
}
return array('class' => $type, 'suffix' => $type, 'path' => $path);
break;
case 'component':
App::import('Core', 'Component', false);
if ($plugin) {
$path = $pluginPath . DS . 'controllers' . DS . 'components' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'lib':
if ($plugin) {
$path = $pluginPath . DS . 'libs' . DS;
}
return array('class' => null, 'suffix' => null, 'path' => $path);
break;
case 'view':
App::import('View', 'View', false);
if ($plugin) {
$path = $pluginPath . DS . 'views' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'helper':
if (!class_exists('AppHelper')) {
App::import($type, 'AppHelper', false);
}
if ($plugin) {
$path = $pluginPath . DS . 'views' . DS . 'helpers' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'shell':
if (!class_exists('Shell')) {
App::import($type, 'Shell', false);
}
if ($plugin) {
$path = $pluginPath . DS . 'console' . DS . 'shells' . DS;
}
return array('class' => $type, 'suffix' => null, 'path' => $path);
break;
case 'vendor':
if ($plugin) {
$path = $pluginPath . DS . 'vendors' . DS;
}
return array('class' => null, 'suffix' => null, 'path' => $path);
break;
default:
$type = $suffix = $path = null;
break;
}
return array('class' => null, 'suffix' => null, 'path' => null);
}
/**
* Returns default search paths.
*
* @param string $type type of object to be searched
* @return array list of paths
*/
private static function __paths($type) {
$type = strtolower($type);
$paths = array();
if ($type === 'core') {
return App::core('libs');
}
if (isset(self::${$type . 's'})) {
return self::${$type . 's'};
}
return $paths;
}
/**
* Removes file location from map if the file has been deleted.
*
* @param string $name name of object
* @param string $type type of object
* @param string $plugin camelized name of plugin
* @return void
*/
private static function __remove($name, $type, $plugin) {
if ($plugin) {
unset(self::$__map['Plugin'][$plugin][$type][$name]);
} else {
unset(self::$__map[$type][$name]);
}
}
/**
* Returns an array of filenames of PHP files in the given directory.
*
* @param string $path Path to scan for files
* @param string $suffix if false, return only directories. if string, match and return files
* @return array List of directories or files in directory
*/
private static function __list($path, $suffix = false, $extension = false) {
if (!class_exists('Folder')) {
require LIBS . 'folder.php';
}
$items = array();
$Folder = new Folder($path);
$contents = $Folder->read(false, true);
if (is_array($contents)) {
if (!$suffix) {
return $contents[0];
} else {
foreach ($contents[1] as $item) {
if (substr($item, - strlen($suffix)) === $suffix) {
if ($extension) {
$items[] = $item;
} else {
$items[] = substr($item, 0, strlen($item) - strlen($suffix));
}
}
}
}
}
return $items;
}
/**
* Object destructor.
*
* Writes cache file if changes have been made to the $__map or $__paths
*
* @return void
*/
public static function shutdown() {
if (self::$__cache) {
$core = App::core('cake');
unset(self::$__paths[rtrim($core[0], DS)]);
Cache::write('dir_map', array_filter(self::$__paths), '_cake_core_');
Cache::write('file_map', array_filter(self::$__map), '_cake_core_');
Cache::write('object_map', self::$__objects, '_cake_core_');
}
}
}

View file

@ -24,35 +24,19 @@
/**
* List of helpers to include
*/
App::import('Core', array('Router', 'CakeRequest', 'CakeResponse'));
App::import('Core', array('Router', 'CakeRequest', 'CakeResponse'), false);
App::import('Controller', 'Controller', false);
/**
* Dispatcher translates URLs to controller-action-paramter triads.
*
* Dispatches the request, creating appropriate models and controllers.
* Dispatcher converts Requests into controller actions. It uses the dispatched Request
* to locate and load the correct controller. If found, the requested action is called on
* the controller.
*
* @package cake
* @subpackage cake.cake
*/
class Dispatcher {
/**
* Base URL
*
* @var string
* @access public
*/
public $base = false;
/**
* webroot path
*
* @var string
* @access public
*/
public $webroot = '/';
/**
* Current URL
*
@ -61,14 +45,6 @@ class Dispatcher {
*/
public $here = false;
/**
* the params for this request
*
* @var string
* @access public
*/
public $params = null;
/**
* The request object
*
@ -97,40 +73,32 @@ class Dispatcher {
}
/**
* Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the
* results (if autoRender is set).
* Dispatches and invokes given Request, handing over control to the involved controller. If the controller is set
* to autoRender, via Controller::$autoRender, then Dispatcher will render the view.
*
* If no controller of given name can be found, invoke() shows error messages in
* the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called
* Actions).
* Actions in CakePHP can be any public method on a controller, that is not declared in Controller. If you
* want controller methods to be public and in-accesible by URL, then prefix them with a `_`.
* For example `public function _loadPosts() { }` would not be accessible via URL. Private and protected methods
* are also not accessible via URL.
*
* @param mixed $url Either a string url or a CakeRequest object information to work on. If $url is a string
* It will be used to create the request object.
* If no controller of given name can be found, invoke() will throw an exception.
* If the controller is found, and the action is not found an exception will be thrown.
*
* @param CakeRequest $request Request object to dispatch.
* @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
* @return boolean Success
* @throws MissingControllerException, MissingActionException, PrivateActionException if any of those error states
* are encountered.
*/
public function dispatch($url = null, $additionalParams = array()) {
if (is_array($url)) {
$url = $this->_extractParams($url, $additionalParams);
}
if ($url instanceof CakeRequest) {
$request = $url;
} else {
$request = new CakeRequest($url);
}
public function dispatch(CakeRequest $request, $additionalParams = array()) {
$this->here = $request->here;
if ($this->asset($request->url) || $this->cached($request->url)) {
return;
}
$request = $this->parseParams($request, $additionalParams);
$this->request = $request;
$controller = $this->_getController();
$controller = $this->_getController($request);
if (!is_object($controller)) {
Router::setRequestInfo($request);
@ -138,6 +106,27 @@ class Dispatcher {
'controller' => Inflector::camelize($request->params['controller']) . 'Controller'
));
}
Router::setRequestInfo($request);
if ($this->_isPrivateAction($request)) {
throw new PrivateActionException(array(
'controller' => Inflector::camelize($request->params['controller']) . "Controller",
'action' => $request->params['action']
));
}
return $this->_invoke($controller, $request);
}
/**
* Check if the request's action is marked as private, with an underscore, of if the request is attempting to
* directly accessing a prefixed action.
*
* @param CakeRequest $request The request to check
* @return boolean
*/
protected function _isPrivateAction($request) {
$privateAction = $request->params['action'][0] === '_';
$prefixes = Router::prefixes();
@ -149,17 +138,7 @@ class Dispatcher {
$privateAction = in_array($prefix, $prefixes);
}
}
Router::setRequestInfo($request);
if ($privateAction) {
throw new PrivateActionException(array(
'controller' => Inflector::camelize($request->params['controller']) . "Controller",
'action' => $request->params['action']
));
}
return $this->_invoke($controller, $request);
return $privateAction;
}
/**
@ -167,18 +146,17 @@ class Dispatcher {
* Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
* Otherwise the return value of the controller action are returned.
*
* @param object $controller Controller to invoke
* @param array $params Parameters with at least the 'action' to invoke
* @param boolean $missingAction Set to true if missing action should be rendered, false otherwise
* @param Controller $controller Controller to invoke
* @param CakeRequest $request The request object to invoke the controller for.
* @return string Output as sent by controller
* @throws MissingActionException when the action being called is missing.
*/
protected function _invoke(&$controller, $request) {
protected function _invoke(Controller $controller, CakeRequest $request) {
$controller->constructClasses();
$controller->startupProcess();
$methods = array_flip($controller->methods);
if (!isset($methods[$request->params['action']])) {
if ($controller->scaffold !== false) {
App::import('Controller', 'Scaffold', false);
@ -206,32 +184,20 @@ class Dispatcher {
}
/**
* Sets the params when $url is passed as an array to Object::requestAction();
* Merges the $url and $additionalParams and creates a string url.
* Applies Routing and additionalParameters to the request to be dispatched.
* If Routes have not been loaded they will be loaded, and app/config/routes.php will be run.
*
* @param array $url Array or request parameters
* @param array $additionalParams Array of additional parameters.
* @return string $url The generated url string.
*/
protected function _extractParams($url, $additionalParams = array()) {
$defaults = array('pass' => array(), 'named' => array(), 'form' => array());
$params = array_merge($defaults, $url, $additionalParams);
$this->params = $params;
$params += array('base' => false, 'url' => array());
return ltrim(Router::reverse($params), '/');
}
/**
* Returns array of GET and POST parameters. GET parameters are taken from given URL.
*
* @param CakeRequest $fromUrl CakeRequest object to mine for parameter information.
* @return array Parameters found in POST and GET.
* @param CakeRequest $request CakeRequest object to mine for parameter information.
* @param array $additionalParams An array of additional parameters to set to the request.
* Useful when Object::requestAction() is involved
* @return CakeRequest The request object with routing params set.
*/
public function parseParams(CakeRequest $request, $additionalParams = array()) {
if (count(Router::$routes) > 0) {
$namedExpressions = Router::getNamedExpressions();
extract($namedExpressions);
include CONFIGS . 'routes.php';
}
$params = Router::parse($request->url);
$request->addParams($params);
@ -248,17 +214,15 @@ class Dispatcher {
* @param array $params Array of parameters
* @return mixed name of controller if not loaded, or object if loaded
*/
protected function &_getController() {
$controller = false;
$ctrlClass = $this->__loadController($this->request);
protected function _getController($request) {
$ctrlClass = $this->_loadController($request);
if (!$ctrlClass) {
return $controller;
return false;
}
$ctrlClass .= 'Controller';
if (class_exists($ctrlClass)) {
$controller = new $ctrlClass($this->request);
return new $ctrlClass($request);
}
return $controller;
}
/**
@ -266,9 +230,8 @@ class Dispatcher {
*
* @param array $params Array of parameters
* @return string|bool Name of controller class name
* @access private
*/
function __loadController($request) {
protected function _loadController($request) {
$pluginName = $pluginPath = $controller = null;
if (!empty($request->params['plugin'])) {
$pluginName = $controller = Inflector::camelize($request->params['plugin']);

View file

@ -67,7 +67,7 @@ class Object {
return false;
}
if (!class_exists('dispatcher')) {
require CAKE . 'dispatcher.php';
require LIBS . 'dispatcher.php';
}
if (in_array('return', $extra, true)) {
$extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
@ -75,9 +75,21 @@ class Object {
if (is_array($url) && !isset($extra['url'])) {
$extra['url'] = array();
}
$params = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
$dispatcher = new Dispatcher;
return $dispatcher->dispatch($url, $params);
$extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
if (is_string($url)) {
$request = new CakeRequest($url);
} elseif (is_array($url)) {
$params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
$params = array_merge($params, $extra);
$request = new CakeRequest(Router::reverse($params), false);
if (isset($params['data'])) {
$request->data = $params['data'];
}
}
$dispatcher = new Dispatcher();
return $dispatcher->dispatch($request, $extra);
}
/**

View file

@ -37,6 +37,7 @@ class AllConfigureTest extends PHPUnit_Framework_TestSuite {
$suite = new PHPUnit_Framework_TestSuite('All Configure, App and ClassRegistry related tests');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'configure.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'app.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php');
return $suite;
}

View file

@ -36,11 +36,13 @@ class AllRoutingTest extends PHPUnit_Framework_TestSuite {
public static function suite() {
$suite = new CakeTestSuite('All Router and Dispatcher class tests');
$suite->addTestFile(CORE_TEST_CASES . DS . 'dispatcher.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'router.test.php');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'libs' . DS . 'route' . DS);
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_response.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'cake_request.test.php');
$libs = CORE_TEST_CASES . DS . 'libs' . DS;
$suite->addTestFile($libs . 'dispatcher.test.php');
$suite->addTestFile($libs . 'router.test.php');
$suite->addTestDirectory($libs . 'route' . DS);
$suite->addTestFile($libs . 'cake_response.test.php');
$suite->addTestFile($libs . 'cake_request.test.php');
return $suite;
}
}

View file

@ -0,0 +1,527 @@
<?php
/**
* AppImportTest class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class AppImportTest extends CakeTestCase {
/**
* testBuild method
*
* @access public
* @return void
*/
function testBuild() {
$old = App::path('models');
$expected = array(
APP . 'models' . DS,
APP,
ROOT . DS . LIBS . 'model' . DS
);
$this->assertEqual($expected, $old);
App::build(array('models' => array('/path/to/models/')));
$new = App::path('models');
$expected = array(
'/path/to/models/',
APP . 'models' . DS,
APP,
ROOT . DS . LIBS . 'model' . DS
);
$this->assertEqual($expected, $new);
App::build(); //reset defaults
$defaults = App::path('models');
$this->assertEqual($old, $defaults);
}
/**
* testBuildWithReset method
*
* @access public
* @return void
*/
function testBuildWithReset() {
$old = App::path('models');
$expected = array(
APP . 'models' . DS,
APP,
ROOT . DS . LIBS . 'model' . DS
);
$this->assertEqual($expected, $old);
App::build(array('models' => array('/path/to/models/')), true);
$new = App::path('models');
$expected = array(
'/path/to/models/'
);
$this->assertEqual($expected, $new);
App::build(); //reset defaults
$defaults = App::path('models');
$this->assertEqual($old, $defaults);
}
/**
* testCore method
*
* @access public
* @return void
*/
function testCore() {
$model = App::core('models');
$this->assertEqual(array(ROOT . DS . LIBS . 'model' . DS), $model);
$view = App::core('views');
$this->assertEqual(array(ROOT . DS . LIBS . 'view' . DS), $view);
$controller = App::core('controllers');
$this->assertEqual(array(ROOT . DS . LIBS . 'controller' . DS), $controller);
}
/**
* testListObjects method
*
* @access public
* @return void
*/
function testListObjects() {
$result = App::objects('class', TEST_CAKE_CORE_INCLUDE_PATH . 'libs', false);
$this->assertTrue(in_array('Xml', $result));
$this->assertTrue(in_array('Cache', $result));
$this->assertTrue(in_array('HttpSocket', $result));
$result = App::objects('behavior', null, false);
$this->assertTrue(in_array('Tree', $result));
$result = App::objects('controller', null, false);
$this->assertTrue(in_array('Pages', $result));
$result = App::objects('component', null, false);
$this->assertTrue(in_array('Auth', $result));
$result = App::objects('view', null, false);
$this->assertTrue(in_array('Media', $result));
$result = App::objects('helper', null, false);
$this->assertTrue(in_array('Html', $result));
$result = App::objects('model', null, false);
$notExpected = array('AppModel', 'ModelBehavior', 'ConnectionManager', 'DbAcl', 'Model', 'CakeSchema');
foreach ($notExpected as $class) {
$this->assertFalse(in_array($class, $result));
}
$result = App::objects('file');
$this->assertFalse($result);
$result = App::objects('file', 'non_existing_configure');
$expected = array();
$this->assertEqual($result, $expected);
$result = App::objects('NonExistingType');
$this->assertFalse($result);
App::build(array(
'plugins' => array(
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS
)
));
$result = App::objects('plugin', null, false);
$this->assertTrue(in_array('Cache', $result));
$this->assertTrue(in_array('Log', $result));
App::build();
}
/**
* test that pluginPath can find paths for plugins.
*
* @return void
*/
function testPluginPath() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$path = App::pluginPath('test_plugin');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS;
$this->assertEqual($path, $expected);
$path = App::pluginPath('TestPlugin');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS;
$this->assertEqual($path, $expected);
$path = App::pluginPath('TestPluginTwo');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin_two' . DS;
$this->assertEqual($path, $expected);
App::build();
}
/**
* test that pluginPath can find paths for plugins.
*
* @return void
*/
function testThemePath() {
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS)
));
$path = App::themePath('test_theme');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
$this->assertEqual($path, $expected);
$path = App::themePath('TestTheme');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
$this->assertEqual($path, $expected);
App::build();
}
/**
* testClassLoading method
*
* @access public
* @return void
*/
function testClassLoading() {
$file = App::import();
$this->assertTrue($file);
$file = App::import('Model', 'Model', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('Model'));
$file = App::import('Controller', 'Controller', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('Controller'));
$file = App::import('Component', 'Component', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('Component'));
$file = App::import('Shell', 'Shell', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('Shell'));
$file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
$this->assertFalse($file);
$file = App::import('Model', 'AppModel', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('AppModel'));
$file = App::import('WrongType', null, true, array(), '');
$this->assertTrue($file);
$file = App::import('Model', 'NonExistingPlugin.NonExistingModel', false);
$this->assertFalse($file);
$file = App::import('Core', 'NonExistingPlugin.NonExistingModel', false);
$this->assertFalse($file);
$file = App::import('Model', array('NonExistingPlugin.NonExistingModel'), false);
$this->assertFalse($file);
$file = App::import('Core', array('NonExistingPlugin.NonExistingModel'), false);
$this->assertFalse($file);
$file = App::import('Core', array('NonExistingPlugin.NonExistingModel.AnotherChild'), false);
$this->assertFalse($file);
if (!class_exists('AppController')) {
$classes = array_flip(get_declared_classes());
$this->assertFalse(isset($classes['PagesController']));
$this->assertFalse(isset($classes['AppController']));
$file = App::import('Controller', 'Pages');
$this->assertTrue($file);
$this->assertTrue(class_exists('PagesController'));
$classes = array_flip(get_declared_classes());
$this->assertTrue(isset($classes['PagesController']));
$this->assertTrue(isset($classes['AppController']));
$file = App::import('Behavior', 'Containable');
$this->assertTrue($file);
$this->assertTrue(class_exists('ContainableBehavior'));
$file = App::import('Component', 'RequestHandler');
$this->assertTrue($file);
$this->assertTrue(class_exists('RequestHandlerComponent'));
$file = App::import('Helper', 'Form');
$this->assertTrue($file);
$this->assertTrue(class_exists('FormHelper'));
$file = App::import('Model', 'NonExistingModel');
$this->assertFalse($file);
$file = App::import('Datasource', 'DboSource');
$this->assertTrue($file);
$this->assertTrue(class_exists('DboSource'));
}
App::build();
}
/**
* test import() with plugins
*
* @return void
*/
function testPluginImporting() {
App::build(array(
'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$result = App::import('Controller', 'TestPlugin.Tests');
$this->assertTrue($result);
$this->assertTrue(class_exists('TestPluginAppController'));
$this->assertTrue(class_exists('TestsController'));
$result = App::import('Lib', 'TestPlugin.TestPluginLibrary');
$this->assertTrue($result);
$this->assertTrue(class_exists('TestPluginLibrary'));
$result = App::import('Lib', 'Library');
$this->assertTrue($result);
$this->assertTrue(class_exists('Library'));
$result = App::import('Helper', 'TestPlugin.OtherHelper');
$this->assertTrue($result);
$this->assertTrue(class_exists('OtherHelperHelper'));
$result = App::import('Helper', 'TestPlugin.TestPluginApp');
$this->assertTrue($result);
$this->assertTrue(class_exists('TestPluginAppHelper'));
$result = App::import('Datasource', 'TestPlugin.TestSource');
$this->assertTrue($result);
$this->assertTrue(class_exists('TestSource'));
App::build();
}
/**
* test that building helper paths actually works.
*
* @return void
* @link http://cakephp.lighthouseapp.com/projects/42648/tickets/410
*/
function testImportingHelpersFromAlternatePaths() {
App::build();
$this->assertFalse(class_exists('BananaHelper'), 'BananaHelper exists, cannot test importing it.');
App::import('Helper', 'Banana');
$this->assertFalse(class_exists('BananaHelper'), 'BananaHelper was not found because the path does not exist.');
App::build(array(
'helpers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'helpers' . DS)
));
App::build(array('vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH)));
$this->assertFalse(class_exists('BananaHelper'), 'BananaHelper exists, cannot test importing it.');
App::import('Helper', 'Banana');
$this->assertTrue(class_exists('BananaHelper'), 'BananaHelper was not loaded.');
App::build();
}
/**
* testFileLoading method
*
* @access public
* @return void
*/
function testFileLoading () {
$file = App::import('File', 'RealFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php');
$this->assertTrue($file);
$file = App::import('File', 'NoFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
$this->assertFalse($file);
}
/**
* testFileLoadingWithArray method
*
* @access public
* @return void
*/
function testFileLoadingWithArray() {
$type = array('type' => 'File', 'name' => 'SomeName', 'parent' => false,
'file' => TEST_CAKE_CORE_INCLUDE_PATH . DS . 'config' . DS . 'config.php');
$file = App::import($type);
$this->assertTrue($file);
$type = array('type' => 'File', 'name' => 'NoFile', 'parent' => false,
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
$file = App::import($type);
$this->assertFalse($file);
}
/**
* testFileLoadingReturnValue method
*
* @access public
* @return void
*/
function testFileLoadingReturnValue () {
$file = App::import('File', 'Name', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', true);
$this->assertTrue(!empty($file));
$this->assertTrue(isset($file['Cake.version']));
$type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', 'return' => true);
$file = App::import($type);
$this->assertTrue(!empty($file));
$this->assertTrue(isset($file['Cake.version']));
}
/**
* testLoadingWithSearch method
*
* @access public
* @return void
*/
function testLoadingWithSearch () {
$file = App::import('File', 'NewName', false, array(TEST_CAKE_CORE_INCLUDE_PATH ), 'config.php');
$this->assertTrue($file);
$file = App::import('File', 'AnotherNewName', false, array(LIBS), 'config.php');
$this->assertFalse($file);
}
/**
* testLoadingWithSearchArray method
*
* @access public
* @return void
*/
function testLoadingWithSearchArray () {
$type = array('type' => 'File', 'name' => 'RandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(TEST_CAKE_CORE_INCLUDE_PATH ));
$file = App::import($type);
$this->assertTrue($file);
$type = array('type' => 'File', 'name' => 'AnotherRandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(LIBS));
$file = App::import($type);
$this->assertFalse($file);
}
/**
* testMultipleLoading method
*
* @access public
* @return void
*/
function testMultipleLoading() {
if (class_exists('I18n', false) || class_exists('CakeSocket', false)) {
$this->markTestSkipped('Cannot test loading of classes that exist.');
}
$toLoad = array('I18n', 'CakeSocket');
$classes = array_flip(get_declared_classes());
$this->assertFalse(isset($classes['i18n']));
$this->assertFalse(isset($classes['CakeSocket']));
$load = App::import($toLoad);
$this->assertTrue($load);
$classes = array_flip(get_declared_classes());
$this->assertTrue(isset($classes['I18n']));
$load = App::import(array('I18n', 'SomeNotFoundClass', 'CakeSocket'));
$this->assertFalse($load);
$load = App::import($toLoad);
$this->assertTrue($load);
}
/**
* This test only works if you have plugins/my_plugin set up.
* plugins/my_plugin/models/my_plugin.php and other_model.php
*/
/*
function testMultipleLoadingByType() {
$classes = array_flip(get_declared_classes());
$this->assertFalse(isset($classes['OtherPlugin']));
$this->assertFalse(isset($classes['MyPlugin']));
$load = App::import('Model', array('MyPlugin.OtherPlugin', 'MyPlugin.MyPlugin'));
$this->assertTrue($load);
$classes = array_flip(get_declared_classes());
$this->assertTrue(isset($classes['OtherPlugin']));
$this->assertTrue(isset($classes['MyPlugin']));
}
*/
function testLoadingVendor() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
), true);
ob_start();
$result = App::import('Vendor', 'TestPlugin.TestPluginAsset', array('ext' => 'css'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'this is the test plugin asset css file');
ob_start();
$result = App::import('Vendor', 'TestAsset', array('ext' => 'css'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'this is the test asset css file');
$result = App::import('Vendor', 'TestPlugin.SamplePlugin');
$this->assertTrue($result);
$this->assertTrue(class_exists('SamplePluginClassTestName'));
$result = App::import('Vendor', 'ConfigureTestVendorSample');
$this->assertTrue($result);
$this->assertTrue(class_exists('ConfigureTestVendorSample'));
ob_start();
$result = App::import('Vendor', 'SomeName', array('file' => 'some.name.php'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is a file with dot in file name');
ob_start();
$result = App::import('Vendor', 'TestHello', array('file' => 'Test'.DS.'hello.php'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is the hello.php file in Test directory');
ob_start();
$result = App::import('Vendor', 'MyTest', array('file' => 'Test'.DS.'MyTest.php'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is the MyTest.php file');
ob_start();
$result = App::import('Vendor', 'Welcome');
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is the welcome.php file in vendors directory');
ob_start();
$result = App::import('Vendor', 'TestPlugin.Welcome');
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is the welcome.php file in test_plugin/vendors directory');
}
}

View file

@ -19,7 +19,6 @@
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'Configure');
/**
* ConfigureTest
@ -295,528 +294,3 @@ class ConfigureTest extends CakeTestCase {
}
}
/**
* AppImportTest class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class AppImportTest extends CakeTestCase {
/**
* testBuild method
*
* @access public
* @return void
*/
function testBuild() {
$old = App::path('models');
$expected = array(
APP . 'models' . DS,
APP,
ROOT . DS . LIBS . 'model' . DS
);
$this->assertEqual($expected, $old);
App::build(array('models' => array('/path/to/models/')));
$new = App::path('models');
$expected = array(
'/path/to/models/',
APP . 'models' . DS,
APP,
ROOT . DS . LIBS . 'model' . DS
);
$this->assertEqual($expected, $new);
App::build(); //reset defaults
$defaults = App::path('models');
$this->assertEqual($old, $defaults);
}
/**
* testBuildWithReset method
*
* @access public
* @return void
*/
function testBuildWithReset() {
$old = App::path('models');
$expected = array(
APP . 'models' . DS,
APP,
ROOT . DS . LIBS . 'model' . DS
);
$this->assertEqual($expected, $old);
App::build(array('models' => array('/path/to/models/')), true);
$new = App::path('models');
$expected = array(
'/path/to/models/'
);
$this->assertEqual($expected, $new);
App::build(); //reset defaults
$defaults = App::path('models');
$this->assertEqual($old, $defaults);
}
/**
* testCore method
*
* @access public
* @return void
*/
function testCore() {
$model = App::core('models');
$this->assertEqual(array(ROOT . DS . LIBS . 'model' . DS), $model);
$view = App::core('views');
$this->assertEqual(array(ROOT . DS . LIBS . 'view' . DS), $view);
$controller = App::core('controllers');
$this->assertEqual(array(ROOT . DS . LIBS . 'controller' . DS), $controller);
}
/**
* testListObjects method
*
* @access public
* @return void
*/
function testListObjects() {
$result = App::objects('class', TEST_CAKE_CORE_INCLUDE_PATH . 'libs', false);
$this->assertTrue(in_array('Xml', $result));
$this->assertTrue(in_array('Cache', $result));
$this->assertTrue(in_array('HttpSocket', $result));
$result = App::objects('behavior', null, false);
$this->assertTrue(in_array('Tree', $result));
$result = App::objects('controller', null, false);
$this->assertTrue(in_array('Pages', $result));
$result = App::objects('component', null, false);
$this->assertTrue(in_array('Auth', $result));
$result = App::objects('view', null, false);
$this->assertTrue(in_array('Media', $result));
$result = App::objects('helper', null, false);
$this->assertTrue(in_array('Html', $result));
$result = App::objects('model', null, false);
$notExpected = array('AppModel', 'ModelBehavior', 'ConnectionManager', 'DbAcl', 'Model', 'CakeSchema');
foreach ($notExpected as $class) {
$this->assertFalse(in_array($class, $result));
}
$result = App::objects('file');
$this->assertFalse($result);
$result = App::objects('file', 'non_existing_configure');
$expected = array();
$this->assertEqual($result, $expected);
$result = App::objects('NonExistingType');
$this->assertFalse($result);
App::build(array(
'plugins' => array(
TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS
)
));
$result = App::objects('plugin', null, false);
$this->assertTrue(in_array('Cache', $result));
$this->assertTrue(in_array('Log', $result));
App::build();
}
/**
* test that pluginPath can find paths for plugins.
*
* @return void
*/
function testPluginPath() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$path = App::pluginPath('test_plugin');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS;
$this->assertEqual($path, $expected);
$path = App::pluginPath('TestPlugin');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS;
$this->assertEqual($path, $expected);
$path = App::pluginPath('TestPluginTwo');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin_two' . DS;
$this->assertEqual($path, $expected);
App::build();
}
/**
* test that pluginPath can find paths for plugins.
*
* @return void
*/
function testThemePath() {
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS)
));
$path = App::themePath('test_theme');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
$this->assertEqual($path, $expected);
$path = App::themePath('TestTheme');
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS;
$this->assertEqual($path, $expected);
App::build();
}
/**
* testClassLoading method
*
* @access public
* @return void
*/
function testClassLoading() {
$file = App::import();
$this->assertTrue($file);
$file = App::import('Model', 'Model', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('Model'));
$file = App::import('Controller', 'Controller', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('Controller'));
$file = App::import('Component', 'Component', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('Component'));
$file = App::import('Shell', 'Shell', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('Shell'));
$file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
$this->assertFalse($file);
$file = App::import('Model', 'AppModel', false);
$this->assertTrue($file);
$this->assertTrue(class_exists('AppModel'));
$file = App::import('WrongType', null, true, array(), '');
$this->assertTrue($file);
$file = App::import('Model', 'NonExistingPlugin.NonExistingModel', false);
$this->assertFalse($file);
$file = App::import('Core', 'NonExistingPlugin.NonExistingModel', false);
$this->assertFalse($file);
$file = App::import('Model', array('NonExistingPlugin.NonExistingModel'), false);
$this->assertFalse($file);
$file = App::import('Core', array('NonExistingPlugin.NonExistingModel'), false);
$this->assertFalse($file);
$file = App::import('Core', array('NonExistingPlugin.NonExistingModel.AnotherChild'), false);
$this->assertFalse($file);
if (!class_exists('AppController')) {
$classes = array_flip(get_declared_classes());
$this->assertFalse(isset($classes['PagesController']));
$this->assertFalse(isset($classes['AppController']));
$file = App::import('Controller', 'Pages');
$this->assertTrue($file);
$this->assertTrue(class_exists('PagesController'));
$classes = array_flip(get_declared_classes());
$this->assertTrue(isset($classes['PagesController']));
$this->assertTrue(isset($classes['AppController']));
$file = App::import('Behavior', 'Containable');
$this->assertTrue($file);
$this->assertTrue(class_exists('ContainableBehavior'));
$file = App::import('Component', 'RequestHandler');
$this->assertTrue($file);
$this->assertTrue(class_exists('RequestHandlerComponent'));
$file = App::import('Helper', 'Form');
$this->assertTrue($file);
$this->assertTrue(class_exists('FormHelper'));
$file = App::import('Model', 'NonExistingModel');
$this->assertFalse($file);
$file = App::import('Datasource', 'DboSource');
$this->assertTrue($file);
$this->assertTrue(class_exists('DboSource'));
}
App::build();
}
/**
* test import() with plugins
*
* @return void
*/
function testPluginImporting() {
App::build(array(
'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$result = App::import('Controller', 'TestPlugin.Tests');
$this->assertTrue($result);
$this->assertTrue(class_exists('TestPluginAppController'));
$this->assertTrue(class_exists('TestsController'));
$result = App::import('Lib', 'TestPlugin.TestPluginLibrary');
$this->assertTrue($result);
$this->assertTrue(class_exists('TestPluginLibrary'));
$result = App::import('Lib', 'Library');
$this->assertTrue($result);
$this->assertTrue(class_exists('Library'));
$result = App::import('Helper', 'TestPlugin.OtherHelper');
$this->assertTrue($result);
$this->assertTrue(class_exists('OtherHelperHelper'));
$result = App::import('Helper', 'TestPlugin.TestPluginApp');
$this->assertTrue($result);
$this->assertTrue(class_exists('TestPluginAppHelper'));
$result = App::import('Datasource', 'TestPlugin.TestSource');
$this->assertTrue($result);
$this->assertTrue(class_exists('TestSource'));
App::build();
}
/**
* test that building helper paths actually works.
*
* @return void
* @link http://cakephp.lighthouseapp.com/projects/42648/tickets/410
*/
function testImportingHelpersFromAlternatePaths() {
App::build();
$this->assertFalse(class_exists('BananaHelper'), 'BananaHelper exists, cannot test importing it.');
App::import('Helper', 'Banana');
$this->assertFalse(class_exists('BananaHelper'), 'BananaHelper was not found because the path does not exist.');
App::build(array(
'helpers' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'helpers' . DS)
));
App::build(array('vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH)));
$this->assertFalse(class_exists('BananaHelper'), 'BananaHelper exists, cannot test importing it.');
App::import('Helper', 'Banana');
$this->assertTrue(class_exists('BananaHelper'), 'BananaHelper was not loaded.');
App::build();
}
/**
* testFileLoading method
*
* @access public
* @return void
*/
function testFileLoading () {
$file = App::import('File', 'RealFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php');
$this->assertTrue($file);
$file = App::import('File', 'NoFile', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
$this->assertFalse($file);
}
/**
* testFileLoadingWithArray method
*
* @access public
* @return void
*/
function testFileLoadingWithArray() {
$type = array('type' => 'File', 'name' => 'SomeName', 'parent' => false,
'file' => TEST_CAKE_CORE_INCLUDE_PATH . DS . 'config' . DS . 'config.php');
$file = App::import($type);
$this->assertTrue($file);
$type = array('type' => 'File', 'name' => 'NoFile', 'parent' => false,
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'cake' . DS . 'config.php');
$file = App::import($type);
$this->assertFalse($file);
}
/**
* testFileLoadingReturnValue method
*
* @access public
* @return void
*/
function testFileLoadingReturnValue () {
$file = App::import('File', 'Name', false, array(), TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', true);
$this->assertTrue(!empty($file));
$this->assertTrue(isset($file['Cake.version']));
$type = array('type' => 'File', 'name' => 'OtherName', 'parent' => false,
'file' => TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php', 'return' => true);
$file = App::import($type);
$this->assertTrue(!empty($file));
$this->assertTrue(isset($file['Cake.version']));
}
/**
* testLoadingWithSearch method
*
* @access public
* @return void
*/
function testLoadingWithSearch () {
$file = App::import('File', 'NewName', false, array(TEST_CAKE_CORE_INCLUDE_PATH ), 'config.php');
$this->assertTrue($file);
$file = App::import('File', 'AnotherNewName', false, array(LIBS), 'config.php');
$this->assertFalse($file);
}
/**
* testLoadingWithSearchArray method
*
* @access public
* @return void
*/
function testLoadingWithSearchArray () {
$type = array('type' => 'File', 'name' => 'RandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(TEST_CAKE_CORE_INCLUDE_PATH ));
$file = App::import($type);
$this->assertTrue($file);
$type = array('type' => 'File', 'name' => 'AnotherRandomName', 'parent' => false, 'file' => 'config.php', 'search' => array(LIBS));
$file = App::import($type);
$this->assertFalse($file);
}
/**
* testMultipleLoading method
*
* @access public
* @return void
*/
function testMultipleLoading() {
if (class_exists('I18n', false) || class_exists('CakeSocket', false)) {
$this->markTestSkipped('Cannot test loading of classes that exist.');
}
$toLoad = array('I18n', 'CakeSocket');
$classes = array_flip(get_declared_classes());
$this->assertFalse(isset($classes['i18n']));
$this->assertFalse(isset($classes['CakeSocket']));
$load = App::import($toLoad);
$this->assertTrue($load);
$classes = array_flip(get_declared_classes());
$this->assertTrue(isset($classes['I18n']));
$load = App::import(array('I18n', 'SomeNotFoundClass', 'CakeSocket'));
$this->assertFalse($load);
$load = App::import($toLoad);
$this->assertTrue($load);
}
/**
* This test only works if you have plugins/my_plugin set up.
* plugins/my_plugin/models/my_plugin.php and other_model.php
*/
/*
function testMultipleLoadingByType() {
$classes = array_flip(get_declared_classes());
$this->assertFalse(isset($classes['OtherPlugin']));
$this->assertFalse(isset($classes['MyPlugin']));
$load = App::import('Model', array('MyPlugin.OtherPlugin', 'MyPlugin.MyPlugin'));
$this->assertTrue($load);
$classes = array_flip(get_declared_classes());
$this->assertTrue(isset($classes['OtherPlugin']));
$this->assertTrue(isset($classes['MyPlugin']));
}
*/
function testLoadingVendor() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'vendors' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'vendors'. DS),
), true);
ob_start();
$result = App::import('Vendor', 'TestPlugin.TestPluginAsset', array('ext' => 'css'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'this is the test plugin asset css file');
ob_start();
$result = App::import('Vendor', 'TestAsset', array('ext' => 'css'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'this is the test asset css file');
$result = App::import('Vendor', 'TestPlugin.SamplePlugin');
$this->assertTrue($result);
$this->assertTrue(class_exists('SamplePluginClassTestName'));
$result = App::import('Vendor', 'ConfigureTestVendorSample');
$this->assertTrue($result);
$this->assertTrue(class_exists('ConfigureTestVendorSample'));
ob_start();
$result = App::import('Vendor', 'SomeName', array('file' => 'some.name.php'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is a file with dot in file name');
ob_start();
$result = App::import('Vendor', 'TestHello', array('file' => 'Test'.DS.'hello.php'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is the hello.php file in Test directory');
ob_start();
$result = App::import('Vendor', 'MyTest', array('file' => 'Test'.DS.'MyTest.php'));
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is the MyTest.php file');
ob_start();
$result = App::import('Vendor', 'Welcome');
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is the welcome.php file in vendors directory');
ob_start();
$result = App::import('Vendor', 'TestPlugin.Welcome');
$text = ob_get_clean();
$this->assertTrue($result);
$this->assertEqual($text, 'This is the welcome.php file in test_plugin/vendors directory');
}
}

View file

@ -757,7 +757,7 @@ class ControllerTest extends CakeTestCase {
* @access public
*/
function testPaginateFieldsDouble(){
$Controller = new Controller();
$Controller = new Controller($this->getMock('CakeRequest'));
$Controller->uses = array('ControllerPost');
$Controller->request = $this->getMock('CakeRequest');
$Controller->request->query = array();

View file

@ -47,6 +47,7 @@ class DebuggerTest extends CakeTestCase {
*/
function setUp() {
parent::setup();
Configure::write('debug', 2);
Configure::write('log', false);
}

View file

@ -17,7 +17,7 @@
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
require_once CAKE . 'dispatcher.php';
App::import('Core', 'Dispatcher', false);
App::import('Core', 'CakeResponse', false);
if (!class_exists('AppController')) {
@ -717,7 +717,7 @@ class DispatcherTest extends CakeTestCase {
try {
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl', '/index.php');
$url = 'some_controller/home/param:value/param2:value2';
$url = new CakeRequest('some_controller/home/param:value/param2:value2');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->fail('No exception thrown');
} catch (MissingControllerException $e) {
@ -733,7 +733,7 @@ class DispatcherTest extends CakeTestCase {
public function testPrivate() {
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl','/index.php');
$url = 'some_pages/_protected/param:value/param2:value2';
$url = new CakeRequest('some_pages/_protected/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, array('return' => 1));
@ -753,7 +753,7 @@ class DispatcherTest extends CakeTestCase {
public function testMissingAction() {
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl', '/index.php');
$url = 'some_pages/home/param:value/param2:value2';
$url = new CakeRequest('some_pages/home/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
@ -771,7 +771,7 @@ class DispatcherTest extends CakeTestCase {
function testMissingActionFromBaseClassMethods() {
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl','/index.php');
$url = 'some_pages/redirect/param:value/param2:value2';
$url = new CakeRequest('some_pages/redirect/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
@ -792,7 +792,7 @@ class DispatcherTest extends CakeTestCase {
));
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl', '/index.php');
$url = 'pages/home/param:value/param2:value2';
$url = new CakeRequest('pages/home/param:value/param2:value2');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = 'Pages';
@ -803,16 +803,15 @@ class DispatcherTest extends CakeTestCase {
Configure::write('App.baseUrl','/pages/index.php');
$url = 'pages/home';
$url = new CakeRequest('pages/home');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = 'Pages';
$this->assertEqual($expected, $controller->name);
$url = 'pages/home/';
$url = new CakeRequest('pages/home/');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertNull($controller->plugin);
$this->assertNull($Dispatcher->params['plugin']);
$expected = 'Pages';
$this->assertEqual($expected, $controller->name);
@ -822,55 +821,27 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher = new TestDispatcher();
Configure::write('App.baseUrl', '/timesheets/index.php');
$url = 'timesheets';
$url = new CakeRequest('timesheets');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = 'Timesheets';
$this->assertEqual($expected, $controller->name);
$url = 'timesheets/';
$url = new CakeRequest('timesheets/');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual('Timesheets', $controller->name);
$this->assertEqual('/timesheets/index.php', $Dispatcher->request->base);
$this->assertEqual('/timesheets/index.php', $url->base);
$url = 'test_dispatch_pages/camelCased';
$url = new CakeRequest('test_dispatch_pages/camelCased');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual('TestDispatchPages', $controller->name);
$url = 'test_dispatch_pages/camelCased/something. .';
$url = new CakeRequest('test_dispatch_pages/camelCased/something. .');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s');
}
/**
* testDispatchWithArray method
*
* @return void
*/
public function testDispatchWithArray() {
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));
Router::reload();
Configure::write('App.baseUrl', '/index.php');
$Dispatcher = new TestDispatcher();
$url = array('controller' => 'pages', 'action' => 'display');
$controller = $Dispatcher->dispatch($url, array(
'pass' => array('home'),
'named' => array('param' => 'value', 'param2' => 'value2'),
'return' => 1
));
$expected = 'Pages';
$this->assertEqual($expected, $controller->name);
$expected = array('0' => 'home', 'param' => 'value', 'param2' => 'value2');
$this->assertIdentical($expected, $controller->passedArgs);
$this->assertEqual($Dispatcher->request->base . '/pages/display/home/param:value/param2:value2', $Dispatcher->request->here);
}
/**
* testAdminDispatch method
*
@ -881,7 +852,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher = new TestDispatcher();
Configure::write('Routing.prefixes', array('admin'));
Configure::write('App.baseUrl','/cake/repo/branches/1.2.x.x/index.php');
$url = 'admin/test_dispatch_pages/index/param:value/param2:value2';
$url = new CakeRequest('admin/test_dispatch_pages/index/param:value/param2:value2');
Router::reload();
$controller = $Dispatcher->dispatch($url, array('return' => 1));
@ -914,10 +885,10 @@ class DispatcherTest extends CakeTestCase {
array('plugin' => 'my_plugin', 'controller' => 'pages', 'action' => 'display')
);
$url = 'my_plugin/some_pages/home/param:value/param2:value2';
$url = new CakeRequest('my_plugin/some_pages/home/param:value/param2:value2');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$result = $Dispatcher->parseParams(new CakeRequest($url));
$result = $Dispatcher->parseParams($url);
$expected = array(
'pass' => array('home'),
'named' => array('param'=> 'value', 'param2'=> 'value2'), 'plugin'=> 'my_plugin',
@ -958,7 +929,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher->base = false;
$url = 'my_plugin/other_pages/index/param:value/param2:value2';
$url = new CakeRequest('my_plugin/other_pages/index/param:value/param2:value2');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertIdentical($controller->plugin, 'my_plugin');
@ -992,7 +963,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher = new TestDispatcher();
$Dispatcher->base = false;
$url = 'my_plugin/my_plugin/add/param:value/param2:value2';
$url = new CakeRequest('my_plugin/my_plugin/add/param:value/param2:value2');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
@ -1012,7 +983,7 @@ class DispatcherTest extends CakeTestCase {
$plugin = 'MyPlugin';
$pluginUrl = Inflector::underscore($plugin);
$url = $pluginUrl;
$url = new CakeRequest($pluginUrl);
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertIdentical($controller->plugin, 'my_plugin');
$this->assertIdentical($controller->name, 'MyPlugin');
@ -1027,7 +998,7 @@ class DispatcherTest extends CakeTestCase {
Router::reload();
$Dispatcher = new TestDispatcher();
$url = 'admin/my_plugin/my_plugin/add/5/param:value/param2:value2';
$url = new CakeRequest('admin/my_plugin/my_plugin/add/5/param:value/param2:value2');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['plugin'], 'my_plugin');
@ -1047,7 +1018,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher = new TestDispatcher();
$controller = $Dispatcher->dispatch('admin/articles_test', array('return' => 1));
$controller = $Dispatcher->dispatch(new CakeRequest('admin/articles_test'), array('return' => 1));
$this->assertIdentical($controller->plugin, 'articles_test');
$this->assertIdentical($controller->name, 'ArticlesTest');
$this->assertIdentical($controller->action, 'admin_index');
@ -1087,7 +1058,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher = new TestDispatcher();
$Dispatcher->base = false;
$url = 'my_plugin/';
$url = new CakeRequest('my_plugin/');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['controller'], 'my_plugin');
$this->assertEqual($controller->params['plugin'], 'my_plugin');
@ -1115,21 +1086,21 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher = new TestDispatcher();
$Dispatcher->base = false;
$url = 'test_plugin/';
$url = new CakeRequest('test_plugin/');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['controller'], 'test_plugin');
$this->assertEqual($controller->params['plugin'], 'test_plugin');
$this->assertEqual($controller->params['action'], 'index');
$this->assertFalse(isset($controller->params['pass'][0]));
$url = '/test_plugin/tests/index';
$url = new CakeRequest('/test_plugin/tests/index');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['controller'], 'tests');
$this->assertEqual($controller->params['plugin'], 'test_plugin');
$this->assertEqual($controller->params['action'], 'index');
$this->assertFalse(isset($controller->params['pass'][0]));
$url = '/test_plugin/tests/index/some_param';
$url = new CakeRequest('/test_plugin/tests/index/some_param');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertEqual($controller->params['controller'], 'tests');
$this->assertEqual($controller->params['plugin'], 'test_plugin');
@ -1152,7 +1123,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher = new TestDispatcher();
$Dispatcher->base = false;
$url = 'my_plugin/not_here/param:value/param2:value2';
$url = new CakeRequest('my_plugin/not_here/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
@ -1165,7 +1136,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher = new TestDispatcher();
$Dispatcher->base = false;
$url = 'my_plugin/param:value/param2:value2';
$url = new CakeRequest('my_plugin/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
$this->fail('No exception.');
@ -1188,7 +1159,7 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher = new TestDispatcher();
$url = 'test_dispatch_pages/admin_index/param:value/param2:value2';
$url = new CakeRequest('test_dispatch_pages/admin_index/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
$this->fail('No exception.');
@ -1214,7 +1185,7 @@ class DispatcherTest extends CakeTestCase {
Router::reload();
Router::parse('/');
$url = '/test_plugin/tests/index';
$url = new CakeRequest('/test_plugin/tests/index');
$result = $Dispatcher->dispatch($url, array('return' => 1));
$this->assertTrue(class_exists('TestsController'));
$this->assertTrue(class_exists('TestPluginAppController'));
@ -1235,7 +1206,7 @@ class DispatcherTest extends CakeTestCase {
public function testChangingParamsFromBeforeFilter() {
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
$Dispatcher = new TestDispatcher();
$url = 'some_posts/index/param:value/param2:value2';
$url = new CakeRequest('some_posts/index/param:value/param2:value2');
try {
$controller = $Dispatcher->dispatch($url, array('return'=> 1));
@ -1244,7 +1215,7 @@ class DispatcherTest extends CakeTestCase {
$this->assertEquals('Action SomePostsController::view() could not be found.', $e->getMessage());
}
$url = 'some_posts/something_else/param:value/param2:value2';
$url = new CakeRequest('some_posts/something_else/param:value/param2:value2');
$controller = $Dispatcher->dispatch($url, array('return' => 1));
$expected = 'SomePosts';
@ -1275,21 +1246,21 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher->response = $this->getMock('CakeResponse', array('_sendHeader'));
try {
$Dispatcher->dispatch('theme/test_theme/../webroot/css/test_asset.css');
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/../webroot/css/test_asset.css'));
$this->fail('No exception');
} catch (MissingControllerException $e) {
$this->assertEquals('Controller class ThemeController could not be found.', $e->getMessage());
}
try {
$Dispatcher->dispatch('theme/test_theme/pdfs');
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs'));
$this->fail('No exception');
} catch (MissingControllerException $e) {
$this->assertEquals('Controller class ThemeController could not be found.', $e->getMessage());
}
ob_start();
$Dispatcher->dispatch('theme/test_theme/flash/theme_test.swf');
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/flash/theme_test.swf'));
$result = ob_get_clean();
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'flash' . DS . 'theme_test.swf');
@ -1297,14 +1268,14 @@ class DispatcherTest extends CakeTestCase {
$this->assertEqual('this is just a test to load swf file from the theme.', $result);
ob_start();
$Dispatcher->dispatch('theme/test_theme/pdfs/theme_test.pdf');
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/pdfs/theme_test.pdf'));
$result = ob_get_clean();
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'pdfs' . DS . 'theme_test.pdf');
$this->assertEqual($file, $result);
$this->assertEqual('this is just a test to load pdf file from the theme.', $result);
ob_start();
$Dispatcher->dispatch('theme/test_theme/img/test.jpg');
$Dispatcher->dispatch(new CakeRequest('theme/test_theme/img/test.jpg'));
$result = ob_get_clean();
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'webroot' . DS . 'img' . DS . 'test.jpg');
$this->assertEqual($file, $result);
@ -1331,14 +1302,14 @@ class DispatcherTest extends CakeTestCase {
$this->assertEqual($result, $expected);
ob_start();
$Dispatcher->dispatch('test_plugin/flash/plugin_test.swf');
$Dispatcher->dispatch(new CakeRequest('test_plugin/flash/plugin_test.swf'));
$result = ob_get_clean();
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'webroot' . DS . 'flash' . DS . 'plugin_test.swf');
$this->assertEqual($file, $result);
$this->assertEqual('this is just a test to load swf file from the plugin.', $result);
ob_start();
$Dispatcher->dispatch('test_plugin/pdfs/plugin_test.pdf');
$Dispatcher->dispatch(new CakeRequest('test_plugin/pdfs/plugin_test.pdf'));
$result = ob_get_clean();
$file = file_get_contents(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'webroot' . DS . 'pdfs' . DS . 'plugin_test.pdf');
$this->assertEqual($file, $result);
@ -1411,8 +1382,6 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher->asset('ccss/cake.generic.css');
$result = ob_get_clean();
$this->assertTrue($Dispatcher->stopped);
}
/**
@ -1471,14 +1440,14 @@ class DispatcherTest extends CakeTestCase {
), true);
$dispatcher = new TestDispatcher();
$url = '/';
$request = new CakeRequest('/');
ob_start();
$dispatcher->dispatch($url);
$dispatcher->dispatch($request);
$out = ob_get_clean();
ob_start();
$dispatcher->cached($url);
$dispatcher->cached($request);
$cached = ob_get_clean();
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
@ -1490,17 +1459,17 @@ class DispatcherTest extends CakeTestCase {
$filename = $this->__cachePath($dispatcher->here);
unlink($filename);
$url = 'test_cached_pages/index';
$request = new CakeRequest('test_cached_pages/index');
$_POST = array(
'slasher' => "Up in your's grill \ '"
);
ob_start();
$dispatcher->dispatch($url);
$dispatcher->dispatch($request);
$out = ob_get_clean();
ob_start();
$dispatcher->cached($url);
$dispatcher->cached($request);
$cached = ob_get_clean();
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
@ -1511,14 +1480,14 @@ class DispatcherTest extends CakeTestCase {
$filename = $this->__cachePath($dispatcher->here);
unlink($filename);
$url = 'TestCachedPages/index';
$request = new CakeRequest('TestCachedPages/index');
ob_start();
$dispatcher->dispatch($url);
$dispatcher->dispatch($request);
$out = ob_get_clean();
ob_start();
$dispatcher->cached($url);
$dispatcher->cached($request);
$cached = ob_get_clean();
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
@ -1529,14 +1498,14 @@ class DispatcherTest extends CakeTestCase {
$filename = $this->__cachePath($dispatcher->here);
unlink($filename);
$url = 'TestCachedPages/test_nocache_tags';
$request = new CakeRequest('TestCachedPages/test_nocache_tags');
ob_start();
$dispatcher->dispatch($url);
$dispatcher->dispatch($request);
$out = ob_get_clean();
ob_start();
$dispatcher->cached($url);
$dispatcher->cached($request);
$cached = ob_get_clean();
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
@ -1547,14 +1516,14 @@ class DispatcherTest extends CakeTestCase {
$filename = $this->__cachePath($dispatcher->here);
unlink($filename);
$url = 'test_cached_pages/view/param/param';
$request = new CakeRequest('test_cached_pages/view/param/param');
ob_start();
$dispatcher->dispatch($url);
$dispatcher->dispatch($request);
$out = ob_get_clean();
ob_start();
$dispatcher->cached($url);
$dispatcher->cached($request);
$cached = ob_get_clean();
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);
@ -1565,14 +1534,14 @@ class DispatcherTest extends CakeTestCase {
$filename = $this->__cachePath($dispatcher->here);
unlink($filename);
$url = 'test_cached_pages/view/foo:bar/value:goo';
$request = new CakeRequest('test_cached_pages/view/foo:bar/value:goo');
ob_start();
$dispatcher->dispatch($url);
$dispatcher->dispatch($request);
$out = ob_get_clean();
ob_start();
$dispatcher->cached($url);
$dispatcher->cached($request);
$cached = ob_get_clean();
$result = str_replace(array("\t", "\r\n", "\n"), "", $out);

View file

@ -824,7 +824,7 @@ class ObjectTest extends CakeTestCase {
function testRequestActionParamParseAndPass() {
$result = $this->object->requestAction('/request_action/params_pass');
$this->assertTrue(isset($result['url']['url']));
$this->assertEqual($result['url']['url'], '/request_action/params_pass');
$this->assertEqual($result['url']['url'], 'request_action/params_pass');
$this->assertEqual($result['controller'], 'request_action');
$this->assertEqual($result['action'], 'params_pass');
$this->assertEqual($result['form'], array());
@ -855,9 +855,12 @@ class ObjectTest extends CakeTestCase {
));
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'));
$expected = null;
$this->assertEqual($expected, $result);
$this->assertEmpty($result);
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'post_pass'), array('data' => $_POST['data']));
$result = $this->object->requestAction(
array('controller' => 'request_action', 'action' => 'post_pass'),
array('data' => $_POST['data'])
);
$expected = $_POST['data'];
$this->assertEqual($expected, $result);

View file

@ -41,15 +41,7 @@
/**
* Set the include path or define app and core path
*/
if (function_exists('ini_set')) {
ini_set('include_path',
ini_get('include_path') . PATH_SEPARATOR . CAKE_CORE_INCLUDE_PATH
. PATH_SEPARATOR . ROOT . DS . APP_DIR . DS
);
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';