All Projects → chubbyphp → chubbyphp-container

chubbyphp / chubbyphp-container

Licence: MIT license
A minimal Dependency Injection Container (DIC) which implements PSR-11.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to chubbyphp-container

Elaina
🔮 Docker-based remote code runner. / 基于 Docker 的远程代码运行器
Stars: ✭ 36 (+157.14%)
Mutual labels:  container
codewind-eclipse
Plugin for developing cloud-native, containerized applications from Eclipse IDE
Stars: ✭ 13 (-7.14%)
Mutual labels:  container
heroku-deploy
A simple action to build, push and deploy your dockerized app to your Heroku Application
Stars: ✭ 40 (+185.71%)
Mutual labels:  container
container-group
AWSKRUG container group
Stars: ✭ 22 (+57.14%)
Mutual labels:  container
finder-frontend
Serves finder and search pages for GOV.UK
Stars: ✭ 15 (+7.14%)
Mutual labels:  container
softwarecontainer
Framework to manage and contain applications in an automotive setting
Stars: ✭ 19 (+35.71%)
Mutual labels:  container
3dcitydb-docker-postgis
3D City Database PostGIS Docker image
Stars: ✭ 37 (+164.29%)
Mutual labels:  container
docker-ttrss
Tiny Tiny RSS feed reader as a Docker image.
Stars: ✭ 55 (+292.86%)
Mutual labels:  container
ovrstat
🎮 An Unofficial Overwatch Stats API
Stars: ✭ 96 (+585.71%)
Mutual labels:  container
docker-tor
TOR Server Docker image
Stars: ✭ 32 (+128.57%)
Mutual labels:  container
publisher
Publishes mainstream content on GOV.UK
Stars: ✭ 42 (+200%)
Mutual labels:  container
container-bootfs
Container image converter aiming to minimize image size and speed up boot time dramatically with block-level de-dupliction and lazy-pull technology.
Stars: ✭ 17 (+21.43%)
Mutual labels:  container
container-security-book
container-security.dev/
Stars: ✭ 123 (+778.57%)
Mutual labels:  container
docs
Documentation repo of nebula orchestration system
Stars: ✭ 16 (+14.29%)
Mutual labels:  container
dioc
A dart simple dependency container based on code generation.
Stars: ✭ 47 (+235.71%)
Mutual labels:  container
mongodb-container
MongoDB container images based on Red Hat Software Collections and intended for OpenShift and general usage. Users can choose between Red Hat Enterprise Linux, Fedora, and CentOS based images.
Stars: ✭ 50 (+257.14%)
Mutual labels:  container
ubuntu-vnc-xfce-chromium
Retired. Headless Ubuntu/Xfce container with VNC/noVNC and Chromium (Generation 1)
Stars: ✭ 20 (+42.86%)
Mutual labels:  container
falcon-helm
Helm Charts for running CrowdStrike Falcon with Kubernetes
Stars: ✭ 34 (+142.86%)
Mutual labels:  container
devtoolset-container
Devtoolset container images based on Red Hat Software Collections, that provide a platform for building and running C and C++ applications. Users can choose between Red Hat Enterprise Linux, Fedora, and CentOS based images.
Stars: ✭ 40 (+185.71%)
Mutual labels:  container
government-frontend
Serves government pages on GOV.UK
Stars: ✭ 42 (+200%)
Mutual labels:  container

chubbyphp-container

CI Coverage Status Infection MSI Latest Stable Version Total Downloads Monthly Downloads

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

A minimal Dependency Injection Container (DIC) which implements PSR-11. DI Container Benchmark.

There is a laminas service manager adapter at chubbyphp/chubbyphp-laminas-config.

Requirements

Installation

Through Composer as chubbyphp/chubbyphp-container.

composer require chubbyphp/chubbyphp-container "^2.1"

Usage

There are two PSR-11 implementations:

  • Chubbyphp\Container\Container prototype (each get will return a new instance) and shared services
  • Chubbyphp\Container\MinimalContainer shared services

MinimalContainer / Container

Factories

<?php

use App\Service\MyService;
use Chubbyphp\Container\MinimalContainer;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

$container = new MinimalContainer();
$container->factories([
    MyService::class => static function (ContainerInterface $container): MyService {
        return new MyService($container->get(LoggerInterface::class));
    },
]);

Factory

<?php

use App\Service\MyService;
use Chubbyphp\Container\MinimalContainer;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

$container = new MinimalContainer();

// new
$container->factory(MyService::class, static function (ContainerInterface $container): MyService {
    return new MyService($container->get(LoggerInterface::class));
});

// existing (replace)
$container->factory(MyService::class, static function (ContainerInterface $container): MyService {
    return new MyService($container->get(LoggerInterface::class));
});

// existing (extend)
$container->factory(
    MyService::class,
    static function (ContainerInterface $container, callable $previous): MyService {
        $myService = $previous($container);
        $myService->setLogger($container->get(LoggerInterface::class));

        return $myService;
    }
);

Factory with Parameter

<?php

use Chubbyphp\Container\MinimalContainer;
use Chubbyphp\Container\Parameter;

$container = new MinimalContainer();
$container->factory('key', new Parameter('value'));

Get

<?php

use App\Service\MyService;
use Chubbyphp\Container\MinimalContainer;

$container = new MinimalContainer();

$myService = $container->get(MyService::class);

Has

<?php

use App\Service\MyService;
use Chubbyphp\Container\MinimalContainer;

$container = new MinimalContainer();
$container->has(MyService::class);

Container

All methods of the MinimalContainer and the following:

Prototype Factories

each get will return a new instance

<?php

use App\Service\MyService;
use Chubbyphp\Container\Container;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

$container = new Container();
$container->prototypeFactories([
    MyService::class => static function (ContainerInterface $container): MyService {
        return new MyService($container->get(LoggerInterface::class));
    },
]);

Prototype Factory

each get will return a new instance

<?php

use App\Service\MyService;
use Chubbyphp\Container\Container;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

$container = new Container();

// new
$container->prototypeFactory(
    MyService::class,
    static function (ContainerInterface $container): MyService {
        return new MyService($container->get(LoggerInterface::class));
    }
);

// existing (replace)
$container->prototypeFactory(
    MyService::class,
    static function (ContainerInterface $container): MyService {
        return new MyService($container->get(LoggerInterface::class));
    }
);

// existing (extend)
$container->prototypeFactory(
    MyService::class,
    static function (ContainerInterface $container, callable $previous): MyService {
        $myService = $previous($container);
        $myService->setLogger($container->get(LoggerInterface::class));

        return $myService;
    }
);

Migration

Copyright

Dominik Zogg 2022

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].