@@ -25,86 +25,86 @@ |
||
25 | 25 | */ |
26 | 26 | class Api |
27 | 27 | { |
28 | - /** |
|
29 | - * @var EndpointsContainer |
|
30 | - */ |
|
31 | - protected $endpointsContainer; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $organizationId; |
|
37 | - |
|
38 | - public function __construct(EndpointsContainer $endpointsContainer) |
|
39 | - { |
|
40 | - $this->endpointsContainer = $endpointsContainer; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Magic method to access different endpoints. |
|
45 | - * |
|
46 | - * @param string $endpoint |
|
47 | - * |
|
48 | - * @return Endpoint |
|
49 | - */ |
|
50 | - public function __get($endpoint) |
|
51 | - { |
|
52 | - $endpoint = $this->endpointsContainer->resolve($endpoint); |
|
53 | - |
|
54 | - if (method_exists($endpoint, 'setOrganizationId')) { |
|
55 | - $endpoint->setOrganizationId($this->organizationId); |
|
56 | - } |
|
57 | - |
|
58 | - return $endpoint; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @param $organizationName |
|
63 | - * @return $this |
|
64 | - */ |
|
65 | - public function setOrganization($organizationName) |
|
66 | - { |
|
67 | - if($organization = $this->getOrganizationByName($organizationName)) { |
|
68 | - $this->setOrganizationId($organization['organizationId']); |
|
69 | - } |
|
70 | - |
|
71 | - return $this; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param int $organizationId |
|
76 | - * @return $this |
|
77 | - */ |
|
78 | - public function setOrganizationId($organizationId) |
|
79 | - { |
|
80 | - $this->organizationId = $organizationId; |
|
81 | - |
|
82 | - return $this; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function getOrganizationId() |
|
90 | - { |
|
91 | - return $this->organizationId; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @param $organization |
|
96 | - * @return bool|array |
|
97 | - */ |
|
98 | - protected function getOrganizationByName($organization) |
|
99 | - { |
|
100 | - $organizations = $this->organizations->getAll(); |
|
101 | - |
|
102 | - foreach ($organizations['entities'] as $entity) { |
|
103 | - if ($entity['name'] == $organization) { |
|
104 | - return $organization; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - return false; |
|
109 | - } |
|
28 | + /** |
|
29 | + * @var EndpointsContainer |
|
30 | + */ |
|
31 | + protected $endpointsContainer; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $organizationId; |
|
37 | + |
|
38 | + public function __construct(EndpointsContainer $endpointsContainer) |
|
39 | + { |
|
40 | + $this->endpointsContainer = $endpointsContainer; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Magic method to access different endpoints. |
|
45 | + * |
|
46 | + * @param string $endpoint |
|
47 | + * |
|
48 | + * @return Endpoint |
|
49 | + */ |
|
50 | + public function __get($endpoint) |
|
51 | + { |
|
52 | + $endpoint = $this->endpointsContainer->resolve($endpoint); |
|
53 | + |
|
54 | + if (method_exists($endpoint, 'setOrganizationId')) { |
|
55 | + $endpoint->setOrganizationId($this->organizationId); |
|
56 | + } |
|
57 | + |
|
58 | + return $endpoint; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @param $organizationName |
|
63 | + * @return $this |
|
64 | + */ |
|
65 | + public function setOrganization($organizationName) |
|
66 | + { |
|
67 | + if($organization = $this->getOrganizationByName($organizationName)) { |
|
68 | + $this->setOrganizationId($organization['organizationId']); |
|
69 | + } |
|
70 | + |
|
71 | + return $this; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param int $organizationId |
|
76 | + * @return $this |
|
77 | + */ |
|
78 | + public function setOrganizationId($organizationId) |
|
79 | + { |
|
80 | + $this->organizationId = $organizationId; |
|
81 | + |
|
82 | + return $this; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function getOrganizationId() |
|
90 | + { |
|
91 | + return $this->organizationId; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @param $organization |
|
96 | + * @return bool|array |
|
97 | + */ |
|
98 | + protected function getOrganizationByName($organization) |
|
99 | + { |
|
100 | + $organizations = $this->organizations->getAll(); |
|
101 | + |
|
102 | + foreach ($organizations['entities'] as $entity) { |
|
103 | + if ($entity['name'] == $organization) { |
|
104 | + return $organization; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + return false; |
|
109 | + } |
|
110 | 110 | } |
111 | 111 | \ No newline at end of file |
@@ -64,7 +64,7 @@ |
||
64 | 64 | */ |
65 | 65 | public function setOrganization($organizationName) |
66 | 66 | { |
67 | - if($organization = $this->getOrganizationByName($organizationName)) { |
|
67 | + if ($organization = $this->getOrganizationByName($organizationName)) { |
|
68 | 68 | $this->setOrganizationId($organization['organizationId']); |
69 | 69 | } |
70 | 70 |