当前位置: 首页>>代码示例>>PHP>>正文


PHP PresenterComponentReflection::convertType方法代码示例

本文整理汇总了PHP中Nette\Application\UI\PresenterComponentReflection::convertType方法的典型用法代码示例。如果您正苦于以下问题:PHP PresenterComponentReflection::convertType方法的具体用法?PHP PresenterComponentReflection::convertType怎么用?PHP PresenterComponentReflection::convertType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\Application\UI\PresenterComponentReflection的用法示例。


在下文中一共展示了PresenterComponentReflection::convertType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveState

 /**
  * 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
         }
     }
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:35,代码来源:PresenterComponent.php

示例2: argsToParams

 /**
  * 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.");
     }
 }
开发者ID:pdostal,项目名称:nette-blog,代码行数:45,代码来源:Presenter.php

示例3: argsToParams

 /**
  * 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.");
     }
 }
开发者ID:voda,项目名称:application,代码行数:45,代码来源:Presenter.php

示例4: saveState

 /**
  * 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
         }
     }
 }
开发者ID:luminousinfoways,项目名称:pccfoas,代码行数:32,代码来源:PresenterComponent.php

示例5: saveState

	/**
	 * 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
			}
		}
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:34,代码来源:PresenterComponent.php


注:本文中的Nette\Application\UI\PresenterComponentReflection::convertType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。