diff --git a/composer.json b/composer.json index a4c2811..d57f835 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "laminas/laminas-servicemanager": "^3.19.0", "phpunit/phpunit": "^9.5.26", "psalm/plugin-phpunit": "^0.18.0", - "vimeo/psalm": "^4.29" + "vimeo/psalm": "^5.0" }, "conflict": { "container-interop/container-interop": "<1.2.0", diff --git a/composer.lock b/composer.lock index 1d71d56..e9bc37d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6178132999bb60617f37001b14f47453", + "content-hash": "5a1a4e765717b861c302feb6973e3839", "packages": [ { "name": "fig/http-message-util", @@ -3949,6 +3949,69 @@ ], "time": "2022-01-02T09:55:41+00:00" }, + { + "name": "symfony/filesystem", + "version": "v6.0.13", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "3adca49133bd055ebe6011ed1e012be3c908af79" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/3adca49133bd055ebe6011ed1e012be3c908af79", + "reference": "3adca49133bd055ebe6011ed1e012be3c908af79", + "shasum": "" + }, + "require": { + "php": ">=8.0.2", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides basic utilities for the filesystem", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/filesystem/tree/v6.0.13" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-09-21T20:25:27+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.27.0", @@ -4582,24 +4645,24 @@ }, { "name": "vimeo/psalm", - "version": "4.30.0", + "version": "5.0.0", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "d0bc6e25d89f649e4f36a534f330f8bb4643dd69" + "reference": "4e177bf0c9f03c17d2fbfd83b7cc9c47605274d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/d0bc6e25d89f649e4f36a534f330f8bb4643dd69", - "reference": "d0bc6e25d89f649e4f36a534f330f8bb4643dd69", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/4e177bf0c9f03c17d2fbfd83b7cc9c47605274d8", + "reference": "4e177bf0c9f03c17d2fbfd83b7cc9c47605274d8", "shasum": "" }, "require": { "amphp/amp": "^2.4.2", "amphp/byte-stream": "^1.5", - "composer/package-versions-deprecated": "^1.8.0", + "composer/package-versions-deprecated": "^1.10.0", "composer/semver": "^1.4 || ^2.0 || ^3.0", - "composer/xdebug-handler": "^1.1 || ^2.0 || ^3.0", + "composer/xdebug-handler": "^2.0 || ^3.0", "dnoegel/php-xdg-base-dir": "^0.1.1", "ext-ctype": "*", "ext-dom": "*", @@ -4608,35 +4671,34 @@ "ext-mbstring": "*", "ext-simplexml": "*", "ext-tokenizer": "*", - "felixfbecker/advanced-json-rpc": "^3.0.3", - "felixfbecker/language-server-protocol": "^1.5", + "felixfbecker/advanced-json-rpc": "^3.1", + "felixfbecker/language-server-protocol": "^1.5.2", "netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0", "nikic/php-parser": "^4.13", "openlss/lib-array2xml": "^1.0", - "php": "^7.1|^8", - "sebastian/diff": "^3.0 || ^4.0", - "symfony/console": "^3.4.17 || ^4.1.6 || ^5.0 || ^6.0", - "symfony/polyfill-php80": "^1.25", - "webmozart/path-util": "^2.3" + "php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0", + "sebastian/diff": "^4.0", + "symfony/console": "^4.1.6 || ^5.0 || ^6.0", + "symfony/filesystem": "^5.4 || ^6.0", + "symfony/polyfill-php80": "^1.25" }, "provide": { "psalm/psalm": "self.version" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.2", - "brianium/paratest": "^4.0||^6.0", + "bamarni/composer-bin-plugin": "^1.4", + "brianium/paratest": "^6.0", "ext-curl": "*", + "mockery/mockery": "^1.5", + "nunomaduro/mock-final-classes": "^1.1", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpdocumentor/reflection-docblock": "^5", - "phpmyadmin/sql-parser": "5.1.0||dev-master", - "phpspec/prophecy": ">=1.9.0", - "phpstan/phpdoc-parser": "1.2.* || 1.6.4", - "phpunit/phpunit": "^9.0", - "psalm/plugin-phpunit": "^0.16", - "slevomat/coding-standard": "^7.0", - "squizlabs/php_codesniffer": "^3.5", - "symfony/process": "^4.3 || ^5.0 || ^6.0", - "weirdan/prophecy-shim": "^1.0 || ^2.0" + "phpstan/phpdoc-parser": "^1.6", + "phpunit/phpunit": "^9.5", + "psalm/plugin-mockery": "^1.1", + "psalm/plugin-phpunit": "^0.18", + "slevomat/coding-standard": "^8.4", + "squizlabs/php_codesniffer": "^3.6", + "symfony/process": "^4.4 || ^5.0 || ^6.0" }, "suggest": { "ext-curl": "In order to send data to shepherd", @@ -4652,17 +4714,14 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev", + "dev-master": "5.x-dev", + "dev-4.x": "4.x-dev", "dev-3.x": "3.x-dev", "dev-2.x": "2.x-dev", "dev-1.x": "1.x-dev" } }, "autoload": { - "files": [ - "src/functions.php", - "src/spl_object_id.php" - ], "psr-4": { "Psalm\\": "src/Psalm/" } @@ -4684,9 +4743,9 @@ ], "support": { "issues": "https://github.com/vimeo/psalm/issues", - "source": "https://github.com/vimeo/psalm/tree/4.30.0" + "source": "https://github.com/vimeo/psalm/tree/5.0.0" }, - "time": "2022-11-06T20:37:08+00:00" + "time": "2022-11-30T06:06:01+00:00" }, { "name": "webimpress/coding-standard", @@ -4742,57 +4801,6 @@ } ], "time": "2022-02-15T19:52:12+00:00" - }, - { - "name": "webmozart/path-util", - "version": "2.3.0", - "source": { - "type": "git", - "url": "https://github.com/webmozart/path-util.git", - "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/path-util/zipball/d939f7edc24c9a1bb9c0dee5cb05d8e859490725", - "reference": "d939f7edc24c9a1bb9c0dee5cb05d8e859490725", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "webmozart/assert": "~1.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\PathUtil\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "A robust cross-platform utility for normalizing, comparing and modifying file paths.", - "support": { - "issues": "https://github.com/webmozart/path-util/issues", - "source": "https://github.com/webmozart/path-util/tree/2.3.0" - }, - "abandoned": "symfony/filesystem", - "time": "2015-12-17T08:42:14+00:00" } ], "aliases": [], diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 42ad504..4ae1b06 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,57 +1,26 @@ - - - - - ZendAcl - - + - - $routeName - - + $routeName - $routeResult - - - getMatchedRouteName - isFailure - + - - $e->getCode() - $e->getCode() - $e->getCode() - $e->getCode() - - + $config['allow'] ?? [] $config['deny'] ?? [] $config['resources'] $config['roles'] - $parent - $parent - $parents - $resource - - $role - $config['allow'] $config['deny'] $config['resources'] $config['roles'] - + $config - $parent - $parents - $resource - $resources @@ -65,12 +34,15 @@ $dependencies - + $json['packages'] $package['extra'] + $package['extra']['laminas'] + $package['extra']['laminas']['config-provider'] - + $config['dependencies']['services'] + $config['dependencies']['services']['config'] $json diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index c11fbab..2c2581e 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -4,8 +4,6 @@ namespace Mezzio\Authorization\Acl; -use Zend\Expressive\Authorization\Acl\ZendAcl; - class ConfigProvider { public function __invoke(): array @@ -20,7 +18,7 @@ public function getDependencies(): array return [ // Legacy Zend Framework aliases 'aliases' => [ - ZendAcl::class => LaminasAcl::class, + 'Zend\Expressive\Authorization\Acl\ZendAcl' => LaminasAcl::class, ], 'factories' => [ LaminasAcl::class => LaminasAclFactory::class, diff --git a/src/LaminasAcl.php b/src/LaminasAcl.php index 1213d30..98aca9e 100644 --- a/src/LaminasAcl.php +++ b/src/LaminasAcl.php @@ -29,7 +29,7 @@ public function __construct(Acl $acl) public function isGranted(string $role, ServerRequestInterface $request): bool { $routeResult = $request->getAttribute(RouteResult::class, false); - if (false === $routeResult) { + if (! $routeResult instanceof RouteResult) { throw new Exception\RuntimeException(sprintf( 'The %s attribute is missing in the request; cannot perform ACL authorization checks', RouteResult::class diff --git a/src/LaminasAclFactory.php b/src/LaminasAclFactory.php index da14238..02e5153 100644 --- a/src/LaminasAclFactory.php +++ b/src/LaminasAclFactory.php @@ -6,6 +6,8 @@ use Laminas\Permissions\Acl\Acl; use Laminas\Permissions\Acl\Exception\ExceptionInterface as AclExceptionInterface; +use Laminas\Permissions\Acl\Resource\ResourceInterface; +use Laminas\Permissions\Acl\Role\RoleInterface; use Mezzio\Authorization\AuthorizationInterface; use Mezzio\Authorization\Exception; use Psr\Container\ContainerInterface; @@ -49,6 +51,7 @@ public function __invoke(ContainerInterface $container): AuthorizationInterface /** * @throws Exception\InvalidConfigException + * @param array> $roles */ private function injectRoles(Acl $acl, array $roles): void { @@ -58,20 +61,21 @@ private function injectRoles(Acl $acl, array $roles): void try { $acl->addRole($parent); } catch (AclExceptionInterface $e) { - throw new Exception\InvalidConfigException($e->getMessage(), $e->getCode(), $e); + throw new Exception\InvalidConfigException($e->getMessage(), (int) $e->getCode(), $e); } } } try { $acl->addRole($role, $parents); } catch (AclExceptionInterface $e) { - throw new Exception\InvalidConfigException($e->getMessage(), $e->getCode(), $e); + throw new Exception\InvalidConfigException($e->getMessage(), (int) $e->getCode(), $e); } } } /** * @throws Exception\InvalidConfigException + * @param list $resources */ private function injectResources(Acl $acl, array $resources): void { @@ -79,13 +83,14 @@ private function injectResources(Acl $acl, array $resources): void try { $acl->addResource($resource); } catch (AclExceptionInterface $e) { - throw new Exception\InvalidConfigException($e->getMessage(), $e->getCode(), $e); + throw new Exception\InvalidConfigException($e->getMessage(), (int) $e->getCode(), $e); } } } /** * @throws Exception\InvalidConfigException + * @param array> $permissions */ private function injectPermissions(Acl $acl, array $permissions, string $type): void { @@ -98,9 +103,11 @@ private function injectPermissions(Acl $acl, array $permissions, string $type): foreach ($permissions as $role => $resources) { try { - $acl->$type($role, $resources); + $type === 'allow' + ? $acl->allow($role, $resources) + : $acl->deny($role, $resources); } catch (AclExceptionInterface $e) { - throw new Exception\InvalidConfigException($e->getMessage(), $e->getCode(), $e); + throw new Exception\InvalidConfigException($e->getMessage(), (int) $e->getCode(), $e); } } }