datashaman / phial-project
Example project for Phial.
Requires
- async-aws/dynamo-db: ^0.3.1
- circli/event-dispatcher: ^2.2
- container-interop/service-provider: ^0.4.0
- datashaman/phial-handler: dev-master
- datashaman/phial-http: dev-master
- fig/http-message-util: ^1.1
- laminas/laminas-diactoros: ^2.3
- latte/latte: ^2.8
- monolog/monolog: ^2.1
- narrowspark/http-status: ^4.1
- nikic/fast-route: ^1.3
- northwoods/broker: ^3.0
- northwoods/lazy-middleware: ^2.0
- php-di/invoker: ^2.1
- php-di/php-di: ^6.2
- psr/container: ^1.0
- psr/event-dispatcher: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
- psr/log: ^1.1
- psr/simple-cache: ^1.0
Requires (Dev)
- symfony/var-dumper: ^5.1
This package is auto-updated.
Last update: 2024-10-28 03:11:51 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. -
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 theRDS
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 invalue
as a gzip compressed serialized version of the data, and theexpires_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.