public function addOutputFilter($cb) { list($f) = Util::reflectionCallable($cb); $params = $f->getParameters(); if (count($params) !== 1) { throw new Exception("Output filter must accepts exactly 1 parameter"); } if (!in_array($cb, $this->outputFilters)) { $this->outputFilters[] = $cb; } }
/** * Set input and output filters * * Input filter is nothing but a callable, which accepts 4 parameters: * http method, uri, handler callback and handler parameters. Returning * anything other than NULL will keep handler from executing, and showing * the result to user. * * Input filter is mean to filter the work flow, so it SHOULD NOT modify * these parameters. * * Output filter is mean to filter data. It is a simple function accepts * the result of handler, manipulate on it, then return it back. Anything * returned from it will show to user, including NULL. */ public function setFilters(array $input = array(), array $output = array()) { // validate input filters foreach ($input as $i) { list($f) = Util::reflectionCallable($i); if (count($f->getParameters()) !== 4) { throw new Exception('Input filter must accepts exactly 4 parameters'); } } // validate output filters foreach ($output as $o) { list($f) = Util::reflectionCallable($o); if (count($f->getParameters()) !== 1) { throw new Exception('Output filter must accepts exactly 1 parameter'); } } $this->currentFilters = array($input, $output); return $this; }