Source of file Callback.php
Size: 2,473 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Filter/Callback.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Filter; use Traversable; class Callback extends AbstractFilter { /** * @var array */ protected $options = array( 'callback' => null, 'callback_params' => array() ); /** * @param callable|array|Traversable $callbackOrOptions * @param array $callbackParams */ public function __construct($callbackOrOptions, $callbackParams = array()) { if (is_callable($callbackOrOptions)) { $this->setCallback($callbackOrOptions); $this->setCallbackParams($callbackParams); } else { $this->setOptions($callbackOrOptions); } } /** * Sets a new callback for this filter * * @param callable $callback * @throws Exception\InvalidArgumentException * @return self */ public function setCallback($callback) { if (!is_callable($callback)) { throw new Exception\InvalidArgumentException( 'Invalid parameter for callback: must be callable' ); } $this->options['callback'] = $callback; return $this; } /** * Returns the set callback * * @return callable */ public function getCallback() { return $this->options['callback']; } /** * Sets parameters for the callback * * @param array $params * @return self */ public function setCallbackParams($params) { $this->options['callback_params'] = (array) $params; return $this; } /** * Get parameters for the callback * * @return array */ public function getCallbackParams() { return $this->options['callback_params']; } /** * Calls the filter per callback * * @param mixed $value Options for the set callable * @return mixed Result from the filter which was called */ public function filter($value) { $params = (array) $this->options['callback_params']; array_unshift($params, $value); return call_user_func_array($this->options['callback'], $params); } } |