1
- <?php namespace light \yii2 ;
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the light/package.
5
+ *
6
+ * (c) lichunqiang <[email protected] >
7
+ *
8
+ * This source file is subject to the MIT license that is bundled
9
+ * with this source code in the file LICENSE.
10
+ */
11
+
12
+ namespace light \yii2 ;
2
13
3
14
use yii \base \Object ;
4
15
use yii \web \BadRequestHttpException ;
5
16
use yii \web \RequestParserInterface ;
6
17
7
18
/**
8
- * The request parser for xml
19
+ * The request parser for xml.
9
20
*
10
- * @package light\yii2
11
21
* @author lichunqiang <[email protected] >
12
22
* @license MIT
23
+ *
13
24
* @version 0.2.11
14
25
*/
15
26
class XmlParser extends Object implements RequestParserInterface
16
27
{
17
28
/**
18
29
* If parser result as array, this is default,
19
30
* if you want to get object, set it to false.
20
- * @var boolean
31
+ *
32
+ * @var bool
21
33
*/
22
34
public $ asArray = true ;
23
35
/**
24
36
* Whether throw the [[BadRequestHttpException]] if the process error.
25
- * @var boolean
37
+ *
38
+ * @var bool
26
39
*/
27
40
public $ throwException = true ;
28
41
29
42
/**
30
- * @inheritdoc
43
+ * { @inheritdoc}
31
44
*/
32
45
public function parse ($ rawBody , $ contentType )
33
46
{
@@ -38,16 +51,17 @@ public function parse($rawBody, $contentType)
38
51
if ($ result === false ) {
39
52
$ errors = libxml_get_errors ();
40
53
$ latestError = array_pop ($ errors );
41
- $ error = array (
54
+ $ error = [
42
55
'message ' => $ latestError ->message ,
43
56
'type ' => $ latestError ->level ,
44
57
'code ' => $ latestError ->code ,
45
58
'file ' => $ latestError ->file ,
46
59
'line ' => $ latestError ->line ,
47
- ) ;
60
+ ] ;
48
61
if ($ this ->throwException ) {
49
62
throw new BadRequestHttpException ($ latestError ->message );
50
63
}
64
+
51
65
return $ error ;
52
66
}
53
67
0 commit comments