|
1
|
|
|
<?php |
|
2
|
|
|
namespace Fi\CoreBundle\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use Fi\CoreBundle\Utils\Entity\Finder; |
|
5
|
|
|
use Fi\CoreBundle\Utils\Entity\EntityUtils; |
|
6
|
|
|
use Fi\CoreBundle\Utils\PermessiUtils; |
|
7
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
8
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
|
9
|
|
|
|
|
10
|
|
|
class FiController extends FiTabellaController |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
protected $bundle; |
|
14
|
|
|
protected $controller; |
|
15
|
|
|
protected $permessi; |
|
16
|
|
|
|
|
17
|
1 |
|
public function __construct(ObjectManager $em, TokenStorageInterface $user) |
|
18
|
|
|
{ |
|
19
|
1 |
|
$matches = array(); |
|
|
|
|
|
|
20
|
1 |
|
$controllo = new \ReflectionClass(get_class($this)); |
|
21
|
|
|
|
|
22
|
1 |
|
preg_match('/(.*)\\\(.*)\\\Controller\\\(.*)Controller/', $controllo->name, $matches); |
|
23
|
1 |
|
if (count($matches) == 0) { |
|
24
|
1 |
|
preg_match('/(.*)(.*)\\\Controller\\\(.*)Controller/', $controllo->name, $matches); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
$this->bundle = ($matches[count($matches) - 2] ? $matches[count($matches) - 2] : $matches[count($matches) - 3]); |
|
|
|
|
|
|
28
|
1 |
|
$this->controller = $matches[count($matches) - 1]; |
|
29
|
|
|
|
|
30
|
1 |
|
$this->permessi = new PermessiUtils($em, $this->getController(), $user->getToken()->getUser()); |
|
31
|
1 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Returns the calling function through a backtrace |
|
35
|
|
|
*/ |
|
36
|
1 |
|
protected function getThisFunctionName() |
|
37
|
|
|
{ |
|
38
|
|
|
// a funciton x has called a function y which called this |
|
39
|
|
|
// see stackoverflow.com/questions/190421 |
|
40
|
1 |
|
$caller = debug_backtrace(); |
|
41
|
1 |
|
$caller = $caller[1]; |
|
42
|
1 |
|
return $caller['function']; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
protected function getEntityClassNotation() |
|
46
|
|
|
{ |
|
47
|
1 |
|
$em = $this->get("doctrine")->getManager(); |
|
|
|
|
|
|
48
|
1 |
|
$entityfinder = new Finder($em, $this->controller); |
|
49
|
1 |
|
$entityutils = new EntityUtils($em); |
|
|
|
|
|
|
50
|
1 |
|
return $entityutils->getClassNameToShortcutNotations($entityfinder->getClassNameFromEntityName()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
protected function getEntityClassName() |
|
54
|
|
|
{ |
|
55
|
1 |
|
$em = $this->get("doctrine")->getManager(); |
|
|
|
|
|
|
56
|
1 |
|
$entityfinder = new Finder($em, $this->controller); |
|
57
|
1 |
|
return $entityfinder->getClassNameFromEntityName(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function getNamespace() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->namespace; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
protected function getBundle() |
|
66
|
|
|
{ |
|
67
|
1 |
|
return $this->bundle; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
protected function getController() |
|
71
|
|
|
{ |
|
72
|
1 |
|
return $this->controller; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
protected function getPermessi() |
|
76
|
|
|
{ |
|
77
|
1 |
|
return $this->permessi; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.