Skip to content

Commit

Permalink
updates tooling
Browse files Browse the repository at this point in the history
updates tests
updates codestyle
address laminas migration
  • Loading branch information
basz committed Feb 28, 2020
1 parent cd4bbc0 commit c79216b
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 114 deletions.
3 changes: 3 additions & 0 deletions .docheader
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@copyright Copyright (c) 2016 bushbaby multimedia. (https://bushbaby.nl)
@author Bas Kamer <baskamer@gmail.com>
@license MIT
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ composer.phar
composer.lock
phpunit.xml
vendor/
/.phpunit.result.cache
/.php_cs.cache
/build/
18 changes: 18 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* @copyright Copyright (c) 2016 bushbaby multimedia. (https://bushbaby.nl)
* @author Bas Kamer <baskamer@gmail.com>
* @license MIT
*/

declare(strict_types=1);

$config = new Bsb\CS\Config();
$config->getFinder()->in(__DIR__)->append(['.php_cs']);

$cacheDir = \getenv('TRAVIS') ? \getenv('HOME') . '/.php-cs-fixer' : __DIR__;

$config->setCacheFile($cacheDir . '/.php_cs.cache');

return $config;
51 changes: 32 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
sudo: false

language: php

cache:
directories:
- $HOME/.composer/cache
- $HOME/.php-cs-fixer

matrix:
fast_finish: true
include:
- php: 5.5
- php: 5.6
- php: 7
- php: hhvm
allow_failures:
- php: hhvm
- php: 7.2
env:
- DEPENDENCIES=""
- EXECUTE_CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- php: 7.3
env:
- DEPENDENCIES=""
- php: 7.3
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- php: 7.4
env:
- DEPENDENCIES=""
- php: 7.4
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"

before_script:
- mkdir -p "$HOME/.php-cs-fixer"
- composer self-update
- composer install --prefer-source
- composer update $DEPENDENCIES

script:
- vendor/bin/phpunit -c ./phpunit.xml
- vendor/bin/phpcs --standard=PSR2 ./src/

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover test/_build/logs/clover.xml
- mkdir -p build/logs
- if [[ $TEST_COVERAGE == 'true' ]]; then php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml; else ./vendor/bin/phpunit; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run; fi

notifications:
irc: "irc.freenode.org#zftalk.modules"
email: false
after_success:
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry php vendor/bin/php-coveralls -v; fi
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@

# ZF2 ServiceManager Doctrine's ManagerRegistry
# Laminas ServiceManager Doctrine's ManagerRegistry

An implementation Doctrine's ManagerRegistry for zend-servicemanager.
An implementation Doctrine's ManagerRegistry for laminas/laminas-servicemanager.

Install
##### Install

```
```bash
composer require "bushbaby/doctrine-managerregistry-servicemanager"
```

Register ManagerRegistryFactory in the service manager.

```
[
'factories' => [
Doctrine\Common\Persistence\ManagerRegistry::class => BsbDoctrineRegistry\Container\ManagerRegistryFactory::class,
],
]
```php
return [
'dependencies' => [
'factories' => [
\Doctrine\Common\Persistence\ManagerRegistry::class => BsbDoctrineRegistry\Container\ManagerRegistryFactory::class,
],
],
];
```

Usage
##### Usage

```
```php
$managerName = 'orm_default';

/** @var \Doctrine\Common\Persistence\ManagerRegistry $managerRegistry */
Expand All @@ -33,4 +35,4 @@ $objectManager = $managerRegistry->getManager($managerName);
/** @var ObjectRepository $repo */
$repo = $objectManager->getRepository(SomeEntity::class);

```
```
66 changes: 38 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
{
"name": "bushbaby/doctrine-managerregistry-servicemanager",
"description": "An implementation of Doctrine's ManagerRegistry for the ZendFramework ServiceManager",
"require": {
"php": "^5.5 || ^7.0",
"zendframework/zend-servicemanager" : "^2.6 || ^3.0",
"doctrine/orm": "^2.4"
},
"require-dev": {
"phpunit/phpunit": "^5.1",
"squizlabs/php_codesniffer": "^2.5"
},
"autoload": {
"psr-4": {
"BsbDoctrineRegistry\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"BsbDoctrineRegistryTest\\": "test/src/"
}
},
"license": "MIT",
"authors": [
{
"name": "Bas Kamer",
"email": "bas@bushbaby.nl"
}
]
"name": "bushbaby/doctrine-managerregistry-servicemanager",
"description": "An implementation of Doctrine's ManagerRegistry for the Laminas ServiceManager",
"require": {
"php": "^7.2",
"laminas/laminas-servicemanager": "^3.0",
"doctrine/orm": "^2.4"
},
"require-dev": {
"bushbaby/php-cs-fixer-config": "^1.0",
"phpunit/phpunit": "^8.5",
"php-coveralls/php-coveralls": "^2.0"
},
"autoload": {
"psr-4": {
"BsbDoctrineRegistry\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"BsbDoctrineRegistryTest\\": "test/"
}
},
"license": "MIT",
"authors": [
{
"name": "Bas Kamer",
"email": "baskamer@gmail.com"
}
],
"scripts": {
"check": [
"@cs",
"@test"
],
"cs": "php-cs-fixer fix -v --diff --dry-run",
"cs-fix": "php-cs-fixer fix -v --diff",
"test": "phpunit"
}
}
25 changes: 25 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<phpunit colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false">

<testsuite name="test">
<directory>./test</directory>
</testsuite>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-html" target="build/html" lowUpperBound="90" highLowerBound="100"/>
</logging>
</phpunit>
23 changes: 10 additions & 13 deletions src/Container/ManagerRegistryFactory.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?php

/**
* @copyright Copyright (c) 2016 bushbaby multimedia. (https://bushbaby.nl)
* @author Bas Kamer <baskamer@gmail.com>
* @license MIT
*/

declare(strict_types=1);

namespace BsbDoctrineRegistry\Container;

use BsbDoctrineRegistry\Registry\ManagerRegistry;
use Interop\Container\ContainerInterface;

/**
* Class ManagerRegistryFactory
*/
class ManagerRegistryFactory
{
public function __invoke(ContainerInterface $container)
Expand All @@ -27,11 +32,7 @@ public function __invoke(ContainerInterface $container)
return $registry;
}

/**
* @param array $options
* @return array
*/
private function getEntityManagers(array $options)
private function getEntityManagers(array $options): array
{
$entityManagers = [];
foreach ($options as $key => $entityManager) {
Expand All @@ -41,11 +42,7 @@ private function getEntityManagers(array $options)
return $entityManagers;
}

/**
* @param array $options
* @return array
*/
private function getConnections(array $options)
private function getConnections(array $options): array
{
$connections = [];
foreach ($options as $key => $connection) {
Expand Down
31 changes: 17 additions & 14 deletions src/Registry/ManagerRegistry.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<?php

/**
* @copyright Copyright (c) 2016 bushbaby multimedia. (https://bushbaby.nl)
* @author Bas Kamer <baskamer@gmail.com>
* @license MIT
*/

declare(strict_types=1);

namespace BsbDoctrineRegistry\Registry;

use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\ORM\ORMException;
use Doctrine\Persistence\ObjectManager;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\ServiceManager;

/**
* Class ManagerRegistry
*/
class ManagerRegistry extends AbstractManagerRegistry
{
/**
* @var ServiceManager
* @var ContainerInterface
*/
private $serviceManager;

/**
* @inheritdoc
*
* @param ServiceManager $container
* {@inheritdoc}
*/
public function __construct(
$name,
Expand All @@ -29,35 +32,35 @@ public function __construct(
$defaultConnection,
$defaultManager,
$proxyInterfaceName,
ServiceManager $serviceManager
ContainerInterface $container
) {
parent::__construct($name, $connections, $managers, $defaultConnection, $defaultManager, $proxyInterfaceName);

$this->serviceManager = $serviceManager;
$this->serviceManager = $container;
}

/**
* {@inheritdoc}
*/
protected function getService($name)
protected function getService($name): ObjectManager
{
return $this->serviceManager->get($name);
}

/**
* {@inheritdoc}
*/
protected function resetService($name)
protected function resetService($name): void
{
$this->serviceManager->setService($name, null);
}

/**
* {@inheritdoc}
*/
public function getAliasNamespace($alias)
public function getAliasNamespace($alias): string
{
foreach (array_keys($this->getManagers()) as $name) {
foreach (\array_keys($this->getManagers()) as $name) {
try {
return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias);
} catch (ORMException $e) {
Expand Down

0 comments on commit c79216b

Please sign in to comment.