Skip to content

Commit

Permalink
Merge c50b0d6 into 3bde189
Browse files Browse the repository at this point in the history
  • Loading branch information
philipobenito committed Jul 23, 2018
2 parents 3bde189 + c50b0d6 commit 637c348
Show file tree
Hide file tree
Showing 54 changed files with 2,110 additions and 1,022 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Expand Up @@ -19,7 +19,7 @@ checks:
tools:
external_code_coverage:
timeout: 600
runs: 3
runs: 2
php_analyzer: true
php_code_coverage: false
php_code_sniffer:
Expand Down
8 changes: 2 additions & 6 deletions .travis.yml
@@ -1,12 +1,8 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

matrix:
fast_finish: true
Expand All @@ -25,5 +21,5 @@ script:
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_success:
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- wget https://scrutinizer-ci.com/ocular.phar; fi
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
26 changes: 24 additions & 2 deletions CHANGELOG.md
Expand Up @@ -2,10 +2,27 @@

All Notable changes to `League\Container` will be documented in this file

## 2.3.0
## Unreleased

### Added
- Now implementation of the PSR-11.
- Service providers can now be pulled from the container if they are registered.
- Definition logic now handled by aggregate for better separation.
- Now able to add tags to a definition to return an array of items containing that tag.

### Changed
- Updated minimum PHP requirements to 7.0.
- Now depend directly on PSR-11 interfaces, including providing PSR-11 exceptions.
- Refactored inflector logic to accept type on construction and use generator to iterate.
- Refactored service provider logic with better separation and performance.
- Merged service provider signature logic in to one interface and abstract.
- Heavily simplified definition logic providing more control to user.

## 2.4.1

### Fixed
- Ensures `ReflectionContainer` converts class name in array callable to object.

## 2.4.0

### Changed
- Can now wrap shared objects as `RawArgument`.
Expand All @@ -17,6 +34,11 @@ All Notable changes to `League\Container` will be documented in this file
- Unused imports removed.
- Unreachable arguments no longer passed.

## 2.3.0

### Added
- Now implementation of the PSR-11.

## 2.2.0

### Changed
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -10,6 +10,8 @@

