Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add compatibility with Symfony 7.0+ #96

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0f55496
👌IMPROVE: compatibility with Symfony 7.0+
barbuslex Sep 26, 2024
910964f
🐛 FIX: symfony bundle test
barbuslex Oct 15, 2024
f31467c
🐛 FIX: revert symfony bundle test
barbuslex Oct 15, 2024
944e503
🐛 FIX: symfony bundle tests
barbuslex Oct 15, 2024
af39c54
Merge pull request #2 from barbuslex/tests
barbuslex Oct 15, 2024
51bfe9f
📖 DOC: update
barbuslex Oct 15, 2024
f2e24b4
🐛 FIX: kernel Request type
barbuslex Oct 15, 2024
bcb2eb0
🐛 FIX: kernet Request type
barbuslex Oct 15, 2024
ce27e90
🐛 FIX: kernel test case
barbuslex Oct 15, 2024
0473cb6
🐛 FIX: kernel test case
barbuslex Oct 15, 2024
a31c29d
🐛 FIX: kernel test case
barbuslex Oct 15, 2024
30b1579
🐛 FIX: kernel test case
barbuslex Oct 15, 2024
1f66be7
🐛 FIX: kernel test case
barbuslex Oct 15, 2024
717c6cc
🐛 FIX: kernel test case
barbuslex Oct 15, 2024
5f28cfd
🐛 FIX: use_nullable_type_declaration
barbuslex Oct 15, 2024
2d67760
🐛 FIX: symfony/phpunit-bridge version
barbuslex Oct 15, 2024
23ce6cf
🐛 FIX: AnnotationRegistry::registerLoader()
barbuslex Oct 15, 2024
e8a4cee
🐛 FIX: CS Fixer
barbuslex Oct 15, 2024
2466d58
🐛 FIX: PHP CS Fixer
barbuslex Oct 15, 2024
0ceea91
🐛 FIX: Test Lowest (7.3)
barbuslex Oct 15, 2024
58a03fb
🐛 FIX: Test Lowest (7.2)
barbuslex Oct 15, 2024
b5cd4f4
🐛 FIX: PHP CS Fixer
barbuslex Oct 15, 2024
482081b
🐛 FIX: PHP CS Fixer
barbuslex Oct 15, 2024
d9b65e4
🐛 FIX: PHP CS Fixer
barbuslex Oct 15, 2024
f1072fc
🐛 FIX: Test Lowest (7.4)
barbuslex Oct 15, 2024
45923c7
🐛 FIX: Test Lowest (7.4)
barbuslex Oct 15, 2024
116cff8
🐛 FIX: github actions
barbuslex Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
'@Symfony' => true,
'@Symfony:risky' => true,
'protected_to_private' => false,
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => false],
'nullable_type_declaration_for_default_null_value' => false,
'get_class_to_class_keyword' => false,
])
->setRiskyAllowed(true)
->setFinder(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Getting Started With BreadcrumbTrailBundle
Getting Started With BreadcrumbTrailBundle
==========================================

This bundle provides a breadcrumb trail service also known as breadcrumbs or Fil d'Ariane.
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"require": {
"php": ">=7.2",
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
"symfony/framework-bundle": "^4.4|^5.0|^6.0|^7.0",
"twig/twig": "^2.15|^3.0",
"symfony/deprecation-contracts": "^2.4|^3.0"
},
Expand All @@ -22,12 +22,12 @@
"psr-4": { "APY\\BreadcrumbTrailBundle\\": "src/" }
},
"require-dev": {
"symfony/phpunit-bridge": "^5.0|^6.0",
"nyholm/symfony-bundle-test": "^v2.0",
"symfony/phpunit-bridge": "^5.0|^6.0|^7.0",
"nyholm/symfony-bundle-test": "^v2.0|^v3.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"doctrine/doctrine-bundle": "^v1.0|^v2.0",
"doctrine/annotations": "^v1.7",
"symfony/twig-bundle": "^3.4|^4.0|^5.0|^6.0"
"doctrine/annotations": "^1.8|^2.0",
"symfony/twig-bundle": "^4.0|^5.0|^6.0|^7.0"
},
"autoload-dev": {
"psr-4": { "APY\\BreadcrumbTrailBundle\\": "tests/" }
Expand Down
21 changes: 7 additions & 14 deletions src/Annotation/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class Breadcrumb
/**
* @var string Title of the breadcrumb
*/
private $title = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the removals of null a result of the nullable_type_declaration_for_default_null_value PHP CS Fixer change? Not having them set to null could after construction potentially lead to exceptions on read when not being instantiated.

private $title;

/**
* @var string The name of the route
*/
private $routeName = null;
private $routeName;

/**
* @var mixed An array of parameters for the route
Expand All @@ -45,7 +45,7 @@ class Breadcrumb
/**
* @var string Template of the breadcrumb trail
*/
private $template = null;
private $template;

/**
* @var array with additional attributes for the breadcrumb
Expand All @@ -61,15 +61,8 @@ class Breadcrumb
* @param ?string $template
* @param array $attributes
*/
public function __construct(
$title = null,
$routeName = null,
$routeParameters = null,
$routeAbsolute = null,
$position = null,
$template = null,
$attributes = null
) {
public function __construct($title = null, $routeName = null, $routeParameters = null, $routeAbsolute = null, $position = null, $template = null, $attributes = null)
{
$data = [];

if (\is_string($title)) {
Expand Down Expand Up @@ -101,7 +94,7 @@ public function __construct(
foreach ($data['route'] as $key => $value) {
$method = 'setRoute'.$key;
if (!method_exists($this, $method)) {
throw new \BadMethodCallException(sprintf("Unknown property '%s' for the 'route' parameter on annotation '%s'.", $key, static::class));
throw new \BadMethodCallException(\sprintf("Unknown property '%s' for the 'route' parameter on annotation '%s'.", $key, static::class));
}
$this->$method($value);
}
Expand All @@ -120,7 +113,7 @@ public function __construct(

$method = 'set'.$key;
if (!method_exists($this, $method)) {
throw new \BadMethodCallException(sprintf("Unknown property '%s' on annotation '%s'.", $key, static::class));
throw new \BadMethodCallException(\sprintf("Unknown property '%s' on annotation '%s'.", $key, static::class));
}
$this->$method($value);
}
Expand Down
12 changes: 3 additions & 9 deletions src/BreadcrumbTrail/Trail.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getTemplate()
*
* @return self
*
*@throws \InvalidArgumentException
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
public function add($breadcrumbOrTitle, $routeName = null, $routeParameters = [], $routeAbsolute = true, $position = 0, $attributes = [])
Expand Down Expand Up @@ -185,17 +185,11 @@ public function reset()
return $this;
}

/**
* {@inheritDoc}
*/
public function count(): int
{
return $this->breadcrumbs->count();
}

/**
* {@inheritDoc}
*/
public function getIterator(): \Traversable
{
$this->breadcrumbs->rewind();
Expand Down Expand Up @@ -246,7 +240,7 @@ private function retrieveChildObject($object, $function, $varName, array $functi
return \call_user_func([$object, $fullFunctionName]);
}

throw new \RuntimeException(sprintf('"%s" is not callable.', implode('.', array_merge([$varName], $functions))));
throw new \RuntimeException(\sprintf('"%s" is not callable.', implode('.', array_merge([$varName], $functions))));
}

/**
Expand All @@ -263,6 +257,6 @@ private function retrieveObjectValue($object, $function, $parameters, $varName,
return \call_user_func_array([$object, $fullFunctionName], $parameters);
}

throw new \RuntimeException(sprintf('"%s" is not callable.', implode('.', array_merge([$varName], $functions))));
throw new \RuntimeException(\sprintf('"%s" is not callable.', implode('.', array_merge([$varName], $functions))));
}
}
3 changes: 0 additions & 3 deletions src/DependencyInjection/APYBreadcrumbTrailExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

class APYBreadcrumbTrailExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Configuration implements ConfigurationInterface
{
#[\ReturnTypeWillChange]
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the return type change because of dropping TwigBundle v3.4?

{
$treeBuilder = new TreeBuilder('apy_breadcrumb_trail');
// BC layer for symfony/config < 4.2
Expand All @@ -27,7 +27,7 @@ public function getConfigTreeBuilder()
->scalarNode('template')
->defaultValue('@APYBreadcrumbTrail/breadcrumbtrail.html.twig')
->end()
->end()
->end()
;

return $treeBuilder;
Expand Down
6 changes: 4 additions & 2 deletions src/EventListener/BreadcrumbListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ public function onKernelController(KernelEvent $event)
}

if ($class->isAbstract()) {
throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class));
throw new \InvalidArgumentException(\sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class));
}

if (HttpKernelInterface::MASTER_REQUEST == $event->getRequestType()) {
$kernelRequest = \defined(HttpKernelInterface::class.'::MASTER_REQUEST') ? HttpKernelInterface::MASTER_REQUEST : HttpKernelInterface::MAIN_REQUEST;

if ($kernelRequest == $event->getRequestType()) {
$this->breadcrumbTrail->reset();

// Annotations from class
Expand Down
7 changes: 7 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController" priority="-1" />
</service>
<service id="apy_breadcrumb_trail.annotation.listener" alias="APY\BreadcrumbTrailBundle\EventListener\BreadcrumbListener" public="true" />

<service id="Doctrine\Common\Annotations\AnnotationReader" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doctrine annotations is optional (part of require-dev), so can not be mentioned as service for this bundle, as that will lead to exceptions on non-dev / prod runtime.

Also, as autowiring on this bundle is enabled by default, there should not be a need to define this service from another dependency.


<service id="APY\BreadcrumbTrailBundle\EventListener\BreadcrumbListener">
<argument type="service" id="Doctrine\Common\Annotations\AnnotationReader" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try getting this done with the autowiring that is enabled on this bundle?

<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController" priority="-1" />
</service>
</services>
</container>
7 changes: 6 additions & 1 deletion tests/Twig/BreadcrumbTrailExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ protected static function createKernel(array $options = []): KernelInterface
*/
public function testTwigFunctionGetsRegistered()
{
$container = self::getContainer();
if (method_exists($this, 'getContainer')) {
$container = self::getContainer();
} else {
self::bootKernel();
$container = self::$container;
}

/** @var BreadcrumbTrailExtension $extension */
$extension = $container->get(BreadcrumbTrailExtension::class);
Expand Down