Adhere feedback

- rename hooks.config.php to strategies.config.php
- change all corresponding classes and tests
This commit is contained in:
Philipp 2023-07-21 22:41:36 +02:00
parent e659a03140
commit cba656383e
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
12 changed files with 72 additions and 121 deletions

View file

@ -23,31 +23,31 @@ namespace Friendica\Core\Hooks\Model;
use Dice\Dice;
use Friendica\Core\Hooks\Capabilities\ICanCreateInstances;
use Friendica\Core\Hooks\Capabilities\ICanRegisterInstances;
use Friendica\Core\Hooks\Capabilities\ICanRegisterStrategies;
use Friendica\Core\Hooks\Exceptions\HookInstanceException;
use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException;
use Friendica\Core\Hooks\Util\HookFileManager;
use Friendica\Core\Hooks\Util\StrategiesFileManager;
/**
* This class represents an instance register, which uses Dice for creation
*
* @see Dice
*/
class DiceInstanceManager implements ICanCreateInstances, ICanRegisterInstances
class DiceInstanceManager implements ICanCreateInstances, ICanRegisterStrategies
{
protected $instance = [];
/** @var Dice */
protected $dice;
public function __construct(Dice $dice, HookFileManager $hookFileManager)
public function __construct(Dice $dice, StrategiesFileManager $strategiesFileManager)
{
$this->dice = $dice;
$hookFileManager->setupHooks($this);
$strategiesFileManager->setupStrategies($this);
}
/** {@inheritDoc} */
public function registerStrategy(string $interface, string $class, ?string $name = null): ICanRegisterInstances
public function registerStrategy(string $interface, string $class, ?string $name = null): ICanRegisterStrategies
{
if (!empty($this->instance[$interface][$name])) {
throw new HookRegisterArgumentException(sprintf('A class with the name %s is already set for the interface %s', $name, $interface));
@ -59,12 +59,12 @@ class DiceInstanceManager implements ICanCreateInstances, ICanRegisterInstances
}
/** {@inheritDoc} */
public function create(string $class, string $name, array $arguments = []): object
public function create(string $class, string $strategy, array $arguments = []): object
{
if (empty($this->instance[$class][$name])) {
throw new HookInstanceException(sprintf('The class with the name %s isn\'t registered for the class or interface %s', $name, $class));
if (empty($this->instance[$class][$strategy])) {
throw new HookInstanceException(sprintf('The class with the name %s isn\'t registered for the class or interface %s', $strategy, $class));
}
return $this->dice->create($this->instance[$class][$name], $arguments);
return $this->dice->create($this->instance[$class][$strategy], $arguments);
}
}