/**
  * 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
         }
     }
 }
Esempio n. 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.");
     }
 }
Esempio n. 3
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
  * @internal
  */
 public static function argsToParams($class, $method, &$args, $supplemental = [])
 {
     $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->getDefaultValue() : NULL;
         list($type, $isClass) = PresenterComponentReflection::getParameterType($param);
         if (!PresenterComponentReflection::convertType($args[$name], $type, $isClass)) {
             throw new InvalidLinkException(sprintf('Argument $%s passed to %s() must be %s, %s given.', $name, $rm->getDeclaringClass()->getName() . '::' . $rm->getName(), $type === 'NULL' ? 'scalar' : $type, is_object($args[$name]) ? get_class($args[$name]) : gettype($args[$name])));
         }
         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.");
     }
 }
 /**
  * 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']) && isset($this->{$name})) {
             $params[$name] = $this->{$name};
             // object property value
         } else {
             continue;
             // ignored parameter
         }
         $type = gettype($meta['def']);
         if (!PresenterComponentReflection::convertType($params[$name], $type)) {
             throw new InvalidLinkException(sprintf("Value passed to persistent parameter '%s' in %s must be %s, %s given.", $name, $this instanceof Presenter ? 'presenter ' . $this->getName() : "component '{$this->getUniqueId()}'", $type === 'NULL' ? 'scalar' : $type, is_object($params[$name]) ? get_class($params[$name]) : gettype($params[$name])));
         }
         if ($params[$name] === $meta['def'] || $meta['def'] === NULL && is_scalar($params[$name]) && (string) $params[$name] === '') {
             $params[$name] = NULL;
             // value transmit is unnecessary
         }
     }
 }
Esempio n. 5
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']);
			if (!PresenterComponentReflection::convertType($params[$name], $type)) {
				throw new InvalidLinkException(sprintf("Invalid value for persistent parameter '%s' in '%s', expected %s.", $name, $this->getName(), $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
			}
		}
	}