mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Refactoring loading of plugins.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5464 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b29366ddc0
commit
ea15f09288
3 changed files with 48 additions and 52 deletions
|
@ -320,15 +320,15 @@
|
|||
if ($name === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$parent = 'AppController';
|
||||
if (strpos($name, '.') !== false) {
|
||||
list($plugin, $name) = explode('.', $name);
|
||||
|
||||
$pluginAppController = Inflector::camelize($plugin . '_app_controller');
|
||||
$parent = Inflector::camelize($plugin . '_app_controller');
|
||||
$plugin = Inflector::underscore($plugin);
|
||||
$pluginAppControllerFile = APP . 'plugins' . DS . $plugin . DS . $plugin . '_app_controller.php';
|
||||
|
||||
if (!class_exists($pluginAppController)) {
|
||||
if (!class_exists($parent)) {
|
||||
if (file_exists($pluginAppControllerFile)) {
|
||||
require($pluginAppControllerFile);
|
||||
} else {
|
||||
|
@ -346,6 +346,7 @@
|
|||
}
|
||||
|
||||
if (!class_exists($name . 'Controller')) {
|
||||
|
||||
$name = Inflector::underscore($name);
|
||||
$file = APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $name . '_controller.php';
|
||||
|
||||
|
@ -365,7 +366,8 @@
|
|||
}
|
||||
|
||||
$className = $name . 'Controller';
|
||||
if (class_exists($className)) {
|
||||
|
||||
if (class_exists($className) && get_parent_class($className) == $parent) {
|
||||
return true;
|
||||
} else {
|
||||
$name = Inflector::underscore($className);
|
||||
|
@ -1629,4 +1631,4 @@
|
|||
}
|
||||
return $val2;
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -110,7 +110,7 @@ class Dispatcher extends Object {
|
|||
$missingAction = $missingView = $privateAction = false;
|
||||
|
||||
$this->base = $this->baseUrl();
|
||||
$controller = $this->__getController($this->params);
|
||||
$controller = $this->__getController();
|
||||
|
||||
if(!is_object($controller)) {
|
||||
if (preg_match('/([\\.]+)/', $controller)) {
|
||||
|
@ -473,7 +473,7 @@ class Dispatcher extends Object {
|
|||
$params = $this->params;
|
||||
}
|
||||
|
||||
$controller = $pluginPath = null;
|
||||
$pluginPath = $controller = $ctrlClass = null;
|
||||
|
||||
if (!empty($params['controller'])) {
|
||||
$controller = Inflector::camelize($params['controller']);
|
||||
|
@ -484,23 +484,29 @@ class Dispatcher extends Object {
|
|||
$this->plugin = $params['plugin'];
|
||||
$pluginPath = Inflector::camelize($this->plugin).'.';
|
||||
|
||||
if(!$controller) {
|
||||
$controller = Inflector::camelize($params['plugin']);
|
||||
$ctrlClass = $controller.'Controller';
|
||||
}
|
||||
}
|
||||
if ($pluginPath . $controller && loadController($pluginPath . $controller)) {
|
||||
$controller =& new $ctrlClass();
|
||||
} elseif ($continue){
|
||||
$this->params = $this->_restructureParams($params);
|
||||
$controller = $this->__getController($this->params, false);
|
||||
if(!class_exists($ctrlClass) && $this->plugin) {
|
||||
$controller = Inflector::camelize($params['plugin']);
|
||||
$ctrlClass = $controller.'Controller';
|
||||
$params = am($this->params, array('plugin'=> $params['plugin'], 'controller'=> $params['plugin']));
|
||||
}
|
||||
if(class_exists($ctrlClass)) {
|
||||
$controller =& new $ctrlClass();
|
||||
}
|
||||
} elseif ($continue == true){
|
||||
$params = $this->_restructureParams($params);
|
||||
$controller = $this->__getController($params, false);
|
||||
return $controller;
|
||||
}
|
||||
|
||||
if(!isset($ctrlClass)) {
|
||||
if(!$ctrlClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->params = $params;
|
||||
return $controller;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||
*/
|
||||
require_once CAKE.'dispatcher.php';
|
||||
require_once CAKE.'app_controller.php';
|
||||
|
||||
class TestDispatcher extends Dispatcher {
|
||||
|
||||
|
@ -78,7 +79,7 @@ class MyPluginController extends MyPluginAppController {
|
|||
}
|
||||
}
|
||||
|
||||
class SomePagesController extends MyPluginAppController {
|
||||
class SomePagesController extends AppController {
|
||||
|
||||
var $name = 'SomePages';
|
||||
var $uses = array();
|
||||
|
@ -92,7 +93,21 @@ class SomePagesController extends MyPluginAppController {
|
|||
}
|
||||
}
|
||||
|
||||
class TestDispatchPagesController extends Controller {
|
||||
class OtherPagesController extends MyPluginAppController {
|
||||
|
||||
var $name = 'OtherPages';
|
||||
var $uses = array();
|
||||
|
||||
function display($page = null) {
|
||||
return $page;
|
||||
}
|
||||
|
||||
function index() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class TestDispatchPagesController extends AppController {
|
||||
|
||||
var $name = 'TestDispatchPages';
|
||||
var $uses = array();
|
||||
|
@ -488,17 +503,16 @@ class DispatcherTest extends UnitTestCase {
|
|||
$dispatcher =& new TestDispatcher();
|
||||
$dispatcher->base = false;
|
||||
|
||||
$url = setUrl('/my_plugin/some_pages/index/param:value/param2:value2');
|
||||
$url = setUrl('/my_plugin/other_pages/index/param:value/param2:value2');
|
||||
|
||||
restore_error_handler();
|
||||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
|
||||
pr($dispatcher->params);
|
||||
$expected = 'my_plugin';
|
||||
$this->assertIdentical($expected, $controller->plugin);
|
||||
|
||||
$expected = 'SomePages';
|
||||
$expected = 'OtherPages';
|
||||
$this->assertIdentical($expected, $controller->name);
|
||||
|
||||
$expected = 'index';
|
||||
|
@ -507,7 +521,7 @@ class DispatcherTest extends UnitTestCase {
|
|||
$expected = array('param'=>'value', 'param2'=>'value2');
|
||||
$this->assertIdentical($expected, $controller->namedArgs);
|
||||
|
||||
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/some_pages/index/param:value/param2:value2';
|
||||
$expected = '/cake/repo/branches/1.2.x.x/my_plugin/other_pages/index/param:value/param2:value2';
|
||||
$this->assertIdentical($expected, $controller->here);
|
||||
|
||||
$expected = '/cake/repo/branches/1.2.x.x';
|
||||
|
@ -539,7 +553,7 @@ class DispatcherTest extends UnitTestCase {
|
|||
$this->assertIdentical($expected, $controller->action);
|
||||
}
|
||||
|
||||
function testAutomaticPluginPluginControllerDispatch() {
|
||||
function testAutomaticPluginControllerMissingActionDispatch() {
|
||||
$_POST = array();
|
||||
$_SERVER['DOCUMENT_ROOT'] = '';
|
||||
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
|
||||
|
@ -553,38 +567,12 @@ class DispatcherTest extends UnitTestCase {
|
|||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
|
||||
$expected = 'my_plugin';
|
||||
$this->assertIdentical($expected, $controller->plugin);
|
||||
|
||||
$expected = 'MyPlugin';
|
||||
$this->assertIdentical($expected, $controller->name);
|
||||
|
||||
$expected = 'index';
|
||||
$this->assertIdentical($expected, $controller->action);
|
||||
}
|
||||
|
||||
function testRouterPluginNullControllerDispatch() {
|
||||
$_POST = array();
|
||||
$_SERVER['DOCUMENT_ROOT'] = '';
|
||||
$_SERVER['SCRIPT_FILENAME'] = '/cake/repo/branches/1.2.x.x/app/webroot/index.php';
|
||||
|
||||
Router::reload();
|
||||
Router::connect('/my_plugin/:controller/:action/*', array('plugin'=> 'my_plugin'));
|
||||
$dispatcher =& new TestDispatcher();
|
||||
$dispatcher->base = false;
|
||||
|
||||
$url = setUrl('/my_plugin/param:value/param2:value2');
|
||||
restore_error_handler();
|
||||
@$controller = $dispatcher->dispatch($url, array('return'=> 1));
|
||||
set_error_handler('simpleTestErrorHandler');
|
||||
|
||||
$expected = 'missingController';
|
||||
$expected = 'missingAction';
|
||||
$this->assertIdentical($expected, $controller);
|
||||
}
|
||||
|
||||
|
||||
function tearDown() {
|
||||
$_GET = $this->_get;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
Loading…
Add table
Reference in a new issue