Skip to content

Factory with magic method #103

@hrach

Description

@hrach

Currently, it is not possible to define service factory as call of magic method. It throws Factory 'Aws\Sdk::createSqs' used in service '237' is not callable. It's because this checks

try {
$reflection = Nette\Utils\Callback::toReflection($entity[0] === '' ? $entity[1] : $entity);
$refClass = $reflection instanceof \ReflectionMethod ? $reflection->getDeclaringClass() : NULL;
} catch (\ReflectionException $e) {
}
if (isset($e) || ($refClass && (!$reflection->isPublic()
|| ($refClass->isTrait() && !$reflection->isStatic())
))) {
$name = array_slice(array_keys($recursive), -1);
throw new ServiceCreationException(sprintf("Factory '%s' used in service '%s' is not callable.", Nette\Utils\Callback::toString($entity), $name[0]));
}
throws ReflectionException: Method Aws\Sdk::createSqs() does not exist. See Sdk class definition.

I would like to create client services for particular AWS services. It's much cleaner to inject client directly, than injecting Sdk and then creating a client in the class.

services:
    - Aws\Sdk({
        credentials: {
            key: %aws.access%,
            secret: %aws.secret%,
        },
        version: latest,
        region: 'eu-west-1',
    })
    -
        class: Aws\Sqs\SqsClient
        factory: @Aws\Sdk::createSqs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions