From e542f6fd945c6533d6004fd77a45d7c98a13b925 Mon Sep 17 00:00:00 2001 From: Alannah Kearney Date: Tue, 4 Jun 2019 23:22:15 +1000 Subject: [PATCH] Updated InputHandlerFactory and InputTypeFactory to work with changes in pointybeard/helpers-foundation-factory 1.0.2 --- src/Input/InputHandlerFactory.php | 19 +++++++++++++------ src/Input/InputTypeFactory.php | 6 ++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Input/InputHandlerFactory.php b/src/Input/InputHandlerFactory.php index 2b06ecf..2ae425c 100644 --- a/src/Input/InputHandlerFactory.php +++ b/src/Input/InputHandlerFactory.php @@ -9,27 +9,34 @@ use pointybeard\Helpers\Foundation\Factory; final class InputHandlerFactory extends Factory\AbstractFactory { - public static function getTemplateNamespace(): string + public function getTemplateNamespace(): string { return __NAMESPACE__.'\\Handlers\\%s'; } - public static function getExpectedClassType(): ?string + public function getExpectedClassType(): ?string { return __NAMESPACE__.'\\Interfaces\\InputHandlerInterface'; } - public static function build(string $name, InputCollection $collection = null, int $flags = null): Interfaces\InputHandlerInterface + public static function build(string $name, ...$arguments): object { + + // Since passing flags is optional, we can use array_pad + // to ensure there are always at least 2 elements in $arguments + [$collection, $flags] = array_pad($arguments, 2, null); + + $factory = new self; + try { - $handler = self::instanciate( - self::generateTargetClassName($name) + $handler = $factory->instanciate( + $factory->generateTargetClassName($name) ); } catch (\Exception $ex) { throw new Exceptions\UnableToLoadInputHandlerException($name, 0, $ex); } - if ($collection instanceof InputCollection) { + if (null !== $collection) { $handler->bind( $collection, $flags diff --git a/src/Input/InputTypeFactory.php b/src/Input/InputTypeFactory.php index dda8115..82b1115 100644 --- a/src/Input/InputTypeFactory.php +++ b/src/Input/InputTypeFactory.php @@ -8,14 +8,12 @@ use pointybeard\Helpers\Foundation\Factory; final class InputTypeFactory extends Factory\AbstractFactory { - use Factory\Traits\hasSimpleFactoryBuildMethodTrait; - - public static function getTemplateNamespace(): string + public function getTemplateNamespace(): string { return __NAMESPACE__.'\\Types\\%s'; } - public static function getExpectedClassType(): ?string + public function getExpectedClassType(): ?string { return __NAMESPACE__.'\\Interfaces\\InputTypeInterface'; }