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: * Factory argument that is a scalar value.
15: */
16: class ScalarArgument extends AbstractArgument implements ArgumentInterface
17: {
18: const TYPE_ARRAY = 'array';
19: const TYPE_BOOL = 'bool';
20: const TYPE_DOUBLE = 'float';
21: const TYPE_FLOAT = 'float';
22: const TYPE_INT = 'int';
23: const TYPE_MIXED = 'mixed';
24: const TYPE_OBJECT = 'object';
25: const TYPE_RESOURCE = 'resource';
26: const TYPE_STRING = 'string';
27:
28: /**
29: * The argument's type.
30: *
31: * @var string
32: */
33: protected $type;
34:
35: /**
36: * The argument's default value, if it is not required.
37: *
38: * @var mixed
39: */
40: protected $default;
41:
42: /**
43: * Constructor.
44: *
45: * @param integer $position
46: * @param string $name
47: * @param string $type
48: * @param boolean $required
49: * @param mixed $default
50: */
51: public function __construct($position, $name, $type, $required = true, $default = null)
52: {
53: parent::__construct($position, $name, $required);
54: $this->type = $type;
55: $this->default = $default;
56: }
57:
58: /**
59: * {@inheritdoc}
60: */
61: public function isClass()
62: {
63: return false;
64: }
65:
66: /**
67: * Get the argument's type.
68: *
69: * @return string
70: */
71: public function getType()
72: {
73: return $this->type;
74: }
75:
76: /**
77: * Get the argument's default value, if it is not required.
78: *
79: * @return mixed
80: */
81: public function getDefault()
82: {
83: if ($this->required) {
84: throw new \Exception('Argument is required and has no default');
85: }
86:
87: return $this->default;
88: }
89: }
90: