Version 1
[yaffs-website] / vendor / alchemy / zippy / src / Parser / ParserFactory.php
diff --git a/vendor/alchemy/zippy/src/Parser/ParserFactory.php b/vendor/alchemy/zippy/src/Parser/ParserFactory.php
new file mode 100644 (file)
index 0000000..8b395c7
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+/*
+ * This file is part of Zippy.
+ *
+ * (c) Alchemy <info@alchemy.fr>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Alchemy\Zippy\Parser;
+
+use Alchemy\Zippy\Exception\InvalidArgumentException;
+
+class ParserFactory
+{
+
+    private static $zipDateFormat = 'Y-m-d H:i';
+
+    /**
+     * @param string $format Date format used to parse ZIP file listings
+     */
+    public static function setZipDateFormat($format)
+    {
+        self::$zipDateFormat = $format;
+    }
+
+    /**
+     * Maps the corresponding parser to the selected adapter
+     *
+     * @param   string $adapterName An adapter name
+     *
+     * @return ParserInterface
+     *
+     * @throws InvalidArgumentException In case no parser were found
+     */
+    public static function create($adapterName)
+    {
+        switch ($adapterName) {
+            case 'gnu-tar':
+                return new GNUTarOutputParser();
+                break;
+            case 'bsd-tar':
+                return new BSDTarOutputParser();
+                break;
+            case 'zip':
+                return new ZipOutputParser(self::$zipDateFormat);
+                break;
+
+            default:
+                throw new InvalidArgumentException(sprintf('No parser available for %s adapter', $adapterName));
+                break;
+        }
+    }
+}