Merge remote-tracking branch 'origin/2.0' into 2.0-class-loading

This commit is contained in:
Jose Lorenzo Rodriguez 2011-03-10 23:17:54 -04:30
commit 90b01b7ec3
10 changed files with 42 additions and 60 deletions

View file

@ -22,10 +22,8 @@ class CakeErrorController extends AppController {
* @access public
* @return void
*/
function __construct() {
parent::__construct();
$this->_set(Router::getPaths());
$this->request = Router::getRequest(false);
function __construct($request = null) {
parent::__construct($request);
$this->constructClasses();
$this->Components->trigger('initialize', array(&$this));
$this->_set(array('cacheAction' => false, 'viewPath' => 'errors'));

View file

@ -147,9 +147,9 @@ class ExceptionRenderer {
if ($__previousError != $exception) {
$__previousError = $exception;
$controller = new CakeErrorController();
$controller = new CakeErrorController(Router::getRequest(false));
} else {
$controller = new Controller();
$controller = new Controller(Router::getRequest(false));
$controller->viewPath = 'errors';
}
return $controller;

View file

@ -40,14 +40,6 @@ App::uses('Debugger', 'Utility');
*/
class Dispatcher {
/**
* The request object
*
* @var CakeRequest
* @access public
*/
public $request = null;
/**
* Response object used for asset/cached responses.
*
@ -90,18 +82,16 @@ class Dispatcher {
return;
}
$this->request = $this->parseParams($request, $additionalParams);
$controller = $this->_getController($this->request);
$request = $this->parseParams($request, $additionalParams);
Router::setRequestInfo($request);
$controller = $this->_getController($request);
if (!is_object($controller)) {
Router::setRequestInfo($request);
if (!($controller instanceof Controller)) {
throw new MissingControllerException(array(
'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",
@ -123,10 +113,8 @@ class Dispatcher {
$privateAction = $request->params['action'][0] === '_';
$prefixes = Router::prefixes();
if (!empty($prefixes)) {
if (isset($request->params['prefix'])) {
$request->params['action'] = $request->params['prefix'] . '_' . $request->params['action'];
} elseif (strpos($request->params['action'], '_') > 0) {
if (!$privateAction && !empty($prefixes)) {
if (empty($request->params['prefix']) && strpos($request->params['action'], '_') > 0) {
list($prefix, $action) = explode('_', $request->params['action']);
$privateAction = in_array($prefix, $prefixes);
}
@ -303,13 +291,13 @@ class Dispatcher {
if (($isCss && empty($filters['css'])) || ($isJs && empty($filters['js']))) {
$this->response->statusCode(404);
$this->response->send();
return $this->_stop();
return true;
} elseif ($isCss) {
include WWW_ROOT . DS . $filters['css'];
$this->_stop();
return true;
} elseif ($isJs) {
include WWW_ROOT . DS . $filters['js'];
$this->_stop();
return true;
}
$controller = null;
$pathSegments = explode('.', $url);

View file

@ -503,6 +503,9 @@ class Router {
break;
}
}
if (isset($out['prefix'])) {
$out['action'] = $out['prefix'] . '_' . $out['action'];
}
if (!empty($ext) && !isset($out['url']['ext'])) {
$out['url']['ext'] = $ext;

View file

@ -39,7 +39,7 @@ App::uses('CakeRequest', 'Network');
* {{{
* class ExampleController extends AppController {
* function download () {
* $this->view = 'Media';
* $this->viewClass = 'Media';
* $params = array(
* 'id' => 'example.zip',
* 'name' => 'example',

View file

@ -23,7 +23,7 @@ App::uses('View', 'View');
*
* Allows the creation of multiple themes to be used in an app. Theme views are regular view files
* that can provide unique HTML and static assets. If theme views are not found for the current view
* the default app view files will be used. You can set `$this->theme` and `$this->view = 'Theme'`
* the default app view files will be used. You can set `$this->theme` and `$this->viewClass = 'Theme'`
* in your Controller to use the ThemeView.
*
* Example of theme path with `$this->theme = 'super_hot';` Would be `app/views/themed/super_hot/posts`

View file

@ -148,6 +148,15 @@ class AuthTestController extends Controller {
function admin_login() {
}
/**
* admin_add method
*
* @access public
* @return void
*/
function admin_add() {
}
/**
* logout method
*
@ -917,6 +926,7 @@ class AuthTest extends CakeTestCase {
$this->Auth->request->addParams(Router::parse($url));
$this->Auth->request->query['url'] = ltrim($url, '/');
$this->Auth->request->base = '';
Router::setRequestInfo($this->Auth->request);
$this->Auth->initialize($this->Controller);

View file

@ -59,15 +59,6 @@ class TestDispatcher extends Dispatcher {
return $controller;
}
/**
* _stop method
*
* @return void
*/
protected function _stop() {
$this->stopped = true;
return true;
}
}
/**
@ -1356,9 +1347,8 @@ class DispatcherTest extends CakeTestCase {
));
ob_start();
$Dispatcher->asset('ccss/cake.generic.css');
$this->assertTrue($Dispatcher->asset('ccss/cake.generic.css'));
$result = ob_get_clean();
$this->assertTrue($Dispatcher->stopped);
}
/**
@ -1373,28 +1363,17 @@ class DispatcherTest extends CakeTestCase {
'js' => '',
'css' => ''
));
$Dispatcher->asset('theme/test_theme/ccss/cake.generic.css');
$this->assertTrue($Dispatcher->stopped);
$this->assertTrue($Dispatcher->asset('theme/test_theme/ccss/cake.generic.css'));
$Dispatcher->stopped = false;
$Dispatcher->asset('theme/test_theme/cjs/debug_kit.js');
$this->assertTrue($Dispatcher->stopped);
$this->assertTrue($Dispatcher->asset('theme/test_theme/cjs/debug_kit.js'));
$Dispatcher->stopped = false;
$Dispatcher->asset('test_plugin/ccss/cake.generic.css');
$this->assertTrue($Dispatcher->stopped);
$this->assertTrue($Dispatcher->asset('test_plugin/ccss/cake.generic.css'));
$Dispatcher->stopped = false;
$Dispatcher->asset('test_plugin/cjs/debug_kit.js');
$this->assertTrue($Dispatcher->stopped);
$this->assertTrue($Dispatcher->asset('test_plugin/cjs/debug_kit.js'));
$Dispatcher->stopped = false;
$Dispatcher->asset('css/ccss/debug_kit.css');
$this->assertFalse($Dispatcher->stopped);
$this->assertFalse($Dispatcher->asset('css/ccss/debug_kit.css'));
$Dispatcher->stopped = false;
$Dispatcher->asset('js/cjs/debug_kit.js');
$this->assertFalse($Dispatcher->stopped);
$this->assertFalse($Dispatcher->asset('js/cjs/debug_kit.js'));
}
/**
* testFullPageCachingDispatch method

View file

@ -360,7 +360,7 @@ class ExceptionRendererTest extends CakeTestCase {
$result = ob_get_clean();
$this->assertPattern('/<h2>Custom message<\/h2>/', $result);
$this->assertPattern("/<strong>'\/posts\/view\/1000'<\/strong>/", $result);
$this->assertPattern("/<strong>'.*?\/posts\/view\/1000'<\/strong>/", $result);
}
/**

View file

@ -1878,7 +1878,7 @@ class RouterTest extends CakeTestCase {
);
$result = Router::parse('/admin/posts/');
$expected = array('pass' => array(), 'named' => array(), 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'admin' => true);
$expected = array('pass' => array(), 'named' => array(), 'prefix' => 'admin', 'plugin' => null, 'controller' => 'posts', 'action' => 'admin_index', 'admin' => true);
$this->assertEqual($result, $expected);
$result = Router::parse('/admin/posts');
@ -1912,7 +1912,7 @@ class RouterTest extends CakeTestCase {
);
$result = Router::parse('/members/posts/index');
$expected = array('pass' => array(), 'named' => array(), 'prefix' => 'members', 'plugin' => null, 'controller' => 'posts', 'action' => 'index', 'members' => true);
$expected = array('pass' => array(), 'named' => array(), 'prefix' => 'members', 'plugin' => null, 'controller' => 'posts', 'action' => 'members_index', 'members' => true);
$this->assertEqual($result, $expected);
$result = Router::url(array('members' => true, 'controller' => 'posts', 'action' =>'index', 'page' => 2));
@ -1942,6 +1942,10 @@ class RouterTest extends CakeTestCase {
$expected = '/company/users/login';
$this->assertEqual($result, $expected);
$result = Router::url(array('controller' => 'users', 'action' => 'company_login', 'company' => true));
$expected = '/company/users/login';
$this->assertEqual($result, $expected);
$request = new CakeRequest();
Router::setRequestInfo(
$request->addParams(array(