-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bd58dd
commit a7800b4
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "tucker-eric/laravel-xml-middleware", | ||
"description": "A Laravel Middleware to accept XML requests", | ||
"keywords": [ | ||
"Laravel", | ||
"xml-middleware", | ||
"xml", | ||
"middleware", | ||
"xml request", | ||
"request" | ||
], | ||
"require": { | ||
"illuminate/http": "~5.0", | ||
"illuminate/support": "~5.0" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Eric Tucker", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"XmlMiddleware\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "dev" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace XmlMiddleware; | ||
|
||
use Closure; | ||
|
||
class XmlRequestMiddleware | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
$request->merge($request->xml()); | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace XmlMiddleware; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Request; | ||
|
||
class XmlRequestServiceProvider extends ServiceProvider | ||
{ | ||
|
||
/** | ||
* Register the application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
Request::macro('isXml', function () { | ||
return strtolower($this->getContentType()) === 'xml'; | ||
}); | ||
|
||
Request::macro('xml', function ($assoc = true) { | ||
if (!$this->isXml()) { | ||
return []; | ||
} | ||
// Returns the xml input from a request | ||
$xml = simplexml_load_string($this->getContent()); | ||
$json = json_encode($xml); | ||
|
||
return json_decode($json, $assoc); | ||
}); | ||
} | ||
} |