pixiekat / symfony-bootstrap
A small library to create and bootstrap an application using Symfony components.
Requires
- php: ^8.2 || ^8.3 || ^8.4
- doctrine/dbal: ^4.2
- doctrine/migrations: ^3.9
- doctrine/orm: ^3.3
- monolog/monolog: ^3.7
- symfony/cache: ^7.2
- symfony/config: ^7.2
- symfony/dependency-injection: ^7.2
- symfony/dotenv: ^7.2
- symfony/http-foundation: ^7.2
- symfony/mailer: ^7.2
- symfony/routing: ^7.2
- symfony/translation: ^7.2
- symfony/twig-bridge: ^7.2
- symfony/yaml: ^7.2
- twig/twig: ^3.0
Requires (Dev)
- kint-php/kint: ^6.0
- symfony/google-mailer: ^7.2
README
This is a basic library which bootstraps an application using Symfony Components.
Installation
composer require pixiekat\symfony-bootstrap:^1.0
or view the releases page on Codeberg.
Usage
Define your routes for your application.
use Symfony\Component\Routing\Annotation\Route;
#[Route(path: '/foo', name: 'foo', methods: ['GET'])]
Then create the application.
try {
$app = (new \Pixiekat\SymfonyBootstrap\Bootstrap)->createApplication('dev');
$response = $app->getResponse(['error_pages_dir' => '/errors']) ;
$response->send();
}
catch (Exception $e) {
throw \Exception('Could not bootstrap.');
}
Pull services from the container with $app->getContainer()
.
Services
You can define services within <root>/config/services.yml
. The Application
class will read them in when bootstrapping.
services:
last_fm_client:
class: Barryvanveen\Lastfm\Lastfm
arguments:
- '@http.client'
- '%env(LAST_FM_API_KEY)%'
app_last_fm_manager:
class: App\Service\LastFmManager
arguments:
- '%env(LAST_FM_API_KEY)%'
- '%env(LAST_FM_USER)%'
- '@cache.app'
- '@logger'
- '@last_fm_client'
app.twig.last_fm_now_playing_extension:
class: App\Twig\LastFmNowPlayingExtension
arguments:
- '@app_last_fm_manager'
- '@app.cache'
- '@request'
- '@logger'
tags:
- { name: twig.extension }
Doctrine
Doctrine is available as doctrine.orm.entity_manager
or using $app->getDoctrine()
.
Add your DB connection string as environment variable DATABASE_URL
.
Add your migrations.yml
to <root>/config/
.
table_storage:
table_name: doctrine_migration_versions
version_column_name: version
version_column_length: 191
executed_at_column_name: executed_at
execution_time_column_name: execution_time
migrations_paths:
'App\Migrations': ./../migrations
all_or_nothing: true
transactional: true
check_database_platform: true
organize_migrations: none
connection: null
em: null
Add your Entities to <root>/src/Entity
.
Add your Repositories to <root>/src/Repository
.
Caveats
This is a very rudimentary project mostly designed for me that's a proof of concept in constant development but feel free to request anything or pull request. :)
License
Anyway this project is licensed under the Anti-Capitalist Software License so basically I don't care if you use this as long as you're not in law enforcement, immigration enforcement, or the military. I am 100% against AI and LLMs, so don't use this package with any combination of those two things either.
Free Palestine. Human beings aren't illegal. Fuck borders.
Contact Me
You can find me on Bluesky mostly. I don't bite. <3