microptimize options and default merge and other string key array merges

This commit is contained in:
euromark 2014-04-08 01:25:14 +02:00
parent 8d47ef43e5
commit 0ece694a75
35 changed files with 121 additions and 133 deletions

View file

@ -130,7 +130,7 @@ class Cache {
} }
if (!empty($settings)) { if (!empty($settings)) {
self::$_config[$name] = array_merge($current, $settings); self::$_config[$name] = $settings + $current;
} }
if (empty(self::$_config[$name]['engine'])) { if (empty(self::$_config[$name]['engine'])) {
@ -253,7 +253,7 @@ class Cache {
if (is_string($settings) && $value !== null) { if (is_string($settings) && $value !== null) {
$settings = array($settings => $value); $settings = array($settings => $value);
} }
$settings = array_merge(self::$_config[$config], $settings); $settings += self::$_config[$config];
if (isset($settings['duration']) && !is_numeric($settings['duration'])) { if (isset($settings['duration']) && !is_numeric($settings['duration'])) {
$settings['duration'] = strtotime($settings['duration']) - time(); $settings['duration'] = strtotime($settings['duration']) - time();
} }

View file

@ -203,7 +203,7 @@ class DbConfigTask extends AppShell {
* @return boolean True if user says it looks good, false otherwise * @return boolean True if user says it looks good, false otherwise
*/ */
protected function _verify($config) { protected function _verify($config) {
$config = array_merge($this->_defaultConfig, $config); $config += $this->_defaultConfig;
extract($config); extract($config);
$this->out(); $this->out();
$this->hr(); $this->hr();

View file

@ -199,7 +199,7 @@ class UpgradeShell extends AppShell {
$dir = $options; $dir = $options;
$options = array(); $options = array();
} }
$options = array_merge($defaultOptions, $options); $options += $defaultOptions;
$this->_movePhpFiles($dir, $options); $this->_movePhpFiles($dir, $options);
} }
} }

View file

@ -299,7 +299,7 @@ class ConsoleOptionParser {
'boolean' => false, 'boolean' => false,
'choices' => array() 'choices' => array()
); );
$options = array_merge($defaults, $options); $options += $defaults;
$option = new ConsoleInputOption($options); $option = new ConsoleInputOption($options);
} }
$this->_options[$name] = $option; $this->_options[$name] = $option;
@ -338,7 +338,7 @@ class ConsoleOptionParser {
'required' => false, 'required' => false,
'choices' => array() 'choices' => array()
); );
$options = array_merge($defaults, $params); $options = $params + $defaults;
$index = $options['index']; $index = $options['index'];
unset($options['index']); unset($options['index']);
$arg = new ConsoleInputArgument($options); $arg = new ConsoleInputArgument($options);
@ -403,7 +403,7 @@ class ConsoleOptionParser {
'help' => '', 'help' => '',
'parser' => null 'parser' => null
); );
$options = array_merge($defaults, $options); $options += $defaults;
$command = new ConsoleInputSubcommand($options); $command = new ConsoleInputSubcommand($options);
} }
$this->_subcommands[$name] = $command; $this->_subcommands[$name] = $command;

View file

