/**
  * PHP-DIのコンテナを初期化する。
  */
 protected function initializeContainer()
 {
     parent::initializeContainer();
     $builder = new \DI\ContainerBuilder();
     $builder->wrapContainer($this->getContainer());
     $builder->useAnnotations(true);
     $this->getContainer()->setFallbackContainer($builder->build());
 }
 /**
  * @param array $definitions
  *
  * @return \DI\Container
  */
 public static function build($definitions)
 {
     $builder = new \DI\ContainerBuilder();
     $builder->useAutowiring(false);
     $builder->useAnnotations(false);
     $builder->addDefinitions($definitions);
     return $builder->build();
 }
Example #3
0
 protected function setUp()
 {
     $builder = new \DI\ContainerBuilder();
     $builder->useAnnotations(true);
     $builder->addDefinitions([Twig_Environment::class => function () {
         $loader = new Twig_Loader_Filesystem(realpath(__DIR__ . '/../../templates'));
         return new Twig_Environment($loader, array('cache' => 'test/template_cache', 'auto_reload' => true));
     }]);
     $this->router = new ControllerRouter($builder->build());
 }
Example #4
0
 public static function run($worker_id, $data)
 {
     $jobs = Config::getJobs();
     $job =& $jobs[$worker_id];
     if ($job === null) {
         var_dump($worker_id);
         return false;
     }
     $builder = new \DI\ContainerBuilder();
     // $builder->setDefinitionCache(new Doctrine\Common\Cache\RedisCache());
     $builder->writeProxiesToFile(true, 'tmp/proxies');
     // $builder->useAutowiring(false);
     $builder->useAnnotations(false);
     $builder->addDefinitions('diconfig.php');
     $container = $builder->build();
     // $dependencies = &$job['dependencies'];
     //
     // if ($dependencies !== null) {
     //     $dependencies_classes = explode(',',$dependencies);
     //     foreach($dependencies_classes  as $class) {
     //         $depend_jober = new $class($params);
     //         $params = $depend_jober->run();
     //         if ($params === false) {
     //             return false;
     //         }
     //     }
     // }
     $retries =& $job['retries'];
     $job_params =& $job['params'];
     $class =& $job['class'];
     $exec_count = 0;
     do {
         $result = $container->get($class)->run($data, $job_params);
         $exec_count++;
     } while ($result === false && $exec_count < $retries);
     if ($result === false) {
         $notify = Config::getNotify();
         switch ($notify['dispatch_mode']) {
             case 1:
                 break;
             case 2:
                 break;
         }
     }
 }
Example #5
0
    }
}
class Body
{
}
class Document
{
    /**
     * @Inject
     * @var Head
     */
    private $head;
    private $body;
    /**
     * @Inject
     * @param Body $body
     */
    public function setBody($body)
    {
        $this->body = $body;
    }
}
// create a container instance
$builder = new DI\ContainerBuilder();
$builder->useAutowiring(false);
$builder->useAnnotations(true);
$builder->addDefinitions(['firstName' => 'Adrian', 'lastName' => 'Pietka']);
$container = $builder->build();
// get instance of Document class
$document = $container->get('Document');
var_dump($document);