本文整理汇总了PHP中Auryn\Injector::share方法的典型用法代码示例。如果您正苦于以下问题:PHP Injector::share方法的具体用法?PHP Injector::share怎么用?PHP Injector::share使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Auryn\Injector
的用法示例。
在下文中一共展示了Injector::share方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addToInjector
public function addToInjector(Injector $injector)
{
foreach ($this->shares as $share) {
$injector->share($share);
}
foreach ($this->aliases as $original => $alias) {
$injector->alias($original, $alias);
}
foreach ($this->definitions as $name => $args) {
$injector->define($name, $args);
}
foreach ($this->params as $param => $value) {
$injector->defineParam($param, $value);
}
foreach ($this->delegates as $param => $callable) {
$injector->delegate($param, $callable);
}
foreach ($this->prepares as $class => $callable) {
$injector->prepare($class, $callable);
}
}
示例2: registerExceptionHandlerServices
private function registerExceptionHandlerServices(Injector $injector)
{
$injector->share(Run::class);
$injector->prepare(Run::class, function (Run $run) {
$run->pushHandler(new PrettyPageHandler());
});
$injector->share(ExceptionHandlingPlugin::class);
}
示例3: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
$injector->alias('Psr\\Http\\Message\\ResponseInterface', 'Zend\\Diactoros\\Response');
$injector->share('Psr\\Http\\Message\\ResponseInterface');
$injector->delegate('Psr\\Http\\Message\\ServerRequestInterface', 'Zend\\Diactoros\\ServerRequestFactory::fromGlobals');
$injector->share('Psr\\Http\\Message\\ServerRequestInterface');
$injector->alias('Psr\\Http\\Message\\RequestInterface', 'Psr\\Http\\Message\\ServerRequestInterface');
}
示例4: setTemplatePath
/**
* Sets the templates path.
*
* @param string $path
* @param \Twig_Environment $twig
* @param array $extensions
* @return self
*/
public function setTemplatePath($path, \Twig_Environment $twig = null, $extensions = [])
{
$this->paths['templates'] = $path;
if (is_null($twig)) {
$loader = new \Twig_Loader_Filesystem($path);
$twig = new \Twig_Environment($loader);
}
$twig->setExtensions($extensions);
$this->injector->share($twig);
return $this;
}
示例5: performInjections
/**
* @param array $injections Single dimensional array of shareable values from the Silex\Application (pimple) object
*
* @return void
*/
public function performInjections(array $injections)
{
foreach ($injections as $shareable) {
$this->injector->share($this->application[$shareable]);
}
/**
* This can only be done here because security / user is only read to be read after boot
*/
if (isset($this->application['twig']) && isset($this->application['security.authorization_checker'])) {
$this->application['twig']->addExtension(new SecurityExtension($this->application['security.authorization_checker']));
}
}
示例6: createInjector
function createInjector()
{
$jigTemplatePath = new \Jig\JigTemplatePath(__DIR__ . "/fixtures/templates/");
$jigCompilePath = new \Jig\JigCompilePath(__DIR__ . "/var/generatedTemplates/");
// Create a JigConfig object
$jigConfig = new JigConfig($jigTemplatePath, $jigCompilePath, Jig::COMPILE_CHECK_MTIME);
$injector = new Injector();
$injector->alias('Jig\\Escaper', 'Jig\\Bridge\\ZendEscaperBridge');
$injector->delegate('FastRoute\\Dispatcher', 'TierTest\\JigBridge\\createDispatcher');
$injector->share('FastRoute\\Dispatcher');
$injector->share($jigConfig);
return $injector;
}
示例7: setUp
public function setUp()
{
parent::setUp();
$this->compileDirectory = new JigCompilePath(dirname(__DIR__) . "/./../tmp/generatedTemplates/");
$this->templateDirectory = new JigTemplatePath(dirname(__DIR__) . "/./templates/");
$jigConfig = new JigConfig($this->templateDirectory, $this->compileDirectory, Jig::COMPILE_ALWAYS, "php.tpl");
$injector = new \Auryn\Injector();
$this->injector = $injector;
$escaper = new ZendEscaperBridge(new ZendEscaper());
$this->injector->alias('Jig\\Escaper', get_class($escaper));
$this->injector->share($escaper);
$this->jigDispatcher = new JigDispatcher($jigConfig, $injector);
}
示例8: setUp
protected function setUp()
{
define('MODEL_DIR', '\\Test\\Model');
//define('DEBUG_MODE', true);
$this->injector = new Injector();
$this->injector->share(Database::class);
$this->database = $this->injector->make('Minute\\Database\\Database', [true]);
try {
$this->pdo = $this->database->getPdo();
} catch (\PDOException $e) {
$this->markTestSkipped('Database connection error: ' . $e->getMessage());
}
parent::setUp();
}
示例9: __invoke
public function __invoke(Injector $injector)
{
$injector->share($injector);
foreach ($this->classes as $class) {
$injector->execute($class);
}
}
示例10: setMedoo
function setMedoo()
{
$injector = new Injector();
$injector->share('medoo');
$injector->define('medoo', [':options' => $this->databaseconfig]);
$this->medoodb = $injector->make('medoo');
}
示例11: run
/**
* Run the application
*
* @param string $runner
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function run($runner = 'Relay\\Relay')
{
foreach ($this->configuration as $entry) {
$this->injector->make($entry)->apply($this->injector);
}
return $this->injector->share($this->middleware)->prepare('Spark\\Directory', $this->routing)->execute($runner);
}
示例12: apply
/**
* Applies a configuration set to a dependency injector.
*
* @param Injector $injector
*/
public function apply(Injector $injector)
{
$paths = ["src/Users/Entity/", "src/Shifts/Entity/"];
$isDevMode = true;
// the connection configuration
$dbParams = array('host' => $_ENV['DB_HOST'], 'driver' => $_ENV['DB_DRIVER'], 'user' => $_ENV['DB_USER'], 'password' => $_ENV['DB_PASSWORD'], 'dbname' => $_ENV['DB_DATABASE_NAME']);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);
$injector->share(EntityManager::create($dbParams, $config));
}
示例13: apply
/**
* Applies a configuration set to a dependency injector.
*
* @param Injector $injector
*/
public function apply(Injector $injector)
{
// Create a new Manager instance.
$manager = new Manager(new ArrayDriver());
// Managers can do everything
$manager->role('manager')->allow('all');
// $manager->role('employee')->allow('guest', 'read');
$injector->share($manager);
}
示例14: apply
public function apply(Injector $injector)
{
//START: auth
$injector->alias(AdapterInterface::class, \trejeraos\SimpleServerMonitor\Auth\FooAdapter::class);
$injector->alias(AuthHandler::class, FooAuthHandler::class);
$injector->share(FooAuthHandler::class);
// get auth token
$injector->alias(TokenExtractorInterface::class, QueryExtractor::class);
$injector->define(QueryExtractor::class, [':parameter' => 'tok']);
// get auth credentials
$injector->alias(CredentialsExtractorInterface::class, BodyExtractor::class);
$injector->define(BodyExtractor::class, [':identifier' => 'user', ':password' => 'password']);
// share valid auth token class
$injector->share(\trejeraos\SimpleServerMonitor\Auth\ValidTokens::class);
//END: auth
// share global config class
$injector->share(\trejeraos\SimpleServerMonitor\Data\Configuration::class);
}
示例15: getServiceLocator
public function getServiceLocator()
{
if (!$this->service_locator) {
$di_container = new DiContainer(new StandardReflector());
$di_container->share($di_container);
$service_provisioner = $di_container->make(ServiceProvisioner::CLASS);
$this->service_locator = $service_provisioner->provision();
}
return $this->service_locator;
}