-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathEntityCollection.php
64 lines (56 loc) · 1.62 KB
/
EntityCollection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Office365;
use Office365\Runtime\Actions\CreateEntityQuery;
use Office365\Runtime\ClientObject;
use Office365\Runtime\ClientObjectCollection;
use Office365\Runtime\ClientRuntimeContext;
use Office365\Runtime\ResourcePath;
/**
* @method GraphServiceClient getContext()
*/
class EntityCollection extends ClientObjectCollection
{
/**
* @param ClientRuntimeContext $ctx
* @param ResourcePath|null $resourcePath
* @param null $itemTypeName
*/
public function __construct(ClientRuntimeContext $ctx, ?ResourcePath $resourcePath = null, $itemTypeName = null)
{
parent::__construct($ctx, $resourcePath, $itemTypeName);
}
/**
* @param string $id Entity Id
* @return ClientObject
*/
function getById($id)
{
return $this->createType(new ResourcePath($id, $this->getResourcePath()));
}
/**
* A generic way to create a new resource
* @return Entity
*/
public function add(){
/** @var Entity $entity */
$entity = $this->createType();
$this->addChild($entity);
$qry = new CreateEntityQuery($entity);
$this->getContext()->addQueryAndResultObject($qry,$entity);
return $entity;
}
/**
* Returns the value at specified offset
*
* @param int|string Entity could be addressed by id/userPrincipalName or by index offset
* @access public
* @return ClientObject
* @abstracting ArrayAccess
*/
public function offsetGet($offset)
{
if(is_int($offset))
return parent::offsetGet($offset);
return $this->getById($offset);
}
}