Skip to content

Commit

Permalink
Merge pull request #5 from travello-gmbh/4-integrate-session-container
Browse files Browse the repository at this point in the history
Add Alexa response factory
  • Loading branch information
Ralf Eggert committed Oct 8, 2017
2 parents 1904598 + d7b15ac commit 6e0d979
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"fig/http-message-util": "^1.1",
"http-interop/http-middleware": "^0.4.1",
"psr/http-message": "^1.0",
"travello-gmbh/amazon-alexa-skill-library": "^2.0",
"travello-gmbh/amazon-alexa-skill-library": "^2.1.0",
"zendframework/zend-expressive-router": "^2.1",
"zendframework/zend-expressive-template": "^1.0",
"zendframework/zend-servicemanager": "^3.3"
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Application/AlexaApplicationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace TravelloAlexaZf\Application;

use Interop\Container\ContainerInterface;
use TravelloAlexaLibrary\Application\AbstractAlexaApplication;
use TravelloAlexaLibrary\Application\AlexaApplication;
use TravelloAlexaLibrary\Configuration\SkillConfiguration;
use TravelloAlexaLibrary\Request\AlexaRequest;
use TravelloAlexaLibrary\Response\AlexaResponse;
Expand All @@ -31,19 +31,19 @@ class AlexaApplicationFactory implements FactoryInterface
* @param string $requestedName
* @param array|null|null $options
*
* @return AbstractAlexaApplication
* @return AlexaApplication
*/
public function __invoke(
ContainerInterface $container,
$requestedName,
array $options = null
): AbstractAlexaApplication {
): AlexaApplication {
$alexaRequest = $container->get(AlexaRequest::class);
$alexaResponse = $container->get(AlexaResponse::class);
$intentManager = $container->get(IntentManager::class);
$skillConfiguration = $container->get(SkillConfiguration::class);

/** @var AbstractAlexaApplication $alexaApplication */
/** @var AlexaApplication $alexaApplication */
$alexaApplication = new $requestedName(
$alexaRequest, $alexaResponse, $intentManager, $skillConfiguration
);
Expand Down
7 changes: 4 additions & 3 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use TravelloAlexaZf\Request\AlexaRequestFactory;
use TravelloAlexaZf\Request\Certificate\CertificateLoaderFactory;
use TravelloAlexaZf\Request\Certificate\CertificateValidatorFactory;
use TravelloAlexaZf\Response\AlexaResponseFactory;
use TravelloAlexaZf\TextHelper\TextHelperFactory;
use Zend\ServiceManager\Factory\InvokableFactory;

Expand All @@ -54,12 +55,12 @@ public function __invoke(): array
return [
'dependencies' => [
'factories' => [
AlexaRequest::class => AlexaRequestFactory::class,
AlexaResponse::class => InvokableFactory::class,

HtmlPageAction::class => HtmlPageActionFactory::class,
SkillAction::class => SkillActionFactory::class,

AlexaRequest::class => AlexaRequestFactory::class,
AlexaResponse::class => AlexaResponseFactory::class,

SkillConfiguration::class => InvokableFactory::class,
TextHelper::class => TextHelperFactory::class,
IntentManager::class => IntentManagerFactory::class,
Expand Down
51 changes: 51 additions & 0 deletions src/Response/AlexaResponseFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Zend Framework Library for Amazon Alexa Skills
*
* @author Ralf Eggert <ralf@travello.audio>
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
* @link https://github.com/travello-gmbh/amazon-alexa-skill-zf
* @link https://www.travello.audio/
*
*/

namespace TravelloAlexaZf\Response;

use Interop\Container\ContainerInterface;
use TravelloAlexaLibrary\Configuration\SkillConfiguration;
use TravelloAlexaLibrary\Request\AlexaRequest;
use TravelloAlexaLibrary\Response\AlexaResponse;
use TravelloAlexaLibrary\Session\SessionContainer;
use Zend\ServiceManager\Factory\FactoryInterface;

/**
* Class AlexaResponseFactory
*
* @package TravelloAlexaZf\Response
*/
class AlexaResponseFactory implements FactoryInterface
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
*
* @return AlexaResponse
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/** @var AlexaRequest $alexaRequest */
$alexaRequest = $container->get(AlexaRequest::class);

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

$sessionContainer = new SessionContainer($skillConfiguration->getSessionDefaults());
$sessionContainer->initAttributes($alexaRequest);

$alexaResponse = new AlexaResponse();
$alexaResponse->setSessionContainer($sessionContainer);

return $alexaResponse;
}
}

0 comments on commit 6e0d979

Please sign in to comment.