Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpKernel\ControllerMetadata; Chris@0: Chris@0: /** Chris@0: * Responsible for storing metadata of an argument. Chris@0: * Chris@0: * @author Iltar van der Berg Chris@0: */ Chris@0: class ArgumentMetadata Chris@0: { Chris@0: private $name; Chris@0: private $type; Chris@0: private $isVariadic; Chris@0: private $hasDefaultValue; Chris@0: private $defaultValue; Chris@0: private $isNullable; Chris@0: Chris@0: /** Chris@0: * @param string $name Chris@0: * @param string $type Chris@0: * @param bool $isVariadic Chris@0: * @param bool $hasDefaultValue Chris@0: * @param mixed $defaultValue Chris@0: * @param bool $isNullable Chris@0: */ Chris@0: public function __construct($name, $type, $isVariadic, $hasDefaultValue, $defaultValue, $isNullable = false) Chris@0: { Chris@0: $this->name = $name; Chris@0: $this->type = $type; Chris@0: $this->isVariadic = $isVariadic; Chris@0: $this->hasDefaultValue = $hasDefaultValue; Chris@0: $this->defaultValue = $defaultValue; Chris@0: $this->isNullable = $isNullable || null === $type || ($hasDefaultValue && null === $defaultValue); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the name as given in PHP, $foo would yield "foo". Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getName() Chris@0: { Chris@0: return $this->name; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the type of the argument. Chris@0: * Chris@0: * The type is the PHP class in 5.5+ and additionally the basic type in PHP 7.0+. Chris@0: * Chris@0: * @return string Chris@0: */ Chris@0: public function getType() Chris@0: { Chris@0: return $this->type; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns whether the argument is defined as "...$variadic". Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isVariadic() Chris@0: { Chris@0: return $this->isVariadic; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns whether the argument has a default value. Chris@0: * Chris@0: * Implies whether an argument is optional. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function hasDefaultValue() Chris@0: { Chris@0: return $this->hasDefaultValue; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns whether the argument accepts null values. Chris@0: * Chris@0: * @return bool Chris@0: */ Chris@0: public function isNullable() Chris@0: { Chris@0: return $this->isNullable; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the default value of the argument. Chris@0: * Chris@0: * @throws \LogicException if no default value is present; {@see self::hasDefaultValue()} Chris@0: * Chris@0: * @return mixed Chris@0: */ Chris@0: public function getDefaultValue() Chris@0: { Chris@0: if (!$this->hasDefaultValue) { Chris@0: throw new \LogicException(sprintf('Argument $%s does not have a default value. Use %s::hasDefaultValue() to avoid this exception.', $this->name, __CLASS__)); Chris@0: } Chris@0: Chris@0: return $this->defaultValue; Chris@0: } Chris@0: }