mirror of
https://github.com/friendica/friendica
synced 2025-04-28 12:24:23 +02:00
Adhere feedback
- rename hooks.config.php to strategies.config.php - change all corresponding classes and tests
This commit is contained in:
parent
e659a03140
commit
cba656383e
12 changed files with 72 additions and 121 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue