Skip to content

Commit

Permalink
Check for active Alexa request to read text helper object for locale …
Browse files Browse the repository at this point in the history
…setting in the middleware.
  • Loading branch information
Ralf Eggert committed Oct 12, 2017
1 parent e7fded0 commit 19e68fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Middleware/SetLocaleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SetLocaleMiddleware implements MiddlewareInterface
* @param TextHelperInterface $textHelper
* @param AlexaRequest $alexaRequest
*/
public function __construct(TextHelperInterface $textHelper, AlexaRequest $alexaRequest = null)
public function __construct(TextHelperInterface $textHelper = null, AlexaRequest $alexaRequest = null)
{
$this->textHelper = $textHelper;
$this->alexaRequest = $alexaRequest;
Expand Down
16 changes: 10 additions & 6 deletions src/Middleware/SetLocaleMiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ class SetLocaleMiddlewareFactory implements FactoryInterface
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/** @var SkillConfiguration $skillConfiguration */
$skillConfiguration = $container->get(SkillConfiguration::class);

/** @var TextHelper $textHelper */
$textHelper = $container->get($skillConfiguration->getTextHelperClass());

/** @var AlexaRequest $alexaRequest */
$alexaRequest = $container->get(AlexaRequest::class);

if ($alexaRequest) {
/** @var SkillConfiguration $skillConfiguration */
$skillConfiguration = $container->get(SkillConfiguration::class);

/** @var TextHelper $textHelper */
$textHelper = $container->get($skillConfiguration->getTextHelperClass());
} else {
$textHelper = null;
}

return new SetLocaleMiddleware($textHelper, $alexaRequest);
}
}

0 comments on commit 19e68fa

Please sign in to comment.