11
0
Fork 0
mirror of https://github.com/n3w/helpers-cli-input.git synced 2025-12-19 12:43:23 +00:00

Updated InputHandlerFactory and InputTypeFactory to work with changes in pointybeard/helpers-foundation-factory 1.0.2

This commit is contained in:
Alannah Kearney 2019-06-04 23:22:15 +10:00
commit e542f6fd94
2 changed files with 15 additions and 10 deletions

View file

@ -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

View file

@ -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';
}