Replacing duplicated code with pluginSplit().

Updating test case.
This commit is contained in:
mark_story 2009-11-15 19:55:20 -05:00
parent a292ef0f16
commit 0783176238
17 changed files with 42 additions and 92 deletions

View file

@ -318,12 +318,7 @@ class ShellDispatcher {
return true; return true;
} }
if (strpos($arg, '.') !== false) { list($plugin, $shell) = pluginSplit($arg);
list($plugin, $shell) = explode('.', $arg);
} else {
$plugin = null;
$shell = $arg;
}
$this->shell = $shell; $this->shell = $shell;
$this->shellName = Inflector::camelize($shell); $this->shellName = Inflector::camelize($shell);
$this->shellClass = $this->shellName . 'Shell'; $this->shellClass = $this->shellName . 'Shell';

View file

@ -57,7 +57,7 @@ class BakeShell extends Shell {
} }
foreach($this->args as $i => $arg) { foreach($this->args as $i => $arg) {
if (strpos($arg, '.')) { if (strpos($arg, '.')) {
list($this->params['plugin'], $this->args[$i]) = explode('.', $arg); list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
break; break;
} }
} }

View file

@ -63,9 +63,10 @@ class SchemaShell extends Shell {
} elseif (!empty($this->args[0])) { } elseif (!empty($this->args[0])) {
$name = $this->params['name'] = $this->args[0]; $name = $this->params['name'] = $this->args[0];
} }
if (strpos($name, '.')) { if (strpos($name, '.')) {
list($this->params['plugin'], $this->params['name']) = explode('.', $name); list($this->params['plugin'], $splitName) = pluginSplit($name);
$name = $this->params['name']; $name = $this->params['name'] = $splitName;
} }
if ($name) { if ($name) {

View file

@ -254,11 +254,7 @@ class Shell extends Object {
$this->modelClass = $modelClassName; $this->modelClass = $modelClassName;
foreach ($uses as $modelClass) { foreach ($uses as $modelClass) {
$plugin = null; list($plugin, $modelClass) = pluginSplit($modelClass, true);
if (strpos($modelClass, '.') !== false) {
list($plugin, $modelClass) = explode('.', $modelClass);
$plugin = $plugin . '.';
}
if (PHP5) { if (PHP5) {
$this->{$modelClass} = ClassRegistry::init($plugin . $modelClass); $this->{$modelClass} = ClassRegistry::init($plugin . $modelClass);
} else { } else {

View file

@ -170,11 +170,8 @@ class Cache {
* @static * @static
*/ */
function engine($name = 'File', $settings = array()) { function engine($name = 'File', $settings = array()) {
$plugin = null;
$class = $name; $class = $name;
if (strpos($name, '.') !== false) { list($plugin, $class) = pluginSplit($name);
list($plugin, $class) = explode('.', $name);
}
$cacheClass = $class . 'Engine'; $cacheClass = $class . 'Engine';
$_this =& Cache::getInstance(); $_this =& Cache::getInstance();
if (!isset($_this->_Engine[$name])) { if (!isset($_this->_Engine[$name])) {

View file

@ -100,10 +100,8 @@ class CakeLog {
* @access protected * @access protected
*/ */
function _getLogger($loggerName) { function _getLogger($loggerName) {
$plugin = null; list($plugin, $loggerName) = pluginSplit($loggerName);
if (strpos($loggerName, '.') !== false) {
list($plugin, $loggerName) = explode('.', $loggerName);
}
if ($plugin) { if ($plugin) {
App::import('Lib', $plugin . '.log/' . $loggerName); App::import('Lib', $plugin . '.log/' . $loggerName);
} else { } else {

View file

@ -118,12 +118,12 @@ class ClassRegistry {
foreach ($objects as $key => $settings) { foreach ($objects as $key => $settings) {
if (is_array($settings)) { if (is_array($settings)) {
$plugin = $pluginPath = null; $pluginPath = null;
$settings = array_merge($defaults, $settings); $settings = array_merge($defaults, $settings);
$class = $settings['class']; $class = $settings['class'];
if (strpos($class, '.') !== false) { list($plugin, $class) = pluginSplit($class);
list($plugin, $class) = explode('.', $class); if ($plugin) {
$pluginPath = $plugin . '.'; $pluginPath = $plugin . '.';
} }

View file

@ -206,14 +206,14 @@ class Configure extends Object {
* @access public * @access public
*/ */
function load($fileName) { function load($fileName) {
$found = $pluginPath = false; $found = $plugin = $pluginPath = false;
if (strpos($fileName, '.') !== false) { list($plugin, $fileName) = pluginSplit($fileName);
$plugin = explode('.', $fileName, 2); if ($plugin) {
$pluginPath = App::pluginPath($plugin[0]); $pluginPath = App::pluginPath($plugin);
} }
if ($pluginPath && file_exists($pluginPath . 'config' . DS . $plugin[1] . '.php')) { if ($pluginPath && file_exists($pluginPath . 'config' . DS . $fileName . '.php')) {
include($pluginPath . 'config' . DS . $plugin[1] . '.php'); include($pluginPath . 'config' . DS . $fileName . '.php');
$found = true; $found = true;
} elseif (file_exists(CONFIGS . $fileName . '.php')) { } elseif (file_exists(CONFIGS . $fileName . '.php')) {
include(CONFIGS . $fileName . '.php'); include(CONFIGS . $fileName . '.php');
@ -266,7 +266,7 @@ class Configure extends Object {
* Used to write a config file to disk. * Used to write a config file to disk.
* *
* {{{ * {{{
* Configure::store('Model', 'class.paths', array('Users' => array( * Configure::store('Model', 'class_paths', array('Users' => array(
* 'path' => 'users', 'plugin' => true * 'path' => 'users', 'plugin' => true
* ))); * )));
* }}} * }}}

View file

@ -189,16 +189,8 @@ class Component extends Object {
$normal = Set::merge(array('Session' => null), $normal); $normal = Set::merge(array('Session' => null), $normal);
} }
foreach ((array)$normal as $component => $config) { foreach ((array)$normal as $component => $config) {
$plugin = null; $plugin = isset($this->__controllerVars['plugin']) ? $this->__controllerVars['plugin'] . '.' : null;
list($plugin, $component) = pluginSplit($component, true, $plugin);
if (isset($this->__controllerVars['plugin'])) {
$plugin = $this->__controllerVars['plugin'] . '.';
}
if (strpos($component, '.') !== false) {
list($plugin, $component) = explode('.', $component);
$plugin = $plugin . '.';
}
$componentCn = $component . 'Component'; $componentCn = $component . 'Component';
if (!class_exists($componentCn)) { if (!class_exists($componentCn)) {

View file

@ -46,9 +46,7 @@ class AclComponent extends Object {
$name = Inflector::camelize(strtolower(Configure::read('Acl.classname'))); $name = Inflector::camelize(strtolower(Configure::read('Acl.classname')));
if (!class_exists($name)) { if (!class_exists($name)) {
if (App::import('Component', $name)) { if (App::import('Component', $name)) {
if (strpos($name, '.') !== false) { list($plugin, $name) = pluginSplit($name);
list($plugin, $name) = explode('.', $name);
}
$name .= 'Component'; $name .= 'Component';
} else { } else {
trigger_error(sprintf(__('Could not find %s.', true), $name), E_USER_WARNING); trigger_error(sprintf(__('Could not find %s.', true), $name), E_USER_WARNING);

View file

@ -391,9 +391,7 @@ class EmailComponent extends Object{
$viewClass = $this->Controller->view; $viewClass = $this->Controller->view;
if ($viewClass != 'View') { if ($viewClass != 'View') {
if (strpos($viewClass, '.') !== false) { list($plugin, $viewClass) = pluginSplit($viewClass);
list($plugin, $viewClass) = explode('.', $viewClass);
}
$viewClass = $viewClass . 'View'; $viewClass = $viewClass . 'View';
App::import('View', $this->Controller->view); App::import('View', $this->Controller->view);
} }

View file

@ -528,11 +528,7 @@ class Controller extends Object {
$plugin = $this->plugin . '.'; $plugin = $this->plugin . '.';
} }
} }
list($plugin, $modelClass) = pluginSplit($modelClass, true, $plugin);
if (strpos($modelClass, '.') !== false) {
list($plugin, $modelClass) = explode('.', $modelClass);
$plugin = $plugin . '.';
}
if ($this->persistModel === true) { if ($this->persistModel === true) {
$cached = $this->_persist($modelClass, null, $object); $cached = $this->_persist($modelClass, null, $object);
@ -808,9 +804,7 @@ class Controller extends Object {
$viewClass = $this->view; $viewClass = $this->view;
if ($this->view != 'View') { if ($this->view != 'View') {
if (strpos($viewClass, '.') !== false) { list($plugin, $viewClass) = pluginSplit($viewClass);
list($plugin, $viewClass) = explode('.', $viewClass);
}
$viewClass = $viewClass . 'View'; $viewClass = $viewClass . 'View';
App::import('View', $this->view); App::import('View', $this->view);
} }
@ -1003,9 +997,8 @@ class Controller extends Object {
if (is_string($object)) { if (is_string($object)) {
$assoc = null; $assoc = null;
if (strpos($object, '.') !== false) { if (strpos($object, '.') !== false) {
list($object, $assoc) = explode('.', $object); list($object, $assoc) = pluginSplit($object);
} }
if ($assoc && isset($this->{$object}->{$assoc})) { if ($assoc && isset($this->{$object}->{$assoc})) {

View file

@ -641,21 +641,16 @@ class Model extends Overloadable {
if (strpos($assoc, '.') !== false) { if (strpos($assoc, '.') !== false) {
$value = $this->{$type}[$assoc]; $value = $this->{$type}[$assoc];
unset($this->{$type}[$assoc]); unset($this->{$type}[$assoc]);
list($plugin, $assoc) = explode('.', $assoc); list($plugin, $assoc) = pluginSplit($assoc, true);
$this->{$type}[$assoc] = $value; $this->{$type}[$assoc] = $value;
$plugin = $plugin . '.';
} }
} }
$className = $assoc; $className = $assoc;
if (isset($value['className']) && !empty($value['className'])) { if (!empty($value['className'])) {
$className = $value['className']; list($plugin, $className) = pluginSplit($value['className'], true);
if (strpos($className, '.') !== false) {
list($plugin, $className) = explode('.', $className);
$plugin = $plugin . '.';
$this->{$type}[$assoc]['className'] = $className; $this->{$type}[$assoc]['className'] = $className;
} }
}
$this->__constructLinkedModel($assoc, $plugin . $className); $this->__constructLinkedModel($assoc, $plugin . $className);
} }
$this->__generateAssociation($type); $this->__generateAssociation($type);
@ -753,13 +748,8 @@ class Model extends Overloadable {
if (is_array($joinClass)) { if (is_array($joinClass)) {
$joinClass = key($joinClass); $joinClass = key($joinClass);
} }
$plugin = null; list($plugin, $joinClass) = pluginSplit($joinClass, true);
if (strpos($joinClass, '.') !== false) {
list($plugin, $joinClass) = explode('.', $joinClass);
$plugin = $plugin . '.';
$this->{$type}[$assocKey]['with'] = $joinClass; $this->{$type}[$assocKey]['with'] = $joinClass;
}
if (!ClassRegistry::isKeySet($joinClass) && $dynamicWith === true) { if (!ClassRegistry::isKeySet($joinClass) && $dynamicWith === true) {
$this->{$joinClass} = new AppModel(array( $this->{$joinClass} = new AppModel(array(

View file

@ -279,10 +279,7 @@ class BehaviorCollection extends Object {
* @access public * @access public
*/ */
function attach($behavior, $config = array()) { function attach($behavior, $config = array()) {
$name = $behavior; list($plugin, $name) = pluginSplit($behavior);
if (strpos($behavior, '.')) {
list($plugin, $name) = explode('.', $behavior, 2);
}
$class = $name . 'Behavior'; $class = $name . 'Behavior';
if (!App::import('Behavior', $behavior)) { if (!App::import('Behavior', $behavior)) {

View file

@ -87,9 +87,8 @@ class JsHelper extends AppHelper {
$className = $settings; $className = $settings;
} }
$engineName = $className; $engineName = $className;
if (strpos($className, '.') !== false) { list($plugin, $className) = pluginSplit($className);
list($plugin, $className) = explode('.', $className);
}
$this->__engineName = $className . 'Engine'; $this->__engineName = $className . 'Engine';
$engineClass = $engineName . 'Engine'; $engineClass = $engineName . 'Engine';
$this->helpers[] = $engineClass; $this->helpers[] = $engineClass;

View file

@ -750,18 +750,14 @@ class View extends Object {
$options = $helper; $options = $helper;
$helper = $i; $helper = $i;
} }
$plugin = $this->plugin; list($plugin, $helper) = pluginSplit($helper, true, $this->plugin);
if (strpos($helper, '.') !== false) {
list($plugin, $helper) = explode('.', $helper);
}
$helperCn = $helper . 'Helper'; $helperCn = $helper . 'Helper';
if (!isset($loaded[$helper])) { if (!isset($loaded[$helper])) {
if (!class_exists($helperCn)) { if (!class_exists($helperCn)) {
$isLoaded = false; $isLoaded = false;
if (!is_null($plugin)) { if (!is_null($plugin)) {
$isLoaded = App::import('Helper', $plugin . '.' . $helper); $isLoaded = App::import('Helper', $plugin . $helper);
} }
if (!$isLoaded) { if (!$isLoaded) {
if (!App::import('Helper', $helper)) { if (!App::import('Helper', $helper)) {

View file

@ -262,9 +262,9 @@ class ConfigureTest extends CakeTestCase {
$this->assertEqual($config, $expected); $this->assertEqual($config, $expected);
$expected = array('data' => array('first' => 'value', 'second' => 'value2')); $expected = array('data' => array('first' => 'value', 'second' => 'value2'));
Configure::store('AnotherExample', 'test.config', $expected); Configure::store('AnotherExample', 'test_config', $expected);
Configure::load('test.config'); Configure::load('test_config');
$config = Configure::read('AnotherExample'); $config = Configure::read('AnotherExample');
$this->assertEqual($config, $expected); $this->assertEqual($config, $expected);
} }