Skip to content
Permalink
Browse files

microptimize options and default merge and other string key array merges

  • Loading branch information...
dereuromark committed Apr 7, 2014
1 parent 8d47ef4 commit 0ece694a75824182bb6656ff08a6b90f72f06604
Showing with 121 additions and 133 deletions.
  1. +2 −2 lib/Cake/Cache/Cache.php
  2. +1 −1 lib/Cake/Console/Command/Task/DbConfigTask.php
  3. +1 −1 lib/Cake/Console/Command/UpgradeShell.php
  4. +3 −3 lib/Cake/Console/ConsoleOptionParser.php
  5. +1 −1 lib/Cake/Console/ShellDispatcher.php
  6. +2 −2 lib/Cake/Controller/Component/Acl/PhpAcl.php
  7. +1 −1 lib/Cake/Controller/Component/RequestHandlerComponent.php
  8. +2 −2 lib/Cake/Core/Object.php
  9. +2 −2 lib/Cake/Model/Behavior/TreeBehavior.php
  10. +1 −1 lib/Cake/Model/Datasource/Database/Sqlite.php
  11. +10 −10 lib/Cake/Model/Model.php
  12. +2 −2 lib/Cake/Model/ModelValidator.php
  13. +1 −1 lib/Cake/Network/Http/HttpSocket.php
  14. +4 −4 lib/Cake/Routing/Router.php
  15. +5 −5 lib/Cake/Test/Case/Model/models.php
  16. +2 −2 lib/Cake/TestSuite/ControllerTestCase.php
  17. +3 −3 lib/Cake/Utility/CakeNumber.php
  18. +4 −7 lib/Cake/Utility/Folder.php
  19. +5 −8 lib/Cake/Utility/ObjectCollection.php
  20. +4 −4 lib/Cake/Utility/Sanitize.php
  21. +2 −2 lib/Cake/Utility/Set.php
  22. +8 −8 lib/Cake/Utility/String.php
  23. +2 −2 lib/Cake/Utility/Validation.php
  24. +2 −2 lib/Cake/Utility/Xml.php
  25. +1 −1 lib/Cake/View/Helper.php
  26. +1 −1 lib/Cake/View/Helper/CacheHelper.php
  27. +6 −6 lib/Cake/View/Helper/FormHelper.php
  28. +6 −6 lib/Cake/View/Helper/HtmlHelper.php
  29. +2 −2 lib/Cake/View/Helper/JqueryEngineHelper.php
  30. +1 −1 lib/Cake/View/Helper/JsBaseEngineHelper.php
  31. +1 −1 lib/Cake/View/Helper/JsHelper.php
  32. +2 −2 lib/Cake/View/Helper/MootoolsEngineHelper.php
  33. +28 −34 lib/Cake/View/Helper/PaginatorHelper.php
  34. +2 −2 lib/Cake/View/Helper/PrototypeEngineHelper.php
  35. +1 −1 lib/Cake/View/Helper/TimeHelper.php
