本文整理匯總了PHP中Auryn\Injector::make方法的典型用法代碼示例。如果您正苦於以下問題:PHP Injector::make方法的具體用法?PHP Injector::make怎麽用?PHP Injector::make使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Auryn\Injector
的用法示例。
在下文中一共展示了Injector::make方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __invoke
/**
* Resolve a class spec into an object, if it is not already instantiated.
*
* @param string|object $specOrObject
*
* @return object
*/
public function __invoke($specOrObject)
{
if (is_object($specOrObject)) {
return $specOrObject;
}
return $this->injector->make($specOrObject);
}
示例2: run
/**
* Start the console application
*
* @return int 0 if everything went fine, or an error code
*/
public function run()
{
$this->configuration->apply($this->injector);
$application = $this->injector->make(ConsoleApplication::class);
array_map(function ($command) use($application) {
$application->add($this->injector->make($command));
}, $this->commands->toArray());
return $application->run();
}
示例3: make
/**
* {@inheritdoc}
*/
public function make($class)
{
try {
return $this->auryn->make($class);
} catch (InjectionException $e) {
throw new DependencyInjectionException('Dependency injection failed while trying to make ' . $class . ', ' . $e->getMessage(), $e->getCode(), $e);
//@codeCoverageIgnoreStart
} catch (ReflectionException $e) {
throw new DependencyInjectionException('Dependency injection failed while trying to make ' . $class . ', ' . $e->getMessage(), $e->getCode(), $e);
//@codeCoverageIgnoreEnd
}
}
示例4: add
/**
* Adds a new instance to the container.
*
* @param string $id
* @param mixed $concrete
*/
public function add($id, $concrete = null)
{
if ($concrete && !is_array($concrete)) {
$this->instances[$id] = $concrete;
return $this;
}
$arguments = [];
if (is_array($concrete)) {
$arguments = $concrete;
}
$this->instances[$id] = $this->injector->make($id, $arguments);
return $this;
}
示例5: execute
/**
*
*/
function execute()
{
$gauges = [];
$counters = [];
$asyncStats = $this->injector->make('Stats\\AsyncStats');
$gauges = array_merge($gauges, $this->getQueueGauges());
$counters = array_merge($counters, $asyncStats->getCounters());
$requiredTimers = [\ImagickDemo\Queue\ImagickTaskRunner::event_imageGenerated, \ImagickDemo\Queue\ImagickTaskRunner::event_pageGenerated];
$gauges = array_merge($gauges, $asyncStats->summariseTimers($requiredTimers));
if (count($counters) || count($gauges)) {
$librato = $this->injector->make('Stats\\Librato');
$librato->send($gauges, $counters);
}
}
示例6: 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();
}
示例7: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
foreach ($this as $class) {
$configuration = $injector->make($class);
$configuration->apply($injector);
}
}
示例8: initialize
/**
* Creates all service hook handlers.
*/
private function initialize()
{
$injector = new Injector();
$namespace = __NAMESPACE__ . "\\Service\\";
$basePath = __DIR__ . "/../vendor/kelunik/chat-services/res/schema/";
$transform = function ($match) {
return strtoupper($match[1]);
};
try {
foreach ($this->config["services"] as $name => $enabled) {
if (!$enabled) {
continue;
}
$service = $injector->make($namespace . preg_replace_callback("~-([a-z])~", $transform, ucfirst($name)));
$found = false;
foreach (scandir($basePath . $name) as $file) {
if ($file === "." || $file === "..") {
continue;
}
$found = true;
$uri = realpath($basePath . $name . "/" . $file);
$schema = $this->retriever->retrieve("file://" . $uri);
$this->schemas[$name][strtok($file, ".")] = $schema;
}
if (!$found) {
throw new RuntimeException("every service must have at least one event schema");
}
$this->services[$name] = $service;
}
} catch (InjectorException $e) {
throw new RuntimeException("couldn't create all services", 0, $e);
}
}
示例9: 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);
}
示例10: setMedoo
function setMedoo()
{
$injector = new Injector();
$injector->share('medoo');
$injector->define('medoo', [':options' => $this->databaseconfig]);
$this->medoodb = $injector->make('medoo');
}
示例11: testApply
/**
* @param string $class
* @dataProvider dataMapping
*/
public function testApply($class)
{
$injector = new Injector();
$configuration = $injector->make(AuraCliConfiguration::class);
$configuration->apply($injector);
$instance = $injector->make($class);
$this->assertInstanceOf($class, $instance);
}
示例12: createController
/**
* resolve router target to class object
* @param string $target route target, format: Class#method or Class/method
* @return array [object, method]
*/
public function createController($target)
{
$matches = null;
if (false === preg_match('/[#|\\/]/', $target, $matches)) {
throw new HttpException(404, 'Invalid route: ' . $target);
}
list($class, $method) = explode($matches[0], $target, 2);
$class = 'Controller\\' . $class;
if (!class_exists($class)) {
throw new HttpException(404, sprintf('Controller "%s" does not exist.', $class));
}
$instance = $this->injector->make($class);
if (!method_exists($instance, $method)) {
throw new HttpException(404, sprintf('Action "%s" not found on controller "%s"', $method, $class));
}
return [$instance, $method];
}
示例13: testApply
public function testApply()
{
$injector = new Injector();
$configuration = $injector->make(PredisConfiguration::class);
$configuration->apply($injector);
$instance = $injector->make(Client::class);
$this->assertInstanceOf(Client::class, $instance);
}
示例14: apply
/**
* @inheritDoc
*/
public function apply(Injector $injector)
{
foreach ($this as $configuration) {
if (!is_object($configuration)) {
$configuration = $injector->make($configuration);
}
$configuration->apply($injector);
}
}
示例15: apply
public function apply(Injector $injector)
{
$injector->prepare(Engine::class, function (Engine $engine) use($injector) {
$session = $injector->make(Session::class);
$engine->registerFunction('is_logged_in', function () use($session) {
return $session->has('rdio.token') && $session->has('tidal.session');
});
});
}