1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the tmilos/scim-schema package. |
5
|
|
|
* |
6
|
|
|
* (c) Milos Tomic <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tmilos\ScimSchema\Builder; |
13
|
|
|
|
14
|
|
|
use Tmilos\ScimSchema\Model\v2\ResourceType; |
15
|
|
|
use Tmilos\ScimSchema\ScimConstants; |
16
|
|
|
use Tmilos\ScimSchema\ScimConstantsV2; |
17
|
|
|
|
18
|
|
|
class ResourceTypeBuilder |
19
|
|
|
{ |
20
|
|
|
private static $builderMap = [ |
21
|
|
|
ScimConstants::RESOURCE_TYPE_RESOURCE_TYPE => 'buildResourceType', |
22
|
|
|
ScimConstants::RESOURCE_TYPE_SCHEMA => 'buildSchema', |
23
|
|
|
ScimConstants::RESOURCE_TYPE_SERVICE_PROVIDER_CONFIG => 'buildServiceProviderConfig', |
24
|
|
|
ScimConstants::RESOURCE_TYPE_USER => 'buildUser', |
25
|
|
|
ScimConstants::RESOURCE_TYPE_GROUP => 'buildGroup', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
private $locationBase = 'http://localhost'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $locationBase |
32
|
|
|
*/ |
33
|
|
|
public function __construct($locationBase = 'http://localhost') |
34
|
|
|
{ |
35
|
|
|
$this->setLocationBase($locationBase); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $locationBase |
40
|
|
|
*/ |
41
|
|
|
public function setLocationBase($locationBase) |
42
|
|
|
{ |
43
|
|
|
$this->locationBase = rtrim($locationBase, '/'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $resourceTypeId |
48
|
|
|
* |
49
|
|
|
* @return ResourceType |
50
|
|
|
*/ |
51
|
|
|
public function build($resourceTypeId) |
52
|
|
|
{ |
53
|
|
|
return $this->{self::$builderMap[$resourceTypeId]}(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return ResourceType |
58
|
|
|
*/ |
59
|
|
|
public function buildResourceType() |
60
|
|
|
{ |
61
|
|
|
$result = new ResourceType(ScimConstants::RESOURCE_TYPE_RESOURCE_TYPE); |
62
|
|
|
$result->setName('ResourceType'); |
63
|
|
|
$result->setDescription('Resource Type'); |
64
|
|
|
$result->setEndpoint('/ResourceTypes'); |
65
|
|
|
$result->setSchema(ScimConstantsV2::SCHEMA_RESOURCE_TYPE); |
66
|
|
|
$result->getMeta()->setLocation($this->locationBase.'/ResourceTypes/'.$result->getId()); |
67
|
|
|
|
68
|
|
|
return $result; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return ResourceType |
73
|
|
|
*/ |
74
|
|
|
public function buildSchema() |
75
|
|
|
{ |
76
|
|
|
$result = new ResourceType(ScimConstants::RESOURCE_TYPE_SCHEMA); |
77
|
|
|
$result->setName('Schema'); |
78
|
|
|
$result->setDescription('Schema'); |
79
|
|
|
$result->setEndpoint('/Schemas'); |
80
|
|
|
$result->setSchema(ScimConstantsV2::SCHEMA_SCHEMA); |
81
|
|
|
$result->getMeta()->setLocation($this->locationBase.'/ResourceTypes/'.$result->getId()); |
82
|
|
|
|
83
|
|
|
return $result; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return ResourceType |
88
|
|
|
*/ |
89
|
|
|
public function buildServiceProviderConfig() |
90
|
|
|
{ |
91
|
|
|
$result = new ResourceType(ScimConstants::RESOURCE_TYPE_SERVICE_PROVIDER_CONFIG); |
92
|
|
|
$result->setName('Service Provider Configuration'); |
93
|
|
|
$result->setDescription('Service Provider Configuration'); |
94
|
|
|
$result->setEndpoint('/ServiceProviderConfigs'); |
95
|
|
|
$result->setSchema(ScimConstantsV2::SCHEMA_SERVICE_PROVIDER_CONFIG); |
96
|
|
|
$result->getMeta()->setLocation($this->locationBase.'/ResourceTypes/'.$result->getId()); |
97
|
|
|
|
98
|
|
|
return $result; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return ResourceType |
103
|
|
|
*/ |
104
|
|
|
public function buildUser() |
105
|
|
|
{ |
106
|
|
|
$result = new ResourceType(ScimConstants::RESOURCE_TYPE_USER); |
107
|
|
|
$result->setName('User'); |
108
|
|
|
$result->setDescription('User Account'); |
109
|
|
|
$result->setEndpoint('/Users'); |
110
|
|
|
$result->setSchema(ScimConstantsV2::SCHEMA_USER); |
111
|
|
|
$result->addSchemaExtension(ScimConstantsV2::SCHEMA_ENTERPRISE_USER, false); |
112
|
|
|
$result->getMeta()->setLocation($this->locationBase.'/ResourceTypes/'.$result->getId()); |
113
|
|
|
|
114
|
|
|
return $result; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return ResourceType |
119
|
|
|
*/ |
120
|
|
|
public function buildGroup() |
121
|
|
|
{ |
122
|
|
|
$result = new ResourceType(ScimConstants::RESOURCE_TYPE_GROUP); |
123
|
|
|
$result->setName('Group'); |
124
|
|
|
$result->setDescription('Group'); |
125
|
|
|
$result->setEndpoint('/Groups'); |
126
|
|
|
$result->setSchema(ScimConstantsV2::SCHEMA_GROUP); |
127
|
|
|
$result->getMeta()->setLocation($this->locationBase.'/ResourceTypes/'.$result->getId()); |
128
|
|
|
|
129
|
|
|
return $result; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|