1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the League\Fractal package. |
5
|
|
|
* |
6
|
|
|
* (c) Phil Sturgeon <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace League\Fractal; |
13
|
|
|
|
14
|
|
|
use League\Fractal\Resource\ResourceInterface; |
15
|
|
|
|
16
|
|
|
class ScopeFactory implements ScopeFactoryInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param Manager $manager |
20
|
|
|
* @param ResourceInterface $resource |
21
|
|
|
* @param string|null $scopeIdentifier |
22
|
|
|
* @return Scope |
23
|
|
|
*/ |
24
|
36 |
|
public function createScopeFor(Manager $manager, ResourceInterface $resource, $scopeIdentifier = null) |
25
|
|
|
{ |
26
|
36 |
|
return new Scope($manager, $resource, $scopeIdentifier); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param Manager $manager |
31
|
|
|
* @param Scope $parentScopeInstance |
32
|
|
|
* @param ResourceInterface $resource |
33
|
|
|
* @param string|null $scopeIdentifier |
34
|
|
|
* @return Scope |
35
|
|
|
*/ |
36
|
30 |
|
public function createChildScopeFor(Manager $manager, Scope $parentScopeInstance, ResourceInterface $resource, $scopeIdentifier = null) |
37
|
|
|
{ |
38
|
30 |
|
$scopeInstance = $this->createScopeFor($manager, $resource, $scopeIdentifier); |
39
|
|
|
|
40
|
|
|
// This will be the new children list of parents (parents parents, plus the parent) |
41
|
30 |
|
$scopeArray = $parentScopeInstance->getParentScopes(); |
42
|
30 |
|
$scopeArray[] = $parentScopeInstance->getScopeIdentifier(); |
43
|
|
|
|
44
|
30 |
|
$scopeInstance->setParentScopes($scopeArray); |
45
|
|
|
|
46
|
30 |
|
return $scopeInstance; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|