Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating to use sys_get_tmp_dir() if not supplied. Updating docs.

  • Loading branch information...
commit 73fca8cc7202f42cda9f38d4e66f1f0533410824 1 parent f307284
@dongilbert authored
View
11 vendor/Joomla/Archive/Archive.php
@@ -43,6 +43,9 @@ class Archive
*/
public function __construct($options = array())
{
+ // Make sure we have a tmp directory.
+ isset($options['tmp_path']) or $options['tmp_path'] = realpath(sys_get_temp_dir());
+
$this->options = $options;
}
@@ -147,7 +150,7 @@ public function extract($archivename, $extractdir)
* Method to override the provided adapter with your own implementation.
*
* @param string $type Name of the adapter to set.
- * @param object $adapter Class which implements ExtractableInterface.
+ * @param string $class FQCN of your class which implements ExtractableInterface.
* @param object $override True to force override the adapter type.
*
* @return Archive This object for chaining.
@@ -155,16 +158,16 @@ public function extract($archivename, $extractdir)
* @since 1.0
* @throws \InvalidArgumentException
*/
- public function setAdapter($type, $adapter, $override = true)
+ public function setAdapter($type, $class, $override = true)
{
- if (!($adapter instanceof ExtractableInterface))
+ if (!($class instanceof ExtractableInterface))
{
throw new \InvalidArgumentException(sprintf('The provided %s adapter %s must implement Joomla\\Archive\\ExtractableInterface', $type), 500);
}
if ($override || !isset($this->adapters[$type]))
{
- $this->adapters[$type] = $value;
+ $this->adapters[$type] = new $class($this->options);
}
return $this;
View
29 vendor/Joomla/Archive/README.md
@@ -25,3 +25,32 @@ $archive = new Archive($options)
$archive->extract(__DIR__ . '/archive.zip', __DIR__ . '/destination');
```
+
+## Overriding Adapters
+
+If you have a custom adapter you would like to use for extracting, this package allows you to override the defaults. Just implement `ExtractableInterface` when creating your adapter, and then use the `setAdapter` method to override.
+
+```php
+
+class MyZipAdapter implements \Joomla\Archive\ExtractableInterface
+{
+ public static function isSupported()
+ {
+ // Do you test
+ return true;
+ }
+
+ public function extract($archive, $destination)
+ {
+ // Your code
+ }
+}
+
+$archive = new Archive;
+
+// You need to pass the fully qualified class name.
+$archive->setAdapter('zip', '\\MyZipAdapter');
+
+// This will use your
+$archive->extract('archive.zip', 'destination');
+```
View
2  vendor/Joomla/Archive/Tests/ArchiveTest.php
@@ -40,7 +40,7 @@ protected function setUp()
mkdir($this->outputPath, 0777);
}
- $this->fixture = new Archive(array('tmp_path' => '/tmp'));
+ $this->fixture = new Archive;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.