File tree Expand file tree Collapse file tree 3 files changed +51
-11
lines changed Expand file tree Collapse file tree 3 files changed +51
-11
lines changed Original file line number Diff line number Diff line change 15
15
16
16
class ParserFactory
17
17
{
18
+
19
+ private static $ zipDateFormat = 'Y-m-d H:i ' ;
20
+
21
+ /**
22
+ * @param string $format Date format used to parse ZIP file listings
23
+ */
24
+ public static function setZipDateFormat ($ format )
25
+ {
26
+ self ::$ zipDateFormat = $ format ;
27
+ }
28
+
18
29
/**
19
30
* Maps the corresponding parser to the selected adapter
20
31
*
@@ -34,7 +45,7 @@ public static function create($adapterName)
34
45
return new BSDTarOutputParser ();
35
46
break ;
36
47
case 'zip ' :
37
- return new ZipOutputParser ();
48
+ return new ZipOutputParser (self :: $ zipDateFormat );
38
49
break ;
39
50
40
51
default :
Original file line number Diff line number Diff line change @@ -19,6 +19,19 @@ class ZipOutputParser implements ParserInterface
19
19
const ISO_DATE = "([0-9]+-[0-9]+-[0-9]+\s+[0-9]+:[0-9]+) " ;
20
20
const FILENAME = "(.*) " ;
21
21
22
+ /**
23
+ * @var string
24
+ */
25
+ private $ dateFormat ;
26
+
27
+ /**
28
+ * @param string $dateFormat
29
+ */
30
+ public function __construct ($ dateFormat = "Y-m-d H:i " )
31
+ {
32
+ $ this ->dateFormat = $ dateFormat ;
33
+ }
34
+
22
35
/**
23
36
* @inheritdoc
24
37
*/
@@ -50,7 +63,7 @@ public function parseFileListing($output)
50
63
$ members [] = array (
51
64
'location ' => $ chunks [3 ],
52
65
'size ' => $ chunks [1 ],
53
- 'mtime ' => \DateTime::createFromFormat (" Y-m-d H:i " , $ chunks [2 ]),
66
+ 'mtime ' => \DateTime::createFromFormat ($ this -> dateFormat , $ chunks [2 ]),
54
67
'is_dir ' => '/ ' === substr ($ chunks [3 ], -1 )
55
68
);
56
69
}
Original file line number Diff line number Diff line change @@ -12,22 +12,38 @@ public function testNewParser()
12
12
return new ZipOutputParser ();
13
13
}
14
14
15
- /**
16
- * @depends testNewParser
17
- */
18
- public function testParseFileListing ($ parser )
15
+ public function getDatasets ()
19
16
{
20
- $ current_timezone = ini_get ('date.timezone ' );
21
- ini_set ('date.timezone ' , 'UTC ' );
22
-
23
- $ output =
24
- "Length Date Time Name
17
+ $ standardOutput =
18
+ "Length Date Time Name
25
19
-------- ---- ---- ----
26
20
0 2006-06-09 12:06 practice/
27
21
10240 2006-06-09 12:06 practice/records
28
22
-------- -------
29
23
785 2 files " ;
30
24
25
+ $ altOutput =
26
+ "Length Date Time Name
27
+ -------- ---- ---- ----
28
+ 0 09-06-06 12:06 practice/
29
+ 10240 09-06-06 12:06 practice/records
30
+ -------- -------
31
+ 785 2 files " ;
32
+
33
+ return array (
34
+ array (new ZipOutputParser (), $ standardOutput ),
35
+ array (new ZipOutputParser ('d-m-y H:i ' ), $ altOutput )
36
+ );
37
+ }
38
+
39
+ /**
40
+ * @dataProvider getDatasets
41
+ */
42
+ public function testParseFileListing ($ parser , $ output )
43
+ {
44
+ $ current_timezone = ini_get ('date.timezone ' );
45
+ ini_set ('date.timezone ' , 'UTC ' );
46
+
31
47
$ members = $ parser ->parseFileListing ($ output );
32
48
33
49
$ this ->assertEquals (2 , count ($ members ));
You can’t perform that action at this time.
0 commit comments