Skip to content

Commit

Permalink
build: twig is now optional; spinoff encoder service (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi authored Apr 6, 2024
1 parent a25aafc commit 4ab5989
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

# 0.8.0

* build: spinoff encoder service definition
* build: twig & twigbundle is now optional

# 0.7.2

* fix: next page skipping bug & lazy loading Pager
Expand Down
5 changes: 1 addition & 4 deletions packages/rekapager-bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
"symfony/config": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/flex": ">=1.3.1",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/routing": "^6.4 || ^7.0",
"symfony/serializer": "^6.4 || ^7.0",
"symfony/stimulus-bundle": "^2.16",
"symfony/twig-bundle": "^6.4 || ^7.0",
"twig/twig": "^3.8"
"symfony/stimulus-bundle": "^2.16"
}
}
44 changes: 44 additions & 0 deletions packages/rekapager-bundle/config/encoders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/rekapager package.
*
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/

use Rekalogika\Rekapager\Keyset\PageIdentifierEncoder\SymfonySerializerKeysetPageIdentifierEncoder;
use Rekalogika\Rekapager\Offset\OffsetPageIdentifierEncoder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

if (class_exists(SymfonySerializerKeysetPageIdentifierEncoder::class)) {
$services
->set(SymfonySerializerKeysetPageIdentifierEncoder::class)
->args([
service(NormalizerInterface::class),
service(DenormalizerInterface::class),
service(EncoderInterface::class),
service(DecoderInterface::class),
])
->tag('rekalogika.rekapager.page_identifier_encoder');
}

if (class_exists(OffsetPageIdentifierEncoder::class)) {
$services
->set(OffsetPageIdentifierEncoder::class)
->tag('rekalogika.rekapager.page_identifier_encoder');
}
};
24 changes: 0 additions & 24 deletions packages/rekapager-bundle/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@
use Rekalogika\Rekapager\Bundle\Twig\RekapagerRuntime;
use Rekalogika\Rekapager\Bundle\Twig\TwigPagerRenderer;
use Rekalogika\Rekapager\Contracts\PageIdentifierEncoderLocatorInterface;
use Rekalogika\Rekapager\Keyset\PageIdentifierEncoder\SymfonySerializerKeysetPageIdentifierEncoder;
use Rekalogika\Rekapager\Offset\OffsetPageIdentifierEncoder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_locator;
Expand Down Expand Up @@ -69,24 +63,6 @@
)
]);

if (class_exists(SymfonySerializerKeysetPageIdentifierEncoder::class)) {
$services
->set(SymfonySerializerKeysetPageIdentifierEncoder::class)
->args([
service(NormalizerInterface::class),
service(DenormalizerInterface::class),
service(EncoderInterface::class),
service(DecoderInterface::class),
])
->tag('rekalogika.rekapager.page_identifier_encoder');
}

if (class_exists(OffsetPageIdentifierEncoder::class)) {
$services
->set(OffsetPageIdentifierEncoder::class)
->tag('rekalogika.rekapager.page_identifier_encoder');
}

$services
->set(
PageUrlGeneratorFactoryInterface::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function load(array $configs, ContainerBuilder $container)
new FileLocator(__DIR__ . '/../../config')
);
$loader->load('services.php');
$loader->load('encoders.php');

if ($debug) {
$loader->load('debug.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/*
* This file is part of rekalogika/rekapager package.
*
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/

namespace Rekalogika\Rekapager\Bundle\DependencyInjection;

use Rekalogika\Rekapager\Bundle\Twig\TwigPagerRenderer;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class RemoveMissingDepsPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('twig')) {
$container->removeDefinition(TwigPagerRenderer::class);
$container->removeDefinition('rekalogika.rekapager.twig.runtime');
$container->removeDefinition('rekalogika.rekapager.twig.extension');
}
}
}
9 changes: 9 additions & 0 deletions packages/rekapager-bundle/src/RekalogikaRekapagerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Rekalogika\Rekapager\Bundle;

use Rekalogika\Rekapager\Bundle\DependencyInjection\RemoveMissingDepsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class RekalogikaRekapagerBundle extends Bundle
Expand All @@ -21,4 +23,11 @@ public function getPath(): string
{
return \dirname(__DIR__);
}

public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new RemoveMissingDepsPass());
}
}

0 comments on commit 4ab5989

Please sign in to comment.