|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* Copyright 2010 Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
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 JMS\SecurityExtraBundle\Metadata; |
|
|
20 |
|
|
|
21 |
use Metadata\MethodMetadata as BaseMethodMetadata; |
|
|
22 |
|
|
|
23 |
/** |
|
|
24 |
* Contains method metadata information |
|
|
25 |
* |
|
|
26 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
27 |
*/ |
|
|
28 |
class MethodMetadata extends BaseMethodMetadata |
|
|
29 |
{ |
|
|
30 |
public $roles = array(); |
|
|
31 |
public $paramPermissions = array(); |
|
|
32 |
public $returnPermissions = array(); |
|
|
33 |
public $runAsRoles = array(); |
|
|
34 |
public $satisfiesParentSecurityPolicy = false; |
|
|
35 |
|
|
|
36 |
/** |
|
|
37 |
* Adds a parameter restriction |
|
|
38 |
* |
|
|
39 |
* @param integer $index 0-based |
|
|
40 |
* @param array $permissions |
|
|
41 |
*/ |
|
|
42 |
public function addParamPermissions($index, array $permissions) |
|
|
43 |
{ |
|
|
44 |
$this->paramPermissions[$index] = $permissions; |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
public function isDeclaredOnInterface() |
|
|
48 |
{ |
|
|
49 |
foreach ($this->reflection->getDeclaringClass()->getInterfaces() as $interface) { |
|
|
50 |
if ($interface->hasMethod($this->name)) { |
|
|
51 |
return true; |
|
|
52 |
} |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
return false; |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
/** |
|
|
59 |
* This allows to merge in metadata from an interface |
|
|
60 |
* |
|
|
61 |
* @param MethodMetadata $method |
|
|
62 |
* @return void |
|
|
63 |
*/ |
|
|
64 |
public function merge(MethodMetadata $method) |
|
|
65 |
{ |
|
|
66 |
if (!$this->roles) { |
|
|
67 |
$this->roles = $method->roles; |
|
|
68 |
} |
|
|
69 |
|
|
|
70 |
if (!$this->returnPermissions) { |
|
|
71 |
$this->returnPermissions = $method->returnPermissions; |
|
|
72 |
} |
|
|
73 |
|
|
|
74 |
if (!$this->runAsRoles) { |
|
|
75 |
$this->runAsRoles = $method->runAsRoles; |
|
|
76 |
} |
|
|
77 |
|
|
|
78 |
foreach ($method->paramPermissions as $index => $permissions) { |
|
|
79 |
if (!isset($this->paramPermissions[$index])) { |
|
|
80 |
$this->paramPermissions[$index] = $permissions; |
|
|
81 |
} |
|
|
82 |
} |
|
|
83 |
} |
|
|
84 |
|
|
|
85 |
public function getAsArray() |
|
|
86 |
{ |
|
|
87 |
return array( |
|
|
88 |
'roles' => $this->roles, |
|
|
89 |
'run_as_roles' => $this->runAsRoles, |
|
|
90 |
'param_permissions' => $this->paramPermissions, |
|
|
91 |
'return_permissions' => $this->returnPermissions, |
|
|
92 |
); |
|
|
93 |
} |
|
|
94 |
} |