|
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\Driver; |
|
|
20 |
|
|
|
21 |
use Doctrine\Common\Annotations\Reader; |
|
|
22 |
use JMS\SecurityExtraBundle\Annotation\RunAs; |
|
|
23 |
use JMS\SecurityExtraBundle\Annotation\SatisfiesParentSecurityPolicy; |
|
|
24 |
use JMS\SecurityExtraBundle\Annotation\Secure; |
|
|
25 |
use JMS\SecurityExtraBundle\Annotation\SecureParam; |
|
|
26 |
use JMS\SecurityExtraBundle\Annotation\SecureReturn; |
|
|
27 |
use JMS\SecurityExtraBundle\Metadata\ClassMetadata; |
|
|
28 |
use JMS\SecurityExtraBundle\Metadata\MethodMetadata; |
|
|
29 |
use Metadata\Driver\DriverInterface; |
|
|
30 |
use \ReflectionClass; |
|
|
31 |
use \ReflectionMethod; |
|
|
32 |
|
|
|
33 |
/** |
|
|
34 |
* Loads security annotations and converts them to metadata |
|
|
35 |
* |
|
|
36 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
37 |
*/ |
|
|
38 |
class AnnotationDriver implements DriverInterface |
|
|
39 |
{ |
|
|
40 |
private $reader; |
|
|
41 |
private $converter; |
|
|
42 |
|
|
|
43 |
public function __construct(Reader $reader) |
|
|
44 |
{ |
|
|
45 |
$this->reader = $reader; |
|
|
46 |
$this->converter = new AnnotationConverter(); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
public function loadMetadataForClass(ReflectionClass $reflection) |
|
|
50 |
{ |
|
|
51 |
$metadata = new ClassMetadata($reflection->getName()); |
|
|
52 |
|
|
|
53 |
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED) as $method) { |
|
|
54 |
// check if the method was defined on this class |
|
|
55 |
if ($method->getDeclaringClass()->getName() !== $reflection->getName()) { |
|
|
56 |
continue; |
|
|
57 |
} |
|
|
58 |
|
|
|
59 |
$annotations = $this->reader->getMethodAnnotations($method); |
|
|
60 |
|
|
|
61 |
if ($annotations && null !== $methodMetadata = $this->converter->convertMethodAnnotations($method, $annotations)) { |
|
|
62 |
$metadata->addMethodMetadata($methodMetadata); |
|
|
63 |
} |
|
|
64 |
} |
|
|
65 |
|
|
|
66 |
return $metadata; |
|
|
67 |
} |
|
|
68 |
} |