Making Configure/App methods static, removing reference operators.

Removing deprecated methods.
This commit is contained in:
Mark Story 2010-04-15 00:06:17 -04:00
parent 23b75f4ed2
commit 1fef9e4a78

View file

@ -41,13 +41,13 @@ class Configure extends Object {
* *
* @return Configure instance * @return Configure instance
*/ */
public function &getInstance($boot = true) { public static function &getInstance($boot = true) {
static $instance = array(); static $instance = array();
if (!$instance) { if (!$instance) {
if (!class_exists('Set')) { if (!class_exists('Set')) {
require LIBS . 'set.php'; require LIBS . 'set.php';
} }
$instance[0] =& new Configure(); $instance[0] = new Configure();
$instance[0]->__loadBootstrap($boot); $instance[0]->__loadBootstrap($boot);
} }
return $instance[0]; return $instance[0];
@ -76,8 +76,8 @@ class Configure extends Object {
* @param mixed $value Value to set for var * @param mixed $value Value to set for var
* @return boolean True if write was successful * @return boolean True if write was successful
*/ */
public function write($config, $value = null) { public static function write($config, $value = null) {
$_this =& Configure::getInstance(); $_this = Configure::getInstance();
if (!is_array($config)) { if (!is_array($config)) {
$config = array($config => $value); $config = array($config => $value);
@ -147,8 +147,8 @@ class Configure extends Object {
* @param string $var Variable to obtain. Use '.' to access array elements. * @param string $var Variable to obtain. Use '.' to access array elements.
* @return string value of Configure::$var * @return string value of Configure::$var
*/ */
public function read($var = 'debug') { public static function read($var = 'debug') {
$_this =& Configure::getInstance(); $_this = Configure::getInstance();
if ($var === 'debug') { if ($var === 'debug') {
return $_this->debug; return $_this->debug;
@ -196,8 +196,8 @@ class Configure extends Object {
* @param string $var the var to be deleted * @param string $var the var to be deleted
* @return void * @return void
*/ */
public function delete($var = null) { public static function delete($var = null) {
$_this =& Configure::getInstance(); $_this = Configure::getInstance();
if (strpos($var, '.') === false) { if (strpos($var, '.') === false) {
unset($_this->{$var}); unset($_this->{$var});
@ -223,7 +223,7 @@ class Configure extends Object {
* should be used, not the extenstion * should be used, not the extenstion
* @return mixed false if file not found, void if load successful * @return mixed false if file not found, void if load successful
*/ */
public function load($fileName) { public static function load($fileName) {
$found = $plugin = $pluginPath = false; $found = $plugin = $pluginPath = false;
list($plugin, $fileName) = pluginSplit($fileName); list($plugin, $fileName) = pluginSplit($fileName);
if ($plugin) { if ($plugin) {
@ -271,8 +271,8 @@ class Configure extends Object {
* @link http://book.cakephp.org/view/930/version * @link http://book.cakephp.org/view/930/version
* @return string Current version of CakePHP * @return string Current version of CakePHP
*/ */
public function version() { public static function version() {
$_this =& Configure::getInstance(); $_this = Configure::getInstance();
if (!isset($_this->Cake['version'])) { if (!isset($_this->Cake['version'])) {
require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php'); require(CORE_PATH . 'cake' . DS . 'config' . DS . 'config.php');
@ -295,7 +295,7 @@ class Configure extends Object {
* @param array $data array of values to store. * @param array $data array of values to store.
* @return void * @return void
*/ */
public function store($type, $name, $data = array()) { public static function store($type, $name, $data = array()) {
$write = true; $write = true;
$content = ''; $content = '';
@ -305,7 +305,7 @@ class Configure extends Object {
if (is_null($type)) { if (is_null($type)) {
$write = false; $write = false;
} }
Configure::__writeConfig($content, $name, $write); Configure::getInstance()->__writeConfig($content, $name, $write);
} }
/** /**
@ -318,7 +318,7 @@ class Configure extends Object {
* @return void * @return void
* @access private * @access private
*/ */
function __writeConfig($content, $name, $write = true) { private function __writeConfig($content, $name, $write = true) {
$file = CACHE . 'persistent' . DS . $name . '.php'; $file = CACHE . 'persistent' . DS . $name . '.php';
if (Configure::read() > 0) { if (Configure::read() > 0) {
@ -344,30 +344,6 @@ class Configure extends Object {
} }
} }
/**
* @deprecated
* @see App::objects()
*/
function listObjects($type, $path = null, $cache = true) {
return App::objects($type, $path, $cache);
}
/**
* @deprecated
* @see App::core()
*/
function corePaths($type = null) {
return App::core($type);
}
/**
* @deprecated
* @see App::build()
*/
function buildPaths($paths) {
return App::build($paths);
}
/** /**
* Loads app/config/bootstrap.php. * Loads app/config/bootstrap.php.
* If the alternative paths are set in this file * If the alternative paths are set in this file
@ -375,9 +351,8 @@ class Configure extends Object {
* *
* @param boolean $boot Load application bootstrap (if true) * @param boolean $boot Load application bootstrap (if true)
* @return void * @return void
* @access private
*/ */
function __loadBootstrap($boot) { private function __loadBootstrap($boot) {
if ($boot) { if ($boot) {
Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT)); Configure::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT));
@ -621,8 +596,8 @@ class App extends Object {
* @param string $type type of path * @param string $type type of path
* @return string array * @return string array
*/ */
public function path($type) { public static function path($type) {
$_this =& App::getInstance(); $_this = App::getInstance();
if (!isset($_this->{$type})) { if (!isset($_this->{$type})) {
return array(); return array();
} }
@ -637,8 +612,8 @@ class App extends Object {
* @param boolean $reset true will set paths, false merges paths [default] false * @param boolean $reset true will set paths, false merges paths [default] false
* @return void * @return void
*/ */
public function build($paths = array(), $reset = false) { public static function build($paths = array(), $reset = false) {
$_this =& App::getInstance(); $_this = App::getInstance();
$defaults = array( $defaults = array(
'models' => array(MODELS), 'models' => array(MODELS),
'behaviors' => array(BEHAVIORS), 'behaviors' => array(BEHAVIORS),
@ -696,8 +671,8 @@ class App extends Object {
* @param string $plugin CamelCased plugin name to find the path of. * @param string $plugin CamelCased plugin name to find the path of.
* @return string full path to the plugin. * @return string full path to the plugin.
*/ */
function pluginPath($plugin) { public static function pluginPath($plugin) {
$_this =& App::getInstance(); $_this = App::getInstance();
$pluginDir = Inflector::underscore($plugin); $pluginDir = Inflector::underscore($plugin);
for ($i = 0, $length = count($_this->plugins); $i < $length; $i++) { for ($i = 0, $length = count($_this->plugins); $i < $length; $i++) {
if (is_dir($_this->plugins[$i] . $pluginDir)) { if (is_dir($_this->plugins[$i] . $pluginDir)) {
@ -715,7 +690,7 @@ class App extends Object {
* 'view', 'helper', 'datasource', 'libs', and 'cake' * 'view', 'helper', 'datasource', 'libs', and 'cake'
* @return array numeric keyed array of core lib paths * @return array numeric keyed array of core lib paths
*/ */
public function core($type = null) { public static function core($type = null) {
static $paths = false; static $paths = false;
if ($paths === false) { if ($paths === false) {
$paths = Cache::read('core_paths', '_cake_core_'); $paths = Cache::read('core_paths', '_cake_core_');
@ -756,7 +731,7 @@ class App extends Object {
* @param boolean $cache Set to false to rescan objects of the chosen type. Defaults to true. * @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. * @return mixed Either false on incorrect / miss. Or an array of found objects.
*/ */
public function objects($type, $path = null, $cache = true) { public static function objects($type, $path = null, $cache = true) {
$objects = array(); $objects = array();
$extension = false; $extension = false;
$name = $type; $name = $type;
@ -767,7 +742,7 @@ class App extends Object {
$extension = true; $extension = true;
$name = $type . str_replace(DS, '', $path); $name = $type . str_replace(DS, '', $path);
} }
$_this =& App::getInstance(); $_this = App::getInstance();
if (empty($_this->__objects) && $cache === true) { if (empty($_this->__objects) && $cache === true) {
$_this->__objects = Cache::read('object_map', '_cake_core_'); $_this->__objects = Cache::read('object_map', '_cake_core_');
@ -828,7 +803,7 @@ class App extends Object {
* statement in it to work: return $variable; * 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 * @return boolean true if Class is already in memory or if file is found and loaded, false if not
*/ */
public function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) { public static function import($type = null, $name = null, $parent = true, $search = array(), $file = null, $return = false) {
$plugin = $directory = null; $plugin = $directory = null;
if (is_array($type)) { if (is_array($type)) {
@ -879,7 +854,7 @@ class App extends Object {
list($plugin, $name) = explode('.', $name); list($plugin, $name) = explode('.', $name);
$plugin = Inflector::camelize($plugin); $plugin = Inflector::camelize($plugin);
} }
$_this =& App::getInstance(); $_this = App::getInstance();
$_this->return = $return; $_this->return = $return;
if (isset($ext)) { if (isset($ext)) {
@ -947,10 +922,10 @@ class App extends Object {
* *
* @return object * @return object
*/ */
public function &getInstance() { public static function &getInstance() {
static $instance = array(); static $instance = array();
if (!$instance) { if (!$instance) {
$instance[0] =& new App(); $instance[0] = new App();
$instance[0]->__map = (array)Cache::read('file_map', '_cake_core_'); $instance[0]->__map = (array)Cache::read('file_map', '_cake_core_');
} }
return $instance[0]; return $instance[0];
@ -964,7 +939,7 @@ class App extends Object {
* @return mixed boolean on fail, $file directory path on success * @return mixed boolean on fail, $file directory path on success
* @access private * @access private
*/ */
function __find($file, $recursive = true) { private function __find($file, $recursive = true) {
static $appPath = false; static $appPath = false;
if (empty($this->search)) { if (empty($this->search)) {
@ -1019,7 +994,7 @@ class App extends Object {
* @return boolean * @return boolean
* @access private * @access private
*/ */
function __load($file) { private function __load($file) {
if (empty($file)) { if (empty($file)) {
return false; return false;
} }
@ -1046,7 +1021,7 @@ class App extends Object {
* @return void * @return void
* @access private * @access private
*/ */
function __map($file, $name, $type, $plugin) { private function __map($file, $name, $type, $plugin) {
if ($plugin) { if ($plugin) {
$this->__map['Plugin'][$plugin][$type][$name] = $file; $this->__map['Plugin'][$plugin][$type][$name] = $file;
} else { } else {
@ -1063,7 +1038,7 @@ class App extends Object {
* @return mixed, file path if found, false otherwise * @return mixed, file path if found, false otherwise
* @access private * @access private
*/ */
function __mapped($name, $type, $plugin) { private function __mapped($name, $type, $plugin) {
if ($plugin) { if ($plugin) {
if (isset($this->__map['Plugin'][$plugin][$type]) && isset($this->__map['Plugin'][$plugin][$type][$name])) { if (isset($this->__map['Plugin'][$plugin][$type]) && isset($this->__map['Plugin'][$plugin][$type][$name])) {
return $this->__map['Plugin'][$plugin][$type][$name]; return $this->__map['Plugin'][$plugin][$type][$name];
@ -1084,7 +1059,7 @@ class App extends Object {
* @param string $name Class name to overload * @param string $name Class name to overload
* @access private * @access private
*/ */
function __overload($type, $name, $parent) { private function __overload($type, $name, $parent) {
if (($type === 'Model' || $type === 'Helper') && $parent !== false) { if (($type === 'Model' || $type === 'Helper') && $parent !== false) {
Overloadable::overload($name); Overloadable::overload($name);
} }
@ -1100,7 +1075,7 @@ class App extends Object {
* @return array * @return array
* @access private * @access private
*/ */
function __settings($type, $plugin, $parent) { private function __settings($type, $plugin, $parent) {
if (!$parent) { if (!$parent) {
return array('class' => null, 'suffix' => null, 'path' => null); return array('class' => null, 'suffix' => null, 'path' => null);
} }
@ -1193,7 +1168,7 @@ class App extends Object {
* @return array list of paths * @return array list of paths
* @access private * @access private
*/ */
function __paths($type) { private function __paths($type) {
$type = strtolower($type); $type = strtolower($type);
$paths = array(); $paths = array();
@ -1215,7 +1190,7 @@ class App extends Object {
* @return void * @return void
* @access private * @access private
*/ */
function __remove($name, $type, $plugin) { private function __remove($name, $type, $plugin) {
if ($plugin) { if ($plugin) {
unset($this->__map['Plugin'][$plugin][$type][$name]); unset($this->__map['Plugin'][$plugin][$type][$name]);
} else { } else {
@ -1231,7 +1206,7 @@ class App extends Object {
* @return array List of directories or files in directory * @return array List of directories or files in directory
* @access private * @access private
*/ */
function __list($path, $suffix = false, $extension = false) { private function __list($path, $suffix = false, $extension = false) {
if (!class_exists('Folder')) { if (!class_exists('Folder')) {
require LIBS . 'folder.php'; require LIBS . 'folder.php';
} }