/** * Call event listener method * * Calls an event listener method and handles return values. * * <b>NOTE:</b> For backwards compatibility with the {@link AeObject::call()} * method, a second parameter is introduced. If the <var>$args</var> parameter * is a string, it is used as the method name, and <var>$ma</var> is used * as an array of parameters for that method * * @see AeCallback::call(), AeObject::call() * * @param array|string $args an array of parameters * @param array $ma * * @return mixed */ public function call($args, $ma = array()) { if (AeType::of($args) == 'string') { return parent::call($args, $ma); } if (parent::call($args) === false) { $args[0]->stop(); } return $this; }
/** * Walk array using callback * * Applies a user callback function to every element of an array and return * the modified array: * <code> $array = new AeArray(array('foo' => 'Foo value', 'bar' => 'Bar value')); * * function myWalkFunction($value, $key) * { * echo "the value of the '$key' key is '$value'\n"; * return $value; * } * * $array->walk(new AeCallback('myWalkFunction'), true);</code> * * The callback function may take as many as two parameters: the current * element value and the current element key respectively. If it returns any * value, this value will be used as the new element value. * * This method does not modify the initial array, but performs all * modifications on it's copy: * <code> $arr1 = new AeArray('FOO'); * $arr2 = $arr1->walk(new AeCallback('strtolower')); * * echo $arr1[0] == $arr2[0] ? 'true' : 'false'; // false</code> * * @param string|array|AeCallback $callback * @param bool $passKey should the element key be passed * to the callback function or not * * @return AeArray */ public function walk($callback) { if (!$callback instanceof AeCallback) { $callback = new AeCallback($callback); } if ($passKey instanceof AeScalar) { $passKey = $passKey->toBoolean()->getValue(); } $array = clone $this; foreach ($array as $key => $value) { $array[$key] = @$callback->call(array($value, $key)); } return $array; }