Skip to content

Commit

Permalink
Added support for laminas/laminas-servicemanager:4.x
Browse files Browse the repository at this point in the history
Signed-off-by: alexmerlin <[email protected]>
  • Loading branch information
alexmerlin committed Jan 20, 2025
1 parent 18575eb commit 23c74de
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignore_php_platform_requirements": {
"8.4": true
},
"backwardCompatibilityCheck": true
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
[![Build Static](https://github.com/dotkernel/dot-navigation/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-navigation/actions/workflows/static-analysis.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-navigation/graph/badge.svg?token=AI9WFYDDX9)](https://codecov.io/gh/dotkernel/dot-navigation)

[![SymfonyInsight](https://insight.symfony.com/projects/68b7c728-4cc9-40ac-a3be-cf17f9b2eaf1/big.svg)](https://insight.symfony.com/projects/68b7c728-4cc9-40ac-a3be-cf17f9b2eaf1)

Allows you to easily define and parse menus inside templates, configuration based approach.

## Installation

Run

composer require dotkernel/dot-navigation
```shell
composer require dotkernel/dot-navigation
```

Merge `ConfigProvider` to your application's configuration.

Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dotkernel/dot-navigation",
"type": "library",
"description": "DotKernel navigation component",
"description": "Dotkernel navigation component",
"license": "MIT",
"homepage": "https://github.com/dotkernel/dot-navigation",
"keywords": [
Expand All @@ -13,7 +13,7 @@
],
"authors": [
{
"name": "DotKernel Team",
"name": "Dotkernel Team",
"email": "[email protected]"
}
],
Expand All @@ -24,17 +24,17 @@
}
},
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"dotkernel/dot-authorization": "^3.4.1",
"dotkernel/dot-helpers": "^3.5.1",
"dotkernel/dot-helpers": "^3.7.0",
"laminas/laminas-escaper": "^2.13.0",
"laminas/laminas-servicemanager": "^3.22.1",
"laminas/laminas-servicemanager": "^4.0",
"mezzio/mezzio-template": "^2.9.0",
"psr/http-message": "^1.0 || ^2.0",
"psr/http-server-middleware": "^1.0.2"
},
"require-dev": {
"laminas/laminas-coding-standard": "^2.5.0",
"laminas/laminas-coding-standard": "^3.0.0",
"phpunit/phpunit": "^10.4.2",
"vimeo/psalm": "^5.16.0"
},
Expand All @@ -51,7 +51,8 @@
"scripts": {
"check": [
"@cs-check",
"@test"
"@test",
"@static-analysis"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
Expand Down
1 change: 0 additions & 1 deletion docs/book/index.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/book/index.md
2 changes: 1 addition & 1 deletion docs/book/v3/overview.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Overview

`dot-navigation` is DotKernel's component that allows you to easily define and parse menus inside templates, using a configuration based approach.
`dot-navigation` is Dotkernel's component that allows you to easily define and parse menus inside templates, using a configuration based approach.
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ nav:
- "Required Page Options": v3/required-page-options.md
- Usage: v3/usage.md
site_name: dot-navigation
site_description: "DotKernel's component that allows you to easily define and parse menus inside templates, using a configuration based approach."
site_description: "Dotkernel's component that allows you to easily define and parse menus inside templates, using a configuration based approach."
repo_url: "https://github.com/dotkernel/dot-navigation"
plugins:
- search
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@
<code>RecursiveIterator</code>
</MissingTemplateParam>
</file>
<file src="src/Provider/ProviderPluginManager.php">
<MissingTemplateParam>
<code>ProviderPluginManager</code>
</MissingTemplateParam>
</file>
</files>
6 changes: 5 additions & 1 deletion src/Provider/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Dot\Navigation\Provider;

use Dot\Navigation\Exception\RuntimeException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;

class Factory implements FactoryInterface
Expand All @@ -18,14 +19,17 @@ public function __construct(ContainerInterface $container, ?ProviderPluginManage
$this->providerPluginManager = $providerPluginManager;
}

/**
* @throws ContainerExceptionInterface
*/
public function create(array $specs): ProviderInterface
{
$type = $specs['type'] ?? '';
if (empty($type)) {
throw new RuntimeException('Undefined navigation provider type');
}

return $this->getProviderPluginManager()->get($type, $specs['options'] ?? null);
return $this->getProviderPluginManager()->build($type, $specs['options'] ?? null);
}

public function getProviderPluginManager(): ProviderPluginManager
Expand Down
30 changes: 24 additions & 6 deletions src/Provider/ProviderPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,42 @@
namespace Dot\Navigation\Provider;

use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\Exception\InvalidServiceException;
use Laminas\ServiceManager\Factory\InvokableFactory;

use function gettype;
use function is_object;
use function sprintf;

/**
* @template InstanceType
* @extends AbstractPluginManager<InstanceType>
*/
class ProviderPluginManager extends AbstractPluginManager
{
/** @var string $instanceOf */
protected $instanceOf = ProviderInterface::class;
protected string $instanceOf = ProviderInterface::class;

/** @var array */
protected $factories = [
protected array $factories = [
ArrayProvider::class => InvokableFactory::class,
];

/** @var string[] $aliases */
protected $aliases = [
protected array $aliases = [
'arrayprovider' => ArrayProvider::class,
'arrayProvider' => ArrayProvider::class,
'ArrayProvider' => ArrayProvider::class,
'array' => ArrayProvider::class,
'Array' => ArrayProvider::class,
];

public function validate(mixed $instance): void
{
if (! $instance instanceof $this->instanceOf) {
throw new InvalidServiceException(sprintf(
'%s can only create instances of %s; %s is invalid',
static::class,
$this->instanceOf,
is_object($instance) ? $instance::class : gettype($instance)
));
}
}
}
12 changes: 6 additions & 6 deletions test/Provider/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;

use function sprintf;

class FactoryTest extends TestCase
{
/**
Expand All @@ -42,6 +41,7 @@ public function testWillCreateFactoryWithProviderPluginManager(): void
}

/**
* @throws ContainerExceptionInterface
* @throws Exception
*/
public function testFactoryWillNotCreateProviderWithoutProviderType(): void
Expand All @@ -55,6 +55,7 @@ public function testFactoryWillNotCreateProviderWithoutProviderType(): void
}

/**
* @throws ContainerExceptionInterface
* @throws Exception
*/
public function testFactoryWillNotCreateProviderWithInvalidProviderType(): void
Expand All @@ -63,10 +64,7 @@ public function testFactoryWillNotCreateProviderWithInvalidProviderType(): void

$this->expectException(ServiceNotFoundException::class);
$this->expectExceptionMessage(
sprintf(
'A plugin by the name "test" was not found in the plugin manager %s',
ProviderPluginManager::class
)
'Unable to resolve service "test" to a factory; are you certain you provided it during configuration?'
);
$factory = new Factory($container);
$factory->create([
Expand All @@ -75,6 +73,7 @@ public function testFactoryWillNotCreateProviderWithInvalidProviderType(): void
}

/**
* @throws ContainerExceptionInterface
* @throws Exception
*/
public function testFactoryWillCreateProviderWithValidProviderTypeAndNoOptions(): void
Expand All @@ -89,6 +88,7 @@ public function testFactoryWillCreateProviderWithValidProviderTypeAndNoOptions()
}

/**
* @throws ContainerExceptionInterface
* @throws Exception
*/
public function testFactoryWillCreateProviderWithValidProviderTypeAndOptions(): void
Expand Down

0 comments on commit 23c74de

Please sign in to comment.