What is an archiver ?

An archiver is a tools that can build archives ( like zip, tar, … ). Thelia comes with 4 archivers:

  • Zip
  • Tar
  • Tar.gz
  • Tar.bz2

Get an archive builder

In order to get an archive builder, you can use the trait to get the manager Thelia\Core\FileFormat\Archive\ArchiveBuilderManagerTrait :

class Foo 
    use ArchiveBuilderManagerTrait;
    public function myMethod() {
        $archiveBuilderManager = $this->getArchiveBuilderManager($myContainer);

Or you can inject it in a service (e.g: an event listener):

<service id="my.super.service" class="My\Super\Class">
    <argument type="service" id="thelia.manager.archive_builder_manager" />

Use an archive builder

Archive builders are defined by the abstract class Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder.

Here are the methods that you have:

// Get the zip archive builder in the manager
$zip = $archiveBuilderManager->get("ZIP");

// Let's create an zip
// Add a file the is on the server

// Add an online file

// Create a file from a string
$zip->addFileFromString("the content of my file", "name_of_my_file", "directory/in/the/archive");

// Get the content of a file

// Delete a file in the archive

// Add an empty directory

// Check if the archive contains a file

// Check if the archive contains a directory

// Build a Thelia Response with the archive file as content
$response = $zip->buildArchiveResponse("filename_of_the_export");

// Get the archive format name
$zip ->getName();

// Get the Mime Type of the archive format

// Get the extension of the archive format

Create an archive builder

If you want to create an archive builder, create a class that extends Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder and implement the functions above, then create a service with the tag thelia.archive_builder, like this:

<service id="thelia.zip_archive_builder" class="Thelia\Core\FileFormat\Archive\ArchiveBuilder\ZipArchiveBuilder">
    <tag name="thelia.archive_builder" />