comparison vendor/symfony/http-kernel/ControllerMetadata/ArgumentMetadata.php @ 0:4c8ae668cc8c

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