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 | * @return ProfiledNamesList Profiled names |
||
82 | * @see Item::isOfType() |
||
83 | * @see Item::getFirstProperty() |
||
84 | * @see ItemList::getFirstItem() |
||
85 | * @see ItemList::getItems() |
||
86 | */ |
||
87 | 20 | public static function createFromArguments(array $args) |
|
99 | |||
100 | /** |
||
101 | * Create a single profiled name by argument consumption |
||
102 | * |
||
103 | * @param array $args Arguments |
||
104 | * @param string|boolean|null $profile Profile |
||
105 | * @return \stdClass Profiled name |
||
106 | */ |
||
107 | 20 | protected static function consumeProfiledName(&$args, &$profile) |
|
125 | |||
126 | /** |
||
127 | * Create a profiled name by consuming a non-scalar argument |
||
128 | * |
||
129 | * @param \stdClass|array $arg Argument |
||
130 | * @param string|boolean|null $profile Profile |
||
131 | * @return \stdClass Profiled name |
||
132 | */ |
||
133 | 10 | protected static function consumeNonScalarProfiledName($arg, &$profile) |
|
143 | |||
144 | /** |
||
145 | * Create a profiled name from an object argument |
||
146 | * |
||
147 | * @param \stdClass $arg Object argument |
||
148 | * @param string|boolean|null $profile Profile |
||
149 | * @return \stdClass Profiled name |
||
150 | * @throws InvalidArgumentException If the name is missing |
||
151 | */ |
||
152 | 8 | protected static function createProfiledNameFromObject($arg, &$profile) |
|
168 | |||
169 | /** |
||
170 | * Create a profiled name from an array argument |
||
171 | * |
||
172 | * @param array $arg Array argument |
||
173 | * @param string|boolean|null $profile Profile |
||
174 | * @return \stdClass Profiled name |
||
175 | * @throws InvalidArgumentException If the array definition is invalid |
||
176 | */ |
||
177 | 3 | protected static function createProfiledNameFromArray(array $arg, &$profile) |
|
196 | |||
197 | /** |
||
198 | * Create a profiled name from string arguments |
||
199 | * |
||
200 | * @param string $name Name |
||
201 | * @param string|boolean|null $profile Profile |
||
202 | * @return \stdClass Profiled name |
||
203 | * @throws InvalidArgumentException If the name is invalid |
||
204 | */ |
||
205 | 18 | protected static function createProfiledNameFromString($name, $profile) |
|
220 | } |
||
221 |