Skip to content
Draft
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
35 changes: 35 additions & 0 deletions .github/workflows/analyse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Static Analysis
on:
pull_request:
push:
branches:
- master
workflow_dispatch:
jobs:
analyse:
name: Static Analysis
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ '7.4', '8.0', '8.1' ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ matrix.php-version }}-{{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php-version }}

- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php-version }}

- name: Lint PHP Files
run: composer run-script lint

- name: PHPStan
run: composer run-script analyse
34 changes: 34 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PHP Code Style
on:
pull_request:
push:
workflow_dispatch:
jobs:
code-style:
name: PHP Code Style Check
strategy:
matrix:
operating-system: [ubuntu-latest]
php-version: ['7.4']
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ matrix.php-version }}-{{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php-version }}

- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php-version }}

- name: PHP Code Style Check
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php-version }}
command: cs-check
40 changes: 0 additions & 40 deletions .github/workflows/php.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests
on:
pull_request:
push:
branches:
- master
workflow_dispatch:
jobs:
tests:
name: Unit Tests
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ '7.4', '8.0', '8.1' ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ matrix.php-version }}-{{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.php-version }}

- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php-version }}

- name: PHPUnit Unit Test Suite
uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php-version }}
memory_limit: -1
command: test
args: -- --testsuite=Unit
12 changes: 7 additions & 5 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?php

declare(strict_types=1);

/**
* This file is part of coisa/container.
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*
* @link https://github.com/coisa/container
*
* @copyright Copyright (c) 2019-2020 Felipe Sayão Lobato Abreu <github@felipeabreu.com.br>
* @copyright Copyright (c) 2019-2022 Felipe Sayão Lobato Abreu <github@felipeabreu.com.br>
* @license https://opensource.org/licenses/MIT MIT License
*/
$paths = array(

$paths = [
__FILE__,
__DIR__,
);
];

$header = \file_get_contents(__DIR__ . '/.docheader');
$header = file_get_contents(__DIR__ . '/.docheader');

