/** * @inheritDoc */ public function apply(Injector $injector) { $injector->alias(RequestInterface::class, ServerRequest::class); $injector->alias(ResponseInterface::class, Response::class); $injector->alias(ServerRequestInterface::class, ServerRequest::class); $injector->delegate(ServerRequest::class, [ServerRequestFactory::class, 'fromGlobals']); }
public function __invoke(Injector $injector) { $injector->share($injector); foreach ($this->classes as $class) { $injector->execute($class); } }
/** * 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); }
/** * @inheritDoc */ public function apply(Injector $injector) { foreach ($this as $class) { $configuration = $injector->make($class); $configuration->apply($injector); } }
/** * 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); } }
public function testStageRunning() { $functionsCalled = []; $tiersByStage = new ExecutableListByTier(); $fn2 = function () use(&$functionsCalled) { $functionsCalled[2] = true; }; $fn0 = function () use(&$functionsCalled, $tiersByStage, $fn2) { $functionsCalled[0] = true; $tiersByStage->addExecutableToTier(4, $fn2); }; $fn1 = function () use(&$functionsCalled) { $functionsCalled[1] = true; }; $tiersByStage->addExecutableToTier(2, $fn0); $tiersByStage->addExecutableToTier(2, $fn1); $injector = new Injector(); foreach ($tiersByStage as $appStage => $executablesForTier) { foreach ($executablesForTier as $executable) { $injector->execute($executable->getCallable()); } } $this->assertArrayHasKey(0, $functionsCalled); $this->assertArrayHasKey(1, $functionsCalled); $this->assertArrayHasKey(2, $functionsCalled); }
/** * @inheritDoc */ public function apply(Injector $injector) { $injector->alias('Psr\\Http\\Message\\RequestInterface', 'Zend\\Diactoros\\ServerRequest'); $injector->alias('Psr\\Http\\Message\\ResponseInterface', 'Zend\\Diactoros\\Response'); $injector->alias('Psr\\Http\\Message\\ServerRequestInterface', 'Zend\\Diactoros\\ServerRequest'); $injector->delegate('Zend\\Diactoros\\ServerRequest', 'Zend\\Diactoros\\ServerRequestFactory::fromGlobals'); }
/** * * {@inheritDoc} * * @see \Spark\Configuration\ConfigurationInterface::apply() */ public function apply(Injector $injector) { $injector->alias(ExtractorInterface::class, HeaderExtractor::class); $injector->define(HeaderExtractor::class, [':header' => 'token']); $injector->alias(\Spark\Auth\Credentials\ExtractorInterface::class, BodyExtractor::class); $injector->alias(AdapterInterface::class, AuthAdapter::class); }
/** * @inheritDoc */ public function apply(Injector $injector) { $injector->define(RelayBuilder::class, ['resolver' => 'Spark\\Resolver\\ResolverInterface']); $injector->delegate('Relay\\Relay', function (RelayBuilder $builder, Middleware $queue) { return $builder->newInstance($queue); }); }
function setMedoo() { $injector = new Injector(); $injector->share('medoo'); $injector->define('medoo', [':options' => $this->databaseconfig]); $this->medoodb = $injector->make('medoo'); }
/** * @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); }
public function testApply() { $injector = new Injector(); $configuration = $injector->make(PredisConfiguration::class); $configuration->apply($injector); $instance = $injector->make(Client::class); $this->assertInstanceOf(Client::class, $instance); }
/** * @inheritDoc */ public function apply(Injector $injector) { $injector->define(RelayBuilder::class, ['resolver' => ResolverInterface::class]); $factory = function (RelayBuilder $builder, MiddlewareSet $queue) { return $builder->newInstance($queue); }; $injector->delegate(Relay::class, $factory); }
public function makeClient(Injector $injector) { if (empty($this->env['chamber_api_secret'])) { throw new \DomainException('Bad API configuration'); } $handler = $injector->execute([$this, 'makeStack']); return new Client(compact('handler')); }
/** * 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); }
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'); }); }); }
/** * @inheritDoc */ public function apply(Injector $injector) { foreach ($this as $configuration) { if (!is_object($configuration)) { $configuration = $injector->make($configuration); } $configuration->apply($injector); } }
/** * 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)); }
/** * 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(); }
private function applyProviderConfig(Injector $injector, array $env) { $config = []; foreach ($env as $key => $value) { list($provider, $key) = explode('_', strtolower($key), 2); $key = $this->toCamelCase($key); $config[$provider][$key] = $value; } $injector->define(__NAMESPACE__ . '\\ProviderConfig', [':config' => $config]); }
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; }
public function apply(Injector $injector) { $injector->alias(Collection::class, DefaultCollection::class); $injector->prepare(Collection::class, function (Collection $collection) { $middleware = $collection->getArrayCopy(); // Do session checking before routing array_splice($middleware, array_search(RouteHandler::class, $middleware), 0, CheckSessionMiddleware::class); $collection->exchangeArray($middleware); }); }
public function testRun() { $application = $this->getMockBuilder(ConsoleApplication::class)->setMethods(['run', 'add'])->getMock(); $application->expects($this->once())->method('run'); $application->expects($this->once())->method('add')->with(new Hello()); $this->configuration->expects($this->once())->method('apply')->with($this->injector); $this->injector->expects($this->exactly(2))->method('make')->will($this->onConsecutiveCalls($application, new Hello())); $this->commands->expects($this->any())->method('toArray')->willReturn([Hello::class]); Application::build($this->injector, $this->configuration, $this->commands)->run(); }
/** * @inheritDoc */ public function apply(Injector $injector) { $injector->define(Loader::class, [':filepaths' => $this->envfile]); $injector->share(Env::class); $injector->prepare(Env::class, function (Env $env, Injector $injector) { $loader = $injector->make(Loader::class); $values = $loader->parse()->toArray(); return $env->withValues($values); }); }
/** * Applies a configuration set to a dependency injector. * * @param Injector $injector */ public function apply(Injector $injector) { foreach (self::$entityRepositoryMap as $entityName => $repoClassName) { $injector->delegate($repoClassName, function () use($entityName, $injector) { /** @var EntityManager $entityManager */ $entityManager = $injector->make(EntityManager::class); return $entityManager->getRepository($entityName); }); } }
/** * * {@inheritDoc} * * @see \Spark\Configuration\ConfigurationInterface::apply() */ public function apply(Injector $injector) { $host = $this->env['DB_HOST']; $username = $this->env['DB_USERNAME']; $password = $this->env['DB_PASSWORD']; $name = $this->env['DB_DBNAME']; $port = $this->env['DB_PORT']; $dsn = "mysql:dbname={$name};host={$host};port={$port}"; $injector->define('PDO', [':dsn' => $dsn, ':username' => $username, ':passwd' => $password]); $injector->define('FluentPDO', [':pdo' => $injector->make('PDO')]); }
/** * @inheritDoc */ public function apply(Injector $injector) { $injector->alias('Equip\\Auth\\Token\\ExtractorInterface', 'Equip\\Auth\\Token\\QueryExtractor'); $injector->define('Equip\\Auth\\Token\\QueryExtractor', [':parameter' => 'tk']); $injector->alias('Equip\\Auth\\Credentials\\ExtractorInterface', 'Equip\\Auth\\Credentials\\BodyExtractor'); $injector->alias('Equip\\Auth\\AdapterInterface', 'Equip\\Project\\Auth\\Adapter'); $dir = dirname(dirname(__DIR__)); $dotenv = new Dotenv($dir); $dotenv->load(); $dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']); }
/** * Applies a configuration set to a dependency injector. * * @param Injector $injector */ public function apply(Injector $injector) { //Specify token parameter from query string $injector->define(QueryExtractor::class, [':parameter' => 'al']); //Use Query Extractor to grab auth token $injector->alias(\Spark\Auth\Token\ExtractorInterface::class, QueryExtractor::class); //Use Json Extractor to grab credentials $injector->alias(\Spark\Auth\Credentials\ExtractorInterface::class, JsonExtractor::class); //Specify custom auth adapter to use $injector->alias(AdapterInterface::class, Adapter::class); }
function generateCompare(\Auryn\Injector $injector, $functionFullname, $filename) { global $imageType; echo "Function " . $functionFullname . "\n"; ob_start(); $injector->execute($functionFullname); $image = ob_get_contents(); ob_end_clean(); $fullFilename = $filename . "." . strtolower($imageType); @mkdir(dirname($filename), 0755, true); file_put_contents($fullFilename, $image); }
/** * @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'])); } }