|
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
|
44 |
|
public function createScopeFor(Manager $manager, ResourceInterface $resource, $scopeIdentifier = null) |
|
25
|
|
|
{ |
|
26
|
44 |
|
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
|
37 |
|
public function createChildScopeFor(Manager $manager, Scope $parentScopeInstance, ResourceInterface $resource, $scopeIdentifier = null) |
|
37
|
|
|
{ |
|
38
|
37 |
|
$scopeInstance = $this->createScopeFor($manager, $resource, $scopeIdentifier); |
|
39
|
|
|
|
|
40
|
|
|
// This will be the new children list of parents (parents parents, plus the parent) |
|
41
|
37 |
|
$scopeArray = $parentScopeInstance->getParentScopes(); |
|
42
|
37 |
|
$scopeArray[] = $parentScopeInstance->getScopeIdentifier(); |
|
43
|
|
|
|
|
44
|
37 |
|
$scopeInstance->setParentScopes($scopeArray); |
|
45
|
|
|
|
|
46
|
37 |
|
return $scopeInstance; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|