Additional optimization refactoring

Removed ability to use deprecated / with plugin, helper, etc combinations. The dot notation is only allowed from this point forward.
Corrected tests for the above changes.
Corrected formating in basics.php

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7623 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-09-18 03:09:19 +00:00
parent e3788dd6fa
commit 8ae5866a1c
11 changed files with 96 additions and 93 deletions

View file

@ -117,7 +117,7 @@ if (!function_exists('clone')) {
print "{$var}\n</pre>\n";
}
}
if (!function_exists('getMicrotime')) {
if (!function_exists('getMicrotime')) {
/**
* Returns microtime for execution time checking
*
@ -127,8 +127,8 @@ if (!function_exists('clone')) {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
}
if (!function_exists('sortByKey')) {
}
if (!function_exists('sortByKey')) {
/**
* Sorts given $array by key $sortby.
*
@ -158,8 +158,8 @@ if (!function_exists('clone')) {
}
return $out;
}
}
if (!function_exists('array_combine')) {
}
if (!function_exists('array_combine')) {
/**
* Combines given identical arrays by using the first array's values as keys,
* and the second one's values as values. (Implemented for back-compatibility with PHP4)
@ -180,14 +180,14 @@ if (!function_exists('clone')) {
if ($c1 <= 0) {
return false;
}
$output = array();
$output=array();
for ($i = 0; $i < $c1; $i++) {
$output[$a1[$i]] = $a2[$i];
}
return $output;
}
}
}
/**
* Convenience method for htmlspecialchars.
*
@ -407,7 +407,7 @@ if (!function_exists('clone')) {
}
return null;
}
if (!function_exists('file_put_contents')) {
if (!function_exists('file_put_contents')) {
/**
* Writes data into file.
*
@ -422,6 +422,7 @@ if (!function_exists('clone')) {
$data = join('', $data);
}
$res = @fopen($fileName, 'w+b');
if ($res) {
$write = @fwrite($res, $data);
if ($write === false) {
@ -433,7 +434,7 @@ if (!function_exists('clone')) {
}
return false;
}
}
}
/**
* Reads/writes temporary data to cache files or session.
*

View file

@ -164,13 +164,15 @@ class Component extends Object {
if (is_array($object->components)) {
$normal = Set::normalize($object->components);
foreach ($normal as $component => $config) {
$parts = preg_split('/\/|\./', $component);
$plugin = null;
if (count($parts) === 1) {
if (isset($this->__controllerVars['plugin'])) {
$plugin = $this->__controllerVars['plugin'] . '.';
} else {
$plugin = Inflector::underscore($parts['0']) . '.';
$component = array_pop($parts);
}
if (strpos($component, '.') !== false) {
list($plugin, $component) = explode('.', $component);
$plugin = $plugin . '.';
}
$componentCn = $component . 'Component';

View file

@ -299,7 +299,8 @@ class DbAcl extends AclBase {
$inherited = array();
$acoIDs = Set::extract($acoPath, '{n}.' . $this->Aco->alias . '.id');
for ($i = 0 ; $i < count($aroPath); $i++) {
$count = count($aroPath);
for ($i = 0 ; $i < $count; $i++) {
$permAlias = $this->Aro->Permission->alias;
$perms = $this->Aro->Permission->find('all', array(

View file

@ -564,7 +564,7 @@ class SecurityComponent extends Object {
}
foreach ($this->disabledFields as $value) {
$parts = preg_split('/\/|\./', $value);
$parts = explode('.', $value);
if (count($parts) == 1) {
$key1[] = $controller->modelClass . '.' . $parts['0'];

View file

@ -228,8 +228,9 @@ class Debugger extends Object {
$backtrace = debug_backtrace();
$back = array();
$count = count($backtrace);
for ($i = $options['start']; $i < count($backtrace) && $i < $options['depth']; $i++) {
for ($i = $options['start']; $i < $count && $i < $options['depth']; $i++) {
$trace = array_merge(
array(
'file' => '[internal]',

View file

@ -143,8 +143,8 @@ class Flay extends Object{
}
}
if (count($links)) {
for ($ii = 0; $ii < count($links); $ii++) {
if ($count = count($links)) {
for ($ii = 0; $ii < $count; $ii++) {
if (preg_match("#^(http|https|ftp|nntp)://#", $links[$ii])) {
$prefix = null;
} else {

View file

@ -1238,7 +1238,8 @@ class DboSource extends DataSource {
function buildStatement($query, $model) {
$query = array_merge(array('offset' => null, 'joins' => array()), $query);
if (!empty($query['joins'])) {
for ($i = 0; $i < count($query['joins']); $i++) {
$count = count($query['joins']);
for ($i = 0; $i < $count; $i++) {
if (is_array($query['joins'][$i])) {
$query['joins'][$i] = $this->buildJoinStatement($query['joins'][$i]);
}

View file

@ -332,7 +332,7 @@ class Helper extends Overloadable {
$model = $view->model;
$sameScope = $hasField = false;
$parts = array_values(Set::filter(preg_split('/\/|\./', $entity), true));
$parts = array_values(Set::filter(explode('.', $entity), true));
if (empty($parts)) {
return;

View file

@ -100,8 +100,8 @@ class FormHelper extends AppHelper {
$defaultModel = $this->params['models'][0];
} elseif (empty($model) && empty($this->params['models'])) {
$model = false;
} elseif (is_string($model) && (strpos($model, '/') !== false || strpos($model, '.') !== false)) {
$path = preg_split('/\/|\./', $model);
} elseif (is_string($model) && strpos($model, '.') !== false) {
$path = explode('.', $model);
$model = $path[count($path) - 1];
}
@ -327,7 +327,7 @@ class FormHelper extends AppHelper {
if (isset($this->params['_Token']) && !empty($this->params['_Token'])) {
if (!empty($this->params['_Token']['disabledFields'])) {
foreach ($this->params['_Token']['disabledFields'] as $value) {
$parts = preg_split('/\/|\./', $value);
$parts = explode('.', $value);
if (count($parts) == 1) {
if ($parts[0] === $field || $parts[0] === $fieldSuffix) {
return;
@ -463,8 +463,8 @@ class FormHelper extends AppHelper {
}
if ($text === null) {
if (strpos($fieldName, '/') !== false || strpos($fieldName, '.') !== false) {
$text = array_pop(preg_split('/[\/\.]+/', $fieldName));
if (strpos($fieldName, '.') !== false) {
$text = array_pop(explode('.', $fieldName));
} else {
$text = $fieldName;
}

View file

@ -702,13 +702,10 @@ class View extends Object {
$options = $helper;
$helper = $i;
}
$parts = preg_split('/\/|\./', $helper);
if (count($parts) === 1) {
$plugin = $this->plugin;
} else {
$plugin = Inflector::underscore($parts['0']);
$helper = $parts[count($parts) - 1];
if (strpos($helper, '.') !== false) {
list($plugin, $helper) = explode('.', $helper);
}
$helperCn = $helper . 'Helper';

View file

@ -1158,7 +1158,7 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Form->hidden('Contact/idontexist');
$result = $this->Form->hidden('Contact.idontexist');
$expected = array(
'input' => array('type' => 'hidden', 'name' => 'data[Contact][idontexist]', 'value' => '', 'id' => 'ContactIdontexist'),
);
@ -1186,7 +1186,7 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Form->input('Contact/password');
$result = $this->Form->input('Contact.password');
$expected = array(
'div' => array('class' => 'input password'),
'label' => array('for' => 'ContactPassword'),
@ -1683,7 +1683,7 @@ class FormHelperTest extends CakeTestCase {
* @return void
*/
function testLabel() {
$this->Form->text('Person/name');
$this->Form->text('Person.name');
$result = $this->Form->label();
$this->assertTags($result, array('label' => array('for' => 'PersonName'), 'Name', '/label'));
@ -1726,12 +1726,12 @@ class FormHelperTest extends CakeTestCase {
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][field]', 'value' => '', 'id' => 'theID')));
$this->Form->data['Model']['text'] = 'test <strong>HTML</strong> values';
$result = $this->Form->text('Model/text');
$result = $this->Form->text('Model.text');
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test &lt;strong&gt;HTML&lt;/strong&gt; values', 'id' => 'ModelText')));
$this->Form->validationErrors['Model']['text'] = 1;
$this->Form->data['Model']['text'] = 'test';
$result = $this->Form->text('Model/text', array('id' => 'theID'));
$result = $this->Form->text('Model.text', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'text', 'name' => 'data[Model][text]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
}
/**
@ -1795,7 +1795,7 @@ class FormHelperTest extends CakeTestCase {
$this->Form->validationErrors['Model']['passwd'] = 1;
$this->Form->data['Model']['passwd'] = 'test';
$result = $this->Form->password('Model/passwd', array('id' => 'theID'));
$result = $this->Form->password('Model.passwd', array('id' => 'theID'));
$this->assertTags($result, array('input' => array('type' => 'password', 'name' => 'data[Model][passwd]', 'value' => 'test', 'id' => 'theID', 'class' => 'form-error')));
}
/**
@ -3546,7 +3546,7 @@ class FormHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Form->textarea('Model/tmp');
$result = $this->Form->textarea('Model.tmp');
$expected = array(
'textarea' => array('name' => 'data[Model][tmp]', 'id' => 'ModelTmp'),
'/textarea',