This repository was archived by the owner on May 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
CompactorInterface
kherge edited this page Mar 8, 2013
·
1 revision
A file compacting class is used to shrink the size of a file's contents, according to the file's type.
To create your own file contents compacting class, you must implement the Herrera\Box\Compactor\CompactorInterface interface.
<?php
namespace Herrera\Box\Compactor;
interface CompactorInterface
{
public function compact($contents);
public function supports($file);
}Compacts the file contents and returns the results.
Returns true if the $file is supported, or false if not.
You may instead extend an existing compactor base class, Herrera\Box\Compactor\Compactor.
<?php
namespace Herrera\Box\Compactor;
abstract class Compactor implements CompactorInterface
{
protected $extensions;
public function setExtensions(array $extensions)
{
$this->extensions = $extensions;
}
public function supports($file)
{
return in_array(pathinfo($file, PATHINFO_EXTENSION), $this->extensions);
}
}The base class handles checking support for a file by its extension. You only need to define the default support file extensions by setting the value of $extensions. You will also need to implement the compact() method.