Skip to content

Commit

Permalink
PHP 8.0 support
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Kosogin <[email protected]>
  • Loading branch information
ekosogin committed May 5, 2021
1 parent a315fc5 commit b60a809
Show file tree
Hide file tree
Showing 36 changed files with 836 additions and 573 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/coveralls-upload.json
/phpunit.xml
/vendor/
/.phpunit.result.cache
/.phpcs-cache
18 changes: 6 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,24 @@ env:
matrix:
fast_finish: true
include:
- php: 5.6
- php: 7.3
env:
- DEPS=lowest
- php: 5.6
- php: 7.3
env:
- DEPS=latest
- TEST_COVERAGE=true
- php: 7
- php: 7.4
env:
- DEPS=lowest
- php: 7
- php: 7.4
env:
- DEPS=latest
- CS_CHECK=true
- php: 7.1
- php: 8.0
env:
- DEPS=lowest
- php: 7.1
env:
- DEPS=latest
- php: 7.2
env:
- DEPS=lowest
- php: 7.2
- php: 8.0
env:
- DEPS=latest

Expand Down
31 changes: 25 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,47 @@
"module": "Laminas\\ApiTools\\Rest"
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/eimkua1/api-tools-api-problem.git"
},
{
"type": "vcs",
"url": "https://github.com/eimkua1/api-tools-content-negotiation.git"
},
{
"type": "vcs",
"url": "https://github.com/eimkua1/api-tools-mvc-auth.git"
},
{
"type": "vcs",
"url": "https://github.com/eimkua1/api-tools-oauth2.git"
}
],
"require": {
"php": "^5.6 || ^7.0",
"laminas-api-tools/api-tools-api-problem": "^1.2.2",
"laminas-api-tools/api-tools-content-negotiation": "^1.2.1",
"php": "^7.3 || ~8.0.0",
"laminas-api-tools/api-tools-api-problem": "^1.4.0",
"laminas-api-tools/api-tools-content-negotiation": "^1.5.0",
"laminas-api-tools/api-tools-hal": "^1.4",
"laminas-api-tools/api-tools-mvc-auth": "^1.4",
"laminas-api-tools/api-tools-mvc-auth": "^1.6",
"laminas/laminas-eventmanager": "^2.6.3 || ^3.0.1",
"laminas/laminas-mvc": "^2.7.14 || ^3.0.2",
"laminas/laminas-paginator": "^2.7",
"laminas/laminas-stdlib": "^2.7.7 || ^3.0.1",
"laminas/laminas-zendframework-bridge": "^1.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "~1.0.0",
"laminas/laminas-coding-standard": "^2.1",
"laminas/laminas-escaper": "^2.5.2",
"laminas/laminas-http": "^2.5.4",
"laminas/laminas-inputfilter": "^2.7.2",
"laminas/laminas-servicemanager": "^2.7.6 || ^3.1",
"laminas/laminas-uri": "^2.5.2",
"laminas/laminas-validator": "^2.8.1",
"laminas/laminas-view": "^2.8.1",
"phpunit/phpunit": "^5.7.27 || ^6.5.8 || ^7.1.5"
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
Expand Down
21 changes: 11 additions & 10 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
* @license https://github.com/laminas-api-tools/api-tools-rest/blob/master/LICENSE.md New BSD License
*/

use Laminas\ApiTools\Rest\Factory\OptionsListenerFactory;
use Laminas\ApiTools\Rest\Factory\RestControllerFactory;
use Laminas\ApiTools\Rest\Listener\RestParametersListener;

return [
'api-tools-rest' => [
'api-tools-rest' => [
// @codingStandardsIgnoreStart
// 'Name of virtual controller' => [
// 'collection_http_methods' => [
Expand Down Expand Up @@ -35,23 +39,20 @@
// repeat for each controller you want to define
// @codingStandardsIgnoreEnd
],

'service_manager' => [
'invokables' => [
'Laminas\ApiTools\Rest\RestParametersListener' => 'Laminas\ApiTools\Rest\Listener\RestParametersListener',
'Laminas\ApiTools\Rest\RestParametersListener' => RestParametersListener::class,
],
'factories' => [
'Laminas\ApiTools\Rest\OptionsListener' => 'Laminas\ApiTools\Rest\Factory\OptionsListenerFactory',
'factories' => [
'Laminas\ApiTools\Rest\OptionsListener' => OptionsListenerFactory::class,
],
],

'controllers' => [
'controllers' => [
'abstract_factories' => [
'Laminas\ApiTools\Rest\Factory\RestControllerFactory',
RestControllerFactory::class,
],
],

'view_manager' => [
'view_manager' => [
// Enable this in your application configuration in order to get full
// exception stack traces in your API-Problem responses.
'display_exceptions' => false,
Expand Down
17 changes: 15 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<?xml version="1.0"?>
<ruleset name="Laminas Coding Standard">
<rule ref="./vendor/laminas/laminas-coding-standard/ruleset.xml"/>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>config</file>
<file>src</file>
<file>test</file>

<!-- Include all rules from Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
22 changes: 11 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="LaminasRest Module Tests">
<directory>./test</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory>./src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory>./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="LaminasRest Module Tests">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
40 changes: 29 additions & 11 deletions src/AbstractResourceListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,82 @@
namespace Laminas\ApiTools\Rest;

use Laminas\ApiTools\ApiProblem\ApiProblem;
use Laminas\ApiTools\MvcAuth\Identity\IdentityInterface;
use Laminas\EventManager\EventManagerInterface;
use Laminas\EventManager\ListenerAggregateInterface;
use Laminas\EventManager\ListenerAggregateTrait;
use Laminas\InputFilter\InputFilterInterface;

use function sprintf;

abstract class AbstractResourceListener implements ListenerAggregateInterface
{
use ListenerAggregateTrait;

/**
* @var ResourceEvent
*/
/** @var ResourceEvent */
protected $event;

/**
* The entity_class config for the calling controller api-tools-rest config
*
* @var string
*/
protected $entityClass;

/**
* The collection_class config for the calling controller api-tools-rest config
*
* @var string
*/
protected $collectionClass;

/**
* Current identity, if discovered in the resource event.
*
* @var \Laminas\ApiTools\MvcAuth\Identity\IdentityInterface
* @var IdentityInterface
*/
protected $identity;

/**
* Input filter, if discovered in the resource event.
*
* @var \Laminas\InputFilter\InputFilterInterface
* @var InputFilterInterface
*/
protected $inputFilter;

/**
* Set the entity_class for the controller config calling this resource
*
* @param string $className
* @return $this
*/
public function setEntityClass($className)
{
$this->entityClass = $className;
return $this;
}

/**
* @return string
*/
public function getEntityClass()
{
return $this->entityClass;
}

/**
* @param string $className
* @return $this
*/
public function setCollectionClass($className)
{
$this->collectionClass = $className;
return $this;
}

/**
* @return string
*/
public function getCollectionClass()
{
return $this->collectionClass;
Expand All @@ -87,7 +106,7 @@ public function getEvent()
* Proxies to the resource event to find the identity, if not already
* composed, and composes it.
*
* @return null|\Laminas\ApiTools\MvcAuth\Identity\IdentityInterface
* @return null|IdentityInterface
*/
public function getIdentity()
{
Expand All @@ -110,7 +129,7 @@ public function getIdentity()
* Proxies to the resource event to find the input filter, if not already
* composed, and composes it.
*
* @return null|\Laminas\InputFilter\InputFilterInterface
* @return null|InputFilterInterface
*/
public function getInputFilter()
{
Expand All @@ -130,7 +149,7 @@ public function getInputFilter()
/**
* Attach listeners for all Resource events
*
* @param EventManagerInterface $events
* @param int $priority
*/
public function attach(EventManagerInterface $events, $priority = 1)
{
Expand All @@ -150,7 +169,6 @@ public function attach(EventManagerInterface $events, $priority = 1)
*
* Marshals arguments from the event parameters.
*
* @param ResourceEvent $event
* @return mixed
*/
public function dispatch(ResourceEvent $event)
Expand All @@ -161,13 +179,13 @@ public function dispatch(ResourceEvent $event)
$data = $event->getParam('data', []);
return $this->create($data);
case 'delete':
$id = $event->getParam('id', null);
$id = $event->getParam('id', null);
return $this->delete($id);
case 'deleteList':
$data = $event->getParam('data', []);
return $this->deleteList($data);
case 'fetch':
$id = $event->getParam('id', null);
$id = $event->getParam('id', null);
return $this->fetch($id);
case 'fetchAll':
$queryParams = $event->getQueryParams() ?: [];
Expand Down
11 changes: 6 additions & 5 deletions src/Factory/OptionsListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
use Laminas\ServiceManager\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;

use function array_key_exists;
use function is_array;

class OptionsListenerFactory implements FactoryInterface
{
/**
* Create and return an OptionsListener instance.
*
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
* @return OptionsListener
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
{
return new OptionsListener($this->getConfig($container));
}
Expand All @@ -33,7 +35,6 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
*
* Provided for backwards compatibility; proxies to __invoke().
*
* @param ServiceLocatorInterface $container
* @return OptionsListener
*/
public function createService(ServiceLocatorInterface $container)
Expand All @@ -44,7 +45,6 @@ public function createService(ServiceLocatorInterface $container)
/**
* Retrieve api-tools-rest config from the container, if available.
*
* @param ContainerInterface $container
* @return array
*/
private function getConfig(ContainerInterface $container)
Expand All @@ -55,7 +55,8 @@ private function getConfig(ContainerInterface $container)

$config = $container->get('config');

if (! array_key_exists('api-tools-rest', $config)
if (
! array_key_exists('api-tools-rest', $config)
|| ! is_array($config['api-tools-rest'])
) {
return [];
Expand Down
Loading

0 comments on commit b60a809

Please sign in to comment.