當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。