Example project for Phial.
This package is auto-updated.
Last update: 2021-01-17 16:52:01 UTC
Example project for phial.
- AWS cli
- SAM cli
- AWS credentials
- 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.
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
sam build sam deploy --guided sam local start-api sam local invoke
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.
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.
- DynamoDB - app/Caches/DynamoDbCache.php
Service providers - Standard service providers wire up required classes using PHP-DI.
Global middleware - Broker handles PSR-15 middleware pipeline.
Ensure that the first middleware handles exceptions, and the last one handles routing.
Logging - Monolog sends logs to the
stderrstream which is relayed to CloudWatch by AWS Lambda.
Database - PDO connections and queries work as expected. The function must be in the same
There is also AsyncAws RDS Data Service.
Event Handling - Add new event listeners by extending
ListenerProviderInterfacein a service provider.
Look at app/Providers/EventServiceProvider.php for an example of how to add a listener.
Psr\EventDispatcher\EventDispatcherInterfaceto get a dispatcher and dispatch as per PSR-14:
Queues - A regular event handler with an SQS event source works as expected.
Cache - PSR-16 DynamoDB cache in app/Caches/DynamoDbCache.php.
Psr\SimpleCache\CacheInterface. Look in template.yaml at the definition of the SimpleTable.
The key created is
key, the cached value is stored in
valueas a gzip compressed serialized version of the data, and the
expires_atvalue store a UNIX timestamp in seconds.
- Cache TTL.
- Form method spoofing.
- Content negotiation.
- Ad-hoc commands.
- Named routes.
- Reverse routing (URL generation).
- Route middleware.
- Rate limiting.
- Route cache.
- Resource controllers.
- Middleware groups.
- Middleware priority.
- Controller middleware.
- Authentication middleware using Cognito.
- Basic authentication.
- Uploaded files.
- File downloads.
- File responses.
- Static assets via S3.
- CSRF protection.