datashaman/phial-project

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Example project for Phial.

dev-master 2020-08-17 15:44 UTC

This package is auto-updated.

Last update: 2021-10-17 18:39:47 UTC


README

Example project for phial.

requirements

  • AWS cli
  • SAM cli
  • AWS credentials

instructions

  • Define version of PHP in .settings.
  • Add any system and PHP packages in Dockerfile. PHP module packages are installed like yum install -y php74-php-gd.
  • Edit php.ini to configure PHP or enable modules.
  • Define your composer dependencies using the usual methods.
  • Adapt bootstrap process in bootstrap.php to suit your needs.
  • Set your function handler in template.yaml to be anything invokable.

handlers

Regular handlers have the following signature:

myHandler(array $event, ContextInterface $context);

Parameters are optional, you can type-hint anything from the container.

If you are developing an HTTP API, use the RequestHandlerAdapter which marshals the request and reponse to and from a PSR-17 RequestHandlerInterface.

workflow

sam build
sam deploy --guided
sam local start-api
sam local invoke

moving parts

You do not have to use a DI container, but it does make things easier. Any PSR-11 implementation will do. The PHP-DI invoker which invokes the handler code will handle DI or no DI, it doesn't care.

To replace the DI container with another implementation, build one in bootstrap.php and pass it into the invoker construction.

PSR standards supported

The following PSR interfaces are supported; any compatible implementation can be used, just pass parameters into the handler constructor or use your DI container to autowire it up.

Also listed is the implementation used in this project. The implementations are configured in the config folder, and wired up in service providers.

roadmap

done

  • Configuration - PHP-DI stores configuration in config folder.

  • Service providers - Standard service providers wire up required classes using PHP-DI.

    Define service providers in app/Providers folder, and add the class to app.providers config in config/app.php.

  • Global middleware - Broker handles PSR-15 middleware pipeline.

    Define middleware in app/Http/Middleware folder, and add the class to http.middleware config in config/http.php.

    Ensure that the first middleware handles exceptions, and the last one handles routing.

  • Logging - Monolog sends logs to the stderr stream which is relayed to CloudWatch by AWS Lambda.

  • Routing - FastRoute routes are defined in routes folder.

  • Templating - Latte for rendering templates in templates folder.

  • Database - PDO connections and queries work as expected. The function must be in the same VPC as the RDS cluster.

    There is also AsyncAws RDS Data Service.

  • Event Handling - Add new event listeners by extending ListenerProviderInterface in a service provider.

    Look at app/Providers/EventServiceProvider.php for an example of how to add a listener.

    Type-hint Psr\EventDispatcher\EventDispatcherInterface to get a dispatcher and dispatch as per PSR-14: $dispatcher->dispatch(new MyEvent());

  • Queues - A regular event handler with an SQS event source works as expected.

  • Cache - PSR-16 DynamoDB cache in app/Caches/DynamoDbCache.php.

    Type-hint is Psr\SimpleCache\CacheInterface. Look in template.yaml at the definition of the SimpleTable.

    The key created is key, the cached value is stored in value as a gzip compressed serialized version of the data, and the expires_at value store a UNIX timestamp in seconds.

todo

general

  • Cache TTL.
  • CORS.
  • Form method spoofing.
  • Validation.
  • Content negotiation.
  • Ad-hoc commands.

routing

  • Named routes.
  • Reverse routing (URL generation).
  • Route middleware.
  • Rate limiting.
  • Route cache.
  • Resource controllers.

middleware

  • Middleware groups.
  • Middleware priority.
  • Controller middleware.
  • Authentication middleware using Cognito.
  • Basic authentication.

files

  • Uploaded files.
  • File downloads.
  • File responses.
  • Static assets via S3.

bottom of the list

  • Cookies.
  • CSRF protection.
  • Session.
  • Scheduler.
  • Migrations.
  • ORM.