1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\DashboardBundle\Widget; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
6
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
9
|
|
|
|
10
|
|
|
class DashboardWidget |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var ContainerAwareCommand |
14
|
|
|
*/ |
15
|
|
|
private $command; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $controller; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string $command |
24
|
|
|
* @param string $controller |
25
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container |
26
|
|
|
*/ |
27
|
|
|
public function __construct($command, $controller, ContainerInterface $container) |
28
|
|
|
{ |
29
|
|
|
$this->command = new $command(); |
30
|
|
|
$this->command->setContainer($container); |
31
|
|
|
$this->controller = $controller; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return ContainerAwareCommand |
36
|
|
|
*/ |
37
|
|
|
public function getCommand() |
38
|
|
|
{ |
39
|
|
|
return $this->command; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function resolvedController() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$annotationReader = new AnnotationReader(); |
45
|
|
|
$reflectionMethod = new \ReflectionMethod($this->controller, 'widgetAction'); |
46
|
|
|
$methodAnnotations = $annotationReader->getMethodAnnotations($reflectionMethod); |
47
|
|
|
foreach ($methodAnnotations as $annotation) { |
48
|
|
|
if ($annotation instanceof Route) { |
49
|
|
|
if (empty($annotation)) { |
50
|
|
|
throw new \Exception('The name is not configured in the annotation'); |
51
|
|
|
} |
52
|
|
|
/* @var \Sensio\Bundle\FrameworkExtraBundle\Configuration\Route $annotation */ |
53
|
|
|
return $annotation->getName(); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
throw new \Exception('There is no route annotation'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.