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
16 changes: 8 additions & 8 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP 7.1
- name: Setup PHP 7.0
uses: shivammathur/setup-php@v2
with:
php-version: 7.1
php-version: 7.0
- name: Install dependencies
uses: "ramsey/composer-install@v2"
- name: Run phpcs
run: make phpcs
phpstan:
name: phpstan on PHP 7.1
name: phpstan on PHP 7.0
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP 7.1
- name: Setup PHP 7.0
uses: shivammathur/setup-php@v2
with:
php-version: 7.1
php-version: 7.0
- name: Install dependencies
uses: "ramsey/composer-install@v2"
- name: Run phpstan
run: make phpstan
phan:
name: phan on PHP 7.1
name: phan on PHP 7.0
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP 7.1
- name: Setup PHP 7.0
uses: shivammathur/setup-php@v2
with:
php-version: 7.1
php-version: 7.0
- name: Install dependencies
uses: "ramsey/composer-install@v2"
- name: Run phan
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php: [ '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
A PHP 5.6+ compatible dependency injection container inspired
> Note: This is a fork by WP Staging as they need to support PHP 7.0

A PHP 7.0+ compatible dependency injection container inspired
by [Laravel IOC](https://laravel.com/docs/5.0/container "Service Container - Laravel - The PHP Framework For Web Artisans")
and [Pimple](http://pimple.sensiolabs.org/ "Pimple - A simple PHP Dependency Injection Container") that works even
better on newer version of PHP.
Expand Down
13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"name": "lucatume/di52",
"name": "wp-staging/di52",
"description": "A PHP 5.6 compatible dependency injection container.",
"license": "GPL-3.0",
"authors": [
{
"name": "Luca Tumedei",
"email": "luca@theaveragedev.com"
"email": "luca@theaveragedev.com",
"role": "Founder"
},
{
"name": "WP STAGING",
"email": "support@wp-staging.com",
"role": "Maintainer",
"homepage": "https://wp-staging.com"
}
],
"autoload": {
Expand All @@ -14,7 +21,7 @@
}
},
"require": {
"php": ">=7.1",
"php": ">=7.0",
"psr/container": "^1.0",
"ext-json": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion config/phan-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist.
// (See `backward_compatibility_checks` for additional options)
// Automatically inferred from composer.json requirement for "php" of ">=5.6"
'target_php_version' => '7.1',
'target_php_version' => '7.0',

// If enabled, missing properties will be created when
// they are first seen. If false, we'll report an
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define xdebug_src
fi
endef

php_versions :=5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3
php_versions :=5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4
build: $(build_php_versions) ## Builds the project PHP images.
mkdir -p var/cache/composer
mkdir -p var/log
Expand Down
10 changes: 5 additions & 5 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function offsetSet($offset, $value)
*
* @throws ContainerException If there's any issue reflecting on the class, interface or the implementation.
*/
public static function singleton($id, $implementation = null, ?array $afterBuildMethods = null)
public static function singleton($id, $implementation = null, $afterBuildMethods = null)
{
static::container()->singleton($id, $implementation, $afterBuildMethods);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ public static function register($serviceProviderClass, ...$alias)
*
* @throws ContainerException If there's an issue while trying to bind the implementation.
*/
public static function bind($id, $implementation = null, ?array $afterBuildMethods = null)
public static function bind($id, $implementation = null, $afterBuildMethods = null)
{
static::container()->bind($id, $implementation, $afterBuildMethods);
}
Expand Down Expand Up @@ -346,7 +346,7 @@ public static function boot()
* @return void This method does not return any value.
* @throws ContainerException
*/
public static function singletonDecorators($id, $decorators, ?array $afterBuildMethods = null)
public static function singletonDecorators($id, $decorators, $afterBuildMethods = null)
{
static::container()->singletonDecorators($id, $decorators, $afterBuildMethods);
}
Expand All @@ -367,7 +367,7 @@ public static function singletonDecorators($id, $decorators, ?array $afterBuildM
* @return void This method does not return any value.
* @throws ContainerException If there's any issue binding the decorators.
*/
public static function bindDecorators($id, array $decorators, ?array $afterBuildMethods = null)
public static function bindDecorators($id, array $decorators, $afterBuildMethods = null)
{
static::container()->bindDecorators($id, $decorators, $afterBuildMethods);
}
Expand Down Expand Up @@ -480,7 +480,7 @@ public static function callback($id, $method)
* @return callable A callable function that will return an instance of the specified class when
* called.
*/
public static function instance($id, ?array $buildArgs = [], ?array $afterBuildMethods = null)
public static function instance($id, $buildArgs = [], $afterBuildMethods = null)
{
return static::container()->instance($id, $buildArgs ?? [], $afterBuildMethods);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Builders/CallableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CallableBuilder implements BuilderInterface, ReinitializableBuilderInterfa
public function __construct(
Container $container,
callable $callable,
?array $afterBuildMethods = null,
$afterBuildMethods = null,
...$buildArgs
) {
$this->container = $container;
Expand Down Expand Up @@ -86,7 +86,7 @@ public function build()
*
* @return void This method does not return any value.
*/
public function reinit(?array $afterBuildMethods = null, ...$buildArgs)
public function reinit($afterBuildMethods = null, ...$buildArgs)
{
$this->afterBuildMethods = $afterBuildMethods ?: [];
$this->buildArgs = $buildArgs;
Expand Down
4 changes: 2 additions & 2 deletions src/Builders/ClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ClassBuilder implements BuilderInterface, ReinitializableBuilderInterface
*
* @throws NotFoundException If the class does not exist.
*/
public function __construct($id, Resolver $resolver, $className, ?array $afterBuildMethods = null, ...$buildArgs)
public function __construct($id, Resolver $resolver, $className, $afterBuildMethods = null, ...$buildArgs)
{
if (!class_exists($className)) {
throw new NotFoundException(
Expand Down Expand Up @@ -236,7 +236,7 @@ protected function resolveParameter(Parameter $parameter)
/**
* {@inheritdoc}
*/
public function reinit(?array $afterBuildMethods = null, ...$buildArgs)
public function reinit($afterBuildMethods = null, ...$buildArgs)
{
$this->afterBuildMethods = $afterBuildMethods;
$this->buildArgs = $buildArgs;
Expand Down
2 changes: 1 addition & 1 deletion src/Builders/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(Container $container, Resolver $resolver)
*
* @throws NotFoundException If a builder cannot find its implementation target.
*/
public function getBuilder($id, $implementation = null, ?array $afterBuildMethods = null, ...$buildArgs)
public function getBuilder($id, $implementation = null, $afterBuildMethods = null, ...$buildArgs)
{
if ($implementation === null) {
$implementation = $id;
Expand Down
2 changes: 1 addition & 1 deletion src/Builders/ReinitializableBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ interface ReinitializableBuilderInterface
*
* @return void This method does not return any value.
*/
public function reinit(?array $afterBuildMethods = null, ...$buildArgs);
public function reinit($afterBuildMethods = null, ...$buildArgs);
}
6 changes: 3 additions & 3 deletions src/Builders/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function setWhenNeedsGive($whenClass, $needsClass, BuilderInterface $buil
* build arguments.
* @throws NotFoundException If the id is a string that does not resolve to an existing, concrete, class.
*/
public function resolveWithArgs($id, ?array $afterBuildMethods = null, ...$buildArgs)
public function resolveWithArgs($id, $afterBuildMethods = null, ...$buildArgs)
{
if (! is_string($id)) {
return $id;
Expand All @@ -197,7 +197,7 @@ public function resolveWithArgs($id, ?array $afterBuildMethods = null, ...$build
*
* @throws NotFoundException If the id is a string that is not bound and is not an existing, concrete, class.
*/
public function resolve($id, ?array $buildLine = null)
public function resolve($id, $buildLine = null)
{
if ($buildLine !== null) {
$this->buildLine = $buildLine;
Expand Down Expand Up @@ -271,7 +271,7 @@ private function resolveBound($id)
* @throws NotFoundException If trying to clone the builder for a non existing id or an id that does not map to a
* concrete class name.
*/
private function cloneBuilder($id, ?array $afterBuildMethods = null, ...$buildArgs)
private function cloneBuilder($id, $afterBuildMethods = null, ...$buildArgs)
{
if (isset($this->bindings[$id]) && $this->bindings[$id] instanceof BuilderInterface) {
$builder = clone $this->bindings[$id];
Expand Down
12 changes: 6 additions & 6 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function offsetSet($offset, $value)
* @return void This method does not return any value.
* @throws ContainerException If there's any issue reflecting on the class, interface or the implementation.
*/
public function singleton($id, $implementation = null, ?array $afterBuildMethods = null)
public function singleton($id, $implementation = null, $afterBuildMethods = null)
{
if ($implementation === null) {
$implementation = $id;
Expand Down Expand Up @@ -527,7 +527,7 @@ private function getDeferredProviderMakeClosure(ServiceProvider $provider, $id)
*
* @throws ContainerException If there's an issue while trying to bind the implementation.
*/
public function bind($id, $implementation = null, ?array $afterBuildMethods = null)
public function bind($id, $implementation = null, $afterBuildMethods = null)
{
if ($implementation === null) {
$implementation = $id;
Expand Down Expand Up @@ -575,7 +575,7 @@ public function boot()
* @return void This method does not return any value.
* @throws ContainerException
*/
public function singletonDecorators($id, $decorators, ?array $afterBuildMethods = null, $afterBuildAll = false)
public function singletonDecorators($id, $decorators, $afterBuildMethods = null, $afterBuildAll = false)
{
$this->resolver->singleton(
$id,
Expand All @@ -601,7 +601,7 @@ public function singletonDecorators($id, $decorators, ?array $afterBuildMethods
private function getDecoratorBuilder(
array $decorators,
$id,
?array $afterBuildMethods = null,
$afterBuildMethods = null,
$afterBuildAll = false
) {
$decorator = array_pop($decorators);
Expand Down Expand Up @@ -640,7 +640,7 @@ private function getDecoratorBuilder(
* @return void This method does not return any value.
* @throws ContainerException If there's any issue binding the decorators.
*/
public function bindDecorators($id, array $decorators, ?array $afterBuildMethods = null, $afterBuildAll = false)
public function bindDecorators($id, array $decorators, $afterBuildMethods = null, $afterBuildAll = false)
{
$this->resolver->bind($id, $this->getDecoratorBuilder($decorators, $id, $afterBuildMethods, $afterBuildAll));
}
Expand Down Expand Up @@ -822,7 +822,7 @@ protected function isStaticMethod($object, $method)
* @return callable|Closure A callable function that will return an instance of the specified class when
* called.
*/
public function instance($id, array $buildArgs = [], ?array $afterBuildMethods = null)
public function instance($id, array $buildArgs = [], $afterBuildMethods = null)
{
return function () use ($id, $afterBuildMethods, $buildArgs) {
if (is_string($id)) {
Expand Down
10 changes: 8 additions & 2 deletions src/ContainerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ private static function getPropertyValue($object, $property)
do {
if ($reflectionClass->hasProperty($property)) {
$traceProperty = $reflectionClass->getProperty($property);
$traceProperty->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$traceProperty->setAccessible(true);
}

return $traceProperty->getValue($object);
}

Expand All @@ -60,7 +63,10 @@ private static function setPropertyValue($object, $property, $value)
do {
if ($reflectionClass->hasProperty($property)) {
$traceProperty = $reflectionClass->getProperty($property);
$traceProperty->setAccessible(true);
if (PHP_VERSION_ID < 80100) {
$traceProperty->setAccessible(true);
}

$traceProperty->setValue($object, $value);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NestedParseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NestedParseError extends \Exception
* @param string $type The type of the entity being loaded.
* @param string $name The name of the entity being loaded.
*/
public function __construct($message = "", $code = 0, ?Throwable $previous = null, $type = '', $name = '')
public function __construct($message = "", $code = 0, $previous = null, $type = '', $name = '')
{
parent::__construct($message, $code, $previous);
$this->type = $type;
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/UnsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class UnsetTest extends TestCase
{
public function test_unset_binding_with_bind_default():void
public function test_unset_binding_with_bind_default()
{
$container = new Container(false);

Expand All @@ -30,7 +30,7 @@ public function test_unset_binding_with_bind_default():void
$this->assertNotSame($previousInstance, $container->get(MySingletonClass::class));
}

public function test_unset_binding_with_singleton_default():void
public function test_unset_binding_with_singleton_default()
{
$container = new Container(true);

Expand All @@ -47,7 +47,7 @@ public function test_unset_binding_with_singleton_default():void
$this->assertNotSame($previousInstance, $container->get(MySingletonClass::class));
}

public function test_unset_singleton_with_bind_default(): void
public function test_unset_singleton_with_bind_default()
{
$container = new Container(false);

Expand All @@ -64,7 +64,7 @@ public function test_unset_singleton_with_bind_default(): void
$this->assertNotSame($previousInstance, $container->get(MySingletonClass::class));
}

public function test_unset_singleton_with_singleton_default(): void
public function test_unset_singleton_with_singleton_default()
{
$container = new Container(true);

Expand All @@ -80,7 +80,7 @@ public function test_unset_singleton_with_singleton_default(): void
$this->assertNotSame($previousInstance, $container->get(MySingletonClass::class));
}

public function test_unset_given_when_then_with_bind_default(): void
public function test_unset_given_when_then_with_bind_default()
{
$container = new Container(false);

Expand All @@ -98,7 +98,7 @@ public function test_unset_given_when_then_with_bind_default(): void
$container->get(MySingletonClassTwo::class);
}

public function test_unset_given_when_then_with_singleton_default(): void
public function test_unset_given_when_then_with_singleton_default()
{
$container = new Container(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Array
[classFQN] => lucatume\DI52\ContainerException
[message] => Error while making unit\data\ThrowErrorOnConstructClass: !!! Error while building class unit\data\ThrowErrorOnConstructClass.
[file] => /src/ContainerException.php
[line] => 122
[line] => 128
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Array
[classFQN] => lucatume\DI52\ContainerException
[message] => Error while making unit\data\ThrowErrorOnConstructClass: !!! Error while building class unit\data\ThrowErrorOnConstructClass.
[file] => /src/ContainerException.php
[line] => 122
[line] => 128
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Array
[classFQN] => lucatume\DI52\ContainerException
[message] => Error while making unit\data\ThrowExceptionOnConstructClass: !!! Exception while building class unit\data\ThrowExceptionOnConstructClass.
[file] => /src/ContainerException.php
[line] => 122
[line] => 128
)
Loading