Skip to content

Commit 4dc7d35

Browse files
committed
initialize
0 parents  commit 4dc7d35

File tree

7 files changed

+100
-0
lines changed

7 files changed

+100
-0
lines changed

.editorconfig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# editorconfig.org
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
charset = utf-8
9+
10+
[*.php]
11+
indent_style = space
12+
indent_size = 4
13+
trim_trailing_whitespace = true
14+
15+
[*.{js,twig,css,scss,html}]
16+
indent_style = space
17+
indent_size = 2
18+
19+
[{Gruntfile.js,bower.json,composer.json,package.json}]
20+
indent_style = space
21+
indent_size = 2
22+
23+
[*.md]
24+
trim_trailing_whitespace = false

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 lichunqiang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

composer.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "light/yii2-xmlparser",
3+
"description": "yii2 xml request parser",
4+
"require": {
5+
"php": ">=5.4.0",
6+
"yiisoft/yii2": "~2.0@dev"
7+
},
8+
"require-dev": {
9+
"phpunit/phpunit": "~4.6@dev"
10+
},
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "lichunqiang",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"autoload": {
19+
"psr-4": {
20+
"light\\": "src/"
21+
}
22+
},
23+
"minimum-stability": "dev"
24+
}

readme.md

Whitespace-only changes.

src/XmlParser.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
namespace light;
3+
4+
use yii\helpers\Json;
5+
use yii\web\RequestParserInterface;
6+
7+
class XmlParser extends RequestParserInterface
8+
{
9+
/**
10+
* Whether throw the [[BadRequestHttpException]] if the process error.
11+
* @var boolean
12+
*/
13+
public $throwException = true;
14+
15+
/**
16+
* @inheritdoc
17+
*/
18+
public function parse($rawBody, $contentType)
19+
{
20+
try {
21+
return Json::decode(Json::encode(simplexml_load_string($rawBody, 'SimpleXMLElement', LIBXML_NOCDATA)));
22+
} catch (Exception $e) {
23+
if ($this->throwException) {
24+
throw new BadRequestHttpException($e->getMessage, 0, $e);
25+
}
26+
return null;
27+
}
28+
}
29+
}

tests/bootstrap.php

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

0 commit comments

Comments
 (0)