From 05eded38992a6ad4f0df69b5ea6f518aac62b256 Mon Sep 17 00:00:00 2001 From: Witold Wasiczko Date: Fri, 3 Jun 2022 12:46:03 +0200 Subject: [PATCH] Allow PHP 8.1 Signed-off-by: Witold Wasiczko --- README.md | 58 -- composer.json | 7 +- composer.lock | 519 +----------------- config/module.config.php | 19 - psalm-baseline.xml | 134 +---- src/Controller/PackageController.php | 352 ------------ src/Model/AuthorizationEntity.php | 3 + test/Controller/PackageControllerTest.php | 125 ----- .../TestAsset/vendor/bin/zfdeploy.php | 7 - 9 files changed, 21 insertions(+), 1203 deletions(-) delete mode 100644 src/Controller/PackageController.php delete mode 100644 test/Controller/PackageControllerTest.php delete mode 100644 test/Controller/TestAsset/vendor/bin/zfdeploy.php diff --git a/README.md b/README.md index 647f75e2..e1f631fb 100644 --- a/README.md +++ b/README.md @@ -613,64 +613,6 @@ The minimum structure for creating a new REST service will appear as follows: } ``` -### api/package - -This endpoint is for building a deploy package for APIs. - -- `Accept`: `application/json` - - Returns a JSON structure on success, an API-Problem payload on error. - -- `Content-Type`: `application/json` - - Expects an object with the property "format", for the file format - ZIP, TAR, TGZ, and ZPK; an "apis" property with a list of the API to - include in the package; a "composer" property that specify if execute - composer or not and an optional "config" property containing the path - to an application config folder to be used in the package. - - -- Methods: `GET`, `POST` - -- Errors: `application/problem+json` - -The request payload for `POST` should have the following structure: - -```JSON -{ - "format": "the file format to be used for the package", - "apis" : { - "Test": true - }, - "composer": true, - "config": "the config path to be used in the package" -} -``` - -On success, the service returns the followings structure: - -```JSON -{ - "token": "a random token string", - "format": "the file format used for the package" -} -``` - -The fields of this response can be used in the `GET` method to download -the package file. Basically, the token is a temporary file name stored in -the system temporary folder (`/tmp` in GNU/Linux). - -The request payload for `GET` should have the following structure: - -``` -GET /api/package?token=xxx&format=yyy -``` - -On success, the service returns the file as `application/octet-stream` -content type. - - - ## API Models The following is a list of various models either returned via the API endpoints listed above, or diff --git a/composer.json b/composer.json index b7b9e49c..9fda77de 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ } }, "require": { - "php": "^7.3 || ~8.0.0", + "php": "^7.3 || ~8.0.0 || ~8.1.0", "laminas-api-tools/api-tools": "^1.4", "laminas-api-tools/api-tools-admin-ui": "^1.3.9", "laminas-api-tools/api-tools-api-problem": "^1.3", @@ -61,15 +61,14 @@ }, "require-dev": { "ext-sqlite3": "*", - "alcaeus/mongo-php-adapter": "^1.2", + "alcaeus/mongo-php-adapter": "^1.2.2", "laminas/laminas-coding-standard": "~2.3.0", "laminas/laminas-config": "^2.6 || ^3.2", "laminas/laminas-loader": "^2.6", "phpspec/prophecy-phpunit": "^2.0.1", "phpunit/phpunit": "^9.5.5", "psalm/plugin-phpunit": "^0.15.0", - "vimeo/psalm": "^4.3", - "zfcampus/zf-deploy": "^1.3" + "vimeo/psalm": "^4.3" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index a980e8b8..de9efadd 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": "aea4bbb5b04c63bd97fd51fc3db5aa64", + "content-hash": "afe9202abbda579b09cbbb69d776b2f4", "packages": [ { "name": "brick/varexporter", @@ -3498,16 +3498,16 @@ "packages-dev": [ { "name": "alcaeus/mongo-php-adapter", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/alcaeus/mongo-php-adapter.git", - "reference": "e9f2cb6ab4ccc59f28eba1360aba96051e02fa33" + "reference": "0e99bf5ea15f8e9b7ddb3a6dc38c11aa95330ca1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/alcaeus/mongo-php-adapter/zipball/e9f2cb6ab4ccc59f28eba1360aba96051e02fa33", - "reference": "e9f2cb6ab4ccc59f28eba1360aba96051e02fa33", + "url": "https://api.github.com/repos/alcaeus/mongo-php-adapter/zipball/0e99bf5ea15f8e9b7ddb3a6dc38c11aa95330ca1", + "reference": "0e99bf5ea15f8e9b7ddb3a6dc38c11aa95330ca1", "shasum": "" }, "require": { @@ -3529,15 +3529,15 @@ "branch-version": "1.x" }, "autoload": { + "files": [ + "lib/Mongo/functions.php" + ], "psr-0": { "Mongo": "lib/Mongo" }, "psr-4": { "Alcaeus\\MongoDbAdapter\\": "lib/Alcaeus/MongoDbAdapter" - }, - "files": [ - "lib/Mongo/functions.php" - ] + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -3560,9 +3560,9 @@ ], "support": { "issues": "https://github.com/alcaeus/mongo-php-adapter/issues", - "source": "https://github.com/alcaeus/mongo-php-adapter/tree/1.2.1" + "source": "https://github.com/alcaeus/mongo-php-adapter/tree/1.2.2" }, - "time": "2021-07-08T11:24:49+00:00" + "time": "2022-01-11T15:05:50+00:00" }, { "name": "amphp/amp", @@ -4298,133 +4298,6 @@ }, "time": "2021-02-22T14:02:09+00:00" }, - { - "name": "herrera-io/json", - "version": "1.0.3", - "source": { - "type": "git", - "url": "https://github.com/kherge-php/json.git", - "reference": "60c696c9370a1e5136816ca557c17f82a6fa83f1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kherge-php/json/zipball/60c696c9370a1e5136816ca557c17f82a6fa83f1", - "reference": "60c696c9370a1e5136816ca557c17f82a6fa83f1", - "shasum": "" - }, - "require": { - "ext-json": "*", - "justinrainbow/json-schema": ">=1.0,<2.0-dev", - "php": ">=5.3.3", - "seld/jsonlint": ">=1.0,<2.0-dev" - }, - "require-dev": { - "herrera-io/phpunit-test-case": "1.*", - "mikey179/vfsstream": "1.1.0", - "phpunit/phpunit": "3.7.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "files": [ - "src/lib/json_version.php" - ], - "psr-0": { - "Herrera\\Json": "src/lib" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kevin Herrera", - "email": "kevin@herrera.io", - "homepage": "http://kevin.herrera.io" - } - ], - "description": "A library for simplifying JSON linting and validation.", - "homepage": "http://herrera-io.github.com/php-json", - "keywords": [ - "json", - "lint", - "schema", - "validate" - ], - "support": { - "issues": "https://github.com/herrera-io/php-json/issues", - "source": "https://github.com/kherge-php/json/tree/1.0.3" - }, - "abandoned": "kherge/json", - "time": "2013-10-30T16:51:34+00:00" - }, - { - "name": "herrera-io/phar-update", - "version": "1.0.3", - "source": { - "type": "git", - "url": "https://github.com/kherge-archive/php-phar-update.git", - "reference": "00a79e1d5b8cf3c080a2e3becf1ddf7a7fea025b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kherge-archive/php-phar-update/zipball/00a79e1d5b8cf3c080a2e3becf1ddf7a7fea025b", - "reference": "00a79e1d5b8cf3c080a2e3becf1ddf7a7fea025b", - "shasum": "" - }, - "require": { - "herrera-io/json": "1.*", - "kherge/version": "1.*", - "php": ">=5.3.3" - }, - "require-dev": { - "herrera-io/phpunit-test-case": "1.*", - "mikey179/vfsstream": "1.1.0", - "phpunit/phpunit": "3.7.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "files": [ - "src/lib/constants.php" - ], - "psr-0": { - "Herrera\\Phar\\Update": "src/lib" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kevin Herrera", - "email": "kevin@herrera.io", - "homepage": "http://kevin.herrera.io" - } - ], - "description": "A library for self-updating Phars.", - "homepage": "http://herrera-io.github.com/php-phar-update", - "keywords": [ - "phar", - "update" - ], - "support": { - "issues": "https://github.com/herrera-io/php-phar-update/issues", - "source": "https://github.com/kherge-archive/php-phar-update/tree/1.0.3" - }, - "abandoned": true, - "time": "2013-10-30T17:23:01+00:00" - }, { "name": "jean85/pretty-package-versions", "version": "2.0.5", @@ -4484,123 +4357,6 @@ }, "time": "2021-10-08T21:21:46+00:00" }, - { - "name": "justinrainbow/json-schema", - "version": "1.6.1", - "source": { - "type": "git", - "url": "https://github.com/justinrainbow/json-schema.git", - "reference": "cc84765fb7317f6b07bd8ac78364747f95b86341" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/cc84765fb7317f6b07bd8ac78364747f95b86341", - "reference": "cc84765fb7317f6b07bd8ac78364747f95b86341", - "shasum": "" - }, - "require": { - "php": ">=5.3.29" - }, - "require-dev": { - "json-schema/json-schema-test-suite": "1.1.0", - "phpdocumentor/phpdocumentor": "~2", - "phpunit/phpunit": "~3.7" - }, - "bin": [ - "bin/validate-json" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6.x-dev" - } - }, - "autoload": { - "psr-4": { - "JsonSchema\\": "src/JsonSchema/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Bruno Prieto Reis", - "email": "bruno.p.reis@gmail.com" - }, - { - "name": "Justin Rainbow", - "email": "justin.rainbow@gmail.com" - }, - { - "name": "Igor Wiedler", - "email": "igor@wiedler.ch" - }, - { - "name": "Robert Schönthal", - "email": "seroscho@googlemail.com" - } - ], - "description": "A library to validate a json schema.", - "homepage": "https://github.com/justinrainbow/json-schema", - "keywords": [ - "json", - "schema" - ], - "support": { - "issues": "https://github.com/justinrainbow/json-schema/issues", - "source": "https://github.com/justinrainbow/json-schema/tree/master" - }, - "time": "2016-01-25T15:43:01+00:00" - }, - { - "name": "kherge/version", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/kherge-archive/Version.git", - "reference": "f07cf83f8ce533be8f93d2893d96d674bbeb7e30" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/kherge-archive/Version/zipball/f07cf83f8ce533be8f93d2893d96d674bbeb7e30", - "reference": "f07cf83f8ce533be8f93d2893d96d674bbeb7e30", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-0": { - "KevinGH\\Version": "src/lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kevin Herrera", - "email": "me@kevingh.com" - } - ], - "description": "A parsing and comparison library for semantic versioning.", - "homepage": "http://github.com/kherge/Version", - "support": { - "issues": "https://github.com/kherge-archive/Version/issues", - "source": "https://github.com/kherge-archive/Version/tree/1.0.1" - }, - "abandoned": true, - "time": "2012-08-16T17:13:03+00:00" - }, { "name": "laminas/laminas-coding-standard", "version": "2.3.0", @@ -4654,72 +4410,6 @@ ], "time": "2021-05-29T15:53:59+00:00" }, - { - "name": "laminas/laminas-console", - "version": "2.8.0", - "source": { - "type": "git", - "url": "https://github.com/laminas/laminas-console.git", - "reference": "478a6ceac3e31fb38d6314088abda8b239ee23a5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-console/zipball/478a6ceac3e31fb38d6314088abda8b239ee23a5", - "reference": "478a6ceac3e31fb38d6314088abda8b239ee23a5", - "shasum": "" - }, - "require": { - "laminas/laminas-stdlib": "^3.2.1", - "laminas/laminas-zendframework-bridge": "^1.0", - "php": "^5.6 || ^7.0" - }, - "replace": { - "zendframework/zend-console": "self.version" - }, - "require-dev": { - "laminas/laminas-coding-standard": "~1.0.0", - "laminas/laminas-filter": "^2.7.2", - "laminas/laminas-json": "^2.6 || ^3.0", - "laminas/laminas-validator": "^2.10.1", - "phpunit/phpunit": "^5.7.23 || ^6.4.3" - }, - "suggest": { - "laminas/laminas-filter": "To support DefaultRouteMatcher usage", - "laminas/laminas-validator": "To support DefaultRouteMatcher usage" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.8.x-dev", - "dev-develop": "2.9.x-dev" - } - }, - "autoload": { - "psr-4": { - "Laminas\\Console\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Build console applications using getopt syntax or routing, complete with prompts", - "homepage": "https://laminas.dev", - "keywords": [ - "console", - "laminas" - ], - "support": { - "chat": "https://laminas.dev/chat", - "docs": "https://docs.laminas.dev/laminas-console/", - "forum": "https://discourse.laminas.dev", - "issues": "https://github.com/laminas/laminas-console/issues", - "rss": "https://github.com/laminas/laminas-console/releases.atom", - "source": "https://github.com/laminas/laminas-console" - }, - "abandoned": "laminas/laminas-cli", - "time": "2019-12-31T16:31:45+00:00" - }, { "name": "mongodb/mongodb", "version": "1.11.0", @@ -6882,69 +6572,6 @@ ], "time": "2020-09-28T06:39:44+00:00" }, - { - "name": "seld/jsonlint", - "version": "1.8.3", - "source": { - "type": "git", - "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "9ad6ce79c342fbd44df10ea95511a1b24dee5b57" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/9ad6ce79c342fbd44df10ea95511a1b24dee5b57", - "reference": "9ad6ce79c342fbd44df10ea95511a1b24dee5b57", - "shasum": "" - }, - "require": { - "php": "^5.3 || ^7.0 || ^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" - }, - "bin": [ - "bin/jsonlint" - ], - "type": "library", - "autoload": { - "psr-4": { - "Seld\\JsonLint\\": "src/Seld/JsonLint/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "JSON Linter", - "keywords": [ - "json", - "linter", - "parser", - "validator" - ], - "support": { - "issues": "https://github.com/Seldaek/jsonlint/issues", - "source": "https://github.com/Seldaek/jsonlint/tree/1.8.3" - }, - "funding": [ - { - "url": "https://github.com/Seldaek", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/seld/jsonlint", - "type": "tidelift" - } - ], - "time": "2020-11-11T09:19:24+00:00" - }, { "name": "slevomat/coding-standard", "version": "7.0.18", @@ -8068,126 +7695,6 @@ }, "abandoned": "symfony/filesystem", "time": "2015-12-17T08:42:14+00:00" - }, - { - "name": "zfcampus/zf-console", - "version": "1.4.0", - "source": { - "type": "git", - "url": "https://github.com/zfcampus/zf-console.git", - "reference": "e4dd16760fe219d8b2745865a883b0e0a492a3ed" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zfcampus/zf-console/zipball/e4dd16760fe219d8b2745865a883b0e0a492a3ed", - "reference": "e4dd16760fe219d8b2745865a883b0e0a492a3ed", - "shasum": "" - }, - "require": { - "php": "^5.6 || ^7.0", - "psr/container": "^1.0", - "zendframework/zend-console": "^2.6" - }, - "require-dev": { - "phpunit/phpunit": "^5.7.25 || ^6.4.4", - "zendframework/zend-coding-standard": "~1.0.0", - "zendframework/zend-filter": "^2.7.1", - "zendframework/zend-validator": "^2.8.1" - }, - "suggest": { - "zendframework/zend-filter": "^2.7.1; Useful for filtering/normalizing argument values", - "zendframework/zend-validator": "^2.8.1; Useful for providing more thorough argument validation logic" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev", - "dev-develop": "1.5-dev" - } - }, - "autoload": { - "psr-4": { - "ZF\\Console\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Library for creating and dispatching console commands", - "keywords": [ - "ZendFramework", - "console", - "zf" - ], - "support": { - "forum": "https://discourse.zendframework.com/c/questions/apigility", - "issues": "https://github.com/zfcampus/zf-console/issues", - "rss": "https://github.com/zfcampus/zf-console/releases.atom", - "slack": "https://zendframework-slack.herokuapp.com", - "source": "https://github.com/zfcampus/zf-console" - }, - "abandoned": true, - "time": "2017-11-27T17:17:19+00:00" - }, - { - "name": "zfcampus/zf-deploy", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/zfcampus/zf-deploy.git", - "reference": "2dfdd510c8a08a852f1109407d2e33ddd2f73781" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/zfcampus/zf-deploy/zipball/2dfdd510c8a08a852f1109407d2e33ddd2f73781", - "reference": "2dfdd510c8a08a852f1109407d2e33ddd2f73781", - "shasum": "" - }, - "require": { - "herrera-io/phar-update": "~1.0", - "php": "^5.6 || ^7.0", - "zendframework/zend-filter": "^2.7.1", - "zfcampus/zf-console": "^1.3" - }, - "require-dev": { - "phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.5", - "zendframework/zend-coding-standard": "~1.0.0" - }, - "bin": [ - "bin/zfdeploy.php" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev", - "dev-develop": "1.4.x-dev" - } - }, - "autoload": { - "psr-4": { - "ZF\\Deploy\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Deployment tool for Zend Framework applications", - "keywords": [ - "ZendFramework", - "apigility", - "zf" - ], - "support": { - "chat": "https://zendframework-slack.herokuapp.com", - "forum": "https://discourse.zendframework.com/c/questions/apigility", - "issues": "https://github.com/zfcampus/zf-deploy/issues", - "rss": "https://github.com/zfcampus/zf-deploy/releases.atom", - "source": "https://github.com/zfcampus/zf-deploy" - }, - "abandoned": true, - "time": "2018-05-07T15:51:51+00:00" } ], "aliases": [], @@ -8196,10 +7703,10 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.3 || ~8.0.0" + "php": "^7.3 || ~8.0.0 || ~8.1.0" }, "platform-dev": { "ext-sqlite3": "*" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/config/module.config.php b/config/module.config.php index 5745e262..7aa8f9f5 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -248,7 +248,6 @@ Controller\ModuleConfig::class => Controller\ModuleConfigController::class, Controller\ModuleCreation::class => Controller\ModuleCreationController::class, Controller\OAuth2Authentication::class => Controller\Authentication::class, - Controller\Package::class => Controller\PackageController::class, Controller\Source::class => Controller\SourceController::class, Controller\Versioning::class => Controller\VersioningController::class, @@ -264,7 +263,6 @@ 'ZF\Apigility\Admin\Controller\ModuleConfig' => Controller\ModuleConfig::class, 'ZF\Apigility\Admin\Controller\ModuleCreation' => Controller\ModuleCreation::class, 'ZF\Apigility\Admin\Controller\OAuth2Authentication' => Controller\OAuth2Authentication::class, - 'ZF\Apigility\Admin\Controller\Package' => Controller\Package::class, 'ZF\Apigility\Admin\Controller\Source' => Controller\Source::class, 'ZF\Apigility\Admin\Controller\Versioning' => Controller\Versioning::class, 'ZF\Apigility\Admin\Controller\ApigilityVersionController' => Controller\ApiToolsVersionController::class, @@ -283,7 +281,6 @@ 'ZF\Apigility\Admin\Controller\InputFilter' => Controller\InputFilter::class, 'ZF\Apigility\Admin\Controller\ModuleConfigController' => Controller\ModuleConfigController::class, 'ZF\Apigility\Admin\Controller\ModuleCreationController' => Controller\ModuleCreationController::class, - 'ZF\Apigility\Admin\Controller\PackageController' => Controller\PackageController::class, 'ZF\Apigility\Admin\Controller\SettingsDashboard' => Controller\SettingsDashboard::class, 'ZF\Apigility\Admin\Controller\SourceController' => Controller\SourceController::class, 'ZF\Apigility\Admin\Controller\Strategy' => Controller\Strategy::class, @@ -307,7 +304,6 @@ Controller\InputFilter::class => Controller\InputFilterControllerFactory::class, Controller\ModuleConfigController::class => Controller\ModuleConfigControllerFactory::class, Controller\ModuleCreationController::class => Controller\ModuleCreationControllerFactory::class, - Controller\PackageController::class => InvokableFactory::class, Controller\SettingsDashboard::class => Controller\DashboardControllerFactory::class, Controller\SourceController::class => Controller\SourceControllerFactory::class, Controller\Strategy::class => Controller\StrategyControllerFactory::class, @@ -669,16 +665,6 @@ ], ], ], - 'package' => [ - 'type' => 'Literal', - 'options' => [ - 'route' => '/package', - 'defaults' => [ - 'controller' => Controller\Package::class, - 'action' => 'index', - ], - ], - ], 'authentication-type' => [ 'type' => 'Literal', 'options' => [ @@ -717,7 +703,6 @@ Controller\Module::class => 'HalJson', Controller\ModuleCreation::class => 'HalJson', Controller\OAuth2Authentication::class => 'HalJson', - Controller\Package::class => 'Json', Controller\RestService::class => 'HalJson', Controller\RpcService::class => 'HalJson', Controller\SettingsDashboard::class => 'HalJson', @@ -1196,10 +1181,6 @@ 'http_methods' => ['GET'], 'route_name' => 'api-tools/api/strategy', ], - Controller\Package::class => [ - 'http_methods' => ['GET', 'POST'], - 'route_name' => 'api-tools/api/package', - ], ], /* diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 4953fc84..78af65fb 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,20 +1,13 @@ - + Model\VersioningModelFactory::class Model\VersioningModelFactory::class Model\VersioningModelFactoryFactory::class - VersioningModelFactory::class - - App - Authentication - AuthenticationType - Authorization - CacheEnabled - Config + Controller\App Controller\App Controller\App @@ -162,11 +155,6 @@ Controller\OAuth2Authentication Controller\OAuth2Authentication Controller\OAuth2Authentication - Controller\Package - Controller\Package - Controller\Package - Controller\Package - Controller\Package Controller\RestService Controller\RestService Controller\RestService @@ -216,24 +204,6 @@ Controller\Versioning Controller\Versioning Controller\Versioning - Dashboard - DbAutodiscovery - Documentation - Filters - FsPermissions - HttpBasicAuthentication - HttpDigestAuthentication - Hydrators - InputFilter - ModuleConfig - ModuleCreation - OAuth2Authentication - Package - SettingsDashboard - Source - Strategy - Validators - Versioning @@ -918,71 +888,6 @@ $container->getServiceLocator() - - - $this->getResponse() - - - ! is_string($assets) - ! is_string($config) - ! is_string($format) - ! is_string($version) - ! is_string($xml) - - - shell_exec($cmd) - - - array|Response|ApiProblemResponse - - - filesize($package) - - - $entry - - - $apis - $assets - $composer - $config - $entry - $this->bodyParam('format', false) - $this->bodyParams() - $this->params()->fromQuery('format', false) - $this->params()->fromQuery('token', false) - $version - $xml - - - $apis - $assets - $composer - $config - $version - $xml - - - fromQuery - fromQuery - - - $sentPackage - PackageController - PackageController - PackageController - PackageController - PackageController - - - ! empty($zfdeployPath) && is_string($zfdeployPath) - is_string($zfdeployPath) - - - bodyParam - bodyParams - - $this->params()->fromQuery('class', false) @@ -3978,41 +3883,6 @@ Module - - - set - set - - - $data['format'] - $data['token'] - $result['format'] - $result['token'] - - - $result - array<string, mixed> - - - addHeaderLine - addHeaderLine - getFieldValue - getFieldValue - getHeaders - getHeaders - getRawBody - isSuccess - - - addHeaderLine - addHeaderLine - getFieldValue - getFieldValue - - - getRawBody - - getServiceLocator diff --git a/src/Controller/PackageController.php b/src/Controller/PackageController.php deleted file mode 100644 index fbf01be9..00000000 --- a/src/Controller/PackageController.php +++ /dev/null @@ -1,352 +0,0 @@ -zfdeployPath = $zfdeployPath; - } - } - - /** - * Handle incoming requests - * - * @return array|Response|ApiProblemResponse - */ - public function indexAction() - { - /** @var Request $request */ - $request = $this->getRequest(); - - switch ($request->getMethod()) { - case $request::METHOD_GET: - return $this->fetch( - $this->params()->fromQuery('token', false), - $this->params()->fromQuery('format', false), - $this->getResponse() - ); - - case $request::METHOD_POST: - return $this->create( - $this->bodyParam('format', false), - $this->bodyParams() - ); - - default: - return new ApiProblemResponse( - new ApiProblem(405, 'Only the method POST is allowed for this URI') - ); - } - } - - /** - * Fetch a generated package. - * - * @param string $fileId - * @param string $format - * @param Response $response - * @return Response - */ - private function fetch($fileId, $format, $response) - { - if (! $fileId || ! $format) { - $response->setStatusCode(404); - return $response; - } - - $package = $this->getPackageFile($fileId, $format); - - if (! file_exists($package)) { - $response->setStatusCode(404); - return $response; - } - - $stream = fopen($package, 'r'); - if (false === $stream) { - $response->setStatusCode(500); - return $response; - } - - // Mark the package for deletion when the request spins down. - $this->sentPackage = $package; - - // Create a streamable response. - $response = new Stream(); - $response->setStream($stream); - $response->getHeaders() - ->addHeaderLine('Content-Type', 'application/octet-stream') - ->addHeaderLine('Content-Disposition', sprintf( - 'attachment; filename="api-tools_%s.%s"', - date('Y-m-d_H-i-s'), - $format - )) - ->addHeaderLine('Content-Length', filesize($package)); - - return $response; - } - - /** - * Create a package, given a format and options. - * - * @param string $format - * @param array $params - * @return array|ApiProblemResponse - */ - private function create($format, array $params) - { - if ( - ! $format - || ! is_string($format) - || ! in_array(strtolower($format), ['zip', 'tar', 'tgz', 'zpk']) - ) { - return new ApiProblemResponse( - new ApiProblem( - 422, - 'Format parameter not valid, we accept only zip, tar, tgz or zpk type', - 'https://tools.ietf.org/html/rfc4918', - 'Unprocessable Entity' - ) - ); - } - - $format = strtolower($format); - $fileId = uniqid(); - $package = $this->getPackageFile($fileId, $format); - $cmd = sprintf('php %s build %s', $this->zfdeployPath, $package); - - $apis = array_key_exists('apis', $params) ? $params['apis'] : null; - $cmd .= $this->createModulesOption($apis); - - $composer = array_key_exists('composer', $params) ? $params['composer'] : null; - $cmd .= $this->createComposerOption($composer); - - $config = array_key_exists('config', $params) ? $params['config'] : null; - $cmd .= $this->createConfigOption($config); - - if ($format === 'zpk') { - $cmd .= $this->createZpkOptions($params); - } - - // Execute zf-deploy - shell_exec($cmd); - - if (! file_exists($package)) { - return new ApiProblemResponse( - new ApiProblem( - 500, - 'Unable to create package, or error creating package' - ) - ); - } - - return ['token' => $fileId, 'format' => $format]; - } - - /** - * Create the package file name. - * - * @param string $fileId - * @param string $format - * @return string - */ - private function getPackageFile($fileId, $format) - { - return sys_get_temp_dir() . '/api-tools_' . $fileId . '.' . strtolower($format); - } - - /** - * Create and return the --modules option, if any. - * - * @param null|array $apis - * @return string - */ - private function createModulesOption($apis) - { - if (! is_array($apis)) { - return ''; - } - - $modules = array_map( - function ($entry) { - return basename($entry); - }, - glob(realpath('module') . '/*', GLOB_ONLYDIR) - ); - - $toInclude = []; - - foreach ($modules as $mod) { - if (! isset($apis[$mod]) || $apis[$mod]) { - $toInclude[] = $mod; - } - } - - return ' --modules=' . escapeshellarg(implode(',', $toInclude)); - } - - /** - * Create the composer option, if any. - * - * @param null|bool $composer - * @return string - */ - private function createComposerOption($composer) - { - if (null === $composer) { - return ''; - } - - return $composer ? ' --composer=on' : ' --composer=off'; - } - - /** - * Create the config option, if any. - * - * @param null|string $config - * @return string - */ - private function createConfigOption($config) - { - if (empty($config) || ! is_string($config)) { - return ''; - } - - return ' --configs=' . escapeshellarg($config); - } - - /** - * Create and return any ZPK-specific options. - * - * @param array $params - * @return string - */ - private function createZpkOptions(array $params) - { - $options = ''; - - $xml = array_key_exists('zpk_xml', $params) ? $params['zpk_xml'] : null; - $options .= $this->createZpkXmlOption($xml); - - $assets = array_key_exists('zpk_assets', $params) ? $params['zpk_assets'] : null; - $options .= $this->createZpkAssetsOption($assets); - - $version = array_key_exists('zpk_version', $params) ? $params['zpk_version'] : null; - return $options . $this->createZpkVersionOption($version); - } - - /** - * Create and return the deploymentxml option. - * - * @param null|string $xml - * @return string - */ - private function createZpkXmlOption($xml) - { - if (null === $xml || ! is_string($xml)) { - return ''; - } - - return ' --deploymentxml=' . escapeshellarg($xml); - } - - /** - * Create and return the zpkdata option. - * - * @param null|string $assets - * @return string - */ - private function createZpkAssetsOption($assets) - { - if (null === $assets || ! is_string($assets)) { - return ''; - } - - return ' --zpkdata=' . escapeshellarg($assets); - } - - /** - * Create and return the version option. - * - * @param null|string $version - * @return string - */ - private function createZpkVersionOption($version) - { - if (null === $version || ! is_string($version)) { - return ''; - } - - return ' --version=' . escapeshellarg($version); - } - - /** - * Set the request object manually - * - * Provided for testing. - * - * @return $this - */ - public function setRequest(Request $request) - { - $this->request = $request; - return $this; - } - - /** - * Unlink any package sent over the wire previously. - */ - public function __destruct() - { - if ($this->sentPackage && file_exists($this->sentPackage)) { - unlink($this->sentPackage); - } - } -} diff --git a/src/Model/AuthorizationEntity.php b/src/Model/AuthorizationEntity.php index 256cede2..815307dd 100644 --- a/src/Model/AuthorizationEntity.php +++ b/src/Model/AuthorizationEntity.php @@ -8,6 +8,7 @@ use Countable; use IteratorAggregate; use Laminas\ApiTools\Admin\Exception; +use ReturnTypeWillChange; use function array_key_exists; use function count; @@ -48,12 +49,14 @@ public function __construct(array $services = []) } /** @return int */ + #[ReturnTypeWillChange] public function count() { return count($this->servicePrivileges); } /** @return ArrayIterator */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->servicePrivileges); diff --git a/test/Controller/PackageControllerTest.php b/test/Controller/PackageControllerTest.php deleted file mode 100644 index 63f0e9c8..00000000 --- a/test/Controller/PackageControllerTest.php +++ /dev/null @@ -1,125 +0,0 @@ -controller = new PackageController('vendor/bin/zfdeploy.php'); - $plugins = new ControllerPluginManager($this->prophesize(ContainerInterface::class)->reveal()); - $plugins->setService('bodyParam', new BodyParam()); - $plugins->setService('bodyParams', new BodyParams()); - $this->controller->setPluginManager($plugins); - } - - /** @psalm-return array */ - public function invalidRequestMethods(): array - { - return [ - ['patch'], - ['put'], - ['delete'], - ]; - } - - /** - * @dataProvider invalidRequestMethods - */ - public function testProcessWithInvalidRequestMethodReturnsApiProblemResponse(string $method): void - { - $request = new Request(); - $request->setMethod($method); - $this->controller->setRequest($request); - $result = $this->controller->indexAction(); - self::assertInstanceOf(ApiProblemResponse::class, $result); - $apiProblem = $result->getApiProblem(); - self::assertEquals(405, $apiProblem->status); - } - - /** @return array */ - public function testProcessPostRequestReturnsToken(): array - { - $request = new Request(); - $request->setMethod('post'); - - $parameters = new ParameterDataContainer(); - $parameters->setBodyParam('format', 'ZIP'); - $event = new MvcEvent(); - $event->setParam('LaminasContentNegotiationParameterData', $parameters); - - $request->getHeaders()->addHeaderLine('Content-Type', 'application/json'); - $request->getHeaders()->addHeaderLine('Accept', 'application/json'); - - $this->controller->setRequest($request); - $this->controller->setEvent($event); - - $cwd = getcwd(); - chdir(__DIR__ . '/TestAsset'); - $result = $this->controller->indexAction(); - chdir($cwd); - - self::assertIsArray($result); - self::assertTrue(isset($result['token'])); - self::assertTrue(isset($result['format'])); - $package = sys_get_temp_dir() . '/api-tools_' . $result['token'] . '.' . $result['format']; - self::assertTrue(file_exists($package)); - - return $result; - } - - /** - * @depends testProcessPostRequestReturnsToken - * @param array $data - */ - public function testProcessGetRequestReturnsFile(array $data): void - { - $request = new Request(); - $request->setMethod('get'); - $request->getQuery()->set('format', $data['format']); - $request->getQuery()->set('token', $data['token']); - - $this->controller->setRequest($request); - - $package = sys_get_temp_dir() . '/api-tools_' . $data['token'] . '.' . $data['format']; - $content = file_get_contents($package); - - $response = $this->controller->indexAction(); - - self::assertTrue($response->isSuccess()); - self::assertEquals($content, $response->getRawBody()); - self::assertEquals('application/octet-stream', $response->getHeaders()->get('Content-Type')->getFieldValue()); - self::assertEquals(strlen($content), $response->getHeaders()->get('Content-Length')->getFieldValue()); - - // Removal of file only happens during destruct - $this->controller->__destruct(); - self::assertFalse(file_exists($package)); - } -} diff --git a/test/Controller/TestAsset/vendor/bin/zfdeploy.php b/test/Controller/TestAsset/vendor/bin/zfdeploy.php deleted file mode 100644 index 5fe0e04f..00000000 --- a/test/Controller/TestAsset/vendor/bin/zfdeploy.php +++ /dev/null @@ -1,7 +0,0 @@ -