annotate vendor/symfony/http-kernel/ControllerMetadata/ArgumentMetadata.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\HttpKernel\ControllerMetadata;
Chris@0 13
Chris@0 14 /**
Chris@0 15 * Responsible for storing metadata of an argument.
Chris@0 16 *
Chris@0 17 * @author Iltar van der Berg <kjarli@gmail.com>
Chris@0 18 */
Chris@0 19 class ArgumentMetadata
Chris@0 20 {
Chris@0 21 private $name;
Chris@0 22 private $type;
Chris@0 23 private $isVariadic;
Chris@0 24 private $hasDefaultValue;
Chris@0 25 private $defaultValue;
Chris@0 26 private $isNullable;
Chris@0 27
Chris@0 28 /**
Chris@0 29 * @param string $name
Chris@0 30 * @param string $type
Chris@0 31 * @param bool $isVariadic
Chris@0 32 * @param bool $hasDefaultValue
Chris@0 33 * @param mixed $defaultValue
Chris@0 34 * @param bool $isNullable
Chris@0 35 */
Chris@0 36 public function __construct($name, $type, $isVariadic, $hasDefaultValue, $defaultValue, $isNullable = false)
Chris@0 37 {
Chris@0 38 $this->name = $name;
Chris@0 39 $this->type = $type;
Chris@0 40 $this->isVariadic = $isVariadic;
Chris@0 41 $this->hasDefaultValue = $hasDefaultValue;
Chris@0 42 $this->defaultValue = $defaultValue;
Chris@0 43 $this->isNullable = $isNullable || null === $type || ($hasDefaultValue && null === $defaultValue);
Chris@0 44 }
Chris@0 45
Chris@0 46 /**
Chris@0 47 * Returns the name as given in PHP, $foo would yield "foo".
Chris@0 48 *
Chris@0 49 * @return string
Chris@0 50 */
Chris@0 51 public function getName()
Chris@0 52 {
Chris@0 53 return $this->name;
Chris@0 54 }
Chris@0 55
Chris@0 56 /**
Chris@0 57 * Returns the type of the argument.
Chris@0 58 *
Chris@0 59 * The type is the PHP class in 5.5+ and additionally the basic type in PHP 7.0+.
Chris@0 60 *
Chris@0 61 * @return string
Chris@0 62 */
Chris@0 63 public function getType()
Chris@0 64 {
Chris@0 65 return $this->type;
Chris@0 66 }
Chris@0 67
Chris@0 68 /**
Chris@0 69 * Returns whether the argument is defined as "...$variadic".
Chris@0 70 *
Chris@0 71 * @return bool
Chris@0 72 */
Chris@0 73 public function isVariadic()
Chris@0 74 {
Chris@0 75 return $this->isVariadic;
Chris@0 76 }
Chris@0 77
Chris@0 78 /**
Chris@0 79 * Returns whether the argument has a default value.
Chris@0 80 *
Chris@0 81 * Implies whether an argument is optional.
Chris@0 82 *
Chris@0 83 * @return bool
Chris@0 84 */
Chris@0 85 public function hasDefaultValue()
Chris@0 86 {
Chris@0 87 return $this->hasDefaultValue;
Chris@0 88 }
Chris@0 89
Chris@0 90 /**
Chris@0 91 * Returns whether the argument accepts null values.
Chris@0 92 *
Chris@0 93 * @return bool
Chris@0 94 */
Chris@0 95 public function isNullable()
Chris@0 96 {
Chris@0 97 return $this->isNullable;
Chris@0 98 }
Chris@0 99
Chris@0 100 /**
Chris@0 101 * Returns the default value of the argument.
Chris@0 102 *
Chris@0 103 * @throws \LogicException if no default value is present; {@see self::hasDefaultValue()}
Chris@0 104 *
Chris@0 105 * @return mixed
Chris@0 106 */
Chris@0 107 public function getDefaultValue()
Chris@0 108 {
Chris@0 109 if (!$this->hasDefaultValue) {
Chris@0 110 throw new \LogicException(sprintf('Argument $%s does not have a default value. Use %s::hasDefaultValue() to avoid this exception.', $this->name, __CLASS__));
Chris@0 111 }
Chris@0 112
Chris@0 113 return $this->defaultValue;
Chris@0 114 }
Chris@0 115 }