Skip to content

Commit

Permalink
Allow requests without session data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Eggert committed Nov 5, 2017
1 parent 9e74ccf commit cb0e609
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 29 deletions.
26 changes: 13 additions & 13 deletions src/Request/AlexaRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ class AlexaRequest implements AlexaRequestInterface
/**
* AlexaRequest constructor.
*
* @param string $version
* @param SessionInterface $session
* @param RequestTypeInterface $request
* @param ContextInterface $context
* @param string $rawRequestData
* @param string $version
* @param RequestTypeInterface $request
* @param SessionInterface|null $session
* @param ContextInterface|null $context
* @param string $rawRequestData
*/
public function __construct(
string $version,
SessionInterface $session,
RequestTypeInterface $request,
SessionInterface $session = null,
ContextInterface $context = null,
string $rawRequestData
) {
$this->version = $version;
$this->session = $session;
$this->request = $request;
$this->session = $session;
$this->context = $context;
$this->rawRequestData = $rawRequestData;
}
Expand All @@ -73,19 +73,19 @@ public function getVersion(): string
}

/**
* @return SessionInterface
* @return RequestTypeInterface
*/
public function getSession(): SessionInterface
public function getRequest(): RequestTypeInterface
{
return $this->session;
return $this->request;
}

/**
* @return RequestTypeInterface
* @return SessionInterface
*/
public function getRequest(): RequestTypeInterface
public function getSession()
{
return $this->request;
return $this->session;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Request/AlexaRequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public function checkApplication(string $applicationId);
public function getVersion(): string;

/**
* @return SessionInterface
* @return RequestTypeInterface
*/
public function getSession(): SessionInterface;
public function getRequest(): RequestTypeInterface;

/**
* @return RequestTypeInterface
* @return SessionInterface
*/
public function getRequest(): RequestTypeInterface;
public function getSession();

/**
* @return ContextInterface|null
Expand Down
20 changes: 12 additions & 8 deletions src/Request/RequestType/RequestTypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ public static function createFromData(string $data): AlexaRequest

$version = $data['version'] ?? AlexaRequest::DEFAULT_VERSION;

$session = new Session(
$data['session']['new'],
$data['session']['sessionId'],
new SessionApplication($data['session']['application']['applicationId']),
$data['session']['attributes'] ?? [],
new SessionUser($data['session']['user']['userId'])
);
if (isset($data['session'])) {
$session = new Session(
$data['session']['new'],
$data['session']['sessionId'],
new SessionApplication($data['session']['application']['applicationId']),
$data['session']['attributes'] ?? [],
new SessionUser($data['session']['user']['userId'])
);
} else {
$session = null;
}

if (isset($data['context'])) {
$audioPlayer = new AudioPlayer(
Expand Down Expand Up @@ -255,6 +259,6 @@ public static function createFromData(string $data): AlexaRequest
break;
}

return new AlexaRequest($version, $session, $request, $context, $rawRequestData);
return new AlexaRequest($version, $request, $session, $context, $rawRequestData);
}
}
2 changes: 1 addition & 1 deletion test/Request/AlexaRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public function testInstantiation()

$alexaRequest = new AlexaRequest(
'version',
$session,
$launchRequest,
$session,
$context,
$rawRequestData
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ private function createAlexaRequest(string $timestamp)

return new AlexaRequest(
'version',
$session,
$launchRequest,
$session,
$context,
json_encode($data)
);
Expand Down
2 changes: 1 addition & 1 deletion test/Request/Certificate/CertificateValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ private function createAlexaRequest(string $timestamp)

return new AlexaRequest(
'version',
$session,
$launchRequest,
$session,
$context,
json_encode($data)
);
Expand Down
2 changes: 1 addition & 1 deletion test/Session/SessionContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ private function createAlexaRequest(): AlexaRequest

$alexaRequest = new AlexaRequest(
'version',
$session,
$launchRequest,
$session,
$context,
$rawRequestData
);
Expand Down

0 comments on commit cb0e609

Please sign in to comment.