diff --git a/.github/workflows/code_checks.yaml b/.github/workflows/code_checks.yaml index 3a4e1d2..4f9f44c 100644 --- a/.github/workflows/code_checks.yaml +++ b/.github/workflows/code_checks.yaml @@ -20,21 +20,11 @@ jobs: stability: prefer-stable minimum-stability: stable is-current: true - - php: '8.4' - symfony-version: '^8.0' - stability: prefer-stable - minimum-stability: dev - is-current: true - php: '8.5' symfony-version: 8.0.* stability: prefer-stable minimum-stability: stable is-current: false - - php: '8.5' - symfony-version: '^8.0' - stability: prefer-stable - minimum-stability: dev - is-current: false name: PHP ${{ matrix.php }} - ${{ matrix.symfony-version }} - ${{ matrix.stability }} steps: diff --git a/config/routing.yaml b/config/routing.yaml new file mode 100644 index 0000000..abc15d7 --- /dev/null +++ b/config/routing.yaml @@ -0,0 +1,3 @@ +fc_load_events: + path: /fc-load-events + controller: CalendarBundle\Controller\CalendarController::load diff --git a/config/services.yaml b/config/services.yaml new file mode 100644 index 0000000..1919c4f --- /dev/null +++ b/config/services.yaml @@ -0,0 +1,23 @@ +services: + CalendarBundle\Serializer\Serializer: + class: CalendarBundle\Serializer\Serializer + + CalendarBundle\Serializer\SerializerInterface: + alias: CalendarBundle\Serializer\Serializer + + calendar.serializer: + alias: CalendarBundle\Serializer\Serializer + + CalendarBundle\Controller\CalendarController: + class: CalendarBundle\Controller\CalendarController + public: true + autowire: true + arguments: + $eventDispatcher: '@event_dispatcher' + $serializer: '@CalendarBundle\Serializer\Serializer' + tags: + - controller.service_arguments + + calendar.controller: + alias: CalendarBundle\Controller\CalendarController + public: true diff --git a/src/Resources/doc/doctrine-crud.md b/docs/doctrine-crud.md similarity index 100% rename from src/Resources/doc/doctrine-crud.md rename to docs/doctrine-crud.md diff --git a/src/Resources/doc/es6-encore.md b/docs/es6-encore.md similarity index 100% rename from src/Resources/doc/es6-encore.md rename to docs/es6-encore.md diff --git a/src/Resources/doc/multi-calendar.md b/docs/multi-calendar.md similarity index 100% rename from src/Resources/doc/multi-calendar.md rename to docs/multi-calendar.md diff --git a/docs/upgrade-to-abstractbundle.md b/docs/upgrade-to-abstractbundle.md new file mode 100644 index 0000000..e9846d5 --- /dev/null +++ b/docs/upgrade-to-abstractbundle.md @@ -0,0 +1,81 @@ +# Migrating to v8.1 + +This guide explains how to upgrade your application when updating CalendarBundle to the version 8.1. + +## What Changed + +The bundle has been modernized to follow Symfony 8 best practices: + +| Before | After | +|--------|-------| +| `src/CalendarBundle.php` extends `Bundle` | Extends `AbstractBundle` | +| `src/DependencyInjection/CalendarExtension.php` | Removed (merged into bundle) | +| `src/DependencyInjection/Configuration.php` | Removed | +| `src/Resources/config/services.yaml` | `config/services.yaml` | +| `src/Resources/config/routing.yaml` | `config/routing.yaml` | +| `src/Resources/views/` | `templates/` | +| `src/Resources/doc/` | `docs/` | +| `tests/DependencyInjection/CalendarExtensionTest.php` | `tests/DependencyInjection/CalendarBundleTest.php` | + +### New Service Aliases + +Short service aliases have been added for convenience: + +| Class Name | Alias | +|------------|-------| +| `CalendarBundle\Serializer\Serializer` | `calendar.serializer` | +| `CalendarBundle\Controller\CalendarController` | `calendar.controller` | + +Both naming conventions are supported. + +## Breaking Changes + +### 1. Routing Configuration Path + +If you import the bundle's routing manually, update the path: + +**Before:** +```yaml +# config/routes/calendar.yaml +calendar: + resource: '@CalendarBundle/Resources/config/routing.yaml' +``` + +**After:** +```yaml +# config/routes/calendar.yaml +calendar: + resource: '@CalendarBundle/config/routing.yaml' +``` + +### 2. Template Path (if overriding) + +If you override the bundle's templates in your application, no change is required. Symfony automatically resolves the correct location. + +## Migration Steps + +1. **Update the bundle** via Composer: + ```bash + composer update tattali/calendar-bundle + ``` + +2. **Update routing import** in `config/routes/calendar.yaml` (if using manual import): + ```yaml + calendar: + resource: '@CalendarBundle/config/routing.yaml' + ``` + +3. **Clear cache**: + ```bash + php bin/console cache:clear + ``` + +## No Changes Required + +The following remain unchanged and fully backward compatible: + +- **Service IDs** - `CalendarBundle\Serializer\Serializer`, `CalendarBundle\Controller\CalendarController`, and `CalendarBundle\Serializer\SerializerInterface` alias +- **Event subscriber pattern** - Your `SetDataEvent` subscribers work exactly the same +- **API endpoint** - `/fc-load-events` route and behavior unchanged +- **Event entity** - `CalendarBundle\Entity\Event` unchanged +- **Frontend integration** - No JavaScript changes needed diff --git a/src/CalendarBundle.php b/src/CalendarBundle.php index 441485d..aa3ff95 100644 --- a/src/CalendarBundle.php +++ b/src/CalendarBundle.php @@ -4,6 +4,20 @@ namespace CalendarBundle; -use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use Symfony\Component\HttpKernel\Bundle\AbstractBundle; -class CalendarBundle extends Bundle {} +class CalendarBundle extends AbstractBundle +{ + /** + * @param array $config + */ + public function loadExtension( + array $config, + ContainerConfigurator $container, + ContainerBuilder $builder, + ): void { + $container->import('../config/services.yaml'); + } +} diff --git a/src/DependencyInjection/CalendarExtension.php b/src/DependencyInjection/CalendarExtension.php deleted file mode 100644 index 162ebee..0000000 --- a/src/DependencyInjection/CalendarExtension.php +++ /dev/null @@ -1,27 +0,0 @@ -processConfiguration($configuration, $configs); - - $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('services.yaml'); - } -} diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php deleted file mode 100644 index a783009..0000000 --- a/src/DependencyInjection/Configuration.php +++ /dev/null @@ -1,24 +0,0 @@ - - */ - public function getConfigTreeBuilder(): TreeBuilder - { - return new TreeBuilder('calendar'); - } -} diff --git a/src/Resources/config/routing.yaml b/src/Resources/config/routing.yaml deleted file mode 100644 index 4febf4d..0000000 --- a/src/Resources/config/routing.yaml +++ /dev/null @@ -1,4 +0,0 @@ -fc_load_events: - path: /fc-load-events - defaults: - _controller: CalendarBundle\Controller\CalendarController::load diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml deleted file mode 100644 index 6f80c6e..0000000 --- a/src/Resources/config/services.yaml +++ /dev/null @@ -1,10 +0,0 @@ -services: - CalendarBundle\Serializer\Serializer: - public: false - - CalendarBundle\Controller\CalendarController: - public: true - autowire: true - arguments: - $eventDispatcher: '@event_dispatcher' - $serializer: '@CalendarBundle\Serializer\Serializer' diff --git a/src/Resources/views/calendar.html b/templates/calendar.html similarity index 100% rename from src/Resources/views/calendar.html rename to templates/calendar.html diff --git a/tests/DependencyInjection/CalendarBundleTest.php b/tests/DependencyInjection/CalendarBundleTest.php new file mode 100644 index 0000000..9f86290 --- /dev/null +++ b/tests/DependencyInjection/CalendarBundleTest.php @@ -0,0 +1,82 @@ +load('services.yaml'); + + self::assertTrue($container->hasDefinition(Serializer::class)); + self::assertTrue($container->hasDefinition(CalendarController::class)); + self::assertTrue($container->hasAlias(SerializerInterface::class)); + } + + public function testSerializerServiceConfiguration(): void + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(\dirname(__DIR__, 2) . '/config')); + $loader->load('services.yaml'); + + $definition = $container->getDefinition(Serializer::class); + self::assertSame(Serializer::class, $definition->getClass()); + } + + public function testControllerServiceConfiguration(): void + { + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(\dirname(__DIR__, 2) . '/config')); + $loader->load('services.yaml'); + + $definition = $container->getDefinition(CalendarController::class); + self::assertSame(CalendarController::class, $definition->getClass()); + self::assertTrue($definition->isPublic()); + self::assertTrue($definition->isAutowired()); + } + + public function testBundleExtendsAbstractBundle(): void + { + $bundle = new CalendarBundle(); + + self::assertInstanceOf(AbstractBundle::class, $bundle); + } + + public function testBundleLoadExtension(): void + { + $bundle = new CalendarBundle(); + $container = new ContainerBuilder(); + $bundlePath = \dirname(__DIR__, 2) . '/src'; + + $locator = new FileLocator($bundlePath); + $resolver = new \Symfony\Component\Config\Loader\LoaderResolver([ + new YamlFileLoader($container, $locator), + new \Symfony\Component\DependencyInjection\Loader\PhpFileLoader($container, $locator), + ]); + $loader = new \Symfony\Component\DependencyInjection\Loader\PhpFileLoader($container, $locator); + $loader->setResolver($resolver); + $instanceOf = []; + + $configurator = new ContainerConfigurator($container, $loader, $instanceOf, $bundlePath, 'calendar_test'); + + $bundle->loadExtension([], $configurator, $container); + + self::assertTrue($container->hasDefinition(Serializer::class)); + self::assertTrue($container->hasDefinition(CalendarController::class)); + } +} diff --git a/tests/DependencyInjection/CalendarExtensionTest.php b/tests/DependencyInjection/CalendarExtensionTest.php deleted file mode 100644 index b4c1e57..0000000 --- a/tests/DependencyInjection/CalendarExtensionTest.php +++ /dev/null @@ -1,35 +0,0 @@ -> - */ - private array $configuration; - - protected function setUp(): void - { - $this->builder = new ContainerBuilder(); - $this->loader = new CalendarExtension(); - - $this->configuration = []; - } - - public function testConfiguration(): void - { - $this->loader->load($this->configuration, $this->builder); - - self::assertSame($this->configuration, $this->builder->getParameterBag()->all()); - } -}