diff --git a/src/Response/Directives/Alexa/Presentation/APLA/Document/APLA.php b/src/Response/Directives/Alexa/Presentation/APLA/Document/APLA.php new file mode 100644 index 0000000..b7c6499 --- /dev/null +++ b/src/Response/Directives/Alexa/Presentation/APLA/Document/APLA.php @@ -0,0 +1,92 @@ + + * @license http://opensource.org/licenses/MIT The MIT License (MIT) + * @link https://github.com/phoice/phlexa + * @link https://www.phoice.tech/ + * @link https://www.travello.audio/ + */ + +declare(strict_types=1); + +namespace Phlexa\Response\Directives\Alexa\Presentation\APLA\Document; + +use Phlexa\Response\Directives\DirectivesInterface; + +/** + * Class APLA + * + * @package Phlexa\Response\Directives\Alexa\Presentation\APLA\Document + */ +class APLA implements DirectivesInterface +{ + /** Type of directive */ + public const DIRECTIVE_TYPE = 'APLA'; + + /** @var string */ + private $version = '0.8'; + + /** @var array */ + private $mainTemplate = []; + + /** + * APLA constructor. + * + * @param array $mainTemplate + */ + public function __construct( + array $mainTemplate + ) { + $this->mainTemplate = $mainTemplate; + } + + /** + * @param $aplaJson + * + * @return APLA + */ + public static function createFromString(string $aplaJson): APLA + { + $aplaData = json_decode($aplaJson, true); + + $mainTemplate = $aplaData['mainTemplate'] ?? []; + + return new APLA($mainTemplate); + } + + /** + * @param string $aplaFile + * + * @return APLA + */ + public static function createFromFile(string $aplaFile): APLA + { + $aplaJson = file_get_contents($aplaFile); + + return self::createFromString($aplaJson); + } + + /** + * @return string + */ + public function getType(): string + { + return self::DIRECTIVE_TYPE; + } + + /** + * @return array + */ + public function toArray(): array + { + $data = [ + 'type' => $this->getType(), + 'version' => $this->version, + 'mainTemplate' => $this->mainTemplate, + ]; + + return $data; + } +} diff --git a/src/Response/Directives/Alexa/Presentation/APLA/RenderDocument.php b/src/Response/Directives/Alexa/Presentation/APLA/RenderDocument.php new file mode 100644 index 0000000..512eea9 --- /dev/null +++ b/src/Response/Directives/Alexa/Presentation/APLA/RenderDocument.php @@ -0,0 +1,74 @@ + + * @license http://opensource.org/licenses/MIT The MIT License (MIT) + * @link https://github.com/phoice/phlexa + * @link https://www.phoice.tech/ + * @link https://www.travello.audio/ + */ + +declare(strict_types=1); + +namespace Phlexa\Response\Directives\Alexa\Presentation\APLA; + +use Phlexa\Response\Directives\Alexa\Presentation\APLA\Document\APLA; +use Phlexa\Response\Directives\DirectivesInterface; + +/** + * Class RenderDocument + * + * @package Phlexa\Response\Directives\Alexa\Presentation\APLA + */ +class RenderDocument implements DirectivesInterface +{ + /** Type of directive */ + public const DIRECTIVE_TYPE = 'Alexa.Presentation.APLA.RenderDocument'; + + /** @var APLA */ + private $document; + + /** @var string */ + private $token; + + /** @var array */ + private $datasources = []; + + /** + * RenderDocument constructor. + * + * @param APLA $document + * @param string $token + * @param array $datasources + */ + public function __construct(APLA $document, string $token, array $datasources) + { + $this->document = $document; + $this->token = $token; + $this->datasources = $datasources; + } + + /** + * @return string + */ + public function getType(): string + { + return self::DIRECTIVE_TYPE; + } + + /** + * @return array + */ + public function toArray(): array + { + $data = [ + 'type' => $this->getType(), + 'document' => $this->document->toArray(), + 'token' => $this->token, + 'datasources' => $this->datasources, + ]; + + return $data; + } +}