Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robiningelbrecht/symfony-skeleton
A Symfony skeleton I use to bootstrap new projects
https://github.com/robiningelbrecht/symfony-skeleton
skeleton symfony website
Last synced: 8 days ago
JSON representation
A Symfony skeleton I use to bootstrap new projects
- Host: GitHub
- URL: https://github.com/robiningelbrecht/symfony-skeleton
- Owner: robiningelbrecht
- License: mit
- Created: 2024-11-09T15:52:02.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-12-10T10:23:52.000Z (about 2 months ago)
- Last Synced: 2024-12-10T11:27:35.850Z (about 2 months ago)
- Topics: skeleton, symfony, website
- Language: PHP
- Homepage: https://packagist.org/packages/robiningelbrecht/symfony-skeleton
- Size: 97.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Symfony Skeleton
---
## Bootstrap new project
```bash
> 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
``````bash
# Install dependencies
> make composer arg="install"
# Setup project (configure containers and functionality)
> make console arg="app:setup"
``````bash
# Build docker containers
> make build-containers
```## Makefile
There are some predefined commands in the `Makefile`:
```bash
# 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:
```php
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:
```php
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:
```php
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](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`:
```yml
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:
```php
#[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](https://symfony.com/doc/current/rate_limiter.html)