robiningelbrecht / symfony-skeleton
A Symfony skeleton I use to bootstrap new projects
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=8.3
- ext-bcmath: *
- ext-ctype: *
- ext-iconv: *
- adrenalinkin/doctrine-naming-strategy: ^3.0
- doctrine/dbal: ^3
- doctrine/doctrine-bundle: ^2.13
- doctrine/doctrine-migrations-bundle: ^3.3
- doctrine/orm: ^3.3
- league/flysystem-bundle: ^3.3
- moneyphp/money: ^4.5
- ramsey/uuid: ^4.7
- respect/validation: ^2.3
- symfony/console: 7.1.*
- symfony/dotenv: 7.1.*
- symfony/flex: ^2
- symfony/framework-bundle: 7.1.*
- symfony/lock: 7.1.*
- symfony/messenger: 7.1.*
- symfony/monolog-bundle: *
- symfony/process: 7.1.*
- symfony/rate-limiter: 7.1.*
- symfony/runtime: 7.1.*
- symfony/yaml: 7.1.*
- thecodingmachine/safe: ^2.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.4
- spatie/phpunit-snapshot-assertions: ^5.1
- symfony/phpunit-bridge: ^7.1
Conflicts
This package is auto-updated.
Last update: 2024-11-13 06:14:07 UTC
README
Bootstrap new project
> composer create-project robiningelbrecht/symfony-skeleton [app-name] --no-install --ignore-platform-reqs
Open .env
and set following ENV VARIABLES:
DOCKER_CONTAINER_BASE_NAME=skeleton
DOCKER_MYSQL_PORT=3306
DOCKER_NGINX_PORT=8081
# Install dependencies > make composer arg="install" # Setup project (configure containers and functionality) > make console arg="app:setup"
# Build docker containers > make build-containers
Makefile
There are some predefined commands in the Makefile
:
# Run test suite > make phpunit # Run cs fixer > make csfix # Run PHPstan > make phpstan # Create and run migrations > make migrate-diff > make migrate-run # Run a console command > make console arg="your:fancy:command"
Events
Recording Events
In your entity use RecordsEvents;
and record events when needed:
class User { use RecordsEvents; public static function create( UserId $id, ): self { // ... $user->recordThat(new UserWasCreated( userId: $user->getUserId(), )); return $user; } }
Publishing Events
In your repository, inject the EventBus
and publish the recorded events:
final readonly class UserRepository implements CommandHandler { public function __construct( private EventBus $eventBus, ) { } public function save(User $user): void { // ... $this->eventBus->publishEvents($user->getRecordedEvents()); }
Registering Event Listeners
Create a manager / event listener and add the AsEventListener
attribute:
final readonly class UserEmailManager { #[AsEventListener] public function reactToUserWasCreated(UserWasCreated $event): void { // ... } }
More info: https://symfony.com/doc/current/event_dispatcher.html#defining-event-listeners-with-php-attributes
Rate Limiter
Create a Rate Limiter
Define a new rate limiter in config/packages/rate_limiter.yaml
:
framework: rate_limiter: anonymous: policy: 'sliding_window' limit: 100 interval: '60 minutes'
Apply a limiter to a route
Then apply it to the necessary routes:
#[RateLimiter('anonymous')] #[Route(path: '/your/important/route', methods: ['GET', 'POST'])] public function handle(Request $request): Response { // ... }
more info: https://symfony.com/doc/current/rate_limiter.html