Code: Select all
class WebhookHandlerFactory
{ // $config['client'] is hardcoded in the .env file in this case and then put into ConfigProvider
protected ContainerInterface $container;
public function __invoke(ContainerInterface $container): RequestHandlerInterface
{
$this->container = $container;
$config = $this->getConfig();
$client = (new SomeClient($config['client']))->getClient();
$controller = (new SomeControllerFactory)($container);
return new WebhookHandler($controller, $config, $client);
}
protected function getConfig(): ArrayObject
{
$config = $this->container->get('config');
// here I use my hardcoded data to find something in the DB and then put it into $config
return $config;
}
< /code>
Das [url=viewtopic.php?t=11587]Problem[/url] ist, dass ich meine Anfrage nicht in der Fabrik erhalten kann. Handlerklasse in __construct und dann nimmt die Handlungsmethode wie folgt zu: < /p>
public function __construct(
ContainerInterface $container,
CreateController $controller,
ArrayObject $config
){
$this->container = $container;
$this->createController = $createController;
$this->config = $config;
$config = $this->getConfig();
$client = (new SomeClient($config['client']))->getClient();
$this->handler = new WebhookHandler($this->controller, $config, $client);
}
public function handle(ServerRequestInterface $request)
{
return $this->handler->handle($request);
}
< /code>
Aber meine Datei Routes.php sieht jetzt irgendwie hässlich aus, wenn ich dachte, ich mache etwas falsch. < /p>
return static function (Application $app): void
{
$app->post('/', App\Handler\WebhookHandlerFactory::class);