2017 © Pedro Peláez
 

library google-actions-php

This library is a helper for google actions with php.

image

maxbeckers/google-actions-php

This library is a helper for google actions with php.

  • Tuesday, April 17, 2018
  • by maxbeckers
  • Repository
  • 2 Watchers
  • 6 Stars
  • 49 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 29 % Grown

The README.md

Google actions php library

This library is a helper for google actions with php., (*1)

Install via composer

Require the package with composer:, (*2)

composer require maxbeckers/google-actions-php

Usage

Handle the request: - map request data to request object - validate request - handle request data - create response - send response, (*3)

Map request data to request object

Map needed request headers and request body to Request., (*4)

use MaxBeckers\GoogleActions\Request\Request;
...
$requestBody  = file_get_contents('php://input');
$googleRequest = Request::fromGoogleRequest($requestBody);

Validate request

The RequestValidator will handle the google request validation., (*5)

use MaxBeckers\GoogleActions\Validation\RequestValidator;
...
$validator = new RequestValidator();
$validator->validate($googleRequest);

Register request handlers

For different requests it's helpful to create different RequestHandlers., (*6)

use MaxBeckers\GoogleActions\RequestHandler\RequestHandlerRegistry;
...
$requestHandlerRegistry = new RequestHandlerRegistry();
$requestHandlerRegistry->addHandler($myRequestHandler);

Use registry to handle request

use MaxBeckers\GoogleActions\RequestHandler\RequestHandlerRegistry;
...
$requestHandler = $requestHandlerRegistry->getSupportingHandler($googleRequest);
$response       = $requestHandler->handleRequest($googleRequest);

Render response

header('Content-Type: application/json');
echo json_encode($response);
exit();

Create a new request handler

The new request handler must extend AbstractRequestHandler. First implement the abstract supportsRequest-method., (*7)

public function supportsRequest(Request $request): bool
{
    return true; // check request data
}

Then implement the handleRequest-method. For simple responses there is a ResponseHelper., (*8)

use MaxBeckers\GoogleActions\Helper\ResponseHelper;
...
/** @var ResponseHelper */
private $responseHelper;
...
public function handleRequest(Request $request): Response
{
    // todo set needed response data
    return $responseHelper->respond('Success :)');
}

The Versions

17/04 2018

dev-master

9999999-dev

This library is a helper for google actions with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php google actions home

07/08 2017

0.1.0

0.1.0.0

This library is a helper for google actions with php.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by Maximilian Beckers

php google actions home