1 | <?php |
||
50 | class ProfiledNamesFactory |
||
51 | { |
||
52 | /** |
||
53 | * Create a list of profiled names from method arguments |
||
54 | * |
||
55 | * The method takes an arbitrary number of arguments and tries to parse them as profiled names. Arguments |
||
56 | * may be strings, arrays or objects. |
||
57 | * |
||
58 | * String values are interpreted as names — with one exception: If the first two arguments are both strings, |
||
59 | * the second one is taken as profile IRI. Optionally following string arguments are taken as names again, |
||
60 | * assuming to share the same profile: |
||
61 | * |
||
62 | * createFromArguments($name1 [, $profile]) |
||
63 | * createFromArguments($name1, $profile1, $name2, $profile2 ...) |
||
64 | * |
||
65 | * Arrays arguments are expected to have at least one argument which is taken as name. If present, the |
||
66 | * second argument is used as profile (otherwise an empty profile is assumed): |
||
67 | * |
||
68 | * createFromArguments(array($name [, $profile])) |
||
69 | * |
||
70 | * Object values are expected to have a "name" and an optional "profile" property: |
||
71 | * |
||
72 | * createFromArguments((object)array('name' => $name [, 'profile' => $profile])) |
||
73 | * |
||
74 | * When an array or object argument is consumed, the profile value will be used for any following string |
||
75 | * argument. You can "reset" the profile to another value by specifying another array or object value in |
||
76 | * this case. |
||
77 | * |
||
78 | * createFromArguments(array($name1, $profile1), $name2, $name3 ...) |
||
79 | * |
||
80 | * @param array $args Arguments |
||
81 | * |
||
82 | * @return ProfiledNamesList Profiled names |
||
83 | * @see Item::isOfType() |
||
84 | * @see Item::getFirstProperty() |
||
85 | * @see ItemList::getFirstItem() |
||
86 | * @see ItemList::getItems() |
||
87 | */ |
||
88 | 17 | public static function createFromArguments(array $args) |
|
100 | |||
101 | /** |
||
102 | * Create a single profiled name by argument consumption |
||
103 | * |
||
104 | * @param array $args Arguments |
||
105 | * @param string|boolean|null $profile Profile |
||
106 | * |
||
107 | * @return \stdClass Profiled name |
||
108 | */ |
||
109 | 17 | protected static function consumeProfiledName(&$args, &$profile) |
|
128 | |||
129 | /** |
||
130 | * Create a profiled name by consuming a non-scalar argument |
||
131 | * |
||
132 | * @param \stdClass|array $arg Argument |
||
133 | * @param string|boolean|null $profile Profile |
||
134 | * |
||
135 | * @return \stdClass Profiled name |
||
136 | */ |
||
137 | 8 | protected static function consumeNonScalarProfiledName($arg, &$profile) |
|
147 | |||
148 | /** |
||
149 | * Create a profiled name from an object argument |
||
150 | * |
||
151 | * @param \stdClass $arg Object argument |
||
152 | * @param string|boolean|null $profile Profile |
||
153 | * |
||
154 | * @return \stdClass Profiled name |
||
155 | * @throws InvalidArgumentException If the name is missing |
||
156 | */ |
||
157 | 7 | protected static function createProfiledNameFromObject($arg, &$profile) |
|
173 | |||
174 | /** |
||
175 | * Create a profiled name from string arguments |
||
176 | * |
||
177 | * @param string $name Name |
||
178 | * @param string|boolean|null $profile Profile |
||
179 | * |
||
180 | * @return \stdClass Profiled name |
||
181 | * @throws InvalidArgumentException If the name is invalid |
||
182 | */ |
||
183 | 17 | protected static function createProfiledNameFromString($name, $profile) |
|
198 | |||
199 | /** |
||
200 | * Create a profiled name from an array argument |
||
201 | * |
||
202 | * @param array $arg Array argument |
||
203 | * @param string|boolean|null $profile Profile |
||
204 | * |
||
205 | * @return \stdClass Profiled name |
||
206 | * @throws InvalidArgumentException If the array definition is invalid |
||
207 | */ |
||
208 | 2 | protected static function createProfiledNameFromArray(array $arg, &$profile) |
|
228 | } |
||
229 |