forked from korra88/amazon-alexa-php
-
Notifications
You must be signed in to change notification settings - Fork 14
Let's see if we can pull the latest changes #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jakubsuchy
wants to merge
31
commits into
jakubsuchy:master
Choose a base branch
from
froodley:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2f9f529
Reconfigured Request as an abstract factory class. Updated construct…
73587b2
Update package name and Readme
cd897a2
Add tag .1.7
62c0c80
Add CustomSkillRequestType abstract
b9d868b
Refactor factory method into a separate class as non-static to improv…
be5ca44
Add getters to Request classes to improve Open/Closed and testability
8daa8a0
Adds setters and a bunch of PSR
ae16211
Breaking change - Move to symfony validation and more PSR and cleanup
ecbff89
Adds HtmlPurifier for xss cleaning
d9fd83a
Access token key is not provided in un-linked services
870cdc4
Add purifier destroyer to make the object easier to log
21a8ceb
Wrong access on method
d95207e
Adds support for the Standard card type and cleans up the rendering i…
3d55558
All setters null check before casting to string
c68a01a
Fix card type
1eae822
Breaking change - Object calisthenics - Made all objects stateless. …
be03b01
Add enumerations for valid card types and outputspeech types
8efe8c7
Update README.md
ab116f2
Fix broken child class constructors. Go back to public destroyPurifi…
44dc407
Fix broken reference
875f6ed
Fix missing return
4334c22
Fix missing calls to ->render()
45722ec
Fix defaulting for purifier
61e5e2e
Update README.md
2359de4
Add all getters from BaseRequest to the interface, should have done t…
d8dd333
Add all getters from BaseRequest to the interface, should have done t…
2f35228
Purifier instantiated in the wrong order
b2ed7b6
Fix typo in error string
da4dd1d
Fix typo in error string
4861a28
At least on the test portal, the empty slots member is not being crea…
e8e0b7c
Add tags
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
# Amazon Alexa PHP Library | ||
|
||
This library provides provides a convient interface for developing Amazon Alexa Skills for your PHP app. | ||
This library provides provides a convenient interface for developing Amazon Alexa Skills for your PHP app. | ||
|
||
It represents a breaking change (and is forked) from jakobsuchy/amazon-alexa-php | ||
|
||
The most important changes are the addition of XSS purification and some basic Doctrine validation, and making | ||
everything stateless, SRP and more testable | ||
|
||
## Usage | ||
|
||
Install via composer: `composer require minicodemonkey/amazon-alexa-php`. | ||
Install via composer: `composer require froodley/amazon-alexa-php` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the correct repo name here |
||
|
||
### Requests | ||
When Amazon Alexa triggers your skill, a HTTP request will be sent to the URL you specified for your app. | ||
|
||
You can get the `JSON` body of the request like so: | ||
```php | ||
$applicationId = "your-application-id-from-alexa"; // See developer.amazon.com and your Application. Will start with "amzn1.echo-sdk-ams.app." | ||
$rawRequest = $request->getContent; // This is how you would retrieve this with Laravel or Symfony 2. | ||
$alexa = new \Alexa\Request\Request($rawRequest, $applicationId); | ||
$alexaRequest = $alexa->fromData(); | ||
$rawRequest = $request->getContent(); // This is how you would retrieve this with Laravel or Symfony 2. | ||
$alexaRequestFactory = new \Alexa\Request\RequestFactory(); | ||
$alexaRequest = $alexaRequestFactory->fromRawData($rawRequest, [$applicationId]); | ||
``` | ||
|
||
The library expect raw request data, not parsed JSON as it needs to validate the request signature. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
{ | ||
"name": "jakubsuchy/amazon-alexa-php", | ||
"description": "Amazon Alexa interface for PHP", | ||
"name": "froodley/amazon-alexa-php", | ||
"description": "Amazon Alexa interface for PHP - XSS Filtering, Improved Testability", | ||
"license": "MIT", | ||
"type": "library", | ||
"keywords": [ | ||
"Amazon Echo", | ||
"Amazon Alexa", | ||
"Alexa", | ||
"Echo" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Mathias Hansen", | ||
|
@@ -15,13 +21,21 @@ | |
{ | ||
"name": "Jakub Suchy", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "froodley", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0" | ||
"php": ">=5.5.9", | ||
"ext-curl": "*", | ||
"doctrine/orm": "^2.5.6", | ||
"symfony/validator": "^3.2.6", | ||
"ezyang/htmlpurifier": "^4.7" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~4.6" | ||
"phpunit/phpunit": "^5.7.15" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will conflict with Drupal's current dependency on ">=4.8.35 <5". Perhaps use "~4.8" here, instead? |
||
}, | ||
"autoload": { | ||
"psr-4": { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,99 @@ | ||
<?php | ||
/** | ||
* @file Application.php | ||
* | ||
* The application abstraction layer to provide Application ID validation to | ||
* Alexa requests. Any implementations might provide their own implementations | ||
* via the $request->setApplicationAbstraction() function but must provide the | ||
* validateApplicationId() function. | ||
*/ | ||
|
||
namespace Alexa\Request; | ||
use InvalidArgumentException; | ||
|
||
class Application { | ||
public $applicationId; | ||
public $requestApplicationId; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
public function __construct($applicationId) { | ||
$this->applicationId = preg_split('/,/', $applicationId); | ||
} | ||
|
||
public function setRequestApplicationId($applicationId) { | ||
$this->requestApplicationId = $applicationId; | ||
} | ||
use Alexa\Utility\Purifier\HasPurifier; | ||
|
||
/** | ||
* Validate that the request Application ID matches our Application. This is required as per Amazon requirements. | ||
* Class Application | ||
* | ||
* Represents an Alexa application | ||
* | ||
* @param $requestApplicationId | ||
Application ID from the Request (typically found in $data['session']['application'] | ||
* @package Alexa\Request | ||
*/ | ||
public function validateApplicationId($requestApplicationId = "") { | ||
if (empty($requestApplicationId)) { | ||
$requestApplicationId = $this->requestApplicationId; | ||
} | ||
if (!in_array($requestApplicationId, $this->applicationId)) { | ||
throw new InvalidArgumentException('Application Id not matched'); | ||
} | ||
} | ||
class Application | ||
{ | ||
// Constants | ||
|
||
const ERROR_APPLICATION_ID_NOT_STRING = 'The provided value for the Alexa application ID was not a string'; | ||
const ERROR_APPLICATION_ID_NOT_MATCHED = 'The application ID \'%s\' found in the request does not match ' . | ||
'any of the expected application IDs.'; | ||
|
||
// Traits | ||
|
||
use HasPurifier; | ||
|
||
// Fields | ||
|
||
/** | ||
* @var string | ||
* | ||
* @Assert\Type("string") | ||
* @Assert\NotBlank | ||
*/ | ||
private $applicationId; | ||
|
||
|
||
// Hooks | ||
|
||
/** | ||
* Application constructor. | ||
* | ||
* @param string $applicationId | ||
* @param \HTMLPurifier $purifier | ||
*/ | ||
public function __construct($applicationId, \HTMLPurifier $purifier) | ||
{ | ||
// Set purifier | ||
$this->setPurifier($purifier); | ||
|
||
// Set application IDs | ||
$this->setApplicationId($applicationId); | ||
} | ||
|
||
// Public Methods | ||
|
||
/** | ||
* validateApplicationId() | ||
* | ||
* Confirms the application ID from the request is one in the list provided as valid | ||
* | ||
* @param array[string] $validApplicationIds | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function validateApplicationId(array $validApplicationIds) | ||
{ | ||
if (!in_array($this->getApplicationId(), $validApplicationIds)) { | ||
throw new \InvalidArgumentException( | ||
sprintf(self::ERROR_APPLICATION_ID_NOT_MATCHED, $this->getApplicationId()) | ||
); | ||
} | ||
} | ||
|
||
// Accessors | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getApplicationId() | ||
{ | ||
return $this->applicationId; | ||
} | ||
|
||
// Mutators | ||
|
||
/** | ||
* @param string $applicationId | ||
*/ | ||
protected function setApplicationId($applicationId) | ||
{ | ||
if (!is_string($applicationId)) { | ||
throw new \InvalidArgumentException(self::ERROR_APPLICATION_ID_NOT_STRING); | ||
} | ||
|
||
$this->applicationId = $applicationId; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reword this statement