1 | <?php |
||
49 | class ProfiledNamesFactory |
||
50 | { |
||
51 | /** |
||
52 | * Create a list of profiled names from function arguments |
||
53 | * |
||
54 | * The method takes an arbitrary number of arguments and tries to parse them as profiled names. Arguments |
||
55 | * may be strings, arrays or objects. |
||
56 | * |
||
57 | * String values are interpreted as names — with one exception: If the first two arguments are both strings, |
||
58 | * the second one is taken as profile IRI. Optionally following string arguments are taken as names again, |
||
59 | * assuming to share the same profile: |
||
60 | * |
||
61 | * createFromArguments($name1 [, $profile]) |
||
62 | * createFromArguments($name1, $profile1, $name2, $profile2 ...) |
||
63 | * |
||
64 | * Arrays arguments are expected to have at least one argument which is taken as name. If present, the |
||
65 | * second argument is used as profile (otherwise an empty profile is assumed): |
||
66 | * |
||
67 | * createFromArguments(array($name [, $profile])) |
||
68 | * |
||
69 | * Object values are expected to have a "name" and an optional "profile" property: |
||
70 | * |
||
71 | * createFromArguments((object)array('name' => $name [, 'profile' => $profile])) |
||
72 | * |
||
73 | * When an array or object argument is consumed, the profile value will be used for any following string |
||
74 | * argument. You can "reset" the profile to another value by specifying another array or object value in |
||
75 | * this case. |
||
76 | * |
||
77 | * createFromArguments(array($name1, $profile1), $name2, $name3 ...) |
||
78 | * |
||
79 | * @param array $args Arguments |
||
80 | * @return ProfiledNamesList Profiled names |
||
81 | * @see Item::isOfType() |
||
82 | * @see Item::firstOf() |
||
83 | */ |
||
84 | 20 | public static function createFromArguments(array $args) |
|
96 | |||
97 | /** |
||
98 | * Create a single profiled name by argument consumption |
||
99 | * |
||
100 | * @param array $args Arguments |
||
101 | * @param string|boolean|null $profile Profile |
||
102 | * @return \stdClass Profiled name |
||
103 | */ |
||
104 | 20 | protected static function consumeProfiledName(&$args, &$profile) |
|
122 | |||
123 | /** |
||
124 | * Create a profiled name by consuming a non-scalar argument |
||
125 | * |
||
126 | * @param \stdClass|array $arg Argument |
||
127 | * @param string|boolean|null $profile Profile |
||
128 | * @return \stdClass Profiled name |
||
129 | */ |
||
130 | 10 | protected static function consumeNonScalarProfiledName($arg, &$profile) |
|
140 | |||
141 | /** |
||
142 | * Create a profiled name from an object argument |
||
143 | * |
||
144 | * @param \stdClass $arg Object argument |
||
145 | * @param string|boolean|null $profile Profile |
||
146 | * @return \stdClass Profiled name |
||
147 | * @throws InvalidArgumentException If the name is missing |
||
148 | */ |
||
149 | 8 | protected static function createProfiledNameFromObject($arg, &$profile) |
|
165 | |||
166 | /** |
||
167 | * Create a profiled name from an array argument |
||
168 | * |
||
169 | * @param array $arg Array argument |
||
170 | * @param string|boolean|null $profile Profile |
||
171 | * @return \stdClass Profiled name |
||
172 | * @throws InvalidArgumentException If the array definition is invalid |
||
173 | */ |
||
174 | 3 | protected static function createProfiledNameFromArray(array $arg, &$profile) |
|
193 | |||
194 | /** |
||
195 | * Create a profiled name from string arguments |
||
196 | * |
||
197 | * @param string $name Name |
||
198 | * @param string|boolean|null $profile Profile |
||
199 | * @return \stdClass Profiled name |
||
200 | * @throws InvalidArgumentException If the name is invalid |
||
201 | */ |
||
202 | 18 | protected static function createProfiledNameFromString($name, $profile) |
|
217 | } |
||
218 |