Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- "8.3"
- "8.4"
- "8.5"
- "8.6"

steps:
- name: Checkout
Expand Down Expand Up @@ -49,6 +50,6 @@ jobs:
run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml

- name: Send code coverage report to Codecov.io
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
7 changes: 4 additions & 3 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
name: Run PHPStan checks

jobs:
mutation:
static-analysis:
name: PHPStan ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}
Expand All @@ -18,6 +18,7 @@ jobs:
- "8.3"
- "8.4"
- "8.5"
- "8.6"

steps:
- name: Checkout
Expand All @@ -27,7 +28,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: pcov
coverage: none
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: composer:v2, cs2pr

Expand All @@ -46,4 +47,4 @@ jobs:
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run static analysis with PHPStan
run: vendor/bin/phpstan analyse
run: vendor/bin/phpstan analyse --memory-limit 1G
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ composer.phar
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock
.phpunit.result.cache
.phpunit.cache
.phpcs-cache
/documentation-theme/
/docs/html/
3 changes: 3 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"ignore_php_platform_requirements": {
"8.6": true
},
"backwardCompatibilityCheck": true
}
97 changes: 95 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,96 @@
## 1.0.0 - 2024-06-06
# Changelog

Initial tagged release
All notable changes to this project are documented in this file.

## 2.0.0 - TBD

### Added

- PHP 8.6 support
- `RuntimeException::notInstantiable()`, `dependencyNotInstantiable()`, `argumentCountMismatch()`, `invalidService()` and `missingPackage()`
- `InvalidArgumentException::emptySegment()`
- Documentation for version 2, including an upgrade guide

### Changed

- `doctrine/orm` moved from `require` to `suggest`; applications using `AttributedRepositoryFactory` must require it, and versions below 2.9 or from 4.0 conflict
- `psr/container` requirement raised to `^1.1 || ^2.0`
- `AttributedServiceFactory::readKeysFromArray()` takes the full service key as its third parameter
- PHPUnit 12.5 and PHPStan level 8; the test suite fails on notices, warnings, deprecations and risky tests

### Deprecated

- Nothing.

### Removed

- `AttributedServiceFactory::$originalKey`

### Fixed

- Requesting an abstract class, an enum or a class with a non-public constructor throws `RuntimeException` instead of a PHP `Error`
- An unregistered dependency that cannot be instantiated without arguments throws `RuntimeException` instead of `ArgumentCountError` or `Error`
- The number of `#[Inject]` entries is checked against the constructor; extra entries were silently ignored
- Empty dot-notation segments throw `InvalidArgumentException` instead of reading the `''` key
- `AttributedRepositoryFactory` checks the type of the entity manager service
- `AttributedRepositoryFactory` names the missing package when `doctrine/orm` is not installed

## 1.4.1 - 2026-09-16

### Fixed

- FAQ menu entry ([#14](https://github.com/dotkernel/dot-dependency-injection/pull/14))

## 1.4.0 - 2026-09-16

### Changed

- `#[Entity]` targets classes and `#[Inject]` targets methods only ([#13](https://github.com/dotkernel/dot-dependency-injection/pull/13))
- Documentation expanded with the "Attributes vs. factories" and FAQ pages ([#13](https://github.com/dotkernel/dot-dependency-injection/pull/13))

### Removed

- PHP 8.2 support ([#13](https://github.com/dotkernel/dot-dependency-injection/pull/13))

### Fixed

- A configuration value of `null` was treated as a missing key ([#13](https://github.com/dotkernel/dot-dependency-injection/pull/13))
- Dot-notation paths continuing past a scalar were silently truncated ([#13](https://github.com/dotkernel/dot-dependency-injection/pull/13))
- `AttributedRepositoryFactory` returned a repository of the wrong class when the entity did not declare `repositoryClass` ([#13](https://github.com/dotkernel/dot-dependency-injection/pull/13))
- An `#[Entity]` attribute naming a missing class was not reported ([#13](https://github.com/dotkernel/dot-dependency-injection/pull/13))

## 1.3.0 - 2025-10-30

### Added

- PHP 8.4 and 8.5 support ([#11](https://github.com/dotkernel/dot-dependency-injection/pull/11))

### Removed

- PHP 8.1 support ([#11](https://github.com/dotkernel/dot-dependency-injection/pull/11))

## 1.2.0 - 2025-03-04

### Changed

- Psalm replaced with PHPStan ([#9](https://github.com/dotkernel/dot-dependency-injection/pull/9))

## 1.1.1 - 2025-01-28

### Changed

- Psalm 6.x ([#7](https://github.com/dotkernel/dot-dependency-injection/pull/7))

## 1.1.0 - 2024-10-22

### Added

- PHP 8.4 support ([#5](https://github.com/dotkernel/dot-dependency-injection/pull/5))

### Changed

- `laminas/laminas-coding-standard` 3.x

## 1.0.0 - 2024-06-07

Initial tagged release.
47 changes: 31 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,48 @@
Instead of a hand-written factory class per service, you declare a class's dependencies with the `#[Inject]` attribute on its constructor - or a repository's entity with `#[Entity]` - and register one of the two reusable factories this package ships.
That removes an entire category of boilerplate files from a project and keeps the dependency list next to the constructor it feeds.

See [Attributes vs. factories](https://docs.dotkernel.org/dot-dependency-injection/v1/attributes-vs-factories/) for the full comparison and the trade-offs.
See [Attributes vs. factories](https://docs.dotkernel.org/dot-dependency-injection/v2/attributes-vs-factories/) for the full comparison and the trade-offs.

## Documentation

Documentation is available at: <https://docs.dotkernel.org/dot-dependency-injection/>.

- [Installation](https://docs.dotkernel.org/dot-dependency-injection/v1/installation/)
- [Configuration](https://docs.dotkernel.org/dot-dependency-injection/v1/configuration/)
- [Attributes vs. factories](https://docs.dotkernel.org/dot-dependency-injection/v1/attributes-vs-factories/)
- [Factories](https://docs.dotkernel.org/dot-dependency-injection/v1/factories/)
- [Inject class dependencies](https://docs.dotkernel.org/dot-dependency-injection/v1/factories/service/)
- [Inject entity repositories](https://docs.dotkernel.org/dot-dependency-injection/v1/factories/repository/)
- [FAQ](https://docs.dotkernel.org/dot-dependency-injection/v1/faq/)
- [Installation](https://docs.dotkernel.org/dot-dependency-injection/v2/installation/)
- [Configuration](https://docs.dotkernel.org/dot-dependency-injection/v2/configuration/)
- [Attributes vs. factories](https://docs.dotkernel.org/dot-dependency-injection/v2/attributes-vs-factories/)
- [Factories](https://docs.dotkernel.org/dot-dependency-injection/v2/factories/)
- [Inject class dependencies](https://docs.dotkernel.org/dot-dependency-injection/v2/factories/service/)
- [Inject entity repositories](https://docs.dotkernel.org/dot-dependency-injection/v2/factories/repository/)
- [FAQ](https://docs.dotkernel.org/dot-dependency-injection/v2/faq/)
- [Upgrading from 1.x](https://docs.dotkernel.org/dot-dependency-injection/v2/upgrading/)

## Versions

| Version | Branch | PHP | Status | Documentation |
| --- | --- | --- | --- | --- |
| 2.x | `2.0` | 8.3, 8.4, 8.5, 8.6 | active | [v2](https://docs.dotkernel.org/dot-dependency-injection/v2/overview/) |
| 1.x | `1.0` | 8.3, 8.4, 8.5 | supported | [v1](https://docs.dotkernel.org/dot-dependency-injection/v1/overview/) |

## Badges

![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-dependency-injection)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-dependency-injection/1.4.1)
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-dependency-injection/2.0.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/blob/1.0/LICENSE.md)
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-dependency-injection)](https://github.com/dotkernel/dot-dependency-injection/blob/2.0/LICENSE.md)

[![Build Static](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/continuous-integration.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/continuous-integration.yml)
[![Build Static](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/continuous-integration.yml/badge.svg?branch=2.0)](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/dot-dependency-injection/graph/badge.svg?token=DayAoD2Oj6)](https://codecov.io/gh/dotkernel/dot-dependency-injection)
[![docs-build](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/docs-build.yml/badge.svg)](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/docs-build.yml)
[![PHPStan](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/static-analysis.yml)
[![PHPStan](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/static-analysis.yml/badge.svg?branch=2.0)](https://github.com/dotkernel/dot-dependency-injection/actions/workflows/static-analysis.yml)

## Requirements

- PHP 8.3, 8.4 or 8.5
- a PSR-11 container, usually `laminas/laminas-servicemanager`
- `doctrine/orm` ^2.9 || ^3.0, if you use `AttributedRepositoryFactory`
- PHP 8.3, 8.4, 8.5 or 8.6
- a PSR-11 container (`psr/container` ^1.1 || ^2.0), usually `laminas/laminas-servicemanager`
- `doctrine/orm` ^2.9 || ^3.0, installed by your application, if you use `AttributedRepositoryFactory`

## Installation

Expand Down Expand Up @@ -94,7 +102,8 @@ public function __construct(

The `#[Inject]` attribute is telling `AttributedServiceFactory` to inject the services specified as parameters, in the same order as the constructor parameters.
Valid service names should be provided, as registered in the service manager.
A name that is not registered in the container, but is an existing class, is instantiated directly.
A name that is not registered in the container, but is a class that can be instantiated without arguments, is instantiated directly.
The number of entries is checked against the constructor; trailing parameters with a default value may be left out.

A class without a constructor does not need the attribute.

Expand All @@ -113,6 +122,12 @@ which will inject `$container->get('config')['debug'];`.

### Using the AttributedRepositoryFactory

`AttributedRepositoryFactory` needs `doctrine/orm`, which this package does not install:

```shell
composer require doctrine/orm
```

You can register doctrine repositories and inject them using the `AttributedRepositoryFactory` as below:

```php
Expand Down
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

| Version | Supported | PHP Version |
| --- | --- | --- |
| 2.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-dependency-injection/2.0.0) |
| 1.x | :white_check_mark: | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-dependency-injection/1.4.1) |

## Reporting Potential Security Issues
Expand Down
14 changes: 10 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@
"service"
],
"require": {
"php": "~8.3.0 || ~8.4.0 || ~8.5.0",
"doctrine/orm": "^2.9 || ^3.0",
"psr/container": "^1.0 || ^2.0"
"php": "~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0",
"psr/container": "^1.1 || ^2.0"
},
"require-dev": {
"doctrine/orm": "^2.9 || ^3.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doctrine components are used in src/Factory/AttributedRepositoryFactory.php.
So. why did this move under require-dev? Is it to make the package usable without Doctrine?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's to run some tests (dev mode), otherwise you need it if you use the repository factory
if you only use #[Inject], composer won't install ORM, DBAL and their dependencies

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had this discussion before with the team - let's keep it open until @arhimede confirms either way.

"laminas/laminas-coding-standard": "^3.0",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.5"
"phpunit/phpunit": "^12.5"
},
"suggest": {
"doctrine/orm": "Required to use AttributedRepositoryFactory"
},
"conflict": {
"doctrine/orm": "<2.9 || >=4.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading
Loading