src/Storage/NamingStrategy/AbstractStrategy.php
<?php
declare(strict_types=1);
namespace Autowp\Image\Storage\NamingStrategy;
use Autowp\Image\Storage\Exception;
use function method_exists;
use function ucfirst;
abstract class AbstractStrategy
{
/**
* @throws Exception
*/
public function __construct(array $options = [])
{
$this->setOptions($options);
}
/**
* @throws Exception
*/
public function setOptions(array $options): self
{
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (! method_exists($this, $method)) {
throw new Exception("Unexpected option '$key'");
}
$this->$method($value);
}
return $this;
}
abstract public function generate(array $options = []): string;
}