fix calendar css, take 2. (#213)
[openemr.git] / interface / modules / zend_modules / library / Zend / Filter / Callback.php
blobfea37c4913a8f1cb442e04b1d2d91acb5cb4c642
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Filter;
12 use Traversable;
14 class Callback extends AbstractFilter
16 /**
17 * @var array
19 protected $options = array(
20 'callback' => null,
21 'callback_params' => array()
24 /**
25 * @param callable|array|Traversable $callbackOrOptions
26 * @param array $callbackParams
28 public function __construct($callbackOrOptions, $callbackParams = array())
30 if (is_callable($callbackOrOptions)) {
31 $this->setCallback($callbackOrOptions);
32 $this->setCallbackParams($callbackParams);
33 } else {
34 $this->setOptions($callbackOrOptions);
38 /**
39 * Sets a new callback for this filter
41 * @param callable $callback
42 * @throws Exception\InvalidArgumentException
43 * @return self
45 public function setCallback($callback)
47 if (!is_callable($callback)) {
48 throw new Exception\InvalidArgumentException(
49 'Invalid parameter for callback: must be callable'
53 $this->options['callback'] = $callback;
54 return $this;
57 /**
58 * Returns the set callback
60 * @return callable
62 public function getCallback()
64 return $this->options['callback'];
67 /**
68 * Sets parameters for the callback
70 * @param array $params
71 * @return self
73 public function setCallbackParams($params)
75 $this->options['callback_params'] = (array) $params;
76 return $this;
79 /**
80 * Get parameters for the callback
82 * @return array
84 public function getCallbackParams()
86 return $this->options['callback_params'];
89 /**
90 * Calls the filter per callback
92 * @param mixed $value Options for the set callable
93 * @return mixed Result from the filter which was called
95 public function filter($value)
97 $params = (array) $this->options['callback_params'];
98 array_unshift($params, $value);
100 return call_user_func_array($this->options['callback'], $params);