Ejemplo n.º 1
0
 /**
  * @dataProvider cbP
  */
 public function testCompileCallable($cb, $expect, $msg)
 {
     $this->assertEquals($expect . '()', Util::compileCallable($cb), $msg);
     $this->assertEquals($expect . '($a)', Util::compileCallable($cb, ['$a']), $msg);
     $this->assertEquals($expect . '($a,$b)', Util::compileCallable($cb, ['$a', '$b']), $msg);
 }
Ejemplo n.º 2
0
 public function exportHandler(array $params, bool $raw = false, Interceptor $int = null)
 {
     if (!is_array($this->handler)) {
         return '';
     }
     list($h, $args) = $this->handler;
     if (is_array($h)) {
         // (new class($args[0], $args[1]...))->method()
         $paramStr = '';
         if (count($params) > 0) {
             $tmp = array();
             foreach ($params as $k => $p) {
                 $tmp[$k] = $raw ? $p : var_export($p, true);
             }
             $paramStr = implode(', ', $tmp);
         }
         $argStr = '';
         if (is_array($args)) {
             $tmp = array();
             foreach ($args as $k => $v) {
                 $tmp[$k] = var_export($v, true);
             }
             $argStr = implode(', ', $tmp);
         }
         $method = var_export($h[1], true);
         $intercept = array();
         if ($int !== null) {
             $intercept[] = '$int->intercept($url, $obj, ' . $method . ');';
         }
         $input = array();
         foreach ($this->inputFilters as $f) {
             $input[] = '$ret = ' . Util::compileCallable($f, array('$method', '$url', '[$obj,' . $method . ']', '$params')) . ';';
             $input[] = 'if ($ret !== null) {';
             $input[] = '    return $ret;';
             $input[] = '}';
         }
         $output = array();
         foreach ($this->outputFilters as $f) {
             $output[] = '$ret = ' . Util::compileCallable($f, array('$ret')) . ';';
         }
         $post = array('return $ret;');
         if (is_object($h[0])) {
             $h[0] = var_export($h[0], true);
             return array_merge(['$obj = ' . $h[0] . ';'], $input, $intercept, [sprintf('$ret = $obj->%s(%s);', $h[1], $paramStr)], $output, $post);
         }
         return array_merge([sprintf('$obj = new %s(%s);', $h[0], $argStr)], $input, $intercept, [sprintf('$ret = $obj->%s(%s);', $h[1], $paramStr)], $output, $post);
     }
     return ['return ' . Util::compileCallable($h, $params) . ';'];
 }