Completed
Push — master ( cc3bea...d6d1d3 )
by Dana
8s
created

Controller::getPrefix()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * This file is part of the silex-annotation-provider package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @license       MIT License
9
 * @copyright (c) 2014, Dana Desrosiers <[email protected]>
10
 */
11
12
namespace DDesrosiers\SilexAnnotations\Annotations;
13
14
use DDesrosiers\SilexAnnotations\AnnotationService;
15
use ReflectionClass;
16
use Silex\Application;
17
18
/**
19
 * @Annotation
20
 * @Target("CLASS")
21
 * @author Dana Desrosiers <[email protected]>
22
 */
23
class Controller
24
{
25
    public $prefix;
26
27
    public function process(Application $app, ReflectionClass $reflectionClass)
28
    {
29
        $controllerCollection = $app['controllers_factory'];
30
        /** @var AnnotationService $annotationService */
31
        $annotationService = $app['annot'];
32
        $annotationService->processClassAnnotations($reflectionClass, $controllerCollection);
33
        $annotationService->processMethodAnnotations($reflectionClass, $controllerCollection);
34
        $app->mount($this->prefix, $controllerCollection);
35
    }
36
37
    public function getPrefix()
38
    {
39
        // the prefix might not start with a forward slash, but the REQUEST_URI always will
40
        // make sure we always have a forward slash so the comparison to REQUEST_URI works as expected
41
        return ($this->prefix[0] !== '/') ? "/$this->prefix" : $this->prefix;
42
    }
43
}