@ -311,7 +311,7 @@ class ShellDispatcher {
$params = str_replace('/', '\\', $params); $params = str_replace('/', '\\', $params);
} }
$this->params = array_merge($this->params, $params); $this->params = $params + $this->params;
} }
/** /**

View file

@ -81,7 +81,7 @@ class PhpAcl extends Object implements AclInterface {
*/ */
public function initialize(Component $Component) { public function initialize(Component $Component) {
if (!empty($Component->settings['adapter'])) { 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'); App::uses('PhpReader', 'Configure');
@ -546,7 +546,7 @@ class PhpAro {
* @return void * @return void
*/ */
public function addAlias(array $alias) { public function addAlias(array $alias) {
$this->aliases = array_merge($this->aliases, $alias); $this->aliases = $alias + $this->aliases;
} }
/** /**

View file

@ -603,7 +603,7 @@ class RequestHandlerComponent extends Component {
if (Configure::read('App.encoding') !== null) { if (Configure::read('App.encoding') !== null) {
$defaults['charset'] = Configure::read('App.encoding'); $defaults['charset'] = Configure::read('App.encoding');
} }
$options = array_merge($defaults, $options); $options += $defaults;
if ($type === 'ajax') { if ($type === 'ajax') {
$controller->layout = $this->ajaxLayout; $controller->layout = $this->ajaxLayout;

View file

@ -84,7 +84,7 @@ class Object {
if ($arrayUrl && !isset($extra['data'])) { if ($arrayUrl && !isset($extra['data'])) {
$extra['data'] = array(); $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; $data = isset($extra['data']) ? $extra['data'] : null;
unset($extra['data']); unset($extra['data']);
@ -95,7 +95,7 @@ class Object {
$request = new CakeRequest($url); $request = new CakeRequest($url);
} elseif (is_array($url)) { } elseif (is_array($url)) {
$params = $url + array('pass' => array(), 'named' => array(), 'base' => false); $params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
$params = array_merge($params, $extra); $params = $extra + $params;
$request = new CakeRequest(Router::reverse($params)); $request = new CakeRequest(Router::reverse($params));
} }
if (isset($data)) { if (isset($data)) {

View file

@ -67,7 +67,7 @@ class TreeBehavior extends ModelBehavior {
$config['type'] = $config[0]; $config['type'] = $config[0];
unset($config[0]); unset($config[0]);
} }
$settings = array_merge($this->_defaults, $config); $settings = $config + $this->_defaults;
if (in_array($settings['scope'], $Model->getAssociated('belongsTo'))) { if (in_array($settings['scope'], $Model->getAssociated('belongsTo'))) {
$data = $Model->getAssociated($settings['scope']); $data = $Model->getAssociated($settings['scope']);
@ -743,7 +743,7 @@ class TreeBehavior extends ModelBehavior {
* @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::reorder * @link http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html#TreeBehavior::reorder
*/ */
public function reorder(Model $Model, $options = array()) { 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); extract($options);
if ($verify && !$this->verify($Model)) { if ($verify && !$this->verify($Model)) {
return false; return false;

View file

@ -395,7 +395,7 @@ class Sqlite extends DboSource {
*/ */
public function buildColumn($column) { public function buildColumn($column) {
$name = $type = null; $name = $type = null;
$column = array_merge(array('null' => true), $column); $column += array('null' => true);
extract($column); extract($column);
if (empty($name) || empty($type)) { if (empty($name) || empty($type)) {

View file

@ -1663,7 +1663,7 @@ class Model extends Object implements CakeEventListener {
$options = array('validate' => $validate, 'fieldList' => array($name)); $options = array('validate' => $validate, 'fieldList' => array($name));
if (is_array($validate)) { 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); return $this->save(array($this->alias => array($this->primaryKey => $id, $name => $value)), $options);
@ -1697,9 +1697,9 @@ class Model extends Object implements CakeEventListener {
$fields = array(); $fields = array();
if (!is_array($validate)) { if (!is_array($validate)) {
$options = array_merge($defaults, compact('validate', 'fieldList')); $options = compact('validate', 'fieldList') + $defaults;
} else { } else {
$options = array_merge($defaults, $validate); $options = $validate + $defaults;
} }
if (!empty($options['fieldList'])) { if (!empty($options['fieldList'])) {
@ -2164,7 +2164,7 @@ class Model extends Object implements CakeEventListener {
* @link http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-array * @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()) { 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 (Hash::numeric(array_keys($data))) {
if ($options['validate'] === 'only') { if ($options['validate'] === 'only') {
return $this->validateMany($data, $options); return $this->validateMany($data, $options);
@ -2206,7 +2206,7 @@ class Model extends Object implements CakeEventListener {
$data = $this->data; $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(); $this->validationErrors = $validationErrors = array();
if (empty($data) && $options['validate'] !== false) { if (empty($data) && $options['validate'] !== false) {
@ -2328,7 +2328,7 @@ class Model extends Object implements CakeEventListener {
$data = $this->data; $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(); $this->validationErrors = $validationErrors = array();
if (empty($data) && $options['validate'] !== false) { if (empty($data) && $options['validate'] !== false) {
@ -2369,9 +2369,9 @@ class Model extends Object implements CakeEventListener {
$saved = false; $saved = false;
if ($validates) { if ($validates) {
if ($options['deep']) { if ($options['deep']) {
$saved = $Model->saveAssociated($values, array_merge($options, array('atomic' => false))); $saved = $Model->saveAssociated($values, array('atomic' => false) + $options);
} else { } 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))); $validates = ($saved === true || (is_array($saved) && !in_array(false, $saved, true)));
} }
@ -2425,7 +2425,7 @@ class Model extends Object implements CakeEventListener {
if ($validates) { if ($validates) {
$options = $Model->_addToWhiteList($key, $options); $options = $Model->_addToWhiteList($key, $options);
if ($options['deep']) { if ($options['deep']) {
$saved = $Model->saveAssociated($values, array_merge($options, array('atomic' => false))); $saved = $Model->saveAssociated($values, array('atomic' => false) + $options);
} else { } else {
$saved = $Model->save($values, $options); $saved = $Model->save($values, $options);
} }
@ -2448,7 +2448,7 @@ class Model extends Object implements CakeEventListener {
} }
$options = $Model->_addToWhiteList($key, $options); $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)) { if (in_array(false, $_return, true)) {
$validationErrors[$association] = $Model->validationErrors; $validationErrors[$association] = $Model->validationErrors;
$validates = false; $validates = false;

View file

@ -127,7 +127,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
*/ */
public function validateAssociated(&$data, $options = array()) { public function validateAssociated(&$data, $options = array()) {
$model = $this->getModel(); $model = $this->getModel();
$options = array_merge(array('atomic' => true, 'deep' => false), $options); $options += array('atomic' => true, 'deep' => false);
$model->validationErrors = $validationErrors = $return = array(); $model->validationErrors = $validationErrors = $return = array();
$model->create(null); $model->create(null);
$return[$model->alias] = true; $return[$model->alias] = true;
@ -204,7 +204,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
*/ */
public function validateMany(&$data, $options = array()) { public function validateMany(&$data, $options = array()) {
$model = $this->getModel(); $model = $this->getModel();
$options = array_merge(array('atomic' => true, 'deep' => false), $options); $options += array('atomic' => true, 'deep' => false);
$model->validationErrors = $validationErrors = $return = array(); $model->validationErrors = $validationErrors = $return = array();
foreach ($data as $key => &$record) { foreach ($data as $key => &$record) {
if ($options['deep']) { if ($options['deep']) {

View file

@ -893,7 +893,7 @@ class HttpSocket extends CakeSocket {
} }
$request['uri'] = $this->_parseUri($request['uri']); $request['uri'] = $this->_parseUri($request['uri']);
$request = array_merge(array('method' => 'GET'), $request); $request += array('method' => 'GET');
if (!empty($this->_proxy['host'])) { if (!empty($this->_proxy['host'])) {
$request['uri'] = $this->_buildUri($request['uri'], '%scheme://%host:%port/%path?%query'); $request['uri'] = $this->_buildUri($request['uri'], '%scheme://%host:%port/%path?%query');
} else { } else {

View file

@ -480,10 +480,10 @@ class Router {
} }
if ($named === true || $named === false) { 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(); $named = array();
} else { } 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) { if ($options['reset'] || self::$_namedConfig['rules'] === false) {
@ -532,11 +532,11 @@ class Router {
*/ */
public static function mapResources($controller, $options = array()) { public static function mapResources($controller, $options = array()) {
$hasPrefix = isset($options['prefix']); $hasPrefix = isset($options['prefix']);
$options = array_merge(array( $options += array(
'connectOptions' => array(), 'connectOptions' => array(),
'prefix' => '/', 'prefix' => '/',
'id' => self::ID . '|' . self::UUID 'id' => self::ID . '|' . self::UUID
), $options); );
$prefix = $options['prefix']; $prefix = $options['prefix'];
$connectOptions = $options['connectOptions']; $connectOptions = $options['connectOptions'];

View file

@ -172,7 +172,7 @@ class TestValidate extends CakeTestModel {
* @return void * @return void
*/ */
public function validateNumber($value, $options) { 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']); $valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']);
return $valid; return $valid;
} }

View file

@ -215,11 +215,11 @@ abstract class ControllerTestCase extends CakeTestCase {
protected function _testAction($url = '', $options = array()) { protected function _testAction($url = '', $options = array()) {
$this->vars = $this->result = $this->view = $this->contents = $this->headers = null; $this->vars = $this->result = $this->view = $this->contents = $this->headers = null;
$options = array_merge(array( $options += array(
'data' => array(), 'data' => array(),
'method' => 'POST', 'method' => 'POST',
'return' => 'result' 'return' => 'result'
), $options); );
$restore = array('get' => $_GET, 'post' => $_POST); $restore = array('get' => $_GET, 'post' => $_POST);

View file

@ -323,18 +323,18 @@ class CakeNumber {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::currency
*/ */
public static function currency($value, $currency = null, $options = array()) { public static function currency($value, $currency = null, $options = array()) {
$default = self::$_currencyDefaults; $defaults = self::$_currencyDefaults;
if ($currency === null) { if ($currency === null) {
$currency = self::defaultCurrency(); $currency = self::defaultCurrency();
} }
if (isset(self::$_currencies[$currency])) { if (isset(self::$_currencies[$currency])) {
$default = self::$_currencies[$currency]; $defaults = self::$_currencies[$currency];
} elseif (is_string($currency)) { } elseif (is_string($currency)) {
$options['before'] = $currency; $options['before'] = $currency;
} }
$options = array_merge($default, $options); $options += $defaults;
if (isset($options['before']) && $options['before'] !== '') { if (isset($options['before']) && $options['before'] !== '') {
$options['wholeSymbol'] = $options['before']; $options['wholeSymbol'] = $options['before'];

View file

@ -645,7 +645,7 @@ class Folder {
$to = $options; $to = $options;
$options = array(); $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']; $fromDir = $options['from'];
$toDir = $options['to']; $toDir = $options['to'];
@ -695,13 +695,13 @@ class Folder {
chmod($to, $mode); chmod($to, $mode);
umask($old); umask($old);
$this->_messages[] = __d('cake_dev', '%s created', $to); $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); $this->copy($options);
} else { } else {
$this->_errors[] = __d('cake_dev', '%s not created', $to); $this->_errors[] = __d('cake_dev', '%s not created', $to);
} }
} elseif (is_dir($from) && $options['scheme'] == Folder::MERGE) { } 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); $this->copy($options);
} }
} }
@ -738,10 +738,7 @@ class Folder {
$to = $options; $to = $options;
$options = (array)$options; $options = (array)$options;
} }
$options = array_merge( $options += array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array());
array('to' => $to, 'from' => $this->path, 'mode' => $this->mode, 'skip' => array()),
$options
);
if ($this->copy($options)) { if ($this->copy($options)) {
if ($this->delete($options['from'])) { if ($this->delete($options['from'])) {

View file

@ -113,14 +113,11 @@ abstract class ObjectCollection {
$parts = explode('.', $event->name()); $parts = explode('.', $event->name());
$callback = array_pop($parts); $callback = array_pop($parts);
} }
$options = array_merge( $options += array(
array(
'break' => false, 'break' => false,
'breakOn' => false, 'breakOn' => false,
'collectReturn' => false, 'collectReturn' => false,
'modParams' => false 'modParams' => false
),
$options
); );
$collected = array(); $collected = array();
$list = array_keys($this->_enabled); $list = array_keys($this->_enabled);

View file

@ -104,14 +104,14 @@ class Sanitize {
$defaultCharset = 'UTF-8'; $defaultCharset = 'UTF-8';
} }
} }
$default = array( $defaults = array(
'remove' => false, 'remove' => false,
'charset' => $defaultCharset, 'charset' => $defaultCharset,
'quotes' => ENT_QUOTES, 'quotes' => ENT_QUOTES,
'double' => true 'double' => true
); );
$options = array_merge($default, $options); $options += $defaults;
if ($options['remove']) { if ($options['remove']) {
$string = strip_tags($string); $string = strip_tags($string);
@ -224,7 +224,7 @@ class Sanitize {
$options = array('connection' => $options); $options = array('connection' => $options);
} }
$options = array_merge(array( $options += array(
'connection' => 'default', 'connection' => 'default',
'odd_spaces' => true, 'odd_spaces' => true,
'remove_html' => false, 'remove_html' => false,
@ -234,7 +234,7 @@ class Sanitize {
'unicode' => true, 'unicode' => true,
'escape' => true, 'escape' => true,
'backslash' => true 'backslash' => true
), $options); );
if (is_array($data)) { if (is_array($data)) {
foreach ($data as $key => $val) { foreach ($data as $key => $val) {

View file

@ -327,7 +327,7 @@ class Set {
return $data; return $data;
} }
$contexts = $data; $contexts = $data;
$options = array_merge(array('flatten' => true), $options); $options += array('flatten' => true);
if (!isset($contexts[0])) { if (!isset($contexts[0])) {
$current = current($data); $current = current($data);
if ((is_array($current) && count($data) < 1) || !is_array($current) || !Set::numeric(array_keys($data))) { if ((is_array($current) && count($data) < 1) || !is_array($current) || !Set::numeric(array_keys($data))) {
@ -1010,7 +1010,7 @@ class Set {
*/ */
public static function apply($path, $data, $callback, $options = array()) { public static function apply($path, $data, $callback, $options = array()) {
$defaults = array('type' => 'pass'); $defaults = array('type' => 'pass');
$options = array_merge($defaults, $options); $options += $defaults;
$extracted = Set::extract($path, $data); $extracted = Set::extract($path, $data);
if ($options['type'] === 'map') { if ($options['type'] === 'map') {

View file

@ -416,12 +416,12 @@ class String {
return $text; return $text;
} }
$default = array( $defaults = array(
'format' => '<span class="highlight">\1</span>', 'format' => '<span class="highlight">\1</span>',
'html' => false, 'html' => false,
'regex' => "|%s|iu" 'regex' => "|%s|iu"
); );
$options = array_merge($default, $options); $options += $defaults;
extract($options); extract($options);
if (is_array($phrase)) { if (is_array($phrase)) {
@ -477,10 +477,10 @@ class String {
* @return string Trimmed string. * @return string Trimmed string.
*/ */
public static function tail($text, $length = 100, $options = array()) { public static function tail($text, $length = 100, $options = array()) {
$default = array( $defaults = array(
'ellipsis' => '...', 'exact' => true 'ellipsis' => '...', 'exact' => true
); );
$options = array_merge($default, $options); $options += $defaults;
extract($options); extract($options);
if (!function_exists('mb_strlen')) { if (!function_exists('mb_strlen')) {
@ -519,15 +519,15 @@ class String {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate
*/ */
public static function truncate($text, $length = 100, $options = array()) { public static function truncate($text, $length = 100, $options = array()) {
$default = array( $defaults = array(
'ellipsis' => '...', 'exact' => true, 'html' => false 'ellipsis' => '...', 'exact' => true, 'html' => false
); );
if (isset($options['ending'])) { if (isset($options['ending'])) {
$default['ellipsis'] = $options['ending']; $defaults['ellipsis'] = $options['ending'];
} elseif (!empty($options['html']) && Configure::read('App.encoding') === 'UTF-8') { } elseif (!empty($options['html']) && Configure::read('App.encoding') === 'UTF-8') {
$default['ellipsis'] = "\xe2\x80\xa6"; $defaults['ellipsis'] = "\xe2\x80\xa6";
} }
$options = array_merge($default, $options); $options += $defaults;
extract($options); extract($options);
if (!function_exists('mb_strlen')) { if (!function_exists('mb_strlen')) {

View file

@ -575,7 +575,7 @@ class Validation {
*/ */
public static function multiple($check, $options = array(), $caseInsensitive = false) { public static function multiple($check, $options = array(), $caseInsensitive = false) {
$defaults = array('in' => null, 'max' => null, 'min' => null); $defaults = array('in' => null, 'max' => null, 'min' => null);
$options = array_merge($defaults, $options); $options += $defaults;
$check = array_filter((array)$check); $check = array_filter((array)$check);
if (empty($check)) { if (empty($check)) {
@ -890,7 +890,7 @@ class Validation {
'deep' => false, 'deep' => false,
'type' => null 'type' => null
); );
$params = array_merge($defaults, $params); $params += $defaults;
if ($params['country'] !== null) { if ($params['country'] !== null) {
$params['country'] = mb_strtolower($params['country']); $params['country'] = mb_strtolower($params['country']);
} }

View file

@ -92,7 +92,7 @@ class Xml {
'return' => 'simplexml', 'return' => 'simplexml',
'loadEntities' => false, 'loadEntities' => false,
); );
$options = array_merge($defaults, $options); $options += $defaults;
if (is_array($input) || is_object($input)) { if (is_array($input) || is_object($input)) {
return self::fromArray((array)$input, $options); return self::fromArray((array)$input, $options);
@ -208,7 +208,7 @@ class Xml {
'return' => 'simplexml', 'return' => 'simplexml',
'pretty' => false 'pretty' => false
); );
$options = array_merge($defaults, $options); $options += $defaults;
$dom = new DOMDocument($options['version'], $options['encoding']); $dom = new DOMDocument($options['version'], $options['encoding']);
if ($options['pretty']) { if ($options['pretty']) {

View file

@ -201,7 +201,7 @@ class Helper extends Object {
*/ */
public function __get($name) { public function __get($name) {
if (isset($this->_helperMap[$name]) && !isset($this->{$name})) { if (isset($this->_helperMap[$name]) && !isset($this->{$name})) {
$settings = array_merge((array)$this->_helperMap[$name]['settings'], array('enabled' => false)); $settings = array('enabled' => false) + (array)$this->_helperMap[$name]['settings'];
$this->{$name} = $this->_View->loadHelper($this->_helperMap[$name]['class'], $settings); $this->{$name} = $this->_View->loadHelper($this->_helperMap[$name]['class'], $settings);
} }
if (isset($this->{$name})) { if (isset($this->{$name})) {

View file

@ -133,7 +133,7 @@ class CacheHelper extends AppHelper {
$options = $cacheAction; $options = $cacheAction;
if (isset($cacheAction[$index])) { if (isset($cacheAction[$index])) {
if (is_array($cacheAction[$index])) { if (is_array($cacheAction[$index])) {
$options = array_merge(array('duration' => 0, 'callbacks' => false), $cacheAction[$index]); $options = $cacheAction[$index] + array('duration' => 0, 'callbacks' => false);
} else { } else {
$cacheTime = $cacheAction[$index]; $cacheTime = $cacheAction[$index];
} }

View file

@ -360,14 +360,14 @@ class FormHelper extends AppHelper {
} }
} }
$options = array_merge(array( $options += array(
'type' => ($created && empty($options['action'])) ? 'put' : 'post', 'type' => ($created && empty($options['action'])) ? 'put' : 'post',
'action' => null, 'action' => null,
'url' => null, 'url' => null,
'default' => true, 'default' => true,
'encoding' => strtolower(Configure::read('App.encoding')), 'encoding' => strtolower(Configure::read('App.encoding')),
'inputDefaults' => array()), 'inputDefaults' => array()
$options); );
$this->inputDefaults($options['inputDefaults']); $this->inputDefaults($options['inputDefaults']);
unset($options['inputDefaults']); unset($options['inputDefaults']);
@ -621,9 +621,9 @@ class FormHelper extends AppHelper {
* *
* @param boolean $lock Whether this field should be part of the validation * @param boolean $lock Whether this field should be part of the validation
* or excluded as part of the unlockedFields. * or excluded as part of the unlockedFields.
* @param string $field Reference to field to be secured. Should be dot separated to indicate nesting. * @param string|array $field Reference to field to be secured. Should be dot separated to indicate nesting.
* @param mixed $value Field value, if value should not be tampered with. * @param mixed $value Field value, if value should not be tampered with.
* @return mixed|null Not used yet * @return void
*/ */
protected function _secure($lock, $field = null, $value = null) { protected function _secure($lock, $field = null, $value = null) {
if (!$field) { if (!$field) {
@ -685,7 +685,7 @@ class FormHelper extends AppHelper {
*/ */
public function error($field, $text = null, $options = array()) { public function error($field, $text = null, $options = array()) {
$defaults = array('wrap' => true, 'class' => 'error-message', 'escape' => true); $defaults = array('wrap' => true, 'class' => 'error-message', 'escape' => true);
$options = array_merge($defaults, $options); $options += $defaults;
$this->setEntity($field); $this->setEntity($field);
$error = $this->tagIsInvalid(); $error = $this->tagIsInvalid();

View file

@ -273,7 +273,7 @@ class HtmlHelper extends AppHelper {
} }
} }
$options = array_merge($type, $options); $options += $type;
$out = null; $out = null;
if (isset($options['link'])) { if (isset($options['link'])) {
@ -522,7 +522,7 @@ class HtmlHelper extends AppHelper {
list($inline, $options) = array($options, array()); list($inline, $options) = array($options, array());
$options['inline'] = $inline; $options['inline'] = $inline;
} }
$options = array_merge(array('block' => null, 'inline' => true, 'once' => true), $options); $options += array('block' => null, 'inline' => true, 'once' => true);
if (!$options['inline'] && empty($options['block'])) { if (!$options['inline'] && empty($options['block'])) {
$options['block'] = __FUNCTION__; $options['block'] = __FUNCTION__;
} }
@ -715,7 +715,7 @@ class HtmlHelper extends AppHelper {
*/ */
public function getCrumbList($options = array(), $startText = false) { public function getCrumbList($options = array(), $startText = false) {
$defaults = array('firstClass' => 'first', 'lastClass' => 'last', 'separator' => '', 'escape' => true); $defaults = array('firstClass' => 'first', 'lastClass' => 'last', 'separator' => '', 'escape' => true);
$options = array_merge($defaults, (array)$options); $options = (array)$options + $defaults;
$firstClass = $options['firstClass']; $firstClass = $options['firstClass'];
$lastClass = $options['lastClass']; $lastClass = $options['lastClass'];
$separator = $options['separator']; $separator = $options['separator'];
@ -1231,13 +1231,13 @@ class HtmlHelper extends AppHelper {
$readerObj = new $readerClass($path); $readerObj = new $readerClass($path);
$configs = $readerObj->read($file); $configs = $readerObj->read($file);
if (isset($configs['tags']) && is_array($configs['tags'])) { if (isset($configs['tags']) && is_array($configs['tags'])) {
$this->_tags = array_merge($this->_tags, $configs['tags']); $this->_tags = $configs['tags'] + $this->_tags;
} }
if (isset($configs['minimizedAttributes']) && is_array($configs['minimizedAttributes'])) { if (isset($configs['minimizedAttributes']) && is_array($configs['minimizedAttributes'])) {
$this->_minimizedAttributes = array_merge($this->_minimizedAttributes, $configs['minimizedAttributes']); $this->_minimizedAttributes = $configs['minimizedAttributes'] + $this->_minimizedAttributes;
} }
if (isset($configs['docTypes']) && is_array($configs['docTypes'])) { if (isset($configs['docTypes']) && is_array($configs['docTypes'])) {
$this->_docTypes = array_merge($this->_docTypes, $configs['docTypes']); $this->_docTypes = $configs['docTypes'] + $this->_docTypes;
} }
if (isset($configs['attributeFormat'])) { if (isset($configs['attributeFormat'])) {
$this->_attributeFormat = $configs['attributeFormat']; $this->_attributeFormat = $configs['attributeFormat'];

View file

@ -171,7 +171,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
*/ */
public function event($type, $callback, $options = array()) { public function event($type, $callback, $options = array()) {
$defaults = array('wrap' => true, 'stop' => true); $defaults = array('wrap' => true, 'stop' => true);
$options = array_merge($defaults, $options); $options += $defaults;
$function = 'function (event) {%s}'; $function = 'function (event) {%s}';
if ($options['wrap'] && $options['stop']) { if ($options['wrap'] && $options['stop']) {
@ -345,7 +345,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper {
* @see JsBaseEngineHelper::serializeForm() for option list. * @see JsBaseEngineHelper::serializeForm() for option list.
*/ */
public function serializeForm($options = array()) { public function serializeForm($options = array()) {
$options = array_merge(array('isForm' => false, 'inline' => false), $options); $options += array('isForm' => false, 'inline' => false);
$selector = $this->selection; $selector = $this->selection;
if (!$options['isForm']) { if (!$options['isForm']) {
$selector = $this->selection . '.closest("form")'; $selector = $this->selection . '.closest("form")';

View file

@ -128,7 +128,7 @@ abstract class JsBaseEngineHelper extends AppHelper {
$defaultOptions = array( $defaultOptions = array(
'prefix' => '', 'postfix' => '', 'prefix' => '', 'postfix' => '',
); );
$options = array_merge($defaultOptions, $options); $options += $defaultOptions;
return $options['prefix'] . json_encode($data) . $options['postfix']; return $options['prefix'] . json_encode($data) . $options['postfix'];
} }

View file

@ -194,7 +194,7 @@ class JsHelper extends AppHelper {
'onDomReady' => $domReady, 'inline' => true, 'onDomReady' => $domReady, 'inline' => true,
'cache' => false, 'clear' => true, 'safe' => true 'cache' => false, 'clear' => true, 'safe' => true
); );
$options = array_merge($defaults, $options); $options += $defaults;
$script = implode("\n", $this->getBuffer($options['clear'])); $script = implode("\n", $this->getBuffer($options['clear']));
if (empty($script)) { if (empty($script)) {

View file

@ -150,7 +150,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
*/ */
public function event($type, $callback, $options = array()) { public function event($type, $callback, $options = array()) {
$defaults = array('wrap' => true, 'stop' => true); $defaults = array('wrap' => true, 'stop' => true);
$options = array_merge($defaults, $options); $options += $defaults;
$function = 'function (event) {%s}'; $function = 'function (event) {%s}';
if ($options['wrap'] && $options['stop']) { if ($options['wrap'] && $options['stop']) {
@ -361,7 +361,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper {
* @see JsBaseEngineHelper::serializeForm() * @see JsBaseEngineHelper::serializeForm()
*/ */
public function serializeForm($options = array()) { public function serializeForm($options = array()) {
$options = array_merge(array('isForm' => false, 'inline' => false), $options); $options += array('isForm' => false, 'inline' => false);
$selection = $this->selection; $selection = $this->selection;
if (!$options['isForm']) { if (!$options['isForm']) {
$selection = '$(' . $this->selection . '.form)'; $selection = '$(' . $this->selection . '.form)';

View file

@ -281,7 +281,7 @@ class PaginatorHelper extends AppHelper {
$defaults = array( $defaults = array(
'rel' => 'prev' 'rel' => 'prev'
); );
$options = array_merge($defaults, (array)$options); $options = (array)$options + $defaults;
return $this->_pagingLink('Prev', $title, $options, $disabledTitle, $disabledOptions); return $this->_pagingLink('Prev', $title, $options, $disabledTitle, $disabledOptions);
} }
@ -307,7 +307,7 @@ class PaginatorHelper extends AppHelper {
$defaults = array( $defaults = array(
'rel' => 'next' 'rel' => 'next'
); );
$options = array_merge($defaults, (array)$options); $options = (array)$options + $defaults;
return $this->_pagingLink('Next', $title, $options, $disabledTitle, $disabledOptions); return $this->_pagingLink('Next', $title, $options, $disabledTitle, $disabledOptions);
} }
@ -331,7 +331,7 @@ class PaginatorHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::sort * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::sort
*/ */
public function sort($key, $title = null, $options = array()) { public function sort($key, $title = null, $options = array()) {
$options = array_merge(array('url' => array(), 'model' => null), $options); $options += array('url' => array(), 'model' => null);
$url = $options['url']; $url = $options['url'];
unset($options['url']); unset($options['url']);
@ -397,12 +397,12 @@ class PaginatorHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::link * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::link
*/ */
public function link($title, $url = array(), $options = array()) { public function link($title, $url = array(), $options = array()) {
$options = array_merge(array('model' => null, 'escape' => true), $options); $options += array('model' => null, 'escape' => true);
$model = $options['model']; $model = $options['model'];
unset($options['model']); unset($options['model']);
if (!empty($this->options)) { if (!empty($this->options)) {
$options = array_merge($this->options, $options); $options += $this->options;
} }
if (isset($options['url'])) { if (isset($options['url'])) {
$url = array_merge((array)$options['url'], (array)$url); $url = array_merge((array)$options['url'], (array)$url);
@ -489,7 +489,7 @@ class PaginatorHelper extends AppHelper {
'url' => array(), 'step' => 1, 'escape' => true, 'model' => null, 'url' => array(), 'step' => 1, 'escape' => true, 'model' => null,
'tag' => 'span', 'class' => strtolower($which), 'disabledTag' => null 'tag' => 'span', 'class' => strtolower($which), 'disabledTag' => null
); );
$options = array_merge($_defaults, (array)$options); $options = (array)$options + $_defaults;
$paging = $this->params($options['model']); $paging = $this->params($options['model']);
if (empty($disabledOptions)) { if (empty($disabledOptions)) {
$disabledOptions = $options; $disabledOptions = $options;
@ -499,7 +499,7 @@ class PaginatorHelper extends AppHelper {
if (!empty($disabledTitle) && $disabledTitle !== true) { if (!empty($disabledTitle) && $disabledTitle !== true) {
$title = $disabledTitle; $title = $disabledTitle;
} }
$options = array_merge($_defaults, (array)$disabledOptions); $options = (array)$disabledOptions + $_defaults;
} elseif (!$this->{$check}($options['model'])) { } elseif (!$this->{$check}($options['model'])) {
return null; return null;
} }
@ -631,13 +631,11 @@ class PaginatorHelper extends AppHelper {
$options = array('format' => $options); $options = array('format' => $options);
} }
$options = array_merge( $options += array(
array(
'model' => $this->defaultModel(), 'model' => $this->defaultModel(),
'format' => 'pages', 'format' => 'pages',
'separator' => __d('cake', ' of ') 'separator' => __d('cake', ' of ')
), );
$options);
$paging = $this->params($options['model']); $paging = $this->params($options['model']);
if (!$paging['pageCount']) { if (!$paging['pageCount']) {
@ -855,16 +853,14 @@ class PaginatorHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::first * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::first
*/ */
public function first($first = '<< first', $options = array()) { public function first($first = '<< first', $options = array()) {
$options = array_merge( $options = (array)$options + array(
array(
'tag' => 'span', 'tag' => 'span',
'after' => null, 'after' => null,
'model' => $this->defaultModel(), 'model' => $this->defaultModel(),
'separator' => ' | ', 'separator' => ' | ',
'ellipsis' => '...', 'ellipsis' => '...',
'class' => null 'class' => null
), );
(array)$options);
$params = array_merge(array('page' => 1), (array)$this->params($options['model'])); $params = array_merge(array('page' => 1), (array)$this->params($options['model']));
unset($options['model']); unset($options['model']);
@ -920,16 +916,14 @@ class PaginatorHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::last * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::last
*/ */
public function last($last = 'last >>', $options = array()) { public function last($last = 'last >>', $options = array()) {
$options = array_merge( $options = (array)$options + array(
array(
'tag' => 'span', 'tag' => 'span',
'before' => null, 'before' => null,
'model' => $this->defaultModel(), 'model' => $this->defaultModel(),
'separator' => ' | ', 'separator' => ' | ',
'ellipsis' => '...', 'ellipsis' => '...',
'class' => null 'class' => null
), );
(array)$options);
$params = array_merge(array('page' => 1), (array)$this->params($options['model'])); $params = array_merge(array('page' => 1), (array)$this->params($options['model']));
unset($options['model']); unset($options['model']);

View file

@ -146,7 +146,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
*/ */
public function event($type, $callback, $options = array()) { public function event($type, $callback, $options = array()) {
$defaults = array('wrap' => true, 'stop' => true); $defaults = array('wrap' => true, 'stop' => true);
$options = array_merge($defaults, $options); $options += $defaults;
$function = 'function (event) {%s}'; $function = 'function (event) {%s}';
if ($options['wrap'] && $options['stop']) { if ($options['wrap'] && $options['stop']) {
@ -354,7 +354,7 @@ class PrototypeEngineHelper extends JsBaseEngineHelper {
* @see JsBaseEngineHelper::serializeForm() * @see JsBaseEngineHelper::serializeForm()
*/ */
public function serializeForm($options = array()) { public function serializeForm($options = array()) {
$options = array_merge(array('isForm' => false, 'inline' => false), $options); $options += array('isForm' => false, 'inline' => false);
$selection = $this->selection; $selection = $this->selection;
if (!$options['isForm']) { if (!$options['isForm']) {
$selection = '$(' . $this->selection . '.form)'; $selection = '$(' . $this->selection . '.form)';

View file

@ -408,7 +408,7 @@ class TimeHelper extends AppHelper {
); );
if (is_array($options['element'])) { if (is_array($options['element'])) {
$element = array_merge($element, $options['element']); $element = $options['element'] + $element;
} else { } else {
$element['tag'] = $options['element']; $element['tag'] = $options['element'];
} }