Fixes #4883 Duplicated component name

Removed bad test since AppController::beforeFilter() is now run when Controller::constructClasses() is called.
Fixed bug with App::import() not caching properly.
More performance changes

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7169 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-06-11 08:54:27 +00:00
parent 763800bf11
commit 8a30290862
9 changed files with 86 additions and 71 deletions

View file

@ -79,7 +79,7 @@ class FileEngine extends CacheEngine {
function init($settings = array()) {
parent::init(array_merge(array('engine' => 'File', 'path' => CACHE, 'prefix'=> 'cake_', 'lock'=> false, 'serialize'=> true), $settings));
if(!isset($this->__File)) {
App::import('File');
uses('file');
$this->__File =& new File($this->settings['path'] . DS . 'cake');
}
$this->settings['path'] = $this->__File->Folder->cd($this->settings['path']);

View file

@ -207,7 +207,7 @@ class Configure extends Object {
* @return array List of directories or files in directory
*/
function __list($path, $suffix = false, $extension = false) {
App::import('Folder');
uses('folder');
$items = array();
$Folder =& new Folder($path);
$contents = $Folder->read(false, true);
@ -276,7 +276,7 @@ class Configure extends Object {
if (!class_exists('Debugger')) {
require LIBS . 'debugger.php';
}
App::import('CakeLog');
uses('cake_log');
Configure::write('log', LOG_NOTICE);
} else {
error_reporting(0);
@ -538,7 +538,7 @@ class Configure extends Object {
}
if ($write === true) {
App::import('File');
uses('file');
$fileClass = new File($file);
if ($fileClass->writable()) {

View file

@ -324,7 +324,7 @@ class ErrorHandler extends Object {
function __outputMessage($template) {
$this->controller->render($template);
$this->controller->afterFilter();
e($this->controller->output);
echo $this->controller->output;
}
}
?>

View file

@ -331,7 +331,6 @@ class Model extends Overloadable {
if ($this->primaryKey === null) {
$this->primaryKey = 'id';
}
ClassRegistry::addObject($this->alias, $this);
$this->id = $id;
@ -535,35 +534,38 @@ class Model extends Overloadable {
}
}
foreach ($this->{$type} as $assoc => $value) {
$plugin = null;
if (is_numeric($assoc)) {
unset ($this->{$type}[$assoc]);
$assoc = $value;
$value = array();
$this->{$type}[$assoc] = $value;
if (!empty($this->{$type})) {
foreach ($this->{$type} as $assoc => $value) {
$plugin = null;
if (strpos($assoc, '.') !== false) {
$value = $this->{$type}[$assoc];
unset($this->{$type}[$assoc]);
list($plugin, $assoc) = explode('.', $assoc);
if (is_numeric($assoc)) {
unset ($this->{$type}[$assoc]);
$assoc = $value;
$value = array();
$this->{$type}[$assoc] = $value;
$plugin = $plugin . '.';
}
}
$className = $assoc;
if (isset($value['className']) && !empty($value['className'])) {
$className = $value['className'];
if (strpos($className, '.') !== false) {
list($plugin, $className) = explode('.', $className);
$plugin = $plugin . '.';
$this->{$type}[$assoc]['className'] = $className;
if (strpos($assoc, '.') !== false) {
$value = $this->{$type}[$assoc];
unset($this->{$type}[$assoc]);
list($plugin, $assoc) = explode('.', $assoc);
$this->{$type}[$assoc] = $value;
$plugin = $plugin . '.';
}
}
$className = $assoc;
if (isset($value['className']) && !empty($value['className'])) {
$className = $value['className'];
if (strpos($className, '.') !== false) {
list($plugin, $className) = explode('.', $className);
$plugin = $plugin . '.';
$this->{$type}[$assoc]['className'] = $className;
}
}
$this->__constructLinkedModel($assoc, $plugin . $className);
}
$this->__constructLinkedModel($assoc, $plugin . $className);
$this->__generateAssociation($type);
}
$this->__generateAssociation($type);
}
}
/**
@ -583,15 +585,17 @@ class Model extends Overloadable {
if(empty($className)) {
$className = $assoc;
}
$model = array('class' => $className, 'alias' => $assoc);
if (PHP5) {
$this->{$assoc} = ClassRegistry::init($model);
} else {
$this->{$assoc} =& ClassRegistry::init($model);
}
if ($assoc) {
$this->tableToModel[$this->{$assoc}->table] = $assoc;
if (!isset($this->{$assoc})) {
$model = array('class' => $className, 'alias' => $assoc);
if (PHP5) {
$this->{$assoc} = ClassRegistry::init($model);
} else {
$this->{$assoc} =& ClassRegistry::init($model);
}
if ($assoc) {
$this->tableToModel[$this->{$assoc}->table] = $assoc;
}
}
}
/**
@ -1871,7 +1875,7 @@ class Model extends Overloadable {
$list = array("{n}.{$this->alias}.{$this->primaryKey}", '{n}.' . $query['fields'][0], null);
$query['fields'] = array("{$this->alias}.{$this->primaryKey}", $query['fields'][0]);
} elseif (count($query['fields']) == 3) {
for ($i = 0; $i < 3; $i++) {
for ($i = 0; $i < 3; $i++) {
if (strpos($query['fields'][$i], '.') === false) {
$query['fields'][$i] = $this->alias . '.' . $query['fields'][$i];
}
@ -1879,7 +1883,7 @@ class Model extends Overloadable {
$list = array('{n}.' . $query['fields'][0], '{n}.' . $query['fields'][1], '{n}.' . $query['fields'][2]);
} else {
for ($i = 0; $i < 2; $i++) {
for ($i = 0; $i < 2; $i++) {
if (strpos($query['fields'][$i], '.') === false) {
$query['fields'][$i] = $this->alias . '.' . $query['fields'][$i];
}

View file

@ -211,7 +211,7 @@ class Router extends Object {
if (isset($default['prefix'])) {
$_this->__prefixes[] = $default['prefix'];
$_this->__prefixes = array_unique($_this->__prefixes);
$_this->__prefixes = array_keys(array_flip($_this->__prefixes));
}
if (list($pattern, $names) = $_this->writeRoute($route, $default, $params)) {
@ -247,18 +247,22 @@ class Router extends Object {
*/
function connectNamed($named, $options = array()) {
$_this =& Router::getInstance();
if (isset($options['argSeparator'])) {
$options['separator'] = $options['argSeparator'];
unset($options['argSeparator']);
}
if ($named === true || $named === false) {
$options = array_merge(array('default' => $named, 'reset' => true, 'greedy' => $named), $options);
$named = array();
}
$options = array_merge(array('default' => false, 'reset' => false, 'greedy' => true), $options);
if ($options['reset'] == true || $_this->named['rules'] === false) {
$_this->named['rules'] = array();
}
if ($options['default']) {
$named = array_merge($named, $_this->named['default']);
}
@ -291,6 +295,7 @@ class Router extends Object {
foreach ((array)$controller as $ctlName) {
$urlName = Inflector::underscore($ctlName);
foreach ($_this->__resourceMap as $params) {
extract($params);
$id = ife($id, '/:id', '');
@ -329,6 +334,7 @@ class Router extends Object {
$q = null;
$element = trim($element);
$namedParam = strpos($element, ':') !== false;
if ($namedParam && preg_match('/^:([^:]+)$/', $element, $r)) {
if (isset($params[$r[1]])) {
if ($r[1] != 'plugin' && array_key_exists($r[1], $default)) {
@ -343,20 +349,24 @@ class Router extends Object {
$parsed[] = '(?:/(.*))?';
} else if ($namedParam && preg_match_all('/(?!\\\\):([a-z_0-9]+)/i', $element, $matches)) {
$matchCount = count($matches[1]);
foreach ($matches[1] as $i => $name) {
$pos = strpos($element, ':' . $name);
$before = substr($element, 0, $pos);
$element = substr($element, $pos+strlen($name)+1);
$after = null;
if ($i + 1 == $matchCount && $element) {
$after = preg_quote($element);
}
if ($i == 0) {
$before = '/' . $before;
}
$before = preg_quote($before, '#');
if (isset($params[$name])) {
if (array_key_exists($name, $default) && $name != 'plugin') {
if (isset($default[$name]) && $name != 'plugin') {
$q = '?';
}
$parsed[] = '(?:' . $before . '(' . $params[$name] . ')' . $q . $after . ')' . $q;
@ -423,9 +433,8 @@ class Router extends Object {
$argOptions['greedy'] = $params['greedy'];
unset($params['greedy']);
}
// remove the first element, which is the url
array_shift($r);
// hack, pre-fill the default route names
foreach ($names as $name) {
$out[$name] = null;
}
@ -444,11 +453,11 @@ class Router extends Object {
if (empty($found)) {
continue;
}
// if $found is a named url element (i.e. ':action')
if (isset($names[$key])) {
$out[$names[$key]] = $_this->stripEscape($found);
} elseif (isset($names[$key]) && empty($names[$key]) && empty($out[$names[$key]])) {
break; //leave the default values;
break;
} else {
$argOptions['context'] = array('action' => $out['action'], 'controller' => $out['controller']);
extract($_this->getArgs($found, $argOptions));
@ -457,7 +466,6 @@ class Router extends Object {
}
}
if (isset($params['pass'])) {
for ($i = count($params['pass']) - 1; $i > -1; $i--) {
if (isset($out[$params['pass'][$i]])) {
@ -741,7 +749,7 @@ class Router extends Object {
$extension = $output = $mapped = $q = $frag = null;
if (is_array($url)) {
if (array_key_exists('base', $url) && $url['base'] === false) {
if (isset($url['base']) && $url['base'] === false) {
$base = null;
unset($url['base']);
}
@ -767,12 +775,12 @@ class Router extends Object {
if ($admin) {
if (!isset($url[$admin]) && !empty($params[$admin])) {
$url[$admin] = true;
} elseif ($admin && array_key_exists($admin, $url) && !$url[$admin]) {
} elseif ($admin && isset($url[$admin]) && !$url[$admin]) {
unset($url[$admin]);
}
}
$plugin = false;
if (array_key_exists('plugin', $url)) {
$plugin = $url['plugin'];
}
@ -970,7 +978,8 @@ class Router extends Object {
}
foreach ($params as $key => $val) {
if ((!isset($url[$key]) || $url[$key] != $val) || (!isset($defaults[$key]) || $defaults[$key] != $val) && !in_array($key, $routeParams)) {
if (array_key_exists($key, $defaults) && $defaults[$key] === null) {
//if (array_key_exists($key, $defaults) && $defaults[$key] === null) {
if (!isset($defaults[$key])) {
continue;
}
return false;

View file

@ -29,28 +29,28 @@
uses('controller' . DS . 'components' . DS .'email');
/**
* EmailTestController class
*
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class EmailTestController extends Controller {
/**
* name property
*
*
* @var string 'EmailTest'
* @access public
*/
var $name = 'EmailTest';
/**
* uses property
*
*
* @var mixed null
* @access public
*/
var $uses = null;
/**
* components property
*
*
* @var array
* @access public
*/
@ -58,21 +58,21 @@ class EmailTestController extends Controller {
}
/**
* EmailTest class
*
*
* @package cake
* @subpackage cake.tests.cases.libs.controller.components
*/
class EmailTest extends CakeTestCase {
/**
* name property
*
*
* @var string 'Email'
* @access public
*/
var $name = 'Email';
/**
* setUp method
*
*
* @access public
* @return void
*/
@ -88,7 +88,7 @@ class EmailTest extends CakeTestCase {
}
/**
* testBadSmtpSend method
*
*
* @access public
* @return void
*/
@ -99,7 +99,7 @@ class EmailTest extends CakeTestCase {
}
/**
* testSmtpSend method
*
*
* @access public
* @return void
*/
@ -151,7 +151,7 @@ TEMPDOC;
}
/**
* testAuthenticatedSmtpSend method
*
*
* @access public
* @return void
*/
@ -186,7 +186,7 @@ TEMPDOC;
}
/**
* testSendFormats method
*
*
* @access public
* @return void
*/
@ -240,7 +240,7 @@ TEMPDOC;
}
/**
* testSendDebug method
*
*
* @access public
* @return void
*/
@ -260,7 +260,7 @@ TEMPDOC;
}
/**
* testContentStripping method
*
*
* @access public
* @return void
*/

View file

@ -163,6 +163,7 @@ class DebuggerTest extends UnitTestCase {
View::$fieldSuffix = NULL
View::$modelId = NULL
View::$uuids = array
View::$output = false
View::$__passedVars = array
View::$__scripts = array
View::$__paths = array
@ -200,7 +201,7 @@ class DebuggerTest extends UnitTestCase {
}
/**
* testDump method
*
*
* @access public
* @return void
*/
@ -226,7 +227,7 @@ class DebuggerTest extends UnitTestCase {
}
/**
* tearDown method
*
*
* @access public
* @return void
*/

View file

@ -35,12 +35,12 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
/**
* MyOrangeComponent class
* OrangeComponent class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class MyOrangeComponent extends Object {
class OrangeComponent extends Object {
/**
* testName property
*
@ -55,7 +55,7 @@ class MyOrangeComponent extends Object {
* @return void
*/
function initialize(&$controller) {
$this->testName = 'MyOrangeComponent';
$this->testName = 'OrangeComponent';
}
}
@ -79,7 +79,7 @@ if (!class_exists('AppController')) {
* @access public
* @return void
*/
var $components = array('MyOrange');
var $components = array('Orange');
/**
* beforeFilter method
*
@ -96,7 +96,7 @@ if (!class_exists('AppController')) {
* @return void
*/
function beforeRender() {
echo $this->MyOrange->testName;
echo $this->Orange->testName;
}
/**
* cakeError method
@ -247,7 +247,7 @@ class TestErrorHandlerTest extends CakeTestCase {
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Controller<\/h2>/', $result);
$this->assertPattern('/<em>PostsController<\/em>/', $result);
$this->assertPattern('/MyOrangeComponent/', $result);
$this->assertPattern('/OrangeComponent/', $result);
}
/**

View file

@ -364,6 +364,7 @@ class SessionTest extends CakeTestCase {
$this->Session->destroy();
$this->assertFalse($this->Session->read('SessionTestCase'));
session_write_close();
}
}
?>