diff --git a/cake/basics.php b/cake/basics.php index b62b8e2fb..8ecc94bd1 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -117,18 +117,18 @@ if (!function_exists('clone')) { print "{$var}\n\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. * diff --git a/cake/libs/controller/component.php b/cake/libs/controller/component.php index e9eb71238..72ed52073 100644 --- a/cake/libs/controller/component.php +++ b/cake/libs/controller/component.php @@ -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'; diff --git a/cake/libs/controller/components/acl.php b/cake/libs/controller/components/acl.php index 3a4ed946f..b518b10f7 100644 --- a/cake/libs/controller/components/acl.php +++ b/cake/libs/controller/components/acl.php @@ -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( diff --git a/cake/libs/controller/components/security.php b/cake/libs/controller/components/security.php index a5615513f..f53e2dc51 100644 --- a/cake/libs/controller/components/security.php +++ b/cake/libs/controller/components/security.php @@ -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']; diff --git a/cake/libs/debugger.php b/cake/libs/debugger.php index 25ff7b90e..670deff11 100644 --- a/cake/libs/debugger.php +++ b/cake/libs/debugger.php @@ -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]', diff --git a/cake/libs/flay.php b/cake/libs/flay.php index 2deec8f9e..102864ff2 100644 --- a/cake/libs/flay.php +++ b/cake/libs/flay.php @@ -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 { diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 627523461..8d82385cf 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -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]); } diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index 00ef64f8f..4703d93da 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -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; diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 24237ae84..81e8c451a 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -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; } diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 779544f40..ff0271119 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -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'; diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 03cf07a5f..e99b6bdc9 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -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 HTML 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',