Beispiel #1
0
 /**
  * Saves state informations for next request.
  * @param  array
  * @param  PresenterComponentReflection (internal, used by Presenter)
  * @return void
  */
 public function saveState(array &$params, $reflection = NULL)
 {
     $reflection = $reflection === NULL ? $this->getReflection() : $reflection;
     foreach ($reflection->getPersistentParams() as $name => $meta) {
         if (isset($params[$name])) {
             // injected value
         } elseif (array_key_exists($name, $params)) {
             // NULLs are skipped
             continue;
         } elseif (!isset($meta['since']) || $this instanceof $meta['since']) {
             $params[$name] = $this->{$name};
             // object property value
         } else {
             continue;
             // ignored parameter
         }
         $type = gettype($meta['def'] === NULL ? $params[$name] : $meta['def']);
         // compatible with 2.0.x
         if (!PresenterComponentReflection::convertType($params[$name], $type)) {
             throw new InvalidLinkException("Invalid value for persistent parameter '{$name}' in '{$this->getName()}', expected " . ($type === 'NULL' ? 'scalar' : $type) . ".");
         }
         if ($params[$name] === $meta['def'] || $meta['def'] === NULL && is_scalar($params[$name]) && (string) $params[$name] === '') {
             $params[$name] = NULL;
             // value transmit is unnecessary
         }
     }
 }
Beispiel #2
0
 /**
  * Converts list of arguments to named parameters.
  * @param  string  class name
  * @param  string  method name
  * @param  array   arguments
  * @param  array   supplemental arguments
  * @return void
  * @throws InvalidLinkException
  */
 private static function argsToParams($class, $method, &$args, $supplemental = array())
 {
     $i = 0;
     $rm = new ReflectionMethod($class, $method);
     foreach ($rm->getParameters() as $param) {
         $name = $param->getName();
         if (array_key_exists($i, $args)) {
             $args[$name] = $args[$i];
             unset($args[$i]);
             $i++;
         } elseif (array_key_exists($name, $args)) {
             // continue with process
         } elseif (array_key_exists($name, $supplemental)) {
             $args[$name] = $supplemental[$name];
         } else {
             continue;
         }
         if ($args[$name] === NULL) {
             continue;
         }
         $def = $param->isDefaultValueAvailable() && $param->isOptional() ? $param->getDefaultValue() : NULL;
         // see PHP bug #62988
         $type = $param->isArray() ? 'array' : gettype($def);
         if (!PresenterComponentReflection::convertType($args[$name], $type)) {
             throw new InvalidLinkException("Invalid value for parameter '{$name}' in method {$class}::{$method}(), expected " . ($type === 'NULL' ? 'scalar' : $type) . ".");
         }
         if ($args[$name] === $def || $def === NULL && is_scalar($args[$name]) && (string) $args[$name] === '') {
             $args[$name] = NULL;
             // value transmit is unnecessary
         }
     }
     if (array_key_exists($i, $args)) {
         $method = $rm->getName();
         throw new InvalidLinkException("Passed more parameters than method {$class}::{$method}() expects.");
     }
 }