This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Dkd\PhpCmis; |
||
3 | |||
4 | /* |
||
5 | * This file is part of php-cmis-client |
||
6 | * |
||
7 | * (c) Sascha Egerer <[email protected]> |
||
8 | * |
||
9 | * For the full copyright and license information, please view the LICENSE |
||
10 | * file that was distributed with this source code. |
||
11 | */ |
||
12 | |||
13 | use Dkd\PhpCmis\CmisObject\CmisObjectInterface; |
||
14 | use Dkd\PhpCmis\Data\AceInterface; |
||
15 | use Dkd\PhpCmis\Data\AclInterface; |
||
16 | use Dkd\PhpCmis\Data\BindingsObjectFactoryInterface; |
||
17 | use Dkd\PhpCmis\Data\ChangeEventInfoInterface; |
||
18 | use Dkd\PhpCmis\Data\ObjectDataInterface; |
||
19 | use Dkd\PhpCmis\Data\ObjectListInterface; |
||
20 | use Dkd\PhpCmis\Data\ObjectTypeInterface; |
||
21 | use Dkd\PhpCmis\Data\PolicyInterface; |
||
22 | use Dkd\PhpCmis\Data\PropertiesInterface; |
||
23 | use Dkd\PhpCmis\Data\PropertyDataInterface; |
||
24 | use Dkd\PhpCmis\Data\PropertyInterface; |
||
25 | use Dkd\PhpCmis\Data\RenditionDataInterface; |
||
26 | use Dkd\PhpCmis\Data\RenditionInterface; |
||
27 | use Dkd\PhpCmis\Data\RepositoryInfoInterface; |
||
28 | use Dkd\PhpCmis\Data\SecondaryTypeInterface; |
||
29 | use Dkd\PhpCmis\DataObjects\Document; |
||
30 | use Dkd\PhpCmis\DataObjects\DocumentType; |
||
31 | use Dkd\PhpCmis\DataObjects\DocumentTypeDefinition; |
||
32 | use Dkd\PhpCmis\DataObjects\Folder; |
||
33 | use Dkd\PhpCmis\DataObjects\FolderType; |
||
34 | use Dkd\PhpCmis\DataObjects\FolderTypeDefinition; |
||
35 | use Dkd\PhpCmis\DataObjects\Item; |
||
36 | use Dkd\PhpCmis\DataObjects\ItemType; |
||
37 | use Dkd\PhpCmis\DataObjects\ItemTypeDefinition; |
||
38 | use Dkd\PhpCmis\DataObjects\Policy; |
||
39 | use Dkd\PhpCmis\DataObjects\PolicyType; |
||
40 | use Dkd\PhpCmis\DataObjects\PolicyTypeDefinition; |
||
41 | use Dkd\PhpCmis\DataObjects\Property; |
||
42 | use Dkd\PhpCmis\DataObjects\PropertyId; |
||
43 | use Dkd\PhpCmis\DataObjects\Relationship; |
||
44 | use Dkd\PhpCmis\DataObjects\RelationshipType; |
||
45 | use Dkd\PhpCmis\DataObjects\RelationshipTypeDefinition; |
||
46 | use Dkd\PhpCmis\DataObjects\Rendition; |
||
47 | use Dkd\PhpCmis\DataObjects\SecondaryType; |
||
48 | use Dkd\PhpCmis\DataObjects\SecondaryTypeDefinition; |
||
49 | use Dkd\PhpCmis\Definitions\DocumentTypeDefinitionInterface; |
||
50 | use Dkd\PhpCmis\Definitions\FolderTypeDefinitionInterface; |
||
51 | use Dkd\PhpCmis\Definitions\ItemTypeDefinitionInterface; |
||
52 | use Dkd\PhpCmis\Definitions\PolicyTypeDefinitionInterface; |
||
53 | use Dkd\PhpCmis\Definitions\PropertyDefinitionInterface; |
||
54 | use Dkd\PhpCmis\Definitions\RelationshipTypeDefinitionInterface; |
||
55 | use Dkd\PhpCmis\Definitions\SecondaryTypeDefinitionInterface; |
||
56 | use Dkd\PhpCmis\Definitions\TypeDefinitionInterface; |
||
57 | use Dkd\PhpCmis\Definitions\TypeMutabilityInterface; |
||
58 | use Dkd\PhpCmis\Enum\BaseTypeId; |
||
59 | use Dkd\PhpCmis\Enum\Cardinality; |
||
60 | use Dkd\PhpCmis\Enum\Updatability; |
||
61 | use Dkd\PhpCmis\Exception\CmisInvalidArgumentException; |
||
62 | use Dkd\PhpCmis\Exception\CmisRuntimeException; |
||
63 | use GuzzleHttp\Stream\StreamInterface; |
||
64 | |||
65 | /** |
||
66 | * Object Factory implementation |
||
67 | * |
||
68 | * @author Sascha Egerer <[email protected]> |
||
69 | */ |
||
70 | class ObjectFactory implements ObjectFactoryInterface |
||
71 | { |
||
72 | /** |
||
73 | * @var SessionInterface |
||
74 | */ |
||
75 | protected $session; |
||
76 | |||
77 | /** |
||
78 | * Initialize the object factory with a session. |
||
79 | * |
||
80 | * @param SessionInterface $session |
||
81 | * @param string[] $parameters |
||
82 | */ |
||
83 | 31 | public function initialize(SessionInterface $session, $parameters = []) |
|
84 | { |
||
85 | 31 | $this->session = $session; |
|
86 | 31 | } |
|
87 | |||
88 | /** |
||
89 | * Convert ACEs to an ACL. |
||
90 | * |
||
91 | * This method does not create a copy of the ACE as the Java OpenCMIS implementation does. # |
||
92 | * For details see the discussion in the mailing list |
||
93 | * |
||
94 | * @see http://mail-archives.apache.org/mod_mbox/chemistry-dev/201501.mbox/<[email protected]> |
||
95 | * |
||
96 | * @param AceInterface[] $aces |
||
97 | * @return AclInterface |
||
98 | */ |
||
99 | 1 | public function convertAces(array $aces) |
|
100 | { |
||
101 | 1 | return $this->getBindingsObjectFactory()->createAccessControlList($aces); |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param ObjectDataInterface $objectData |
||
106 | * @return ChangeEventInfoInterface |
||
107 | */ |
||
108 | public function convertChangeEvent(ObjectDataInterface $objectData) |
||
109 | { |
||
110 | // TODO: Implement convertChangeEvent() method. |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @param string $changeLogToken |
||
115 | * @param ObjectListInterface $objectList |
||
116 | * @return ChangeEventsInterface |
||
117 | */ |
||
118 | public function convertChangeEvents($changeLogToken, ObjectListInterface $objectList) |
||
119 | { |
||
120 | // TODO: Implement convertChangeEvents() method. |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Converts a high level ContentStream object into a low level ContentStream object. |
||
125 | * |
||
126 | * @param StreamInterface $contentStream the original ContentStream object |
||
127 | * @return StreamInterface the ContentStream object |
||
128 | */ |
||
129 | public function convertContentStream(StreamInterface $contentStream) |
||
130 | { |
||
131 | // TODO: Implement convertContentStream() method. |
||
132 | return $contentStream; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Convert given ObjectData to a high level API object |
||
137 | * |
||
138 | * @param ObjectDataInterface $objectData |
||
139 | * @param OperationContextInterface $context |
||
140 | * @return CmisObjectInterface |
||
141 | * @throws CmisRuntimeException |
||
142 | */ |
||
143 | public function convertObject(ObjectDataInterface $objectData, OperationContextInterface $context) |
||
144 | { |
||
145 | $type = $this->getTypeFromObjectData($objectData); |
||
146 | if ($type === null) { |
||
147 | throw new CmisRuntimeException('Could not get type from object data.'); |
||
148 | } |
||
149 | $baseTypeId = $objectData->getBaseTypeId(); |
||
150 | |||
151 | if ($baseTypeId->equals(BaseTypeId::CMIS_DOCUMENT)) { |
||
152 | return new Document($this->session, $type, $context, $objectData); |
||
153 | } elseif ($baseTypeId->equals(BaseTypeId::CMIS_FOLDER)) { |
||
154 | return new Folder($this->session, $type, $context, $objectData); |
||
155 | } elseif ($baseTypeId->equals(BaseTypeId::CMIS_POLICY)) { |
||
156 | return new Policy($this->session, $type, $context, $objectData); |
||
157 | } elseif ($baseTypeId->equals(BaseTypeId::CMIS_RELATIONSHIP)) { |
||
158 | return new Relationship($this->session, $type, $context, $objectData); |
||
159 | } elseif ($baseTypeId->equals(BaseTypeId::CMIS_ITEM)) { |
||
160 | return new Item($this->session, $type, $context, $objectData); |
||
161 | } elseif ($baseTypeId->equals(BaseTypeId::CMIS_SECONDARY)) { |
||
162 | throw new CmisRuntimeException('Secondary type is used as object type: ' . $baseTypeId); |
||
163 | } else { |
||
164 | throw new CmisRuntimeException('Unsupported base type: ' . $baseTypeId); |
||
165 | } |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Converts a list of Policy objects into a list of there string representations |
||
170 | * |
||
171 | * @param PolicyInterface[] $policies |
||
172 | * @return string[] |
||
173 | */ |
||
174 | public function convertPolicies(array $policies) |
||
175 | { |
||
176 | $result = []; |
||
177 | |||
178 | foreach ($policies as $policy) { |
||
179 | if ($policy->getId() !== null) { |
||
180 | $result[] = $policy->getId(); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | return $result; |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Convert Properties in Properties instance to a list of PropertyInterface objects |
||
189 | * |
||
190 | * @param ObjectTypeInterface $objectType |
||
191 | * @param SecondaryTypeInterface[] $secondaryTypes |
||
192 | * @param PropertiesInterface $properties |
||
193 | * @return PropertyInterface[] |
||
194 | * @throws CmisInvalidArgumentException |
||
195 | */ |
||
196 | public function convertPropertiesDataToPropertyList( |
||
197 | ObjectTypeInterface $objectType, |
||
198 | array $secondaryTypes, |
||
199 | PropertiesInterface $properties |
||
200 | ) { |
||
201 | if (count($objectType->getPropertyDefinitions()) === 0) { |
||
202 | throw new CmisInvalidArgumentException('Object type has no property definitions!'); |
||
203 | } |
||
204 | if (count($properties->getProperties()) === 0) { |
||
205 | throw new CmisInvalidArgumentException('Properties must be set'); |
||
206 | } |
||
207 | |||
208 | // Iterate trough properties and convert them to Property objects |
||
209 | $result = []; |
||
210 | foreach ($properties->getProperties() as $propertyKey => $propertyData) { |
||
211 | // find property definition |
||
212 | $apiProperty = $this->convertProperty($objectType, $secondaryTypes, $propertyData); |
||
213 | $result[$propertyKey] = $apiProperty; |
||
214 | } |
||
215 | |||
216 | return $result; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * Convert PropertyData into a property API object |
||
221 | * |
||
222 | * @param ObjectTypeInterface $objectType |
||
223 | * @param SecondaryTypeInterface[] $secondaryTypes |
||
224 | * @param PropertyDataInterface $propertyData |
||
225 | * @return PropertyInterface |
||
226 | * @throws CmisRuntimeException |
||
227 | */ |
||
228 | protected function convertProperty( |
||
229 | ObjectTypeInterface $objectType, |
||
230 | array $secondaryTypes, |
||
231 | PropertyDataInterface $propertyData |
||
232 | ) { |
||
233 | $definition = $objectType->getPropertyDefinition($propertyData->getId()); |
||
234 | |||
235 | // search secondary types |
||
236 | if ($definition === null && !empty($secondaryTypes)) { |
||
237 | foreach ($secondaryTypes as $secondaryType) { |
||
238 | $propertyDefinitions = $secondaryType->getPropertyDefinitions(); |
||
239 | View Code Duplication | if (!empty($propertyDefinitions)) { |
|
0 ignored issues
–
show
|
|||
240 | $definition = $secondaryType->getPropertyDefinition($propertyData->getId()); |
||
241 | if ($definition !== null) { |
||
242 | break; |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | } |
||
247 | |||
248 | // the type might have changed -> reload type definitions |
||
249 | if ($definition === null) { |
||
250 | $reloadedObjectType = $this->session->getTypeDefinition($objectType->getId(), false); |
||
251 | $definition = $reloadedObjectType->getPropertyDefinition($propertyData->getId()); |
||
252 | |||
253 | if ($definition === null && !empty($secondaryTypes)) { |
||
254 | foreach ($secondaryTypes as $secondaryType) { |
||
255 | $reloadedSecondaryType = $this->session->getTypeDefinition($secondaryType->getId(), false); |
||
256 | $propertyDefinitions = $reloadedSecondaryType->getPropertyDefinitions(); |
||
257 | View Code Duplication | if (!empty($propertyDefinitions)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
258 | $definition = $reloadedSecondaryType->getPropertyDefinition($propertyData->getId()); |
||
259 | if ($definition !== null) { |
||
260 | break; |
||
261 | } |
||
262 | } |
||
263 | } |
||
264 | } |
||
265 | } |
||
266 | |||
267 | if ($definition === null) { |
||
268 | // property without definition |
||
269 | throw new CmisRuntimeException(sprintf('Property "%s" doesn\'t exist!', $propertyData->getId())); |
||
270 | } |
||
271 | |||
272 | return $this->createProperty($definition, $propertyData->getValues()); |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Convert properties to their property data objects and put them into a Properties object |
||
277 | * |
||
278 | * @param mixed[] $properties |
||
279 | * @param ObjectTypeInterface|null $type |
||
280 | * @param SecondaryTypeInterface[] $secondaryTypes |
||
281 | * @param Updatability[] $updatabilityFilter |
||
282 | * @return PropertiesInterface |
||
283 | * @throws CmisInvalidArgumentException |
||
284 | */ |
||
285 | 2 | public function convertProperties( |
|
286 | array $properties, |
||
287 | ObjectTypeInterface $type = null, |
||
288 | array $secondaryTypes = [], |
||
289 | array $updatabilityFilter = [] |
||
290 | ) { |
||
291 | 2 | if (empty($properties)) { |
|
292 | 1 | return null; |
|
293 | } |
||
294 | |||
295 | 1 | if ($type === null) { |
|
296 | 1 | $type = $this->getTypeDefinition( |
|
297 | 1 | isset($properties[PropertyIds::OBJECT_TYPE_ID]) ? $properties[PropertyIds::OBJECT_TYPE_ID] : null |
|
298 | 1 | ); |
|
299 | 1 | } |
|
300 | |||
301 | // get secondary types |
||
302 | 1 | $allSecondaryTypes = []; |
|
303 | 1 | $secondaryTypeIds = $this->getValueFromArray(PropertyIds::SECONDARY_OBJECT_TYPE_IDS, $properties); |
|
304 | |||
305 | 1 | if (is_array($secondaryTypeIds)) { |
|
306 | foreach ($secondaryTypeIds as $secondaryTypeId) { |
||
307 | $secondaryType = $this->getTypeDefinition((string) $secondaryTypeId); |
||
308 | |||
309 | if (!$secondaryType instanceof SecondaryType) { |
||
310 | throw new CmisInvalidArgumentException( |
||
311 | 'Secondary types property contains a type that is not a secondary type: ' . $secondaryTypeId, |
||
312 | 1425479398 |
||
313 | ); |
||
314 | } |
||
315 | $allSecondaryTypes[] = $secondaryType; |
||
316 | } |
||
317 | 1 | } elseif ($secondaryTypeIds !== null) { |
|
318 | 1 | throw new CmisInvalidArgumentException( |
|
319 | 1 | sprintf( |
|
320 | 1 | 'The property "%s" must be of type array or undefined but is of type "%s"', |
|
321 | 1 | PropertyIds::SECONDARY_OBJECT_TYPE_IDS, |
|
322 | 1 | gettype($secondaryTypeIds) |
|
323 | 1 | ), |
|
324 | 1425473414 |
||
325 | 1 | ); |
|
326 | } |
||
327 | |||
328 | if (!empty($secondaryTypes) && empty($allSecondaryTypes)) { |
||
329 | $allSecondaryTypes = $secondaryTypes; |
||
330 | } |
||
331 | |||
332 | $propertyList = []; |
||
333 | |||
334 | foreach ($properties as $propertyId => $propertyValue) { |
||
335 | $value = $propertyValue; |
||
336 | |||
337 | if ($value instanceof PropertyInterface) { |
||
338 | if ($value->getId() !== $propertyId) { |
||
339 | throw new CmisInvalidArgumentException( |
||
340 | sprintf('Property id mismatch: "%s" != "%s"', $propertyId, $value->getId()) |
||
341 | ); |
||
342 | } |
||
343 | $value = ($value->isMultiValued()) ? $value->getValues() : $value->getFirstValue(); |
||
344 | } |
||
345 | |||
346 | $definition = $type->getPropertyDefinition($propertyId); |
||
347 | |||
348 | if ($definition === null && !empty($allSecondaryTypes)) { |
||
349 | foreach ($allSecondaryTypes as $secondaryType) { |
||
350 | $definition = $secondaryType->getPropertyDefinition($propertyId); |
||
351 | |||
352 | if ($definition !== null) { |
||
353 | break; |
||
354 | } |
||
355 | } |
||
356 | } |
||
357 | |||
358 | if ($definition === null) { |
||
359 | throw new CmisInvalidArgumentException( |
||
360 | sprintf('Property "%s" is not valid for this type or one of the secondary types!', $propertyId) |
||
361 | ); |
||
362 | } |
||
363 | |||
364 | // check updatability |
||
365 | if (!empty($updatabilityFilter) && !in_array($definition->getUpdatability(), $updatabilityFilter)) { |
||
366 | continue; |
||
367 | } |
||
368 | |||
369 | if (is_array($value)) { |
||
370 | if (!$definition->getCardinality()->equals(Cardinality::MULTI)) { |
||
371 | throw new CmisInvalidArgumentException( |
||
372 | sprintf('Property "%s" is not a multi value property but multiple values given!', $propertyId) |
||
373 | ); |
||
374 | } |
||
375 | $values = $value; |
||
376 | } else { |
||
377 | if (!$definition->getCardinality()->equals(Cardinality::SINGLE)) { |
||
378 | throw new CmisInvalidArgumentException( |
||
379 | sprintf('Property "%s" is not a single value property but single value given!', $propertyId) |
||
380 | ); |
||
381 | } |
||
382 | $values = []; |
||
383 | $values[] = $value; |
||
384 | } |
||
385 | |||
386 | $propertyList[] = $this->getBindingsObjectFactory()->createPropertyData($definition, $values); |
||
387 | } |
||
388 | |||
389 | return $this->getBindingsObjectFactory()->createPropertiesData($propertyList); |
||
390 | } |
||
391 | |||
392 | /** |
||
393 | * Get a type definition for the given object type id. If an empty id is given throw an exception. |
||
394 | * |
||
395 | * @param string $objectTypeId |
||
396 | * @return ObjectTypeInterface |
||
397 | * @throws CmisInvalidArgumentException |
||
398 | */ |
||
399 | 1 | private function getTypeDefinition($objectTypeId) |
|
400 | { |
||
401 | 1 | if (empty($objectTypeId) || !is_string($objectTypeId)) { |
|
402 | throw new CmisInvalidArgumentException( |
||
403 | 'Type property must be set and must be of type string but is empty or not a string.' |
||
404 | ); |
||
405 | } |
||
406 | |||
407 | 1 | return $this->session->getTypeDefinition($objectTypeId); |
|
408 | } |
||
409 | |||
410 | /** |
||
411 | * Get a value from an array. Return <code>null</code> if the key does not exist in the array. |
||
412 | * |
||
413 | * @param integer|string $needle |
||
414 | * @param mixed $haystack |
||
415 | * @return mixed |
||
416 | */ |
||
417 | 1 | private function getValueFromArray($needle, $haystack) |
|
418 | { |
||
419 | 1 | if (!is_array($haystack) || !isset($haystack[$needle])) { |
|
420 | return null; |
||
421 | } |
||
422 | |||
423 | 1 | return $haystack[$needle]; |
|
424 | } |
||
425 | |||
426 | /** |
||
427 | * @param PropertiesInterface $properties |
||
428 | * @return PropertyDataInterface[] |
||
429 | */ |
||
430 | 9 | public function convertQueryProperties(PropertiesInterface $properties) |
|
431 | { |
||
432 | 9 | return $properties->getProperties(); |
|
433 | } |
||
434 | |||
435 | /** |
||
436 | * Converts ObjectData to QueryResult |
||
437 | * |
||
438 | * @param ObjectDataInterface $objectData |
||
439 | * @return QueryResult |
||
440 | */ |
||
441 | 1 | public function convertQueryResult(ObjectDataInterface $objectData) |
|
442 | { |
||
443 | 1 | return new QueryResult($this->session, $objectData); |
|
444 | } |
||
445 | |||
446 | /** |
||
447 | * Converts RenditionData to Rendition |
||
448 | * |
||
449 | * @param string $objectId |
||
450 | * @param RenditionDataInterface $renditionData |
||
451 | * @return RenditionInterface |
||
452 | */ |
||
453 | public function convertRendition($objectId, RenditionDataInterface $renditionData) |
||
454 | { |
||
455 | $rendition = new Rendition($this->session, $objectId); |
||
456 | $rendition->populate($renditionData); |
||
457 | |||
458 | return $rendition; |
||
459 | } |
||
460 | |||
461 | /** |
||
462 | * @param RepositoryInfoInterface $repositoryInfo |
||
463 | * @return RepositoryInfoInterface |
||
464 | */ |
||
465 | public function convertRepositoryInfo(RepositoryInfoInterface $repositoryInfo) |
||
466 | { |
||
467 | // TODO: Implement convertRepositoryInfo() method. |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * Convert a type definition to a type |
||
472 | * |
||
473 | * @param TypeDefinitionInterface $typeDefinition |
||
474 | * @return ObjectTypeInterface |
||
475 | * @throws CmisRuntimeException |
||
476 | */ |
||
477 | 7 | public function convertTypeDefinition(TypeDefinitionInterface $typeDefinition) |
|
478 | { |
||
479 | 7 | if ($typeDefinition instanceof DocumentTypeDefinitionInterface) { |
|
480 | 1 | return new DocumentType($this->session, $typeDefinition); |
|
481 | 6 | } elseif ($typeDefinition instanceof FolderTypeDefinitionInterface) { |
|
482 | 1 | return new FolderType($this->session, $typeDefinition); |
|
483 | 5 | } elseif ($typeDefinition instanceof RelationshipTypeDefinitionInterface) { |
|
484 | 1 | return new RelationshipType($this->session, $typeDefinition); |
|
485 | 4 | } elseif ($typeDefinition instanceof PolicyTypeDefinitionInterface) { |
|
486 | 1 | return new PolicyType($this->session, $typeDefinition); |
|
487 | 3 | } elseif ($typeDefinition instanceof ItemTypeDefinitionInterface) { |
|
488 | 1 | return new ItemType($this->session, $typeDefinition); |
|
489 | 2 | } elseif ($typeDefinition instanceof SecondaryTypeDefinitionInterface) { |
|
490 | 1 | return new SecondaryType($this->session, $typeDefinition); |
|
491 | } else { |
||
492 | 1 | throw new CmisRuntimeException( |
|
493 | 1 | sprintf('Unknown base type! Received "%s"', get_class($typeDefinition)), |
|
494 | 1422028427 |
||
495 | 1 | ); |
|
496 | } |
||
497 | } |
||
498 | |||
499 | /** |
||
500 | * @param string $principal |
||
501 | * @param string[] $permissions |
||
502 | * @return AceInterface |
||
503 | */ |
||
504 | public function createAce($principal, array $permissions) |
||
505 | { |
||
506 | // TODO: Implement createAce() method. |
||
507 | } |
||
508 | |||
509 | /** |
||
510 | * @param AceInterface[] $aces |
||
511 | * @return AclInterface |
||
512 | */ |
||
513 | public function createAcl(array $aces) |
||
514 | { |
||
515 | // TODO: Implement createAcl() method. |
||
516 | } |
||
517 | |||
518 | /** |
||
519 | * Creates an object that implements the ContentStream interface. |
||
520 | * |
||
521 | * @param string $filename |
||
522 | * @param integer $length |
||
523 | * @param string $mimeType |
||
524 | * @param mixed $stream @TODO define datatype |
||
525 | * @param boolean $partial |
||
526 | * @return StreamInterface |
||
527 | */ |
||
528 | public function createContentStream($filename, $length, $mimeType, $stream, $partial = false) |
||
529 | { |
||
530 | // TODO: Implement createContentStream() method. |
||
531 | } |
||
532 | |||
533 | /** |
||
534 | * Create a public API Property that contains the property definition and values. |
||
535 | * |
||
536 | * @param PropertyDefinitionInterface $type |
||
537 | * @param array $values |
||
538 | * @return Property |
||
539 | */ |
||
540 | public function createProperty(PropertyDefinitionInterface $type, array $values) |
||
541 | { |
||
542 | return new Property($type, $values); |
||
543 | } |
||
544 | |||
545 | /** |
||
546 | * Try to determined what object type the given objectData belongs to and return that type. |
||
547 | * |
||
548 | * @param ObjectDataInterface $objectData |
||
549 | * @return ObjectTypeInterface|null The object type or <code>null</code> if type could not be determined |
||
550 | */ |
||
551 | public function getTypeFromObjectData(ObjectDataInterface $objectData) |
||
552 | { |
||
553 | if ($objectData->getProperties() === null || count($objectData->getProperties()->getProperties()) === 0) { |
||
554 | return null; |
||
555 | } |
||
556 | |||
557 | $typeProperty = $objectData->getProperties()->getProperties()[PropertyIds::OBJECT_TYPE_ID]; |
||
558 | |||
559 | if (!$typeProperty instanceof PropertyId) { |
||
560 | return null; |
||
561 | } |
||
562 | |||
563 | return $this->session->getTypeDefinition($typeProperty->getFirstValue()); |
||
564 | } |
||
565 | |||
566 | /** |
||
567 | * Get the bindings object factory for the current session binding |
||
568 | * |
||
569 | * @return BindingsObjectFactoryInterface |
||
570 | */ |
||
571 | 1 | protected function getBindingsObjectFactory() |
|
572 | { |
||
573 | 1 | return $this->session->getBinding()->getObjectFactory(); |
|
574 | } |
||
575 | |||
576 | /** |
||
577 | * Create a type definition with all required properties. |
||
578 | * |
||
579 | * @param string $id This opaque attribute identifies this object-type in the repository. |
||
580 | * @param string $localName This attribute represents the underlying repository’s name for the object-type. |
||
581 | * This field is opaque and has no uniqueness constraint imposed by this specification. |
||
582 | * @param string $baseTypeIdString A value that indicates whether the base type for this object-type is the |
||
583 | * document, folder, relationship, policy, item, or secondary base type. |
||
584 | * @param string $parentId The id of the object-type’s immediate parent type. It MUST be "not set" for a base |
||
585 | * type. Depending on the binding this means it might not exist on the base type object-type definition. |
||
586 | * @param boolean $creatable Indicates whether new objects of this type MAY be created. If the value of this |
||
587 | * attribute is FALSE, the repository MAY contain objects of this type already, but MUST NOT allow new objects |
||
588 | * of this type to be created. |
||
589 | * @param boolean $fileable Indicates whether or not objects of this type are file-able. |
||
590 | * @param boolean $queryable Indicates whether or not this object-type can appear in the FROM clause of a query |
||
591 | * statement. A non-queryable object-type is not visible through the relational view that is used for query, |
||
592 | * and CAN NOT appear in the FROM clause of a query statement. |
||
593 | * @param boolean $controllablePolicy Indicates whether or not objects of this type are controllable via policies. |
||
594 | * Policy objects can only be applied to controllablePolicy objects. |
||
595 | * @param boolean $controllableACL This attribute indicates whether or not objects of this type are controllable by |
||
596 | * ACL’s. Only objects that are controllableACL can have an ACL. |
||
597 | * @param boolean $fulltextIndexed Indicates whether objects of this type are indexed for full-text search for |
||
598 | * querying via the CONTAINS() query predicate. If the value of this attribute is TRUE, the full-text index |
||
599 | * MUST cover the content and MAY cover the metadata. |
||
600 | * @param boolean $includedInSupertypeQuery Indicates whether this type and its subtypes appear in a query of this |
||
601 | * type’s ancestor types. For example: if Invoice is a sub-type of cmis:document, if this is TRUE on Invoice |
||
602 | * then for a query on cmis:document, instances of Invoice will be returned if they match. If this attribute |
||
603 | * is FALSE, no instances of Invoice will be returned even if they match the query. |
||
604 | * @param string $localNamespace This attribute allows repositories to represent the internal namespace of |
||
605 | * the underlying repository’s name for the object-type. |
||
606 | * @param string $queryName Used for query and filter operations on object-types. This is an opaque string with |
||
607 | * limitations. See 2.1.2.1.3 Query Names of the CMIS 1.1 standard for details. |
||
608 | * @param string $displayName Used for presentation by application. |
||
609 | * @param string $description Description of this object-type, such as the nature of content, or its intended use. |
||
610 | * Used for presentation by application. |
||
611 | * @param TypeMutabilityInterface|null $typeMutability |
||
612 | * typeMutability.create - Indicates whether new child types may be created with this type as the parent. |
||
613 | * typeMutability.update - Indicates whether clients may make changes to this type per the constraints |
||
614 | * defined in this specification. |
||
615 | * typeMutability.delete - Indicates whether clients may delete this type if there are no instances of it in |
||
616 | * the repository. |
||
617 | * @return FolderTypeDefinition|DocumentTypeDefinition|RelationshipTypeDefinition|PolicyTypeDefinition|ItemTypeDefinition|SecondaryTypeDefinition |
||
618 | */ |
||
619 | public function createTypeDefinition( |
||
620 | $id, |
||
621 | $localName, |
||
622 | $baseTypeIdString, |
||
623 | $parentId, |
||
624 | $creatable, |
||
625 | $fileable, |
||
626 | $queryable, |
||
627 | $controllablePolicy, |
||
628 | $controllableACL, |
||
629 | $fulltextIndexed, |
||
630 | $includedInSupertypeQuery, |
||
631 | $localNamespace = '', |
||
632 | $queryName = '', |
||
633 | $displayName = '', |
||
634 | $description = '', |
||
635 | TypeMutabilityInterface $typeMutability = null |
||
636 | ) { |
||
637 | $typeDefinition = $this->getBindingsObjectFactory()->getTypeDefinitionByBaseTypeId($baseTypeIdString, $id); |
||
638 | |||
639 | $typeDefinition->setLocalName($localName); |
||
640 | $typeDefinition->setParentTypeId($parentId); |
||
641 | $typeDefinition->setIsCreatable($creatable); |
||
642 | $typeDefinition->setIsFileable($fileable); |
||
643 | $typeDefinition->setIsQueryable($queryable); |
||
644 | $typeDefinition->setisControllablePolicy($controllablePolicy); |
||
645 | $typeDefinition->setIsControllableAcl($controllableACL); |
||
646 | $typeDefinition->setIsFulltextIndexed($fulltextIndexed); |
||
647 | $typeDefinition->setIsIncludedInSupertypeQuery($includedInSupertypeQuery); |
||
648 | $typeDefinition->setLocalNamespace($localNamespace); |
||
649 | $typeDefinition->setQueryName($queryName); |
||
650 | $typeDefinition->setDisplayName($displayName); |
||
651 | $typeDefinition->setDescription($description); |
||
652 | if ($typeMutability !== null) { |
||
653 | $typeDefinition->setTypeMutability($typeMutability); |
||
654 | } |
||
655 | |||
656 | return $typeDefinition; |
||
657 | } |
||
658 | } |
||
659 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.