Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 0 deletions src/Knp/Menu/Factory/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

/**
* core factory extension with the main logic
*
* @final since 3.8.0
* @internal since 3.8.0
*/
class CoreExtension implements ExtensionInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Integration/Symfony/RoutingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* Factory able to use the Symfony Routing component to build the url
*
* @final since 3.8.0
*/
class RoutingExtension implements ExtensionInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Iterator/CurrentItemFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
* @template TKey
* @template-extends \FilterIterator<TKey, ItemInterface, \Iterator<TKey, ItemInterface>>
*
* @final since 3.8.0
*/
class CurrentItemFilterIterator extends \FilterIterator
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Iterator/DisplayedItemFilterIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

/**
* Filter iterator keeping only current items
*
* @final since 3.8.0
*/
class DisplayedItemFilterIterator extends \RecursiveFilterIterator
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Iterator/RecursiveItemIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* @extends \IteratorIterator<TKey, ItemInterface, \Traversable<TKey, ItemInterface>>
*
* @implements \RecursiveIterator<TKey, ItemInterface>
*
* @final since 3.8.0
*/
class RecursiveItemIterator extends \IteratorIterator implements \RecursiveIterator
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Loader/ArrayLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Loader importing a menu tree from an array.
*
* The array should match the output of MenuManipulator::toArray
*
* @final since 3.8.0
*/
class ArrayLoader implements LoaderInterface
{
Expand Down
3 changes: 3 additions & 0 deletions src/Knp/Menu/Loader/NodeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Knp\Menu\ItemInterface;
use Knp\Menu\NodeInterface;

/**
* @final since 3.8.0
*/
class NodeLoader implements LoaderInterface
{
public function __construct(private FactoryInterface $factory)
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Matcher/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* A MatcherInterface implementation using a voter system
*
* @final since 3.8.0
*/
class Matcher implements MatcherInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Matcher/Voter/RegexVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/**
* Implements the VoterInterface which can be used as voter for "current" class
* `matchItem` will return true if the pattern you're searching for is found in the URI of the item
*
* @final since 3.8.0
*/
class RegexVoter implements VoterInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Matcher/Voter/RouteVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* Voter based on the route
*
* @final since 3.8.0
*/
class RouteVoter implements VoterInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Matcher/Voter/UriVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

/**
* Voter based on the uri
*
* @final since 3.8.0
*/
class UriVoter implements VoterInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/MenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* Factory to create a menu from a tree
*
* @final since 3.8.0
*/
class MenuFactory implements FactoryInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Provider/ArrayAccessProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* In case the value stored in the registry is a callable rather than an ItemInterface,
* it will be called with the options as first argument and the registry as second argument
* and is expected to return a menu item.
*
* @final since 3.8.0
*/
class ArrayAccessProvider implements MenuProviderInterface
{
Expand Down
3 changes: 3 additions & 0 deletions src/Knp/Menu/Provider/ChainProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Knp\Menu\ItemInterface;

/**
* @final since 3.8.0
*/
class ChainProvider implements MenuProviderInterface
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Provider/LazyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Builders can either be callables or a factory for an object callable
* represented as [Closure, method], where the Closure gets called
* to instantiate the object.
*
* @final since 3.8.0
*/
class LazyProvider implements MenuProviderInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Provider/PsrProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*
* This menu provider does not support using options, as it cannot pass them to the container
* to alter the menu building. Use a different provider in case you need support for options.
*
* @final since 3.8.0
*/
class PsrProvider implements MenuProviderInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Renderer/ArrayAccessProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

/**
* A renderer provider getting the renderers from a class implementing ArrayAccess.
*
* @final since 3.8.0
*/
class ArrayAccessProvider implements RendererProviderInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Renderer/ListRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* Renders MenuItem tree as unordered list
*
* @final since 3.8.0
*/
class ListRenderer extends Renderer implements RendererInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Knp/Menu/Renderer/PsrProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*
* This menu provider does not support using options, as it cannot pass them to the container
* to alter the menu building. Use a different provider in case you need support for options.
*
* @final since 3.8.0
*/
class PsrProvider implements RendererProviderInterface
{
Expand Down
3 changes: 3 additions & 0 deletions src/Knp/Menu/Renderer/TwigRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Knp\Menu\Matcher\MatcherInterface;
use Twig\Environment;

/**
* @final since 3.8.0
*/
class TwigRenderer implements RendererInterface
{
/**
Expand Down
21 changes: 21 additions & 0 deletions src/Knp/Menu/Twig/MenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Twig\TwigFunction;
use Twig\TwigTest;

/**
* @final since 3.8.0
*/
class MenuExtension extends AbstractExtension
{
private ?MenuRuntimeExtension $runtimeExtension = null;
Expand Down Expand Up @@ -68,6 +71,8 @@ public function getLastModified(): int
/**
* @param array<int, string> $path
* @param array<string, mixed> $options
*
* @internal since 3.8.0
*/
public function get(ItemInterface|string $menu, array $path = [], array $options = []): ItemInterface
{
Expand All @@ -79,6 +84,8 @@ public function get(ItemInterface|string $menu, array $path = [], array $options
/**
* @param string|ItemInterface|array<ItemInterface|string> $menu
* @param array<string, mixed> $options
*
* @internal since 3.8.0
*/
public function render(array|ItemInterface|string $menu, array $options = [], ?string $renderer = null): string
{
Expand All @@ -94,6 +101,8 @@ public function render(array|ItemInterface|string $menu, array $options = [], ?s
*
* @return array<int, array<string, mixed>>
* @phpstan-return list<array{label: string, uri: string|null, item: ItemInterface|null}>
*
* @internal since 3.8.0
*/
public function getBreadcrumbsArray(array|ItemInterface|string $menu, array|string|null $subItem = null): array
{
Expand All @@ -102,27 +111,39 @@ public function getBreadcrumbsArray(array|ItemInterface|string $menu, array|stri
return $this->runtimeExtension->getBreadcrumbsArray($menu, $subItem);
}

/**
* @internal since 3.8.0
*/
public function getCurrentItem(ItemInterface|string $menu): ItemInterface
{
assert(null !== $this->runtimeExtension);

return $this->runtimeExtension->getCurrentItem($menu);
}

/**
* @internal since 3.8.0
*/
public function pathAsString(ItemInterface $menu, string $separator = ' > '): string
{
assert(null !== $this->runtimeExtension);

return $this->runtimeExtension->pathAsString($menu, $separator);
}

/**
* @internal since 3.8.0
*/
public function isCurrent(ItemInterface $item): bool
{
assert(null !== $this->runtimeExtension);

return $this->runtimeExtension->isCurrent($item);
}

/**
* @internal since 3.8.0
*/
public function isAncestor(ItemInterface $item, ?int $depth = null): bool
{
assert(null !== $this->runtimeExtension);
Expand Down
17 changes: 17 additions & 0 deletions src/Knp/Menu/Twig/MenuRuntimeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Knp\Menu\Util\MenuManipulator;
use Twig\Extension\RuntimeExtensionInterface;

/**
* @final since 3.8.0
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The MenuRuntimeExtension itself cannot become @internal as its instantiation has to be a public API to be usable by projects registering the runtime into Twig (KnpMenuBundle in the common case, but that's still a separate package), but all the methods can be @internal as they are only meant to be referenced by the MenuExtension as implementation of the (public) Twig callables.

*/
class MenuRuntimeExtension implements RuntimeExtensionInterface
{
public function __construct(
Expand All @@ -21,6 +24,8 @@ public function __construct(
*
* @param array<int, string> $path
* @param array<string, mixed> $options
*
* @internal since 3.8.0
*/
public function get(ItemInterface|string $menu, array $path = [], array $options = []): ItemInterface
{
Expand All @@ -32,6 +37,8 @@ public function get(ItemInterface|string $menu, array $path = [], array $options
*
* @param string|ItemInterface|array<ItemInterface|string> $menu
* @param array<string, mixed> $options
*
* @internal since 3.8.0
*/
public function render(array|ItemInterface|string $menu, array $options = [], ?string $renderer = null): string
{
Expand All @@ -47,6 +54,8 @@ public function render(array|ItemInterface|string $menu, array $options = [], ?s
*
* @return array<int, array<string, mixed>>
* @phpstan-return list<array{label: string, uri: string|null, item: ItemInterface|null}>
*
* @internal since 3.8.0
*/
public function getBreadcrumbsArray(array|ItemInterface|string $menu, array|string|null $subItem = null): array
{
Expand All @@ -55,6 +64,8 @@ public function getBreadcrumbsArray(array|ItemInterface|string $menu, array|stri

/**
* Returns the current item of a menu.
*
* @internal since 3.8.0
*/
public function getCurrentItem(ItemInterface|string $menu): ItemInterface
{
Expand All @@ -73,6 +84,8 @@ public function getCurrentItem(ItemInterface|string $menu): ItemInterface
* A string representation of this menu item
*
* e.g. Top Level > Second Level > This menu
*
* @internal since 3.8.0
*/
public function pathAsString(ItemInterface $menu, string $separator = ' > '): string
{
Expand All @@ -85,6 +98,8 @@ public function pathAsString(ItemInterface $menu, string $separator = ' > '): st

/**
* Checks whether an item is current.
*
* @internal since 3.8.0
*/
public function isCurrent(ItemInterface $item): bool
{
Expand All @@ -99,6 +114,8 @@ public function isCurrent(ItemInterface $item): bool
* Checks whether an item is the ancestor of a current item.
*
* @param int|null $depth The max depth to look for the item
*
* @internal since 3.8.0
*/
public function isAncestor(ItemInterface $item, ?int $depth = null): bool
{
Expand Down