Skip to content

Commit

Permalink
Merge pull request #162 from koriym/php7.0
Browse files Browse the repository at this point in the history
Support PHP 7.0
  • Loading branch information
koriym committed Aug 20, 2017
2 parents 34f5e41 + de31d02 commit 8c01f4e
Show file tree
Hide file tree
Showing 70 changed files with 239 additions and 284 deletions.
3 changes: 2 additions & 1 deletion .php_cs
Expand Up @@ -125,5 +125,6 @@ return \PhpCsFixer\Config::create()
->setFinder(
PhpCsFixer\Finder::create()
->exclude('tests/Fake')
->in('src')
->exclude('tests/tmp')
->in(__DIR__)
)->setLineEnding("\n");
7 changes: 3 additions & 4 deletions .travis.yml
Expand Up @@ -2,10 +2,9 @@ language: php
sudo: required
dist: trusty
php:
- 5.6
- 7
- 7.0
- 7.1
- hhvm
- 7.2
cache:
directories:
- vendor
Expand All @@ -19,7 +18,7 @@ before_script:
- composer update $DEPENDENCIES
script:
- ./vendor/bin/phpunit --coverage-clover=coverage.clover;
- if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar && php php-cs-fixer-v2.phar fix --config=.php_cs -v --dry-run --using-cache=no --path-mode=intersection `git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE`; fi
- if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.4.0/php-cs-fixer.phar && php php-cs-fixer.phar fix --config=.php_cs -v --dry-run --using-cache=no --path-mode=intersection `git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE`; fi

after_script:
- if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
14 changes: 4 additions & 10 deletions README.ja.md
Expand Up @@ -572,28 +572,22 @@ $lister = $injector->getInstance(ListerInterface::class);

`Ray.Di` のためのさまざまなモジュールが利用可能です。 https://github.com/Ray-Di

## 要件

* PHP 5.6+
* hhvm


## インストール