@@ -130,7 +130,7 @@ public static function config($name = null, $settings = array()) {
}
if (!empty($settings)) {
self::$_config[$name] = array_merge($current, $settings);
self::$_config[$name] = $settings + $current;
}
if (empty(self::$_config[$name]['engine'])) {
@@ -253,7 +253,7 @@ public static function set($settings = array(), $value = null, $config = 'defaul
if (is_string($settings) && $value !== null) {
$settings = array($settings => $value);
}
$settings = array_merge(self::$_config[$config], $settings);
$settings += self::$_config[$config];
if (isset($settings['duration']) && !is_numeric($settings['duration'])) {
$settings['duration'] = strtotime($settings['duration']) - time();
}
@@ -203,7 +203,7 @@ protected function _interactive() {
* @return boolean True if user says it looks good, false otherwise
*/
protected function _verify($config) {
$config = array_merge($this->_defaultConfig, $config);
$config += $this->_defaultConfig;
extract($config);
$this->out();
$this->hr();
@@ -199,7 +199,7 @@ public function locations() {
$dir = $options;
$options = array();
}
$options = array_merge($defaultOptions, $options);
$options += $defaultOptions;
$this->_movePhpFiles($dir, $options);
}
}
@@ -299,7 +299,7 @@ public function addOption($name, $options = array()) {
'boolean' => false,
'choices' => array()
);
$options = array_merge($defaults, $options);
$options += $defaults;
$option = new ConsoleInputOption($options);
}
$this->_options[$name] = $option;
@@ -338,7 +338,7 @@ public function addArgument($name, $params = array()) {
'required' => false,
'choices' => array()
);
$options = array_merge($defaults, $params);
$options = $params + $defaults;
$index = $options['index'];
unset($options['index']);
$arg = new ConsoleInputArgument($options);
@@ -403,7 +403,7 @@ public function addSubcommand($name, $options = array()) {
'help' => '',
'parser' => null
);
$options = array_merge($defaults, $options);
$options += $defaults;
$command = new ConsoleInputSubcommand($options);
}
$this->_subcommands[$name] = $command;
@@ -311,7 +311,7 @@ public function parseParams($args) {
$params = str_replace('/', '\\', $params);
}
$this->params = array_merge($this->params, $params);
$this->params = $params + $this->params;
}
/**
@@ -81,7 +81,7 @@ public function __construct() {
*/
public function initialize(Component $Component) {
if (!empty($Component->settings['adapter'])) {
$this->options = array_merge($this->options, $Component->settings['adapter']);
$this->options = $Component->settings['adapter'] + $this->options;
}
App::uses('PhpReader', 'Configure');
@@ -546,7 +546,7 @@ public function addRole(array $aro) {
* @return void
*/
public function addAlias(array $alias) {
$this->aliases = array_merge($this->aliases, $alias);
$this->aliases = $alias + $this->aliases;
}
/**
@@ -603,7 +603,7 @@ public function renderAs(Controller $controller, $type, $options = array()) {
if (Configure::read('App.encoding') !== null) {
$defaults['charset'] = Configure::read('App.encoding');
}
$options = array_merge($defaults, $options);
$options += $defaults;
if ($type === 'ajax') {
$controller->layout = $this->ajaxLayout;
@@ -84,7 +84,7 @@ public function requestAction($url, $extra = array()) {
if ($arrayUrl && !isset($extra['data'])) {
$extra['data'] = array();
}
$extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
$extra += array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1);
$data = isset($extra['data']) ? $extra['data'] : null;
unset($extra['data']);
@@ -95,7 +95,7 @@ public function requestAction($url, $extra = array()) {
$request = new CakeRequest($url);
} elseif (is_array($url)) {
$params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
$params = array_merge($params, $extra);
$params = $extra + $params;
$request = new CakeRequest(Router::reverse($params));
}
if (isset($data)) {
@@ -67,7 +67,7 @@ public function setup(Model $Model, $config = array()) {
$config['type'] = $config[0];
unset($config[0]);
}
$settings = array_merge($this->_defaults, $config);
$settings = $config + $this->_defaults;
if (in_array($settings['scope'], $Model->getAssociated('belongsTo'))) {
$data = $Model->getAssociated($settings['scope']);
@@ -743,7 +743,7 @@ protected function _recoverByParentId(Model $Model, $counter = 1, $parentId = nu
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::reorder
*/
public function reorder(Model $Model, $options = array()) {
$options = array_merge(array('id' => null, 'field' => $Model->displayField, 'order' => 'ASC', 'verify' => true), $options);
$options += array('id' => null, 'field' => $Model->displayField, 'order' => 'ASC', 'verify' => true);
extract($options);
if ($verify && !$this->verify($Model)) {
return false;
@@ -395,7 +395,7 @@ public function limit($limit, $offset = null) {
*/
public function buildColumn($column) {
$name = $type = null;
$column = array_merge(array('null' => true), $column);
$column += array('null' => true);
extract($column);
if (empty($name) || empty($type)) {
@@ -1663,7 +1663,7 @@ public function saveField($name, $value, $validate = false) {
$options = array('validate' => $validate, 'fieldList' => array($name));
if (is_array($validate)) {
$options = array_merge(array('validate' => false, 'fieldList' => array($name)), $validate);
$options = $validate + array('validate' => false, 'fieldList' => array($name));
}
return $this->save(array($this->alias => array($this->primaryKey => $id, $name => $value)), $options);
@@ -1697,9 +1697,9 @@ public function save($data = null, $validate = true, $fieldList = array()) {
$fields = array();
if (!is_array($validate)) {
$options = array_merge($defaults, compact('validate', 'fieldList'));
$options = compact('validate', 'fieldList') + $defaults;
} else {
$options = array_merge($defaults, $validate);
$options = $validate + $defaults;
}
if (!empty($options['fieldList'])) {
@@ -2164,7 +2164,7 @@ protected function _prepareUpdateFields($data) {
* @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-array
*/
public function saveAll($data = array(), $options = array()) {
$options = array_merge(array('validate' => 'first'), $options);
$options += array('validate' => 'first');
if (Hash::numeric(array_keys($data))) {
if ($options['validate'] === 'only') {
return $this->validateMany($data, $options);
@@ -2206,7 +2206,7 @@ public function saveMany($data = null, $options = array()) {
$data = $this->data;
}
$options = array_merge(array('validate' => 'first', 'atomic' => true, 'deep' => false), $options);
$options += array('validate' => 'first', 'atomic' => true, 'deep' => false);
$this->validationErrors = $validationErrors = array();
if (empty($data) && $options['validate'] !== false) {
@@ -2328,7 +2328,7 @@ public function saveAssociated($data = null, $options = array()) {
$data = $this->data;
}
$options = array_merge(array('validate' => 'first', 'atomic' => true, 'deep' => false), $options);
$options += array('validate' => 'first', 'atomic' => true, 'deep' => false);
$this->validationErrors = $validationErrors = array();
if (empty($data) && $options['validate'] !== false) {
@@ -2369,9 +2369,9 @@ public function saveAssociated($data = null, $options = array()) {
$saved = false;
if ($validates) {
if ($options['deep']) {
$saved = $Model->saveAssociated($values, array_merge($options, array('atomic' => false)));
$saved = $Model->saveAssociated($values, array('atomic' => false) + $options);
} else {
$saved = $Model->save($values, array_merge($options, array('atomic' => false)));
$saved = $Model->save($values, array('atomic' => false) + $options);
}
$validates = ($saved === true || (is_array($saved) && !in_array(false, $saved, true)));
}
@@ -2425,7 +2425,7 @@ public function saveAssociated($data = null, $options = array()) {
if ($validates) {
$options = $Model->_addToWhiteList($key, $options);
if ($options['deep']) {
$saved = $Model->saveAssociated($values, array_merge($options, array('atomic' => false)));
$saved = $Model->saveAssociated($values, array('atomic' => false) + $options);
} else {
$saved = $Model->save($values, $options);
}
@@ -2448,7 +2448,7 @@ public function saveAssociated($data = null, $options = array()) {
}
$options = $Model->_addToWhiteList($key, $options);
$_return = $Model->saveMany($values, array_merge($options, array('atomic' => false)));
$_return = $Model->saveMany($values, array('atomic' => false) + $options);
if (in_array(false, $_return, true)) {
$validationErrors[$association] = $Model->validationErrors;
$validates = false;
@@ -127,7 +127,7 @@ public function validates($options = array()) {
*/
public function validateAssociated(&$data, $options = array()) {
$model = $this->getModel();
$options = array_merge(array('atomic' => true, 'deep' => false), $options);
$options += array('atomic' => true, 'deep' => false);
$model->validationErrors = $validationErrors = $return = array();
$model->create(null);
$return[$model->alias] = true;
@@ -204,7 +204,7 @@ public function validateAssociated(&$data, $options = array()) {
*/
public function validateMany(&$data, $options = array()) {
$model = $this->getModel();
$options = array_merge(array('atomic' => true, 'deep' => false), $options);
$options += array('atomic' => true, 'deep' => false);
$model->validationErrors = $validationErrors = $return = array();
foreach ($data as $key => &$record) {
if ($options['deep']) {
@@ -893,7 +893,7 @@ protected function _buildRequestLine($request = array(), $versionToken = 'HTTP/1
}
$request['uri'] = $this->_parseUri($request['uri']);
$request = array_merge(array('method' => 'GET'), $request);
$request += array('method' => 'GET');
if (!empty($this->_proxy['host'])) {
$request['uri'] = $this->_buildUri($request['uri'], '%scheme://%host:%port/%path?%query');
} else {
@@ -480,10 +480,10 @@ public static function connectNamed($named, $options = array()) {
}
if ($named === true || $named === false) {
$options = array_merge(array('default' => $named, 'reset' => true, 'greedy' => $named), $options);
$options += array('default' => $named, 'reset' => true, 'greedy' => $named);
$named = array();
} else {
$options = array_merge(array('default' => false, 'reset' => false, 'greedy' => true), $options);
$options += array('default' => false, 'reset' => false, 'greedy' => true);
}
if ($options['reset'] || self::$_namedConfig['rules'] === false) {
@@ -532,11 +532,11 @@ public static function namedConfig() {
*/
public static function mapResources($controller, $options = array()) {
$hasPrefix = isset($options['prefix']);
$options = array_merge(array(
$options += array(
'connectOptions' => array(),
'prefix' => '/',
'id' => self::ID . '|' . self::UUID
), $options);
);
$prefix = $options['prefix'];
$connectOptions = $options['connectOptions'];
@@ -172,7 +172,7 @@ class TestValidate extends CakeTestModel {
* @return void
*/
public function validateNumber($value, $options) {
$options = array_merge(array('min' => 0, 'max' => 100), $options);
$options += array('min' => 0, 'max' => 100);
$valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']);
return $valid;
}
@@ -1511,8 +1511,8 @@ class SomethingElse extends CakeTestModel {
/**
* afterFind callBack
*
* @param array $results
*
* @param array $results
* @param bool $primary
* @return array
*/
@@ -1550,8 +1550,8 @@ class JoinThing extends CakeTestModel {
/**
* afterFind callBack
*
* @param array $results
*
* @param array $results
* @param bool $primary
* @return array
*/
@@ -215,11 +215,11 @@ public function __call($name, $arguments) {
protected function _testAction($url = '', $options = array()) {
$this->vars = $this->result = $this->view = $this->contents = $this->headers = null;
$options = array_merge(array(
$options += array(
'data' => array(),
'method' => 'POST',
'return' => 'result'
), $options);
);
$restore = array('get' => $_GET, 'post' => $_POST);
@@ -323,18 +323,18 @@ protected static function _numberFormat($value, $places = 0, $decimals = '.', $t
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency
*/
public static function currency($value, $currency = null, $options = array()) {
$default = self::$_currencyDefaults;
$defaults = self::$_currencyDefaults;
if ($currency === null) {
$currency = self::defaultCurrency();
}
if (isset(self::$_currencies[$currency])) {
$default = self::$_currencies[$currency];
$defaults = self::$_currencies[$currency];
} elseif (is_string($currency)) {
$options['before'] = $currency;
}
$options = array_merge($default, $options);
$options += $defaults;
if (isset($options['before']) && $options['before'] !== '') {
$options['wholeSymbol'] = $options['before'];
@@ -645,7 +645,7 @@ public function copy($options) {
$to = $options;
$options = array();
}
$options = array_merge(array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array(), 'scheme' => Folder::MERGE), $options);
$options += array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array(), 'scheme' => Folder::MERGE);
$fromDir = $options['from'];
$toDir = $options['to'];
@@ -695,13 +695,13 @@ public function copy($options) {
chmod($to, $mode);
umask($old);
$this->_messages[] = __d('cake_dev', '%s created', $to);
$options = array_merge($options, array('to' => $to, 'from' => $from));
$options = array('to' => $to, 'from' => $from) + $options;
$this->copy($options);
} else {
$this->_errors[] = __d('cake_dev', '%s not created', $to);
}
} elseif (is_dir($from) && $options['scheme'] == Folder::MERGE) {
$options = array_merge($options, array('to' => $to, 'from' => $from));
$options = array('to' => $to, 'from' => $from) + $options;
$this->copy($options);
}
}
@@ -738,10 +738,7 @@ public function move($options) {
$to = $options;
$options = (array)$options;
}
$options = array_merge(
array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array()),
$options
);
$options += array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array());
if ($this->copy($options)) {
if ($this->delete($options['from'])) {
@@ -113,14 +113,11 @@ public function trigger($callback, $params = array(), $options = array()) {
$parts = explode('.', $event->name());
$callback = array_pop($parts);
}
$options = array_merge(
array(
'break' => false,
'breakOn' => false,
'collectReturn' => false,
'modParams' => false
),
$options
$options += array(
'break' => false,
'breakOn' => false,
'collectReturn' => false,
'modParams' => false
);
$collected = array();
$list = array_keys($this->_enabled);
Oops, something went wrong.

0 comments on commit 0ece694

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.