[![SensioLabsInsight](https://insight.sensiolabs.com/projects/ad6b4c3e-8f93-4968-8dd3-391d39a4c3c2/big.png)](https://insight.sensiolabs.com/projects/ad6b4c3e-8f93-4968-8dd3-391d39a4c3c2)

**Warning! `3.x` branch is in active development and is in no way ready for production!**

This package is compliant with [PSR-1], [PSR-2] and [PSR-4]. If you notice compliance oversights,
please send a patch via pull request.

Expand All @@ -32,7 +34,6 @@ The following versions of PHP are supported by this version.

* PHP 7.0
* PHP 7.1
* HHVM

## Documentation

Expand Down
11 changes: 9 additions & 2 deletions composer.json
Expand Up @@ -22,10 +22,11 @@
],
"require": {
"php": "^7.0",
"container-interop/container-interop": "^1.2"
"psr/container": "^1.0"
},
"require-dev": {
"phpunit/phpunit" : "^6.0"
"phpunit/phpunit" : "^6.0",
"squizlabs/php_codesniffer": "^3.3"
},
"provide": {
"psr/container-implementation": "^1.0"
Expand All @@ -38,8 +39,14 @@
"League\\Container\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"League\\Container\\Test\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-3.x": "3.x-dev",
"dev-2.x": "2.x-dev",
"dev-1.x": "1.x-dev"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/3.x/auto-wiring.md
Expand Up @@ -5,7 +5,7 @@ title: Auto Wiring

# Auto Wiring

> Note: Auto wiring is turned off by default but can be turned on by registering the `ReflectionContainer` as a container delegate. Read below and see the [documentation on delegates](/delegates/).
> Note: Auto wiring is turned off by default but can be turned on by registering the `ReflectionContainer` as a container delegate. Read below and see the [documentation on delegate containers](/3.x/delegate-containers/).
Container has the power to automatically resolve your objects and all of their dependencies recursively by inspecting the type hints of your constructor arguments. Unfortunately, this method of resolution has a few small limitations but is great for smaller apps. First of all, you are limited to constructor injection and secondly, all injections must be objects.

Expand Down
10 changes: 5 additions & 5 deletions docs/3.x/delegates.md → docs/3.x/delegate-containers.md
@@ -1,20 +1,20 @@
---
layout: default
title: Delegates
title: Delegate Containers
---

# Delegates
# Delegate Containers

Delegates are a way to allow you to register one or multiple backup containers that will be used to attempt the resolution of services when they cannot be resolved via this container.
Delegate containers are a way to allow you to register one or multiple backup containers that will be used to attempt the resolution of services when they cannot be resolved via this container.

A delegate must be an implementation of the [container-interop](https://github.com/container-interop/container-interop) project and can be registered using the `delegate` method.
A delegate must be a [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md) implementation and can be registered using the `delegate` method.

~~~ php
<?php

namespace Acme\Container;

use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;

class DelegateContainer implements ContainerInterface
{
Expand Down
6 changes: 3 additions & 3 deletions docs/3.x/factory-closures.md → docs/3.x/factories.md
@@ -1,11 +1,11 @@
---
layout: default
title: Factory Closures
title: Factories
---

# Factory Closures
# Factories

The most performant way to use Container is to use factory closures/anonymous functions to build your objects. By registering a closure that returns a fully configured object, when resolved, your object will be lazy loaded as and when you need access to it.
The most performant way to use Container is to use factory functions to build your objects. By registering a closure that returns a fully configured object, when resolved, your object will be lazy loaded as and when you need access to it.

Consider an object `Foo` that depends on another object `Bar`. The following will return an instance of `Foo` containing a member `bar` that contains an instance of `Bar`.

Expand Down
15 changes: 4 additions & 11 deletions docs/_data/menu.yml
Expand Up @@ -6,17 +6,10 @@
Constructor Injection: '/3.x/constructor-injection/'
Setter Injection: '/3.x/setter-injection/'
Factories: '/3.x/factories/'
Definitions:
Introduction: '/3.x/definitions-introduction/'
Usage: '/3.x/definitions-usage/'
Service Providers:
Introduction: '/3.x/service-providers-introduction/'
Usage: '/3.x/service-providers-usage/'
Inflectors:
Introduction: '/3.x/inflectors-introduction/'
Usage: '/3.x/inflectors-usage/'
Delegates:
Containers: '/3.x/delegate-containers/'
Concepts:
Service Providers: '/3.x/service-providers/'
Inflectors: '/3.x/inflectors/'
Delegate Containers: '/3.x/delegate-containers/'
Auto Wiring: '/3.x/auto-wiring/'
'2.x':
Getting Started:
Expand Down
18 changes: 10 additions & 8 deletions src/Argument/ArgumentResolverInterface.php
@@ -1,26 +1,28 @@
<?php
<?php declare(strict_types=1);

namespace League\Container\Argument;

use League\Container\ImmutableContainerAwareInterface;
use League\Container\ContainerAwareInterface;
use ReflectionFunctionAbstract;

interface ArgumentResolverInterface extends ImmutableContainerAwareInterface
interface ArgumentResolverInterface extends ContainerAwareInterface
{
/**
* Resolve an array of arguments to their concrete implementations.
*
* @param array $arguments
* @param array $arguments
*
* @return array
*/
public function resolveArguments(array $arguments);
public function resolveArguments(array $arguments): array;

/**
* Resolves the correct arguments to be passed to a method.
*
* @param \ReflectionFunctionAbstract $method
* @param array $args
* @param \ReflectionFunctionAbstract $method
* @param array $args
*
* @return array
*/
public function reflectArguments(ReflectionFunctionAbstract $method, array $args = []);
public function reflectArguments(ReflectionFunctionAbstract $method, array $args = []): array;
}
28 changes: 19 additions & 9 deletions src/Argument/ArgumentResolverTrait.php
@@ -1,9 +1,10 @@
<?php
<?php declare(strict_types=1);

namespace League\Container\Argument;

use League\Container\Exception\NotFoundException;
use League\Container\Exception\{ContainerException, NotFoundException};
use League\Container\ReflectionContainer;
use Psr\Container\ContainerInterface;
use ReflectionFunctionAbstract;
use ReflectionParameter;

Expand All @@ -12,24 +13,33 @@ trait ArgumentResolverTrait
/**
* {@inheritdoc}
*/
public function resolveArguments(array $arguments)
public function resolveArguments(array $arguments): array
{
foreach ($arguments as &$arg) {
if ($arg instanceof RawArgumentInterface) {
$arg = $arg->getValue();
continue;
}

if ($arg instanceof ClassNameInterface) {
$arg = $arg->getValue();
}

if (! is_string($arg)) {
continue;
}

$container = $this->getContainer();
$container = null;

if (is_null($container) && $this instanceof ReflectionContainer) {
$container = $this;
try {
$container = $this->getContainer();
} catch (ContainerException $e) {
if ($this instanceof ReflectionContainer) {
$container = $this;
}
}


if (! is_null($container) && $container->has($arg)) {
$arg = $container->get($arg);

Expand All @@ -47,7 +57,7 @@ public function resolveArguments(array $arguments)
/**
* {@inheritdoc}
*/
public function reflectArguments(ReflectionFunctionAbstract $method, array $args = [])
public function reflectArguments(ReflectionFunctionAbstract $method, array $args = []): array
{
$arguments = array_map(function (ReflectionParameter $param) use ($method, $args) {
$name = $param->getName();
Expand Down Expand Up @@ -76,7 +86,7 @@ public function reflectArguments(ReflectionFunctionAbstract $method, array $args
}

/**
* @return \League\Container\ContainerInterface
* @return \Psr\Container\ContainerInterface
*/
abstract public function getContainer();
abstract public function getContainer(): ContainerInterface;
}
29 changes: 29 additions & 0 deletions src/Argument/ClassName.php
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);

namespace League\Container\Argument;

class ClassName implements ClassNameInterface
{
/**
* @var string
*/
protected $value;

/**
* Construct.
*
* @param string $value
*/
public function __construct(string $value)
{
$this->value = $value;
}

/**
* {@inheritdoc}
*/
public function getValue(): string
{
return $this->value;
}
}
13 changes: 13 additions & 0 deletions src/Argument/ClassNameInterface.php
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace League\Container\Argument;

interface ClassNameInterface
{
/**
* Return the class name.
*
* @return string
*/
public function getValue(): string;
}
6 changes: 4 additions & 2 deletions src/Argument/RawArgument.php
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace League\Container\Argument;

Expand All @@ -10,7 +10,9 @@ class RawArgument implements RawArgumentInterface
protected $value;

/**
* {@inheritdoc}
* Construct.
*
* @param mixed $value
*/
public function __construct($value)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Argument/RawArgumentInterface.php
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace League\Container\Argument;

Expand Down

0 comments on commit 637c348

Please sign in to comment.