예제 #1
0
 public function __construct($function, $unwrap_args = true, $args = null, $arity = null, $reify_exceptions = null, $origin = null)
 {
     if ($origin === null) {
         if (is_string($function)) {
             $origin = $function;
         } else {
             $origin = V::ANONYMUS_FUNCTION_ORIGIN;
         }
     }
     parent::__construct($origin);
     if (is_string($function)) {
         C::guardIsCallable($function);
     } else {
         C::guardIsClosure($function);
     }
     C::guardIsBool($unwrap_args);
     $args = self::defaultTo($args, array());
     $reify_exceptions = self::defaultTo($reify_exceptions, array());
     C::guardIsArray($args);
     C::guardIfNotNull($arity, "guardIsUInt");
     C::guardIsArray($reify_exceptions);
     foreach ($args as $key => $value) {
         $args[$key] = $this->toValue($value, null);
     }
     if ($arity === null) {
         $refl = new ReflectionFunction($function);
         $this->_arity = $refl->getNumberOfParameters() - count($args);
     } else {
         $this->_arity = $arity - count($args);
     }
     if ($this->_arity < 0) {
         throw new Exception("FunctionValue::__construct: more args then parameters.");
     }
     $this->_function = $function;
     $this->_unwrap_args = $unwrap_args;
     $this->_args = $args;
     $this->_reify_exceptions = $reify_exceptions;
 }