PHP code example of huge / ioc

1. Go to this page and download the library: Download huge/ioc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

huge / ioc example snippets


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

    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()
                ));
            }
    }

    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())
));

    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;
        }
    }

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

$ioc = new DefaultIoC();
$ioc->setLogger(new MyApp\Log4phpLoggerImpl('DefaultIoC'));
$ioc->addDefinitions(array(
    array(
        'class' => 'MyApp\Log4phpFactoryImpl',
        'factory' => SimpleFactory::getInstance() // retourne un singleton (optimisation)
    )
));