2017 © Pedro PelĂĄez
 

library ioc

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

image

huge/ioc

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  • Wednesday, September 3, 2014
  • by floorent
  • Repository
  • 1 Watchers
  • 2 Stars
  • 127 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 19 Versions
  • 0 % Grown

The README.md

Huge IoC

Framework IoC Simple et efficace pour php5. Le principe de cette librairie est de gĂ©rer les instances des objets PHP Ă  votre place. De cette façon vous n'ĂȘtes plus obligĂ© de gĂ©rer vous-mĂȘme dans vos constructeurs les instances en paramĂštres. Il est possible d'injecter via une annotation @Autowired., (*1)

Installation

  • Installer avec composer ``` json { "require": { "huge/ioc": "..." } }
* Cache : https://github.com/doctrine/cache
* Initialisation 
```php
  $loader = require(__DIR__.'/../../../vendor/autoload.php');

  // nécessaire charger les annotations
  \Huge\IoC\Container\SuperIoC::registerLoader(array($loader, 'loadClass'));

 Fonctionnalités

  • DĂ©finition d'un bean : @Component
  • Gestion de plusieurs conteneurs d'objets
  • Injection des instances via l'annotation @Autowired("ID_BEAN")
  • Injection d'une implĂ©mentation via l'annotation @Autowired("INTERFACE")
  • Injection d'une sous classe via l'annotation @Autowired("CLASSE_PARENTE")
  • GĂšre l'instanciation request ou lazy (sur demande)
  • Surcharge IFactory pour l'instanciation
  • CrĂ©ation de conteneur spĂ©cifique possible (entends SuperIoC)
  • Cache : basĂ© sur doctrine cache
  • Annotations basĂ© sur doctrine annotations

Conteneurs

  • Etendre \Huge\IoC\Container\SuperIoC
    namespace MyApp;

    class GarageIoC extends \Huge\IoC\Container\SuperIoC{
            public function __construct($config) {
                parent::__construct(__CLASS__, '1.0');

                $memcache = new Memcache();
                $memcache->connect($config['memcache.host'], $config['memcache.port']);
                $cache = new \Doctrine\Common\Cache\MemcacheCache();
                $cache->setMemcache($memcache);

                $this->setCacheImpl($cache);
                $this->addDefinitions(array(
                    array(
                        'class' => 'Huge\IoC\Fixtures\Contact',
                        'factory' => new \Huge\Io\Factory\ConstructFactory(array('DUPUIT', 'Pierre'))
                    )
                ));
                $this->addOtherContainers(array(
                    new AudiIoC(),
                    new RenaultIoC()
                ));
            }
    }
  • Attention, il est nĂ©cessaire de mettre Ă  jour la version en cas de relivraison (rafraĂźchissement du cache)

Factories

  1. Créer vos factories : implémenter Huge\IoC\Factory\IFactory
    namespace MyApp;

    class MyNullFactoy implements \Huge\IoC\Factory\IFactory{
            public function __construct() {}

            public function create($classname) {
                        return null;
            }
    }

$c = new DefaultIoC();
$c->addDefinitions(array(
    array('class' => 'MyClass', 'factory' => new MyNullFactory())
));

Injecter les instances

Injecter dans vos beans d'autres beans, (*2)

    use Huge\IoC\Annotations\Component;
    use Huge\IoC\Annotations\Autowired;

    /**
    * @Component
    */
    class MyController{
        /**
        * @Autowired("MyApp\MyCustomIoC")
        */
        private $ioc;

        /**
        * @Autowired("Huge\IoC\Fixtures\Contact");
        */
        private $daoContact;

        /**
         * @Autowired("Huge\IoC\Factory\ILogFactory")
         * @var \Huge\IoC\Factory\ILogFactory
         */
        private $loggerFactory;

        /**
        * Nécessaire au conteneur pour setter la valeur
        */
        public function setIoc($ioc){
            $this->ioc = $ioc;
        }
        public function setDaoContact($contact){
            $this->daoContact = $contact;
        }

        public function getLoggerFactory() {
            return $this->loggerFactory;
        }

        public function setLoggerFactory(\Huge\IoC\Factory\ILogFactory $loggerFactory) {
            $this->loggerFactory = $loggerFactory;
        }
    }

 Limitations

  • Cache Doctrine
  • Annotations Doctrine
  • Logger basĂ© sur l'interface Psr\Log

Cache

Utilisation des implémentations Doctrine\Common\Cache\Cache, (*3)

    $c = new DefaultIoC('default', '1.0');
    $c->setCacheImpl(new \Doctrine\Common\Cache\ArrayCache());

Attention, les définitions des beans est mise en cache, par conséquent, les paramÚtres donnés au RUN le sont aussi., (*4)

Logger

  1. Implémentation du composant factory : Huge\IoC\Factory\ILogFactory
$ioc = new DefaultIoC();
$ioc->setLogger(new MyApp\Log4phpLoggerImpl('DefaultIoC'));
$ioc->addDefinitions(array(
    array(
        'class' => 'MyApp\Log4phpFactoryImpl',
        'factory' => SimpleFactory::getInstance() // retourne un singleton (optimisation)
    )
));
  1. Plus d'information : http://www.php-fig.org/psr/psr-3/

The Versions

03/09 2014

dev-master

9999999-dev

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

03/09 2014

v2.2.0

2.2.0.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

02/09 2014

v2.1.7

2.1.7.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

01/09 2014

v2.1.6

2.1.6.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

31/08 2014

v2.1.5

2.1.5.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

31/08 2014

v2.1.4

2.1.4.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

30/08 2014

v2.1.3

2.1.3.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

26/08 2014

v2.1.2

2.1.2.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

12/08 2014

v2.1.1

2.1.1.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

10/08 2014

v2.1.0

2.1.0.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

05/08 2014

v2.0.2

2.0.2.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

05/08 2014

v2.0.1

2.0.1.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

03/08 2014

v2.0.0

2.0.0.0

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Florent FREMONT

ioc loader injector singleton bean

22/07 2014

2.0.0-BETA

2.0.0.0-beta

Framework IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

by Florent FREMONT

ioc loader injector singleton bean

14/07 2014

1.2.0

1.2.0.0

IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

by Florent FREMONT

ioc loader injector singleton bean

13/07 2014

1.1.0

1.1.0.0

IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

by Florent FREMONT

ioc loader injector singleton bean

12/07 2014

1.0.0

1.0.0.0

IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

by Florent FREMONT

ioc loader injector singleton bean

12/07 2014

1.0-beta

1.0.0.0-beta

IoC simple d'utilisation et efficace. HugeIoC permet de gérer et d'injecter des objets php trÚs simple.

  Sources   Download

MIT

The Requires

 

by Florent FREMONT

ioc loader injector singleton bean

12/07 2014

0.1

0.1.0.0

  Sources   Download

The Requires