Browse Source

added parameters middleware

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
92acbc1a9e

+ 3
- 2
src/Utils/LuBusiness.php View File

3
 namespace Luticate\Utils;
3
 namespace Luticate\Utils;
4
 
4
 
5
 abstract class LuBusiness {
5
 abstract class LuBusiness {
6
+    public static $parameters = array();
6
 
7
 
7
     /**
8
     /**
8
      * @param string $name
9
      * @param string $name
11
      */
12
      */
12
     public static function getParam($name, $default = null)
13
     public static function getParam($name, $default = null)
13
     {
14
     {
14
-        return array_key_exists($name, LuController::$parameters) ? LuController::$parameters[$name] : $default;
15
+        return array_key_exists($name, self::$parameters) ? self::$parameters[$name] : $default;
15
     }
16
     }
16
 
17
 
17
     /**
18
     /**
21
     public static function hasParam(array $params)
22
     public static function hasParam(array $params)
22
     {
23
     {
23
         foreach ($params as $p) {
24
         foreach ($params as $p) {
24
-            if (!array_key_exists($p, LuController::$parameters)) {
25
+            if (!array_key_exists($p, self::$parameters)) {
25
                 return false;
26
                 return false;
26
             }
27
             }
27
         }
28
         }

+ 0
- 4
src/Utils/LuController.php View File

6
 
6
 
7
 class LuController extends BaseController
7
 class LuController extends BaseController
8
 {
8
 {
9
-    public static $parameters = array();
10
-
11
     function execute($businessClass, $businessMethod)
9
     function execute($businessClass, $businessMethod)
12
     {
10
     {
13
-        self::$parameters = array_merge($_GET, $_POST, app('request')->route()[2], self::$parameters);
14
-
15
         $reflect = new \ReflectionMethod($businessClass, $businessMethod);
11
         $reflect = new \ReflectionMethod($businessClass, $businessMethod);
16
         $params = $reflect->getParameters();
12
         $params = $reflect->getParameters();
17
 
13
 

+ 1
- 1
src/Utils/LuRoute.php View File

6
     /**
6
     /**
7
      * @var string[]
7
      * @var string[]
8
      */
8
      */
9
-    private $middleware = array();
9
+    private $middleware = array('Luticate\Utils\ParametersMiddleware');
10
 
10
 
11
     /**
11
     /**
12
      * @param $middleware string
12
      * @param $middleware string

+ 27
- 0
src/Utils/ParametersMiddleware.php View File

1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 10/19/15
6
+ * Time: 10:20 PM
7
+ */
8
+
9
+namespace Luticate\Utils;
10
+
11
+use Closure;
12
+use Illuminate\Http\Request;
13
+
14
+class ParametersMiddleware
15
+{
16
+    /**
17
+     * @param $request Request
18
+     * @param Closure $next
19
+     * @param ...$permissions
20
+     * @return mixed
21
+     */
22
+    public function handle($request, Closure $next, ...$permissions)
23
+    {
24
+        LuBusiness::$parameters = array_merge($_GET, $_POST, $request->route()[2], LuBusiness::$parameters);
25
+        return $next($request);
26
+    }
27
+}

Loading…
Cancel
Save