Ray.Diをインストールにするには [Composer](http://getcomposer.org)を利用します。

```bash
# Add Ray.Di as a dependency
$ composer require ray/di ~2.0@dev
$ composer require ray/di ^2.0
```

## テスト

インストールしてテストとデモプログラムを実行します。

```bash
$ composer create-project ray/di Ray.Di ~2.0@dev
$ git clone https://github.com/ray-di/Ray.Di.git
$ cd Ray.Di
$ phpunit
$ ./vendor/bin/phpunit
$ php docs/demo/run.php
```
```
11 changes: 3 additions & 8 deletions README.md
Expand Up @@ -861,27 +861,22 @@ $lister = $injector->getInstance(ListerInterface::class);

Various modules for `Ray.Di` are available at https://github.com/Ray-Di.

## Requirements ##

* PHP 5.6+
* hhvm

## Installation ##

The recommended way to install Ray.Di is through [Composer](https://github.com/composer/composer).

```bash
# Add Ray.Di as a dependency
$ composer require ray/di ~2.0
$ composer require ray/di ^2.0
```

## Testing Ray.Di ##

Here's how to install Ray.Di from source and run the unit tests and demos.

```bash
$ composer create-project ray/di:~2.0 Ray.Di
$ git clone https://github.com/ray-di/Ray.Di.git
$ cd Ray.Di
$ phpunit
$ ./vendor/bin/phpunit
$ php docs/demo/run.php
```
8 changes: 3 additions & 5 deletions composer.json
Expand Up @@ -16,14 +16,12 @@
}
],
"require": {
"php": ">=5.6.0",
"ray/aop": "^2.4.1",
"php": ">=7.0.0",
"ray/aop": "^2.5",
"ray/compiler": "^1.1.5"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^2.8",
"phpmd/phpmd": "^2.6"
"phpunit/phpunit": "^6.3.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion docs/demo/01-linked-binding-setter-injection.php
Expand Up @@ -4,7 +4,7 @@
use Ray\Di\Di\Inject;
use Ray\Di\Injector;

require __DIR__.'/bootstrap.php';
require __DIR__ . '/bootstrap.php';

interface FinderInterface
{
Expand Down
2 changes: 1 addition & 1 deletion docs/demo/01-linked-binding.php
Expand Up @@ -3,7 +3,7 @@
use Ray\Di\AbstractModule;
use Ray\Di\Injector;

require __DIR__.'/bootstrap.php';
require __DIR__ . '/bootstrap.php';

interface FinderInterface
{
Expand Down
5 changes: 1 addition & 4 deletions docs/demo/02-provider-binding.php
Expand Up @@ -36,9 +36,6 @@ class ModernMovieLister implements MovieListerInterface
{
public $finder;

/**
*
*/
public function __construct(FinderInterface $finder)
{
$this->finder = $finder;
Expand All @@ -55,7 +52,7 @@ public function __construct(InjectionPointInterface $ip)
}

/**
* @inheritDoc
* {@inheritdoc}
*/
public function get()
{
Expand Down
1 change: 0 additions & 1 deletion docs/demo/02b-named-by-named.php
Expand Up @@ -2,7 +2,6 @@

use Ray\Di\AbstractModule;
use Ray\Di\Di\Named;
use Ray\Di\Di\Qualifier;
use Ray\Di\Injector;

require __DIR__ . '/bootstrap.php';
Expand Down
4 changes: 2 additions & 2 deletions docs/demo/03-injection-point.php
Expand Up @@ -5,7 +5,7 @@
use Ray\Di\Injector;
use Ray\Di\ProviderInterface;

require __DIR__.'/bootstrap.php';
require __DIR__ . '/bootstrap.php';

interface FinderInterface
{
Expand Down Expand Up @@ -79,4 +79,4 @@ protected function configure()
$result = $movieLister->finder->find();
$works = ($result === 'search for [MovieLister]');

echo($works ? 'It works!' : 'It DOES NOT work!').PHP_EOL;
echo($works ? 'It works!' : 'It DOES NOT work!') . PHP_EOL;
2 changes: 1 addition & 1 deletion docs/demo/04-untarget-binding.php
Expand Up @@ -4,7 +4,7 @@
use Ray\Di\Injector;
use Ray\Di\Scope;

require __DIR__.'/bootstrap.php';
require __DIR__ . '/bootstrap.php';

class Finder
{
Expand Down
1 change: 0 additions & 1 deletion docs/demo/05b-constructor-binding-setter-injection.php
@@ -1,5 +1,4 @@
<?php

namespace Ray\Di\Demo;

use Ray\Di\AbstractModule;
Expand Down
2 changes: 1 addition & 1 deletion docs/demo/06-install.php
Expand Up @@ -3,7 +3,7 @@
use Ray\Di\AbstractModule;
use Ray\Di\Injector;

require __DIR__.'/bootstrap.php';
require __DIR__ . '/bootstrap.php';

interface FinderInterface
{
Expand Down
2 changes: 1 addition & 1 deletion docs/demo/07-assisted-injection.php
Expand Up @@ -4,7 +4,7 @@
use Ray\Di\Di\Assisted;
use Ray\Di\Injector;

require __DIR__.'/bootstrap.php';
require __DIR__ . '/bootstrap.php';

interface FinderInterface
{
Expand Down
16 changes: 8 additions & 8 deletions docs/demo/12-dependency-chain-error-message.php
Expand Up @@ -58,20 +58,20 @@ protected function configure()
$injector->getInstance(A::class);
} catch (Unbound $e) {
echo $e->getMessage();
// dependency 'B' with name '' used in12-dependency-chain-error-message.php:11
// dependency 'B' with name '' used in12-dependency-chain-error-message.php:11
echo PHP_EOL . '---------' . PHP_EOL;
echo $e;
// exception 'Ray\Di\Exception\Unbound' with message 'EInterface-'
// - dependency 'EInterface' with name '' used in12-dependency-chain-error-message.php:26
// - dependency 'D' with name '' used in12-dependency-chain-error-message.php:21
// - dependency 'C' with name '' used in12-dependency-chain-error-message.php:16
// - dependency 'B' with name '' used in12-dependency-chain-error-message.php:11
// ...
// exception 'Ray\Di\Exception\Unbound' with message 'EInterface-'
// - dependency 'EInterface' with name '' used in12-dependency-chain-error-message.php:26
// - dependency 'D' with name '' used in12-dependency-chain-error-message.php:21
// - dependency 'C' with name '' used in12-dependency-chain-error-message.php:16
// - dependency 'B' with name '' used in12-dependency-chain-error-message.php:11
// ...
echo PHP_EOL . '---------' . PHP_EOL;
do {
echo get_class($e) . ':' . $e->getMessage() . PHP_EOL;
} while ($e = $e->getPrevious());
// Ray\Di\Exception\Unbound:dependency 'B' with name '' used in12-dependency-chain-error-message.php:11
// Ray\Di\Exception\Unbound:dependency 'B' with name '' used in12-dependency-chain-error-message.php:11
// Ray\Di\Exception\Unbound:dependency 'C' with name '' used in12-dependency-chain-error-message.php:16
// Ray\Di\Exception\Unbound:dependency 'D' with name '' used in12-dependency-chain-error-message.php:21
// Ray\Di\Exception\Unbound:dependency 'EInterface' with name '' used in12-dependency-chain-error-message.php:26
Expand Down
24 changes: 15 additions & 9 deletions docs/demo/finder_module.php
Expand Up @@ -36,12 +36,16 @@ class DbFinder implements FinderInterface
public function __construct(DbInterface $db)
{
}
/** @Inject */public function setDb(DbInterface $db)
{
}
/** @Inject */public function setSorter(Sorter $sorter, Sorter $sorte2)
{
}

/** @Inject */
public function setDb(DbInterface $db)
{
}

/** @Inject */
public function setSorter(Sorter $sorter, Sorter $sorte2)
{
}
}

interface MovieListerInterface
Expand All @@ -53,9 +57,11 @@ class MovieLister implements MovieListerInterface
public function __construct(FinderInterface $finder)
{
}
/** @Inject */public function setFinder01(FinderInterface $finder, FinderInterface $finder1, FinderInterface $finder2)
{
}

/** @Inject */
public function setFinder01(FinderInterface $finder, FinderInterface $finder1, FinderInterface $finder2)
{
}
}

class FinderModule extends AbstractModule
Expand Down
19 changes: 8 additions & 11 deletions src/AbstractModule.php
@@ -1,4 +1,6 @@
<?php

declare(strict_types=1);
/**
* This file is part of the Ray.Di package.
*
Expand Down Expand Up @@ -40,8 +42,6 @@ public function __construct(

/**
* Install module
*
* @param AbstractModule $module
*/
public function install(AbstractModule $module)
{
Expand All @@ -50,8 +50,6 @@ public function install(AbstractModule $module)

/**
* Override module
*
* @param AbstractModule $module
*/
public function override(AbstractModule $module)
{
Expand All @@ -64,7 +62,7 @@ public function override(AbstractModule $module)
*
* @return Container
*/
public function getContainer()
public function getContainer() : Container
{
if (! $this->container) {
$this->activate();
Expand Down Expand Up @@ -113,7 +111,7 @@ public function bindPriorityInterceptor(AbstractMatcher $classMatcher, AbstractM
* @param string $sourceName Original binding name
* @param string $targetInterface Original interface
*/
public function rename($interface, $newName, $sourceName = Name::ANY, $targetInterface = '')
public function rename(string $interface, string $newName, string $sourceName = Name::ANY, string $targetInterface = '')
{
$targetInterface = $targetInterface ?: $interface;
$this->lastModule->getContainer()->move($interface, $sourceName, $targetInterface, $newName);
Expand All @@ -126,18 +124,17 @@ abstract protected function configure();

/**
* Bind interface
*
* @param string $interface
*
* @return Bind
*/
protected function bind($interface = '')
protected function bind(string $interface = '') : Bind
{
$bind = new Bind($this->getContainer(), $interface);

return $bind;
}

/**
* Activate bindings
*/
private function activate()
{
$this->container = new Container;
Expand Down
5 changes: 2 additions & 3 deletions src/AnnotatedClass.php
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of the Ray.Di package.
*
Expand All @@ -7,7 +8,6 @@
namespace Ray\Di;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Ray\Di\Di\PostConstruct;

final class AnnotatedClass
Expand All @@ -24,7 +24,6 @@ final class AnnotatedClass

public function __construct(AnnotationReader $reader)
{
AnnotationRegistry::registerFile(__DIR__ . '/DoctrineAnnotations.php');
$this->reader = $reader;
$this->injectionMethod = new AnnotatedClassMethods($reader);
}
Expand Down Expand Up @@ -64,7 +63,7 @@ public function getPostConstruct(\ReflectionClass $class)
$methods = $class->getMethods();
foreach ($methods as $method) {
/* @var $annotation PostConstruct|null */
$annotation = $this->reader->getMethodAnnotation($method, 'Ray\Di\Di\PostConstruct');
$annotation = $this->reader->getMethodAnnotation($method, PostConstruct::class);
if ($annotation instanceof PostConstruct) {
return $method;
}
Expand Down

0 comments on commit 8c01f4e

Please sign in to comment.