🍭 PHP - API
🍃 Let's know some helpers & tips.
Assure you are running your php
container 👇
make run-php
make run-php
🗃 Requirements
Assume you have:
- PHP FPM
>=8.1
min (recommended 8.2) - Composer install Globally
- ☕ / 🍵
💾 Installation
👇 Copy Variable Environment scope
# copy .env to .env.local override
cp .env .env.local
# copy .env to .env.local override
cp .env .env.local
And configure you dev environment
APP_DEBUG=1
APP_ENV=dev
APP_DEBUG=1
APP_ENV=dev
👇 Hit in your terminal for setup
composer install
composer install
💫 Makefile
👇 Available Makefile script CMD Shortcut:
make
ormake help
for display helpingmake check-schema
Check Schemamake check-mapping
Check Mapping, Entity, Relation, Codemake validator
Validate asserts entitiesmake lint
Lint / Prettier PHPmake analyse
Analyse PHP CODEmake cc
Clear cache DEV & PRODmake clc
Cache clearing, linting, and doctrine checks
🍭 Update dependencies
# Update composer.lock
composer update
# update the file composer.json
composer bump
# Update composer.lock
composer update
# update the file composer.json
composer bump
🍭 DOCS
👇 Symfony command
Clear the cache / logs:
php bin/console cache:clear
php bin/console cache:clear --env=prod
php bin/console cache:clear
php bin/console cache:clear --env=prod
Debug the router:
php bin/console debug:router
php bin/console debug:router
Make entity
- Ajust your .env file
- Create dbal connection in config/packages/doctrine.yaml
- Create entity_managers in config/packages/doctrine.yaml
- Create entity with make:entity
php bin/console make:entity
php bin/console make:entity
Regenerate entity after change
php bin/console make:entity --regenerate
php bin/console make:entity --regenerate
Debug the Entity Validator (Check if Validator is up-to-date to entity):
# php bin/console debug:validator ['App\Application\Entity']
php bin/console debug:validator 'App\Domain\Entity\Article\Article'
# php bin/console debug:validator ['App\Application\Entity']
php bin/console debug:validator 'App\Domain\Entity\Article\Article'
Validate the doctrine entity and relations (Check if Entity is conformed to DB):
php bin/console doctrine:schema:validate
# OR
php bin/console doctrine:schema:validate -v
# OR
#php bin/console doctrine:schema:validate --em=[name_of_your_em] -v
php bin/console doctrine:schema:validate --em="default" -v
# php bin/console doctrine:schema:validate --skip-sync
php bin/console doctrine:schema:validate
# OR
php bin/console doctrine:schema:validate -v
# OR
#php bin/console doctrine:schema:validate --em=[name_of_your_em] -v
php bin/console doctrine:schema:validate --em="default" -v
# php bin/console doctrine:schema:validate --skip-sync
Serializer Debug Command:
# php bin/console debug:serializer [name_of_your_entity]
php bin/console debug:serializer 'App\Domain\Entity\Redaction\Article\Article'
# php bin/console debug:serializer [name_of_your_entity]
php bin/console debug:serializer 'App\Domain\Entity\Redaction\Article\Article'
Validate the doctrine mappings:
# php bin/console doctrine:mapping:info --em=[name_of_your_em]
php bin/console doctrine:mapping:info --em=default
# php bin/console doctrine:mapping:info --em=[name_of_your_em]
php bin/console doctrine:mapping:info --em=default
Format with PHPCS - Fix Code Standard (lint) :
php vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix
# php vendor/friendsofphp/php-cs-fixer/php-cs-fixer list-files
php vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix
# php vendor/friendsofphp/php-cs-fixer/php-cs-fixer list-files
Analyse code bugs with PHPSTAN :
php vendor/bin/phpstan analyse
php vendor/bin/phpstan analyse
Local PHP Security Checker :
If you have run the project with the project's Docker, you can check the php composer security dependencies.
local-php-security-checker
# OR
local-php-security-checker --path=/var/www/leaders-api
local-php-security-checker
# OR
local-php-security-checker --path=/var/www/leaders-api
🕵 LOGS
Show logs in terminal:
# -f: live log
tail -f var/log/dev.log | grep -a --color=auto "ERROR\|CRITICAL"
# -n 5: 5 last logs
tail -n 5 var/log/dev.log | grep -a --color=auto "ERROR\|CRITICAL"
# -f: live log
tail -f var/log/dev.log | grep -a --color=auto "ERROR\|CRITICAL"
# -n 5: 5 last logs
tail -n 5 var/log/dev.log | grep -a --color=auto "ERROR\|CRITICAL"
🧐 Tests
Write test cases in the tests/
folder.
Run the tests with:
php bin/phpunit
# OR
php bin/phpunit --debug
php bin/phpunit
# OR
php bin/phpunit --debug
🔗 Usefull links
- Symfony: https://symfony.com/doc/current/index.html
- PHP CS: https://cs.symfony.com/
- PHP STAN: https://phpstan.org/user-guide/rule-levels
Todo
- Utiliser les Traits php au lieu des commons (use createdAtTrait;)
- Utiliser normaliser pour les request post.