Skip to content

🍭 PHP - API

🍃 Let's know some helpers & tips.

Assure you are running your php container 👇

shell
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

bash
# 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

txt
APP_DEBUG=1
APP_ENV=dev
APP_DEBUG=1
APP_ENV=dev

👇 Hit in your terminal for setup

bash
composer install
composer install

💫 Makefile

👇 Available Makefile script CMD Shortcut:

  • make or make help for display helping
  • make check-schema Check Schema
  • make check-mapping Check Mapping, Entity, Relation, Code
  • make validator Validate asserts entities
  • make lint Lint / Prettier PHP
  • make analyse Analyse PHP CODE
  • make cc Clear cache DEV & PROD
  • make clc Cache clearing, linting, and doctrine checks

🍭 Update dependencies

shell
# 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:

shell
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:

shell
php bin/console debug:router
php bin/console debug:router

Make entity

  1. Ajust your .env file
  2. Create dbal connection in config/packages/doctrine.yaml
  3. Create entity_managers in config/packages/doctrine.yaml
  4. Create entity with make:entity
bash
php bin/console make:entity
php bin/console make:entity

Regenerate entity after change

bash
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):

shell
# 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):

shell
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:

shell
# 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:

shell
# 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) :

shell
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 :

shell
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.

shell
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:

shell
# -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:

shell
php bin/phpunit
# OR
php bin/phpunit --debug
php bin/phpunit
# OR
php bin/phpunit --debug

Todo

  • Utiliser les Traits php au lieu des commons (use createdAtTrait;)
  • Utiliser normaliser pour les request post.

Released under the MIT License.