The main goal is to get some template for making fast and tiny REST or Asynchronous services on PHP8+, using parts of Yii3 and other PSR-compatible components:
- complete set of environments configured with docker-compose
- optionally runs inside single immutable docker containers
- with both of Swoole / RoadRunner for multi-threading long-living processes
- using strict PSR-compatible components (as widely as possible)
- with Redis / RabbitMQ for queues and sessions
- with WebSockets for web / mobile clients
- puts application level logs, sessions and uploaded files into network / cloud storages only
- collects system level logs through Filebeat to ELK
- LetsEncrypt SSL auto refreshing
- CLI project generator
On application layer project runs with:
- PHP8+
- Mixed runtime CLI / WEB / Daemon (Swoole ✓ | RoadRunner ✓)
- Mysql ✓ / Postgresql for state storage
- Redis ✓
- WebSockets support
- Xdebug 3 ✓
Framework's code use:
- Yiisoft components:
- Config
- PSR-11 DI Container ✓
- PSR-3 Logger
- PSR-6 Cache
- DB Layer / ActiveRecord ✓
- Other components for HTTP:
- PSR-7/17 Messages / Factories (Httpsoft)
- PSR-15 Middlewares (custom)
- PSR-18 Client (Guzzle)
- Also:
- Codeception Unit / REST / E2E testing and coverage
- autogenerated OpenApi specification with SwaggerUI ✓
- autogenerated PhpDoc sources documentation
- Edit
.env
or addenso.localhost
to systemhosts
- Run
docker-compose up -d --build
Wait for such result for docker-compose ps
:
Name Command State Ports
---------------------------------------------------------------------------------------------------------------------------------------------------------
enso_db_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp,:::3306->3306/tcp
nginx nginx -g daemon off; Up 0.0.0.0:80->80/tcp,:::80->80/tcp, 0.0.0.0:81->81/tcp,:::81->81/tcp, 0.0.0.0:82->82/tcp,:::82->82/tcp
open-api /docker-entrypoint.sh sh / ... Up 80/tcp, 0.0.0.0:8080->8080/tcp,:::8080->8080/tcp
php docker-php-entrypoint bash ... Up 9000/tcp, 0.0.0.0:8282->9666/tcp,:::8282->9666/tcp
php-sw /entrypoint.sh bash -c com ... Up 9999/tcp
redis docker-entrypoint.sh redis ... Up 6379/tcp
Initially we have three kind of HTTP JSON API services with different environment, images, lifecycles, HTTP servers. Hovewer all of them executing the same application and actions code:
- Default Nginx + FPM access
http://enso.localhost/(index|open-api)
- Swoole HTTP Server
http://enso.localhost:81/(index|open-api)
- RoadRunner HTTP Server
http://enso.localhost:82/(index|open-api)
Which executes the same application, routing and actions (by default).
For example:
docker-compose exec php ./enso default/open-api
will print out current specs tostdout
streamdocker-compose exec php ./enso default/open-api > ./open-api.json
will save it to local file on host FS
- Swagger UI
http://enso.localhost:8080/
- Codeception coverage and test report:
http://enso.localhost:(80|81|82)/_status/report.html
http://enso.localhost:(80|81|82)/_status/coverage/
- PhpDoc documentation:
http://enso.localhost:(80|81|82)/docs
-
docker-compose exec php vendor/bin/codecept build
-
docker-compose exec php vendor/bin/codecept run
-
docker-compose exec php-sw vendor/bin/codecept run
Api Tests (8) -----------------------------------------------------------------------------------------------------------------------------------------------------
✔ ApiCest: Try api default route (0.18s)
✔ ApiCest: Try default index (0.15s)
✔ ApiCest: Try default view (0.13s)
✔ ApiCest: Try bad route (0.13s)
✔ EnsoTest: Class can be created (0.05s)
✔ EnsoTest: Cli default route (0.23s)
✔ EnsoTest: Cli default view (0.21s)
✔ EnsoTest: Cli bad route (0.20s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Api-sw Tests (8) --------------------------------------------------------------------------------------------------------------------------------------------------
✔ ApiCest: Try api default route (0.02s)
✔ ApiCest: Try default index (0.02s)
✔ ApiCest: Try default view (0.02s)
✔ ApiCest: Try bad route (0.02s)
✔ EnsoTest: Class can be created (0.01s)
✔ EnsoTest: Cli default route (0.21s)
✔ EnsoTest: Cli default view (0.19s)
✔ EnsoTest: Cli bad route (0.20s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Api-rr Tests (8) --------------------------------------------------------------------------------------------------------------------------------------------------
✔ ApiCest: Try api default route (0.08s)
✔ ApiCest: Try default index (0.09s)
✔ ApiCest: Try default view (0.02s)
✔ ApiCest: Try bad route (0.03s)
✔ EnsoTest: Class can be created (0.01s)
✔ EnsoTest: Cli default route (0.22s)
✔ EnsoTest: Cli default view (0.20s)
✔ EnsoTest: Cli bad route (0.20s)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
docker-compose exec php vendor/bin/codecept run --coverage-html
docker run --rm -v $(pwd):/src phpdoc/phpdoc -d /src/enso-psr -i vendor -t /src/enso-psr/docs/phpdoc
or
./generate-docs.sh
- Set up
Docker
as an IDE Key and port9005
to listen to - Run as "Local Web Server" on
http://hostname/
(only for80
port via FPM).