Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Refactoring of the Dependency Injection component (v3) #6

Merged
merged 27 commits into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
88ea6eb
Refactor for version 3
tux-rampage Nov 3, 2017
c63c126
remove old phpunit bootstrap
stefanotorresi Oct 6, 2016
d09eab5
update travis config
stefanotorresi Oct 6, 2016
835c79b
Update composer deps
tux-rampage Nov 4, 2017
1323c64
Remove src_dir
tux-rampage Nov 4, 2017
a28a8f0
Style fixes
tux-rampage Nov 4, 2017
aec7018
Add php 7.1 to travis build
tux-rampage Nov 4, 2017
4590ad0
Add composer scripts
tux-rampage Nov 4, 2017
9bdc845
Remove ignore-platform-reqs
tux-rampage Nov 4, 2017
187773c
Drop support for hhvm and php < 5.6
tux-rampage Nov 9, 2017
d4056ed
Remove support code for PHP < 7.1
tux-rampage Nov 9, 2017
8f3872f
Update PHPUnit dependency
tux-rampage Nov 9, 2017
ac5124c
Upgrade PHPUnit to version 6.x
tux-rampage Nov 9, 2017
d9452bf
Upgrade to PHP 7.1
tux-rampage Nov 9, 2017
60d0d83
(wip) Migration guide
tux-rampage Nov 10, 2017
b49ca75
Update changelog
tux-rampage Nov 13, 2017
2304db2
Restore legacy docs
tux-rampage Nov 13, 2017
020f099
Add legacy config for migration from v2 to v3
tux-rampage Nov 13, 2017
2cedc6e
Improve migration guide
tux-rampage Nov 13, 2017
08eba0f
Improve psr container usage docs
tux-rampage Nov 13, 2017
7b0ecb5
Fix container reference from Interop to PSR
tux-rampage Nov 14, 2017
22b6ba7
Add descriptive comment
tux-rampage Nov 14, 2017
5eb94b9
Switch to zendframework/zend-coding-standard
tux-rampage Nov 14, 2017
79a4b2f
Fix style violations
tux-rampage Nov 14, 2017
a2190cc
Fix mkdocs.yml
tux-rampage Nov 14, 2017
da944d7
Remove DEPLOY_DOCS from travis config
tux-rampage Nov 14, 2017
caf46ff
Fix typo instanciator -> instantiator
tux-rampage Nov 14, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
coverage_clover: clover.xml
json_path: coveralls-upload.json
src_dir: src
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ tmp/
zf-mkdoc-theme/

