1: <?php
2: /**
3: * You may not change or alter any portion of this comment or credits
4: * of supporting developers from this source code or any supporting source code
5: * which is considered copyrighted (c) material of the original comment or credit authors.
6: * This program is distributed in the hope that it will be useful,
7: * but WITHOUT ANY WARRANTY; without even the implied warranty of
8: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9: */
10:
11: namespace Xoops\Core\Handler;
12:
13: use Xoops\Core\Kernel\XoopsObjectHandler;
14:
15: /**
16: * HandlerFactory
17: *
18: * @category Xoops\Core\Handler\FactorySpec
19: * @package Xoops\Core
20: * @author Richard Griffith <richard@geekwright.com>
21: * @copyright 2015 XOOPS Project (http://xoops.org)
22: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
23: * @link http://xoops.org
24: */
25: class FactorySpec
26: {
27: protected $factory;
28:
29: protected $specScheme;
30: protected $specName;
31: protected $specDirname;
32: protected $specOptional = false;
33: protected $specFQN;
34:
35: /**
36: * get a new specification instance.
37: *
38: * Usually called by the Handler Factory newSpec() operation instead of direct
39: * @param Factory $factory factory that created the spec
40: *
41: * @return FactorySpec
42: */
43: public static function getInstance(Factory $factory)
44: {
45: $specClass = get_called_class();
46: $instance = new $specClass($factory);
47:
48: return $instance;
49: }
50:
51: /**
52: * @param Factory $factory factory that created the spec
53: */
54: protected function __construct(Factory $factory)
55: {
56: $this->factory = $factory;
57: }
58:
59: /**
60: * Set Scheme
61: *
62: * @param string $value
63: *
64: * @return FactorySpec $this for fluent use
65: */
66: public function scheme($value)
67: {
68: $this->specScheme = $value;
69: return $this;
70: }
71:
72: /**
73: * Set Name
74: *
75: * @param string $value
76: *
77: * @return FactorySpec $this for fluent use
78: */
79: public function name($value)
80: {
81: $this->specName = $value;
82: return $this;
83: }
84:
85: /**
86: * Set Dirname
87: *
88: * @param string $value
89: *
90: * @return FactorySpec $this for fluent use
91: */
92: public function dirname($value)
93: {
94: $this->specDirname = $value;
95: return $this;
96: }
97:
98: /**
99: * Set Optional
100: *
101: * @param boolean $value
102: *
103: * @return FactorySpec $this for fluent use
104: */
105: public function optional($value)
106: {
107: $this->specOptional = (bool) $value;
108: return $this;
109: }
110:
111: /**
112: * Set FQN
113: *
114: * @param string $value
115: *
116: * @return FactorySpec $this for fluent use
117: */
118: public function fqn($value)
119: {
120: $this->specFQN = $value;
121: return $this;
122: }
123:
124: /**
125: * request build from factory
126: *
127: * @return XoopsObjectHandler|null
128: */
129: public function build()
130: {
131: return $this->factory->build($this);
132: }
133:
134: /**
135: * @return string
136: */
137: public function getScheme()
138: {
139: return $this->specScheme;
140: }
141:
142: /**
143: * @return string
144: */
145: public function getName()
146: {
147: return $this->specName;
148: }
149:
150: /**
151: * @return string
152: */
153: public function getDirname()
154: {
155: return $this->specDirname;
156: }
157:
158: /**
159: * @return bool
160: */
161: public function getOptional()
162: {
163: return $this->specOptional;
164: }
165:
166: /**
167: * @return string
168: */
169: public function getFQN()
170: {
171: return $this->specFQN;
172: }
173:
174: /**
175: * @return Factory
176: */
177: public function getFactory()
178: {
179: return $this->factory;
180: }
181: }
182: