CoreFiles by mySites.guru
CompressionMethodManagerFactory.php66 lines, 1,877 bytes, from Joomla_5.1.0-beta1-Beta-Full_Package.zip
Raw History Compare with 5.0.0-beta3
md5
7dd7bc9091175a946dc6587c2741703b
sha1
e6f744014fdc55b1c3893969f6823c3900f28275
sha256
a8f9a0ee546a953ed4f20c68dd0b547b3bcf6a3489a1589862cfb1d7e4535ebc
<?php

declare(strict_types=1);

namespace Jose\Component\Encryption\Compression;

use InvalidArgumentException;

class CompressionMethodManagerFactory
{
    /**
     * @var CompressionMethod[]
     */
    private array $compressionMethods = [];

    /**
     * This method adds a compression method to this factory. The method is uniquely identified by an alias. This allows
     * the same method to be added twice (or more) using several configuration options.
     */
    public function add(string $alias, CompressionMethod $compressionMethod): void
    {
        $this->compressionMethods[$alias] = $compressionMethod;
    }

    /**
     * Returns the list of compression method aliases supported by the factory.
     *
     * @return string[]
     */
    public function aliases(): array
    {
        return array_keys($this->compressionMethods);
    }

    /**
     * Returns all compression methods supported by this factory.
     *
     * @return CompressionMethod[]
     */
    public function all(): array
    {
        return $this->compressionMethods;
    }

    /**
     * Creates a compression method manager using the compression methods identified by the given aliases. If one of the
     * aliases does not exist, an exception is thrown.
     *
     * @param string[] $aliases
     */
    public function create(array $aliases): CompressionMethodManager
    {
        $compressionMethods = [];
        foreach ($aliases as $alias) {
            if (! isset($this->compressionMethods[$alias])) {
                throw new InvalidArgumentException(sprintf(
                    'The compression method with the alias "%s" is not supported.',
                    $alias
                ));
            }
            $compressionMethods[] = $this->compressionMethods[$alias];
        }

        return new CompressionMethodManager($compressionMethods);
    }
}

The same content is in 17 releases, Joomla 5.1.0-beta1 to 5.2.0-alpha1. See them all, or every version of this file.