Skip to content

Commit 20fa825

Browse files
committed
Environment aware interface.
1 parent ecc1898 commit 20fa825

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2015 Cloud Creativity Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace CloudCreativity\JsonApi\Contracts\Integration;
20+
21+
/**
22+
* Interface EnvironmentAwareInterface
23+
* @package CloudCreativity\JsonApi
24+
*/
25+
interface EnvironmentAwareInterface
26+
{
27+
28+
/**
29+
* @param EnvironmentInterface $environment
30+
* @return $this
31+
*/
32+
public function setEnvironment(EnvironmentInterface $environment);
33+
34+
/**
35+
* @return EnvironmentInterface
36+
*/
37+
public function getEnvironment();
38+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2015 Cloud Creativity Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
namespace CloudCreativity\JsonApi\Integration;
20+
21+
use CloudCreativity\JsonApi\Contracts\Integration\EnvironmentInterface;
22+
use RuntimeException;
23+
24+
/**
25+
* Class EnvironmentAwareTrait
26+
* @package CloudCreativity\JsonApi
27+
*/
28+
trait EnvironmentAwareTrait
29+
{
30+
31+
/**
32+
* @var EnvironmentInterface|null
33+
*/
34+
private $environment;
35+
36+
/**
37+
* @param EnvironmentInterface $environment
38+
* @return $this
39+
*/
40+
public function setEnvironment(EnvironmentInterface $environment)
41+
{
42+
$this->environment = $environment;
43+
44+
return $this;
45+
}
46+
47+
/**
48+
* @return EnvironmentInterface
49+
*/
50+
public function getEnvironment()
51+
{
52+
if (!$this->environment instanceof EnvironmentInterface) {
53+
throw new RuntimeException(sprintf('%s expects to be injected with a %s instance.', static::class, EnvironmentInterface::class));
54+
}
55+
56+
return $this->environment;
57+
}
58+
}

0 commit comments

Comments
 (0)