clover.xml
composer.lock
coveralls-upload.json
phpunit.xml
vendor
1 change: 0 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $config->fixers(
'braces',
'duplicate_semicolon',
'elseif',
'empty_return',
'encoding',
'eof_ending',
'function_call_space',
Expand Down
74 changes: 47 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,57 @@ cache:

env:
global:
- CODE_VERSION="^3.0"
- SITE_URL: https://zendframework.github.io/zend-di
- GH_USER_NAME: "Matthew Weier O'Phinney"
- GH_USER_EMAIL: matthew@weierophinney.net
- GH_REF: github.com/zendframework/zend-di.git
- COMPOSER_ARGS="--no-interaction"
- SITE_URL="https://zendframework.github.io/zend-di"
- GH_USER_NAME="Matthew Weier O'Phinney"
- GH_USER_EMAIL="matthew@weierophinney.net"
- GH_REF="github.com/zendframework/zend-di.git"
- secure: "nhJ+hLBlGBu5P8udHwGk5eF6mUKubWF5ID+FXHcP86puQzprYIR7Trdv2u4N9M5AKTPKg3Me1QFqR2WgbNyyVWrtyGovCOAFMeZiMBExpNXONoVaAXGlsXCZe6a85Wn54HXeBjuJMKDNlt6LiJqteMf0axyk44h1V/rTbWK5ALKPy2kuILLZgVyEYtwVmrELBduvqR3uHx5PjuGCeJP8LOICuuu7m2JBhWqUBse89vYqhalvXsIButjSrxPmwgSpjOt7zksf//5HwoY1A83+cb6LfR/ZBe1bOgLtfjBBtYyjwL3DsnYPWecfd4qgO69oHT5ZhxOfzLxjSlvtPK0SrH8WEIcFjUnpcGeqyOnydq7HgEC9J6Fnq1VwKLI2VbM/+qQQqvlVDYAQuXvb/YG0sV0x0ad9zEtJ7QPOY8C6ygGm41+lERd39VzQqq5w8IkjXeUAhWzX+ts7w2aIZ3uPYCHoqmvV9DK44/fkmtFHsJU9guDcW1GU/QT91DGVSNMP0qZsZmw6H/kQtDH672GM4xQzv2FgIyqzSY0oggQwtG5y1XkPCr+X2VsSvtTXuihi+ru9g7iqEXU+2aUOyMfB3xnZQ5qiiQUpaatWO/KzRfp/h3b7InPne+nYTrCDfkjJ8N6bypkXv8D6EC/a4zK3XaaMyn0rQ4yPcd99BjHRIOs="

matrix:
fast_finish: true
include:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- php: 5.5
- php: 5.6
env:
- CODE_VERSION="^2.6"
- DEPS=lowest
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- DEPS=locked
- TEST_COVERAGE=true
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
- PATH="$HOME/.local/bin:$PATH"
- php: 5.6
env:
- CODE_VERSION="^2.6"
- DEPS=latest
- php: 7
env:
- DEPS=lowest
- php: 7
env:
- DEPS=locked
- CHECK_CS=true
- php: 7
env:
- CODE_VERSION="^2.6"
- DEPS=latest
- php: 7.1
env:
- DEPS=lowest
- php: 7.1
env:
- DEPS=locked
- CHECK_CS=true
- php: 7.1
env:
- DEPS=latest
- php: hhvm
env:
- DEPS=lowest
- php: hhvm
env:
- DEPS=locked
- php: hhvm
env:
- CODE_VERSION="^2.6"
- DEPS=latest
allow_failures:
- php: hhvm

Expand All @@ -55,22 +74,23 @@ notifications:
email: false

before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
- composer require --no-update "zendframework/zend-code:$CODE_VERSION"
- travis_retry composer self-update
- if [[ $TRAVIS_PHP_VERSION != "hhvm" && $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS satooshi/php-coveralls:^1.0 ; fi
- travis_retry composer install $COMPOSER_ARGS
- composer show

script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi

after_success:
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $CHECK_CS == 'true' ]]; then composer cs-check ; fi
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then travis_retry curl -sSL https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh | bash ; fi

after_script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer upload-coverage ; fi

after_success:
- if [[ $DEPLOY_DOCS == "true" ]]; then ./zf-mkdoc-theme/deploy.sh ; fi
54 changes: 54 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,60 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 3.0.0 - WIP

### Added

- A definition compiler which will utilize `RuntimeDefinition` for Consistency to compile.
- Setters without parameters will not be created by `RuntimeDefinition` (and therefore not accidentially called)
- `Zend\Di\ServiceLocator` now implements `Interop\Container\ContainerInterface` and utilizes the dependency injector to be completely exchangible
- `Zend\Di\Container` as implementation of `Interop\Container\ContainerInterface`
* Provides the dependency injector as standalone container
* Provides `build()` to be signature compatible with `Zend\ServiceManager\ServiceManager`
- `Zend\Di\DependencyInjectionInterface`
* Added `canInstanciate()` method to check the injectors ability to instanciate a type
* Added `injectDependencies()` method to perform injections on existing instances
- `Zend\Di\DependencyInjector`
* Provides instanciator to create new instances
* Is used by `Zend\Di\DefaultContainer`
* Utilizes `Zend\Di\Resolver\DependencyResolverInterface`
- Moved strategies to resolve method parameters to `Zend\Di\Resolver`
- PHP7 compatible introspection strategies
- Classes to wrap value and type injections
- Support for zend-component-installer
- An interface for the di configuration
- Resolver greedyness per type
* Option to enable eager method resolving for each type configuration
* Option to make eager resolving strict
- Code generator for generating a pre-resolved dependency injector

### Deprecated

- Nothing

### Removed

- `Zend\Di\Defintion\CompilerDefinition` in favour of the `Zend\Di\Definition\Compiler` implementation, which creates an array definition
- `Zend\Di\InstanceManager` in favour of `Interop\Container\ContainerInterface`
- `Zend\Di\ServiceLocator`, `Zend\Di\ServiceLocatorInterface` and `Zend\Di\LocatorInterface` in favour of `Interop\Container\ContainerInterface`
- `Zend\Di\Di` is removed in favour of `Zend\Di\Container`
- `Zend\Di\DefintionList` moved to `Zend\Di\Defintion\DefinitionList`
- `Zend\Di\Definition\BuilderDefinition`
* Removed `createClassesFromArray()` - Obsolete since there is an array definition
- `Zend\Di\DependencyInjectionInterface`
* No longer implements `LocatorInterface`
- Parameters passed to `newInstance()` will only be used for constructing the requested class and no longer be forwarded to nested instanciations.
- `get()` does no longer support a `$parameters` array, `newInstance()` still does
- Separated the definition from the configuration.
- Removed always auto wiring for eager methods.
* Only configured injections will be performed automatically by default.
* Eager resolving must be enabled

### Fixed

- [#6](https://github.com/zendframework/zend-di/pull/6) Full ZF3 Compatibility


## 2.7.0 - TBD

### Added
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@
[![Build Status](https://secure.travis-ci.org/zendframework/zend-di.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-di)
[![Coverage Status](https://coveralls.io/repos/zendframework/zend-di/badge.svg?branch=master)](https://coveralls.io/r/zendframework/zend-di?branch=master)

`Zend\Di` is an example of an Inversion of Control (IoC) container. IoC containers
`Zend\Di` provides auto wiring to implement Inversion of Control (IoC) containers. IoC containers
are widely used to create object instances that have all dependencies resolved
and injected. Dependency Injection containers are one form of IoC – but not the
only form.

`Zend\Di` is designed to be simple, fast and reusable. It provides the following features:

* Constructor injection
* Autowiring:
- Recursively through all dependencies
- With configured type preferences
- with configured injections
- With injections passed in the create() call
* Code generators to create factories usable by other IoC containers like Zend\ServiceManager

It does __not__ provide:

* Setter, interface, property or any other injection method than constructor injection
* Support for factories
* Declaring shared/unshared instances
- the injector always creates new instances
- the default container always shares instances
* Support for variadic arguments in __construct

If you need these features combine it with another IoC container like [`Zend\ServiceManager`](https://docs.zendframework.com/zend-servicemanager/).


- File issues at https://github.com/zendframework/zend-di/issues
- Documentation is at https://zendframework.github.io/zend-di/


77 changes: 50 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,61 @@
{
"name": "zendframework/zend-di",
"description": " ",
"license": "BSD-3-Clause",
"keywords": [
"name" : "zendframework/zend-di",
"description" : " ",
"require" : {
"php" : "^5.6 || ^7.0",
"psr/container" : "^1.0",
"zendframework/zend-stdlib" : "^2.7 || ^3.0"
},
"require-dev" : {
"fabpot/php-cs-fixer" : "1.7.*",
"phpunit/PHPUnit" : "^5.0",
"zendframework/zend-code" : "^2.6 || ^3.0",
"zendframework/zend-servicemanager" : "^3.0"
},
"conflict": {
"zendframework/zend-servicemanager-di": "*"
},
"license" : "BSD-3-Clause",
"keywords" : [
"zf2",
"di"
],
"homepage": "https://github.com/zendframework/zend-di",
"autoload": {
"psr-4": {
"Zend\\Di\\": "src/"
"autoload-dev" : {
"psr-4" : {
"ZendTest\\Di\\" : "test/"
}
},
"require": {
"php": "^5.5 || ^7.0",
"container-interop/container-interop": "^1.1",
"zendframework/zend-code": "^2.6 || ^3.0",
"zendframework/zend-stdlib": "^2.7 || ^3.0"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "2.6-dev",
"dev-develop": "2.7-dev"
"extra" : {
"branch-alias" : {
"dev-master" : "2.6-dev",
"dev-develop" : "2.7-dev"
},
"zf" : {
"component" : "Zend\\Di",
"config-provider" : "Zend\\Di\\ConfigProvider"
}
},
"autoload-dev": {
"psr-4": {
"ZendTest\\Di\\": "test/"
"minimum-stability" : "dev",
"autoload" : {
"psr-4" : {
"Zend\\Di\\" : "src/"
}
},
"suggest" : {
"zendframework/zend-servicemanager" : "An IoC container without auto wiring capabilities",
"zendframework/zend-code" : "Required if you want to generate code"
},
"homepage" : "https://github.com/zendframework/zend-di",
"prefer-stable" : true,
"scripts": {
"check": [
"@cs-check",
"@test"
],
"upload-coverage": "coveralls -v",
"cs-check": "php-cs-fixer --version && php-cs-fixer fix -v --diff --dry-run",
"cs-fix": "php-cs-fixer fix -v",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
}
}