File tree Expand file tree Collapse file tree 4 files changed +85
-0
lines changed Expand file tree Collapse file tree 4 files changed +85
-0
lines changed Original file line number Diff line number Diff line change
1
+ /vendor /
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " tucker-eric/laravel-xml-middleware" ,
3
+ "description" : " A Laravel Middleware to accept XML requests" ,
4
+ "keywords" : [
5
+ " Laravel" ,
6
+ " xml-middleware" ,
7
+ " xml" ,
8
+ " middleware" ,
9
+ " xml request" ,
10
+ " request"
11
+ ],
12
+ "require" : {
13
+ "illuminate/http" : " ~5.0" ,
14
+ "illuminate/support" : " ~5.0"
15
+ },
16
+ "license" : " MIT" ,
17
+ "authors" : [
18
+ {
19
+ "name" : " Eric Tucker" ,
20
+
21
+ }
22
+ ],
23
+ "autoload" : {
24
+ "psr-4" : {
25
+ "XmlMiddleware\\ " : " src/"
26
+ }
27
+ },
28
+ "minimum-stability" : " dev"
29
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace XmlMiddleware ;
4
+
5
+ use Closure ;
6
+
7
+ class XmlRequestMiddleware
8
+ {
9
+ /**
10
+ * Handle an incoming request.
11
+ *
12
+ * @param \Illuminate\Http\Request $request
13
+ * @param \Closure $next
14
+ * @return mixed
15
+ */
16
+ public function handle ($ request , Closure $ next )
17
+ {
18
+ $ request ->merge ($ request ->xml ());
19
+
20
+ return $ next ($ request );
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace XmlMiddleware ;
4
+
5
+ use Illuminate \Support \ServiceProvider ;
6
+ use Request ;
7
+
8
+ class XmlRequestServiceProvider extends ServiceProvider
9
+ {
10
+
11
+ /**
12
+ * Register the application services.
13
+ *
14
+ * @return void
15
+ */
16
+ public function register ()
17
+ {
18
+ Request::macro ('isXml ' , function () {
19
+ return strtolower ($ this ->getContentType ()) === 'xml ' ;
20
+ });
21
+
22
+ Request::macro ('xml ' , function ($ assoc = true ) {
23
+ if (!$ this ->isXml ()) {
24
+ return [];
25
+ }
26
+ // Returns the xml input from a request
27
+ $ xml = simplexml_load_string ($ this ->getContent ());
28
+ $ json = json_encode ($ xml );
29
+
30
+ return json_decode ($ json , $ assoc );
31
+ });
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments