1: <?php
2: /**
3: * This file is part of the Autarky package.
4: *
5: * (c) Andreas Lutro <anlutro@gmail.com>
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10:
11: namespace Autarky\Container\Factory;
12:
13: /**
14: * Abstract factory argument class.
15: */
16: abstract class AbstractArgument
17: {
18: /**
19: * The position of the argument in the factory method.
20: *
21: * @var int
22: */
23: protected $position;
24:
25: /**
26: * The variable name of the argument.
27: *
28: * @var string
29: */
30: protected $name;
31:
32: /**
33: * Whether or not the argument is required.
34: *
35: * @var boolean
36: */
37: protected $required;
38:
39: /**
40: * Constructor.
41: *
42: * @param int $position
43: * @param string $name
44: * @param boolean $required
45: */
46: public function __construct($position, $name, $required = true)
47: {
48: $this->position = (int) $position;
49:
50: if (!is_string($name) || strlen($name) < 1) {
51: throw new \InvalidArgumentException('Argument name must be a non-empty string');
52: }
53:
54: if ($name[0] !== '$') {
55: $name = '$'.$name;
56: }
57:
58: $this->name = $name;
59: $this->required = (bool) $required;
60: }
61:
62: /**
63: * {@inheridoc}
64: */
65: public function getPosition()
66: {
67: return $this->position;
68: }
69:
70: /**
71: * {@inheridoc}
72: */
73: public function getName()
74: {
75: return $this->name;
76: }
77:
78: /**
79: * {@inheridoc}
80: */
81: public function isRequired()
82: {
83: return $this->required;
84: }
85:
86: /**
87: * {@inheridoc}
88: */
89: public function isOptional()
90: {
91: return !$this->required;
92: }
93: }
94: