Skip to content

Commit

Permalink
Merge branch 'abraxa1982-apla-support' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Eggert committed Jul 24, 2020
2 parents 0bdcb43 + aa51d87 commit e7fb776
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
92 changes: 92 additions & 0 deletions src/Response/Directives/Alexa/Presentation/APLA/Document/APLA.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Build voice applications for Amazon Alexa with phlexa and PHP
*
* @author Meike Ziesecke <[email protected]>
* @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;
}
}
74 changes: 74 additions & 0 deletions src/Response/Directives/Alexa/Presentation/APLA/RenderDocument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Build voice applications for Amazon Alexa with phlexa and PHP
*
* @author Meike Ziesecke <[email protected]>
* @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;
}
}

0 comments on commit e7fb776

Please sign in to comment.