mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge branch '1.3' of git://github.com/cakephp/cakephp1x into 1.3
This commit is contained in:
commit
07870bacfb
5 changed files with 108 additions and 49 deletions
|
@ -61,14 +61,6 @@ class Dispatcher extends Object {
|
|||
*/
|
||||
var $here = false;
|
||||
|
||||
/**
|
||||
* Plugin being served (if any)
|
||||
*
|
||||
* @var string
|
||||
* @access public
|
||||
*/
|
||||
var $plugin = null;
|
||||
|
||||
/**
|
||||
* the params for this request
|
||||
*
|
||||
|
@ -159,7 +151,7 @@ class Dispatcher extends Object {
|
|||
$controller->base = $this->base;
|
||||
$controller->here = $this->here;
|
||||
$controller->webroot = $this->webroot;
|
||||
$controller->plugin = $this->plugin;
|
||||
$controller->plugin = isset($this->params['plugin']) ? $this->params['plugin'] : null;
|
||||
$controller->params =& $this->params;
|
||||
$controller->action =& $this->params['action'];
|
||||
$controller->passedArgs = array_merge($this->params['pass'], $this->params['named']);
|
||||
|
@ -399,16 +391,8 @@ class Dispatcher extends Object {
|
|||
'pass' => array_merge($pass, $params['pass']),
|
||||
'named' => array_merge($named, $params['named'])
|
||||
));
|
||||
$this->plugin = $params['plugin'];
|
||||
} else {
|
||||
$params['plugin'] = $params['controller'];
|
||||
$params['controller'] = $params['action'];
|
||||
if (isset($params['pass'][0])) {
|
||||
$params['action'] = $params['pass'][0];
|
||||
array_shift($params['pass']);
|
||||
} else {
|
||||
$params['action'] = null;
|
||||
}
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
@ -420,19 +404,15 @@ class Dispatcher extends Object {
|
|||
* @return mixed name of controller if not loaded, or object if loaded
|
||||
* @access private
|
||||
*/
|
||||
function &__getController($params = null) {
|
||||
if (!is_array($params)) {
|
||||
$original = $params = $this->params;
|
||||
}
|
||||
function &__getController() {
|
||||
$original = $params = $this->params;
|
||||
|
||||
$controller = false;
|
||||
$ctrlClass = $this->__loadController($params);
|
||||
if (!$ctrlClass) {
|
||||
if (!isset($params['plugin'])) {
|
||||
$params = $this->_restructureParams($params);
|
||||
} else {
|
||||
if (empty($original['pass']) && $original['action'] == 'index') {
|
||||
$params['action'] = null;
|
||||
}
|
||||
$params = $this->_restructureParams($params, true);
|
||||
}
|
||||
$ctrlClass = $this->__loadController($params);
|
||||
|
@ -441,15 +421,13 @@ class Dispatcher extends Object {
|
|||
return $controller;
|
||||
}
|
||||
} else {
|
||||
$params = $this->params;
|
||||
if (!isset($params['plugin'])) {
|
||||
$params = $this->_restructureParams($params);
|
||||
}
|
||||
}
|
||||
$name = $ctrlClass;
|
||||
$ctrlClass = $ctrlClass . 'Controller';
|
||||
$ctrlClass .= 'Controller';
|
||||
if (class_exists($ctrlClass)) {
|
||||
if (strtolower(get_parent_class($ctrlClass)) === strtolower($name . 'AppController') && empty($params['plugin'])) {
|
||||
$params = $this->_restructureParams($params);
|
||||
$params = $this->_restructureParams($params, true);
|
||||
}
|
||||
$this->params = $params;
|
||||
$controller =& new $ctrlClass();
|
||||
}
|
||||
|
@ -466,10 +444,9 @@ class Dispatcher extends Object {
|
|||
function __loadController($params) {
|
||||
$pluginName = $pluginPath = $controller = null;
|
||||
if (!empty($params['plugin'])) {
|
||||
$this->plugin = $params['plugin'];
|
||||
$pluginName = Inflector::camelize($params['plugin']);
|
||||
$pluginPath = $pluginName . '.';
|
||||
$this->params['controller'] = $this->plugin;
|
||||
$this->params['controller'] = $params['plugin'];
|
||||
$controller = $pluginName;
|
||||
}
|
||||
if (!empty($params['controller'])) {
|
||||
|
|
|
@ -272,7 +272,7 @@ class Router {
|
|||
$self->__prefixes[] = $defaults['prefix'];
|
||||
$self->__prefixes = array_keys(array_flip($self->__prefixes));
|
||||
}
|
||||
$defaults += array('action' => 'index', 'plugin' => null, 'controller' => null);
|
||||
$defaults += array('action' => 'index', 'plugin' => null);
|
||||
$routeClass = 'CakeRoute';
|
||||
if (isset($options['routeClass'])) {
|
||||
$routeClass = $options['routeClass'];
|
||||
|
@ -424,7 +424,11 @@ class Router {
|
|||
if (!$self->__defaultsMapped && $self->__connectDefaults) {
|
||||
$self->__connectDefaultRoutes();
|
||||
}
|
||||
$out = array('pass' => array(), 'named' => array());
|
||||
$out = array(
|
||||
'pass' => array(),
|
||||
'named' => array(),
|
||||
'controller' => null,
|
||||
);
|
||||
$r = $ext = null;
|
||||
|
||||
if (ini_get('magic_quotes_gpc') === '1') {
|
||||
|
|
|
@ -33,15 +33,17 @@ class MediaView extends View {
|
|||
'cpio' => 'application/x-cpio', 'cpt' => 'application/mac-compactpro', 'csh' => 'application/x-csh',
|
||||
'csv' => 'application/csv', 'dcr' => 'application/x-director', 'dir' => 'application/x-director',
|
||||
'dms' => 'application/octet-stream', 'doc' => 'application/msword', 'drw' => 'application/drafting',
|
||||
'dvi' => 'application/x-dvi', 'dwg' => 'application/acad', 'dxf' => 'application/dxf', 'dxr' => 'application/x-director',
|
||||
'eps' => 'application/postscript', 'exe' => 'application/octet-stream', 'ez' => 'application/andrew-inset',
|
||||
'dvi' => 'application/x-dvi', 'dwg' => 'application/acad', 'dxf' => 'application/dxf',
|
||||
'dxr' => 'application/x-director', 'eot' => 'application/vnd.ms-fontobject', 'eps' => 'application/postscript',
|
||||
'exe' => 'application/octet-stream', 'ez' => 'application/andrew-inset',
|
||||
'flv' => 'video/x-flv', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip',
|
||||
'bz2' => 'application/x-bzip', '7z' => 'application/x-7z-compressed', 'hdf' => 'application/x-hdf',
|
||||
'hqx' => 'application/mac-binhex40', 'ico' => 'image/vnd.microsoft.icon', 'ips' => 'application/x-ipscript',
|
||||
'ipx' => 'application/x-ipix', 'js' => 'application/x-javascript', 'latex' => 'application/x-latex',
|
||||
'lha' => 'application/octet-stream', 'lsp' => 'application/x-lisp', 'lzh' => 'application/octet-stream',
|
||||
'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'mif' => 'application/vnd.mif',
|
||||
'ms' => 'application/x-troff-ms', 'nc' => 'application/x-netcdf', 'oda' => 'application/oda', 'pdf' => 'application/pdf',
|
||||
'ms' => 'application/x-troff-ms', 'nc' => 'application/x-netcdf', 'oda' => 'application/oda',
|
||||
'otf' => 'font/otf', 'pdf' => 'application/pdf',
|
||||
'pgn' => 'application/x-chess-pgn', 'pot' => 'application/mspowerpoint', 'pps' => 'application/mspowerpoint',
|
||||
'ppt' => 'application/mspowerpoint', 'ppz' => 'application/mspowerpoint', 'pre' => 'application/x-freelance',
|
||||
'prt' => 'application/pro_eng', 'ps' => 'application/postscript', 'roff' => 'application/x-troff',
|
||||
|
@ -55,7 +57,8 @@ class MediaView extends View {
|
|||
'swf' => 'application/x-shockwave-flash', 't' => 'application/x-troff',
|
||||
'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex',
|
||||
'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', 'tr' => 'application/x-troff',
|
||||
'tsp' => 'application/dsptype', 'unv' => 'application/i-deas', 'ustar' => 'application/x-ustar',
|
||||
'tsp' => 'application/dsptype', 'ttf' => 'font/ttf',
|
||||
'unv' => 'application/i-deas', 'ustar' => 'application/x-ustar',
|
||||
'vcd' => 'application/x-cdlink', 'vda' => 'application/vda', 'xlc' => 'application/vnd.ms-excel',
|
||||
'xll' => 'application/vnd.ms-excel', 'xlm' => 'application/vnd.ms-excel', 'xls' => 'application/vnd.ms-excel',
|
||||
'xlw' => 'application/vnd.ms-excel', 'zip' => 'application/zip', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff',
|
||||
|
|
|
@ -1599,11 +1599,18 @@ class DispatcherTest extends CakeTestCase {
|
|||
$_SERVER['PHP_SELF'] = '/cake/repo/branches/1.2.x.x/index.php';
|
||||
|
||||
Router::reload();
|
||||
Router::connect('/my_plugin/:controller/:action/*', array('plugin'=>'my_plugin'));
|
||||
Router::connect('/my_plugin/:controller/:action/*', array('plugin' => 'my_plugin'));
|
||||
|
||||
$Dispatcher =& new TestDispatcher();
|
||||
$Dispatcher->base = false;
|
||||
|
||||
$url = 'my_plugin/';
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$this->assertEqual($controller->params['controller'], 'my_plugin');
|
||||
$this->assertEqual($controller->params['plugin'], 'my_plugin');
|
||||
$this->assertEqual($controller->params['action'], 'index');
|
||||
$this->assertFalse(isset($controller->params['pass'][0]));
|
||||
|
||||
$url = 'my_plugin/my_plugin/add';
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$this->assertFalse(isset($controller->params['pass'][0]));
|
||||
|
@ -1620,7 +1627,6 @@ class DispatcherTest extends CakeTestCase {
|
|||
|
||||
$url = 'my_plugin/add';
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
|
||||
$this->assertFalse(isset($controller->params['pass'][0]));
|
||||
|
||||
$Dispatcher =& new TestDispatcher();
|
||||
|
@ -1628,14 +1634,48 @@ class DispatcherTest extends CakeTestCase {
|
|||
|
||||
$url = 'my_plugin/add/0';
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$this->assertIdentical('0',$controller->params['pass'][0]);
|
||||
$this->assertEqual($controller->params['controller'], 'my_plugin');
|
||||
$this->assertEqual($controller->params['plugin'], 'my_plugin');
|
||||
$this->assertEqual($controller->params['action'], 'add');
|
||||
$this->assertIdentical('0', $controller->params['pass'][0]);
|
||||
|
||||
$Dispatcher =& new TestDispatcher();
|
||||
$Dispatcher->base = false;
|
||||
|
||||
$url = 'my_plugin/add/1';
|
||||
$controller = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$this->assertIdentical('1',$controller->params['pass'][0]);
|
||||
|
||||
$this->assertEqual($controller->params['controller'], 'my_plugin');
|
||||
$this->assertEqual($controller->params['plugin'], 'my_plugin');
|
||||
$this->assertEqual($controller->params['action'], 'add');
|
||||
$this->assertIdentical('1', $controller->params['pass'][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* test plugin shortcut urls with controllers that need to be loaded,
|
||||
* the above test uses a controller that has already been included.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testPluginShortCutUrlsWithControllerThatNeedsToBeLoaded() {
|
||||
$loaded = class_exists('TestPluginController', false);
|
||||
if ($this->skipIf($loaded, 'TestPluginController already loaded, this test will always pass, skipping %s')) {
|
||||
return true;
|
||||
}
|
||||
Router::reload();
|
||||
App::build(array(
|
||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
||||
), true);
|
||||
$Dispatcher =& new TestDispatcher();
|
||||
$Dispatcher->base = false;
|
||||
|
||||
$url = '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]));
|
||||
App::build();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1711,7 +1751,7 @@ class DispatcherTest extends CakeTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* undocumented function
|
||||
* Test dispatching into the TestPlugin in the test_app
|
||||
*
|
||||
* @return void
|
||||
* @access public
|
||||
|
@ -1721,6 +1761,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
App::build(array(
|
||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
||||
));
|
||||
App::objects('plugin', null, false);
|
||||
Router::reload();
|
||||
Router::parse('/');
|
||||
|
||||
$url = '/test_plugin/tests/index';
|
||||
$result = $Dispatcher->dispatch($url, array('return' => 1));
|
||||
$this->assertTrue(class_exists('TestsController'));
|
||||
|
@ -1728,6 +1772,10 @@ class DispatcherTest extends CakeTestCase {
|
|||
$this->assertTrue(class_exists('OtherComponentComponent'));
|
||||
$this->assertTrue(class_exists('PluginsComponentComponent'));
|
||||
|
||||
$this->assertEqual($result->params['controller'], 'tests');
|
||||
$this->assertEqual($result->params['plugin'], 'test_plugin');
|
||||
$this->assertEqual($result->params['action'], 'index');
|
||||
|
||||
App::build();
|
||||
}
|
||||
|
||||
|
|
|
@ -508,6 +508,16 @@ class RouterTest extends CakeTestCase {
|
|||
$result = Router::url(array('plugin' => 'shows', 'controller' => 'shows', 'action' => 'calendar', 'year' => 2007, 'month' => 10, 'min-forestilling'));
|
||||
$expected = '/kalender/10/2007/min-forestilling';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
Router::reload();
|
||||
Router::connect('/:controller/:action/*', array(), array(
|
||||
'controller' => 'source|wiki|commits|tickets|comments|view',
|
||||
'action' => 'branches|history|branch|logs|view|start|add|edit|modify'
|
||||
));
|
||||
Router::defaults(false);
|
||||
$result = Router::parse('/foo/bar');
|
||||
$expected = array('pass' => array(), 'named' => array(), 'controller' => null);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1844,7 +1854,7 @@ class RouterTest extends CakeTestCase {
|
|||
Router::connect('/government', $url);
|
||||
Router::parse('/government');
|
||||
$route =& Router::currentRoute();
|
||||
$this->assertEqual(array_merge($url, array('plugin' => false)), $route->defaults);
|
||||
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
|
||||
}
|
||||
/**
|
||||
* testRequestRoute
|
||||
|
@ -1857,21 +1867,21 @@ class RouterTest extends CakeTestCase {
|
|||
Router::connect('/government', $url);
|
||||
Router::parse('/government');
|
||||
$route =& Router::requestRoute();
|
||||
$this->assertEqual(array_merge($url, array('plugin' => false)), $route->defaults);
|
||||
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
|
||||
|
||||
// test that the first route is matched
|
||||
$newUrl = array('controller' => 'products', 'action' => 'display', 6);
|
||||
Router::connect('/government', $url);
|
||||
Router::parse('/government');
|
||||
$route =& Router::requestRoute();
|
||||
$this->assertEqual(array_merge($url, array('plugin' => false)), $route->defaults);
|
||||
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
|
||||
|
||||
// test that an unmatched route does not change the current route
|
||||
$newUrl = array('controller' => 'products', 'action' => 'display', 6);
|
||||
Router::connect('/actor', $url);
|
||||
Router::parse('/government');
|
||||
$route =& Router::requestRoute();
|
||||
$this->assertEqual(array_merge($url, array('plugin' => false)), $route->defaults);
|
||||
$this->assertEqual(array_merge($url, array('plugin' => null)), $route->defaults);
|
||||
}
|
||||
/**
|
||||
* testGetParams
|
||||
|
@ -1884,7 +1894,7 @@ class RouterTest extends CakeTestCase {
|
|||
$params = array('param1' => '1', 'param2' => '2');
|
||||
Router::setRequestInfo(array($params, $paths));
|
||||
$expected = array(
|
||||
'plugin' => false, 'controller' => false, 'action' => false,
|
||||
'plugin' => null, 'controller' => false, 'action' => false,
|
||||
'param1' => '1', 'param2' => '2'
|
||||
);
|
||||
$this->assertEqual(Router::getparams(), $expected);
|
||||
|
@ -1896,7 +1906,7 @@ class RouterTest extends CakeTestCase {
|
|||
|
||||
$params = array('controller' => 'pages', 'action' => 'display');
|
||||
Router::setRequestInfo(array($params, $paths));
|
||||
$expected = array('plugin' => false, 'controller' => 'pages', 'action' => 'display');
|
||||
$expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display');
|
||||
$this->assertEqual(Router::getparams(), $expected);
|
||||
$this->assertEqual(Router::getparams(true), $expected);
|
||||
}
|
||||
|
@ -2125,6 +2135,23 @@ class CakeRouteTestCase extends CakeTestCase {
|
|||
'extra' => null,
|
||||
);
|
||||
$this->assertEqual($route->defaults, $expected);
|
||||
|
||||
$route =& new CakeRoute(
|
||||
'/:controller/:action/*',
|
||||
array('project' => false),
|
||||
array(
|
||||
'controller' => 'source|wiki|commits|tickets|comments|view',
|
||||
'action' => 'branches|history|branch|logs|view|start|add|edit|modify'
|
||||
)
|
||||
);
|
||||
$this->assertFalse($route->parse('/chaw_test/wiki'));
|
||||
|
||||
$result = $route->compile();
|
||||
$this->assertNoPattern($result, '/some_project/source');
|
||||
$this->assertPattern($result, '/source/view');
|
||||
$this->assertPattern($result, '/source/view/other/params');
|
||||
$this->assertNoPattern($result, '/chaw_test/wiki');
|
||||
$this->assertNoPattern($result, '/source/wierd_action');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue