mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
e3788dd6fa
commit
8ae5866a1c
11 changed files with 96 additions and 93 deletions
119
cake/basics.php
119
cake/basics.php
|
@ -117,18 +117,18 @@ if (!function_exists('clone')) {
|
|||
print "{$var}\n</pre>\n";
|
||||
}
|
||||
}
|
||||
if (!function_exists('getMicrotime')) {
|
||||
if (!function_exists('getMicrotime')) {
|
||||
/**
|
||||
* Returns microtime for execution time checking
|
||||
*
|
||||
* @return float Microtime
|
||||
*/
|
||||
function getMicrotime() {
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
return ((float)$usec + (float)$sec);
|
||||
}
|
||||
function getMicrotime() {
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
return ((float)$usec + (float)$sec);
|
||||
}
|
||||
if (!function_exists('sortByKey')) {
|
||||
}
|
||||
if (!function_exists('sortByKey')) {
|
||||
/**
|
||||
* Sorts given $array by key $sortby.
|
||||
*
|
||||
|
@ -138,28 +138,28 @@ if (!function_exists('clone')) {
|
|||
* @param integer $type Type of sorting to perform
|
||||
* @return mixed Sorted array
|
||||
*/
|
||||
function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
|
||||
if (!is_array($array)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($array as $key => $val) {
|
||||
$sa[$key] = $val[$sortby];
|
||||
}
|
||||
|
||||
if ($order == 'asc') {
|
||||
asort($sa, $type);
|
||||
} else {
|
||||
arsort($sa, $type);
|
||||
}
|
||||
|
||||
foreach ($sa as $key => $val) {
|
||||
$out[] = $array[$key];
|
||||
}
|
||||
return $out;
|
||||
function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
|
||||
if (!is_array($array)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($array as $key => $val) {
|
||||
$sa[$key] = $val[$sortby];
|
||||
}
|
||||
|
||||
if ($order == 'asc') {
|
||||
asort($sa, $type);
|
||||
} else {
|
||||
arsort($sa, $type);
|
||||
}
|
||||
|
||||
foreach ($sa as $key => $val) {
|
||||
$out[] = $array[$key];
|
||||
}
|
||||
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)
|
||||
|
@ -168,26 +168,26 @@ if (!function_exists('clone')) {
|
|||
* @param array $a2 Array to use for values
|
||||
* @return mixed Outputs either combined array or false.
|
||||
*/
|
||||
function array_combine($a1, $a2) {
|
||||
$a1 = array_values($a1);
|
||||
$a2 = array_values($a2);
|
||||
$c1 = count($a1);
|
||||
$c2 = count($a2);
|
||||
function array_combine($a1, $a2) {
|
||||
$a1 = array_values($a1);
|
||||
$a2 = array_values($a2);
|
||||
$c1 = count($a1);
|
||||
$c2 = count($a2);
|
||||
|
||||
if ($c1 != $c2) {
|
||||
return false;
|
||||
}
|
||||
if ($c1 <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$output=array();
|
||||
for ($i = 0; $i < $c1; $i++) {
|
||||
$output[$a1[$i]] = $a2[$i];
|
||||
}
|
||||
return $output;
|
||||
if ($c1 != $c2) {
|
||||
return false;
|
||||
}
|
||||
if ($c1 <= 0) {
|
||||
return false;
|
||||
}
|
||||
$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.
|
||||
*
|
||||
|
@ -417,23 +417,24 @@ if (!function_exists('clone')) {
|
|||
* @param mixed $data String or array.
|
||||
* @return boolean Success
|
||||
*/
|
||||
function file_put_contents($fileName, $data) {
|
||||
if (is_array($data)) {
|
||||
$data = join('', $data);
|
||||
}
|
||||
$res = @fopen($fileName, 'w+b');
|
||||
if ($res) {
|
||||
$write = @fwrite($res, $data);
|
||||
if ($write === false) {
|
||||
return false;
|
||||
} else {
|
||||
@fclose($res);
|
||||
return $write;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
function file_put_contents($fileName, $data) {
|
||||
if (is_array($data)) {
|
||||
$data = join('', $data);
|
||||
}
|
||||
$res = @fopen($fileName, 'w+b');
|
||||
|
||||
if ($res) {
|
||||
$write = @fwrite($res, $data);
|
||||
if ($write === false) {
|
||||
return false;
|
||||
} else {
|
||||
@fclose($res);
|
||||
return $write;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Reads/writes temporary data to cache files or session.
|
||||
*
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -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]',
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -702,13 +702,10 @@ class View extends Object {
|
|||
$options = $helper;
|
||||
$helper = $i;
|
||||
}
|
||||
$parts = preg_split('/\/|\./', $helper);
|
||||
$plugin = $this->plugin;
|
||||
|
||||
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';
|
||||
|
||||
|
|
|
@ -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'),
|
||||
|
@ -1438,7 +1438,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
|
||||
for ($i = 1; $i < 5; $i++) {
|
||||
$result = $this->Form->input("Contact.{$i}.email", array('type' => 'checkbox', 'value' => $i));
|
||||
$expected = array(
|
||||
|
@ -1451,7 +1451,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* testFormInputs method
|
||||
|
@ -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 <strong>HTML</strong> 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')));
|
||||
}
|
||||
/**
|
||||
|
@ -1993,7 +1993,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
|
||||
$result = $this->Form->input('Newsletter.subscribe', array('legend' => false, 'label' => false, 'type' => 'radio', 'value' => '1', 'options' => array('0' => 'Unsubscribe', '1' => 'Subscribe')));
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input radio'),
|
||||
|
@ -2490,7 +2490,7 @@ class FormHelperTest extends CakeTestCase {
|
|||
array('input' => array('type' => 'checkbox', 'name' => 'data[CustomField][1][value]', 'value' => '1', 'id' => 'CustomField1Value'))
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
|
||||
$result = $this->Form->checkbox('Test.test', array('name' => 'myField'));
|
||||
$expected = array(
|
||||
'input' => array('type' => 'hidden', 'name' => 'myField', 'value' => '0', 'id' => 'TestTest_'),
|
||||
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue