Skip to content

Commit

Permalink
Require symfony/dependency-injection v6.0
Browse files Browse the repository at this point in the history
Since symfony/dependency-injection v6.0 requires PHP 8.0+,
also update the codebase.
  • Loading branch information
olvlvl committed May 22, 2022
1 parent 67b5684 commit 07c6c00
Show file tree
Hide file tree
Showing 24 changed files with 224 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ insert_final_newline = true
indent_style = space
indent_size = 4

[*.yml]
[{*.yaml,*yml,*.neon}]
indent_size = 2

[Makefile]
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ on:
- pull_request

jobs:
phpstan:
name: PHPCS
phpcs:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "8.0"
ini-values: memory_limit=-1
tools: composer:v2, phpcs

- name: Run PHPCS
run: phpcs
tools: phpcs, cs2pr
- name: Run PHP Code Sniffer
run: phpcs -q --report=checkstyle | cs2pr
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
phpstan:
name: PHPStan
name: phpstan
runs-on: ubuntu-20.04
steps:
- name: Checkout
Expand All @@ -28,5 +28,5 @@ jobs:
- name: Install dependencies
run: composer install --no-interaction --no-progress

- name: Run PHPStan
- name: Analyze
run: vendor/bin/phpstan
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ jobs:
strategy:
matrix:
php-version:
- "7.2"
- "7.4"
- "8.0"
- "8.1"
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -40,7 +39,7 @@ jobs:
run: make test-coveralls

- name: Upload code coverage
if: ${{ matrix.php-version == '7.2' }}
if: ${{ matrix.php-version == '8.0' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down
7 changes: 3 additions & 4 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ representative at an online or offline event.

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[INSERT CONTACT METHOD].
<olivier.laviale@gmail.com>.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down Expand Up @@ -119,16 +119,15 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].

Community Impact Guidelines were inspired by
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].