return CoiSA\PhpCsFixer\PhpCsFixer::create($paths, $header);
26 changes: 13 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@
}
],
"require": {
"php": ">=5.3",
"coisa/exceptions": "~1.0",
"coisa/factory": "~1.6",
"coisa/service-provider": "~1.1",
"php": "^7.4 || ^8.0",
"coisa/exceptions": "^1.0",
"coisa/factory": "^1.7",
"coisa/service-provider": "^2.0",
"container-interop/service-provider": "^0.4.0",
"psr/container": "^1.0"
"psr/container": "^1.1 || ^2.0"
},
"provide": {
"psr/container-implementation": "^1.0"
"psr/container-implementation": "^1.1 || ^2.0"
},
"require-dev": {
"coisa/php-cs-fixer": "^1.0",
"jakub-onderka/php-console-highlighter": "^0.3.2 || ^0.4",
"jakub-onderka/php-parallel-lint": "^1.0",
"phpunit/phpunit": "^4.8",
"sensiolabs/security-checker": "^4.1",
"squizlabs/php_codesniffer": "^2.9 || ^3.0"
"coisa/php-cs-fixer": "^2.1",
"php-parallel-lint/php-console-highlighter": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpunit/phpunit": "^9.5",
"sensiolabs/security-checker": "^6.0",
"squizlabs/php_codesniffer": "^3.6"
},
"config": {
"prefer-stable": true,
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
"dev-master": "2.x-dev"
}
},
"autoload": {
Expand Down
30 changes: 20 additions & 10 deletions config/autoload.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
<?php

declare(strict_types=1);

/**
* This file is part of coisa/container.
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*
* @link https://github.com/coisa/container
*
* @copyright Copyright (c) 2019-2020 Felipe Sayão Lobato Abreu <github@felipeabreu.com.br>
* @copyright Copyright (c) 2019-2022 Felipe Sayão Lobato Abreu <github@felipeabreu.com.br>
* @license https://opensource.org/licenses/MIT MIT License
*/

namespace CoiSA\Container;

use CoiSA\Container\Factory\AggregateContainerAbstractFactory;
use CoiSA\Container\Factory\ContainerAbstractFactory;
use CoiSA\Factory\AbstractFactory;
use CoiSA\Factory\AbstractFactoryFactory;
use CoiSA\Factory\AliasFactory;
use Psr\Container\ContainerInterface as PsrContainer;

\call_user_func(
function($aggregateContainerFactory, $containerFactory, $aliasFactory) {
AbstractFactory::setFactory('CoiSA\\Container\\AggregateContainer', $aggregateContainerFactory);
AbstractFactory::setFactory('CoiSA\\Container\\Container', $containerFactory);
AbstractFactory::setFactory('CoiSA\\Container\\ContainerInterface', $aliasFactory);
AbstractFactory::setFactory('Psr\\Container\\ContainerInterface', $aliasFactory);
function (
AbstractFactoryFactory $aggregateContainerFactory,
AbstractFactoryFactory $containerFactory,
AliasFactory $aliasFactory
): void {
AbstractFactory::setFactory(AggregateContainer::class, $aggregateContainerFactory);
AbstractFactory::setFactory(Container::class, $containerFactory);
AbstractFactory::setFactory(ContainerInterface::class, $aliasFactory);
AbstractFactory::setFactory(PsrContainer::class, $aliasFactory);
},
'CoiSA\\Container\\Factory\\AggregateContainerFactory',
new AbstractFactoryFactory('CoiSA\\Container\\Factory\\ContainerAbstractFactory'),
new AliasFactory('CoiSA\\Container\\Container')
new AbstractFactoryFactory(AggregateContainerAbstractFactory::class),
new AbstractFactoryFactory(ContainerAbstractFactory::class),
new AliasFactory(Container::class)
);
30 changes: 30 additions & 0 deletions examples/autowire.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/**
* This file is part of coisa/container.
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*
* @link https://github.com/coisa/container
* @copyright Copyright (c) 2019-2022 Felipe Sayão Lobato Abreu <github@felipeabreu.com.br>
* @license https://opensource.org/licenses/MIT MIT License
*/

use CoiSA\Container\AggregateContainer;
use CoiSA\Container\Factory\ContainerAbstractFactory;
use Laminas\Di\Injector;

require_once 'vendor/autoload.php';

/** @var \Laminas\ConfigAggregator\ConfigAggregator $config */
// $config = require __DIR__ . '/config.php';

$coisaContainer = ContainerAbstractFactory::create(/* $config */);

return new AggregateContainer([
$coisaContainer,
(new Injector())->getContainer(),
]);
55 changes: 55 additions & 0 deletions examples/coisa-factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

/**
* This file is part of coisa/container.
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*
* @link https://github.com/coisa/container
* @copyright Copyright (c) 2019-2022 Felipe Sayão Lobato Abreu <github@felipeabreu.com.br>
* @license https://opensource.org/licenses/MIT MIT License
*/

use CoiSA\Container\Test\Stub\ServiceProvider\ExampleOtherServiceProvider;
use CoiSA\Container\Test\Stub\ServiceProvider\ExampleServiceProvider;
use CoiSA\Factory\AbstractFactory;
use Psr\Container\ContainerInterface;

require_once __DIR__ . '/../vendor/autoload.php';

$serviceProvider = new ExampleOtherServiceProvider();

// Create a container instance
$container = AbstractFactory::create(
ContainerInterface::class,

// Register service-provider using full-qualified class name
ExampleServiceProvider::class,

// Register service-provider using an object instance
$serviceProvider,

// You can also register service-provider using Laminas ConfigProvider pattern dependencies array maping
// @see examples/laminas-config-provider-pattern.php for more details

// Or use a full-qualified ConfigProvider class name
// ConfiProvider::class,

// ...keep adding the service-providers of your application
);

// You would be able to access the service-provider instance using the container
var_dump($container->has(ExampleServiceProvider::class), $container->get(ExampleServiceProvider::class));
var_dump($container->has(ExampleOtherServiceProvider::class), $container->get(ExampleOtherServiceProvider::class));

// If you register a service-provider using an object instance, you can access it using the container
var_dump($serviceProvider === $container->get(ExampleOtherServiceProvider::class));

// You can also get the factory instance for a service-provider
var_dump(AbstractFactory::getFactory(ExampleOtherServiceProvider::class));

// Memory usage
var_dump(memory_get_peak_usage(true) / 1024 / 1024);
Loading