コード例 #1
0
 /**
  * @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();
 }
コード例 #2
0
ファイル: annotations.php プロジェクト: adrianpietka/notes
    }
}
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);
コード例 #3
0
ファイル: container.php プロジェクト: arcostasi/php-di
<?php

// Create cache provider
$cache = new \Doctrine\Common\Cache\FilesystemCache(CACHE_PATH);
// Create the dependency injection container
$builder = new \DI\ContainerBuilder();
// The container uses a technique called autowiring.
$builder->useAutowiring(true);
// Set cache provider
$builder->setDefinitionCache($cache);
// Added dependencies settings
$builder->addDefinitions(CONFIG_PATH . '/dependencies.php');
// Builder container
$container = $builder->build();
// Check request uri is defined
$console = empty($_SERVER['REQUEST_URI']) ? true : false;
// Good to go!
$app = $container->get(App\Autoload::class);
$app->run($console);