For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
at [https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations

26 changes: 18 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
ARG PHP_VERSION
FROM php:${PHP_VERSION}-alpine
FROM php:${PHP_VERSION}-cli-buster

RUN apk add --no-cache make $PHPIZE_DEPS &&\
RUN apt-get update && \
apt-get install -y autoconf pkg-config && \
pecl channel-update pecl.php.net && \
pecl install xdebug &&\
docker-php-ext-enable xdebug &&\
echo $'\
docker-php-ext-enable opcache xdebug

RUN echo '\
xdebug.client_host=host.docker.internal\n\
xdebug.mode=develop\n\
xdebug.start_with_request=yes\n\
' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

ENV COMPOSER_ALLOW_SUPERUSER 1
RUN echo '\
display_errors=On\n\
error_reporting=E_ALL\n\
date.timezone=UTC\n\
' >> /usr/local/etc/php/conf.d/php.ini

RUN curl -s https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php -- --quiet && \
mv composer.phar /usr/local/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER 1

ENV PATH /root/.composer/vendor/bin:$PATH
RUN apt-get update && \
apt-get install unzip && \
curl -s https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php -- --quiet && \
mv composer.phar /usr/local/bin/composer && \
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"\n' >> /root/.bashrc

RUN composer global require squizlabs/php_codesniffer

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The olvlvl/symfony-dependency-injection-proxy package is free software.
It is released under the terms of the following BSD License.

Copyright (c) 2018-2020 by Olivier Laviale
Copyright (c) 2018-2022 by Olivier Laviale
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
24 changes: 24 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Migration

## v3.x to v4.x

### New requirements

- Requires PHP v8.0.2+
- Requires `symfony/dependency-injection` v6.0+

### New features

N/A

### Backward Incompatible Changes

N/A

### Deprecated Features

N/A

### Other Changes

N/A
37 changes: 19 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,41 @@ PHPUNIT = vendor/bin/phpunit
vendor:
@composer install

.PHONY: test-dependencies
test-dependencies: vendor test-cleanup

.PHONY: test
test: test-setup
test: test-dependencies
@$(PHPUNIT)

.PHONY: test-coverage
test-coverage: test-setup
test-coverage: test-dependencies
@mkdir -p build/coverage
@XDEBUG_MODE=coverage $(PHPUNIT) --coverage-html build/coverage

.PHONY: test-coveralls
test-coveralls: test-setup
test-coveralls: test-dependencies
@mkdir -p build/logs
@XDEBUG_MODE=coverage $(PHPUNIT) --coverage-clover build/logs/clover.xml

.PHONY: test-container-72
test-container-72:
@docker-compose run --rm app72 sh
@docker-compose down
.PHONY: test-cleanup
test-cleanup:
@rm -rf tests/sandbox/*

.PHONY: test-container-74
test-container-74:
@docker-compose run --rm app74 sh
@docker-compose down
.PHONY: test-container
test-container: test-container-80

.PHONY: test-container-80
test-container-80:
@docker-compose run --rm app80 sh
@docker-compose down
@-docker-compose run --rm app80 bash
@docker-compose down -v

.PHONY: test-setup
test-setup: vendor $(PHPUNIT_FILENAME)
@rm -f tests/sandbox/*
.PHONY: test-container-81
test-container-81:
@-docker-compose run --rm app81 bash
@docker-compose down -v

.PHONY: lint
lint:
@phpcs
@vendor/bin/phpstan
@XDEBUG_MODE=off phpcs -s
@XDEBUG_MODE=off vendor/bin/phpstan
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
[![Code Quality](https://img.shields.io/scrutinizer/g/olvlvl/symfony-dependency-injection-proxy.svg)](https://scrutinizer-ci.com/g/olvlvl/symfony-dependency-injection-proxy)
[![Code Coverage](https://img.shields.io/coveralls/olvlvl/symfony-dependency-injection-proxy.svg)](https://coveralls.io/r/olvlvl/symfony-dependency-injection-proxy)

This package provides a proxy generator for [Symfony's dependency injection component][1] that generates super tiny,
super simple proxies, especially when [compared to Symfony's default implementation][2]. Here are some differences:
This package provides a proxy generator for [Symfony's dependency injection component][1] that
generates super tiny, super simple proxies, especially when [compared to Symfony's default
implementation][2]. Here are some differences:

- Can proxy `final` classes.
- Can only proxy classes with interfaces.
- The generated proxies are self-contained.
- The package is ~10Kb and doesn't have dependencies, other than `symfony/dependency-injection` of course.
- The package can be removed once the proxies have been generated.

> If you're not familiar with proxy services, better have a look at [Symfony's documentation][3] before going any
> further.
If you're not familiar with proxy services, better have a look at [Symfony's documentation][3]
before going any further.



Expand All @@ -29,9 +30,10 @@ composer require olvlvl/symfony-dependency-injection-proxy

## How it works

The generator works with the following assumptions: the service we want to proxy implements an interface, and services
using that service expect that interface, following the [dependency inversion principle][4]. Now, consider the following
code, where an `ExceptionHandler` service requires a logger implementing `LoggerInterface`:
The generator works with the following assumptions: the service we want to proxy implements an
interface, and services using that service expect that interface, following the [dependency
inversion principle][4]. Now, consider the following code, where an `ExceptionHandler` service
requires a logger implementing `LoggerInterface`:

```php
<?php
Expand All @@ -40,22 +42,20 @@ use Psr\Log\LoggerInterface;

class ExceptionHandler
{
private $logger;

public function __construct(LoggerInterface $logger)
public function __construct(private LoggerInterface $logger)
{
$this->logger = $logger;
}

// …
}
```

Imagine we're using [Monolog](https://github.com/Seldaek/monolog) as logger, and we have an expansive stream to set up.
Why waste time building the logger for every request when it's seldom used? That's when we mark our service as _lazy_.
Imagine we're using [Monolog](https://github.com/Seldaek/monolog) as logger, and we have an
expansive stream to set up. Why waste time building the logger for every request when it's seldom
used? That's when we mark our service as _lazy_.

The following example demonstrates how we can mark our `Psr\Log\LoggerInterface` service as lazy (we could use PHP code
or XML just the same):
The following example demonstrates how we can mark our `Psr\Log\LoggerInterface` service as lazy (we
could use PHP code or XML just the same):

```yaml
services:
Expand All @@ -75,8 +75,9 @@ services:
#
```

> We don't have to define our service with a class, we could use `logger` instead of `Psr\Log\LoggerInterface` just
> the same, except we would have to define `class` for the factory one.
**Note:** We don't have to define our service with a class, we could use `logger` instead of
`Psr\Log\LoggerInterface` just > the same, except we would have to define `class` for the factory
one.

Now let's see how to build our container.

Expand Down Expand Up @@ -116,8 +117,9 @@ There you have it. We can use our container as usual and everything is awesome.

### What if my lazy service implements multiple interfaces?

The basic interface resolver will have a hard time figuring out which interface to implement if a service implements
many. For instance, if a service was an instance of `ArrayObject` the following exception would be thrown:
The basic interface resolver will have a hard time figuring out which interface to implement if a
service implements many. For instance, if a service was an instance of `ArrayObject` the following
exception would be thrown:

```
Don't know which interface to choose from for ArrayObject: IteratorAggregate, Traversable, ArrayAccess, Serializable, Countable.
Expand All @@ -138,7 +140,7 @@ ArrayObject:
## Continuous Integration
The project is continuously tested by [GitHub actions](https://github.com/olvlvl/event-dispatcher/actions).
The project is continuously tested by [GitHub actions](https://github.com/olvlvl/symfony-dependency-injection-proxy/actions).
[![Tests](https://github.com/olvlvl/symfony-dependency-injection-proxy/workflows/test/badge.svg?branch=master)](https://github.com/olvlvl/symfony-dependency-injection-proxy/actions?query=workflow%3Atest)
[![Static Analysis](https://github.com/olvlvl/symfony-dependency-injection-proxy/workflows/static-analysis/badge.svg?branch=master)](https://github.com/olvlvl/symfony-dependency-injection-proxy/actions?query=workflow%3Astatic-analysis)
Expand All @@ -148,8 +150,8 @@ The project is continuously tested by [GitHub actions](https://github.com/olvlvl
## Code of Conduct
This project adheres to a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project and its
community, you are expected to uphold this code.
This project adheres to a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in
this project and its community, you are expected to uphold this code.
Expand Down
25 changes: 17 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,32 @@
"authors": [
{
"name": "Olivier Laviale",
"email": "olivier.laviale@gmail.com"
"email": "olivier.laviale@gmail.com",
"homepage": "https://olvlvl.com/",
"role": "Developer"
}
],
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"prefer-dist": true,
"require": {
"php": ">=7.2.5",
"php": ">=8.0.2",
"ext-json": "*",
"symfony/dependency-injection": "^5.0"
"symfony/dependency-injection": "^6.0"
},
"require-dev": {
"jangregor/phpstan-prophecy": "^0.8.1",
"jangregor/phpstan-prophecy": "^1.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^0.12.92",
"phpunit/phpunit": "^8.5",
"symfony/config": "^5.0"
"phpstan/phpstan": "^1.6",
"phpunit/phpunit": "^9.5",
"symfony/config": "^6.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 07c6c00

Please sign in to comment.