Completed
Push — master ( a2ff31...667b20 )
by Anthony
12s
created
Service/AccessRights.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -10,114 +10,114 @@
 block discarded – undo
10 10
 
11 11
 class AccessRights
12 12
 {
13
-    private $em;
14
-    private $router;
15
-    private $session;
16
-    private $request;
17
-
18
-    /**
19
-     * AccessRights constructor.
20
-     * @param ContainerInterface $em
21
-     * @param RouterInterface $router
22
-     * @param Session $session
23
-     * @param RequestStack $request
24
-     */
25
-    public function __construct(ContainerInterface $em, RouterInterface $router, Session $session, RequestStack $request)
26
-    {
27
-        $this->em = $em;
28
-        $this->router = $router;
29
-        $this->session = $session;
30
-        $this->request = $request;
31
-    }
32
-
33
-    public function onKernelController()
34
-    {
35
-        $route = $this->request->getCurrentRequest()->get("_route");
36
-        $admin_page = explode("_", $route)[0];
37
-
38
-        //comment because it cause errore redirect
39
-        /*if ($route == "fos_user_security_login" || $route == "fos_user_registration_register") {
13
+				private $em;
14
+				private $router;
15
+				private $session;
16
+				private $request;
17
+
18
+				/**
19
+				 * AccessRights constructor.
20
+				 * @param ContainerInterface $em
21
+				 * @param RouterInterface $router
22
+				 * @param Session $session
23
+				 * @param RequestStack $request
24
+				 */
25
+				public function __construct(ContainerInterface $em, RouterInterface $router, Session $session, RequestStack $request)
26
+				{
27
+								$this->em = $em;
28
+								$this->router = $router;
29
+								$this->session = $session;
30
+								$this->request = $request;
31
+				}
32
+
33
+				public function onKernelController()
34
+				{
35
+								$route = $this->request->getCurrentRequest()->get("_route");
36
+								$admin_page = explode("_", $route)[0];
37
+
38
+								//comment because it cause errore redirect
39
+								/*if ($route == "fos_user_security_login" || $route == "fos_user_registration_register") {
40 40
             $this->session->clear();
41 41
             $this->em->get("security.token_storage")->setToken(null);
42 42
         }*/
43 43
 
44
-        //to show admin panel
45
-        if (in_array($route, ["_profiler", "_profiler_search_bar", "_wdt"])) {
46
-            return;
47
-        }
48
-
49
-        $ribs_admin_rights = json_decode(file_get_contents($this->em->get('kernel')->getRootDir() . "/../src/Ribs/RibsAdminBundle/Resources/json/ribsadmin_rights.json"));
50
-
51
-        if ($admin_page == "ribsadmin" && ($route !== 404) && ($route !== null)) {
52
-            $route_right = $this->in_array_recursive($route, $ribs_admin_rights);
53
-            $user_rights = $this->getUserRights();
54
-
55
-            if ($route_right === false) {
56
-                throw new AccessDeniedException("No access");
57
-            }
58
-
59
-            foreach ($user_rights as $right) {
60
-                if (in_array($right, $route_right)) {
61
-                    return;
62
-                }
63
-            }
64
-
65
-            throw new AccessDeniedException("No access");
66
-        }
67
-    }
68
-
69
-    /**
70
-     * @param $needle
71
-     * @param $haystack
72
-     * @return bool|mixed
73
-     * fonction that search if the right contain an url or more
74
-     */
75
-    private function in_array_recursive($needle, $haystack)
76
-    {
77
-        $rights = [];
78
-        $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($haystack));
79
-
80
-        foreach ($it AS $element => $value) {
81
-            if ($value == $needle) {
82
-                $rights[] = $it->getInnerIterator()["right"];
83
-            }
84
-        }
85
-
86
-        if (count($rights) === 0) {
87
-            return false;
88
-        }
89
-
90
-        return $rights;
91
-    }
92
-
93
-
94
-    /**
95
-     * @return array function that retun a array that contain all user rights or empty array if no right found
96
-     */
97
-    private function getUserRights(): array
98
-    {
99
-        $user_rights = $this->em->get("security.token_storage")->getToken()->getUser()->getUser()->getAccessRights();
100
-
101
-        if ($user_rights) {
102
-            return explode(",", $user_rights);
103
-        }
104
-
105
-        return [""];
106
-    }
107
-
108
-    /**
109
-     * @param string $right
110
-     * @return bool
111
-     * function that allow to test a right directly in the view
112
-     */
113
-    public function testRight(string $right): bool
114
-    {
115
-        $user_rights = $this->getUserRights();
116
-
117
-        if (in_array($right, $user_rights)) {
118
-            return true;
119
-        }
120
-
121
-        return false;
122
-    }
44
+								//to show admin panel
45
+								if (in_array($route, ["_profiler", "_profiler_search_bar", "_wdt"])) {
46
+												return;
47
+								}
48
+
49
+								$ribs_admin_rights = json_decode(file_get_contents($this->em->get('kernel')->getRootDir() . "/../src/Ribs/RibsAdminBundle/Resources/json/ribsadmin_rights.json"));
50
+
51
+								if ($admin_page == "ribsadmin" && ($route !== 404) && ($route !== null)) {
52
+												$route_right = $this->in_array_recursive($route, $ribs_admin_rights);
53
+												$user_rights = $this->getUserRights();
54
+
55
+												if ($route_right === false) {
56
+																throw new AccessDeniedException("No access");
57
+												}
58
+
59
+												foreach ($user_rights as $right) {
60
+																if (in_array($right, $route_right)) {
61
+																				return;
62
+																}
63
+												}
64
+
65
+												throw new AccessDeniedException("No access");
66
+								}
67
+				}
68
+
69
+				/**
70
+				 * @param $needle
71
+				 * @param $haystack
72
+				 * @return bool|mixed
73
+				 * fonction that search if the right contain an url or more
74
+				 */
75
+				private function in_array_recursive($needle, $haystack)
76
+				{
77
+								$rights = [];
78
+								$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($haystack));
79
+
80
+								foreach ($it AS $element => $value) {
81
+												if ($value == $needle) {
82
+																$rights[] = $it->getInnerIterator()["right"];
83
+												}
84
+								}
85
+
86
+								if (count($rights) === 0) {
87
+												return false;
88
+								}
89
+
90
+								return $rights;
91
+				}
92
+
93
+
94
+				/**
95
+				 * @return array function that retun a array that contain all user rights or empty array if no right found
96
+				 */
97
+				private function getUserRights(): array
98
+				{
99
+								$user_rights = $this->em->get("security.token_storage")->getToken()->getUser()->getUser()->getAccessRights();
100
+
101
+								if ($user_rights) {
102
+												return explode(",", $user_rights);
103
+								}
104
+
105
+								return [""];
106
+				}
107
+
108
+				/**
109
+				 * @param string $right
110
+				 * @return bool
111
+				 * function that allow to test a right directly in the view
112
+				 */
113
+				public function testRight(string $right): bool
114
+				{
115
+								$user_rights = $this->getUserRights();
116
+
117
+								if (in_array($right, $user_rights)) {
118
+												return true;
119
+								}
120
+
121
+								return false;
122
+				}
123 123
 }
124 124
\ No newline at end of file
Please login to merge, or discard this patch.