/** * Bind additional classes to the Container * * @param Container $app * * @return void */ public function register(Container $app) { $app->bind('newrelic', function ($app) { return new RocketeerNewrelicConfig($app['config']->get('rocketeer-newrelic::config')); }); return $app; }
public function make(RequestContainer $requestContainer, Container $app) { if ($requestContainer->getId()) { return new InstanceQuery($app->make('query_builders'), $requestContainer); } return new CollectionQuery($app->make('query_builders'), $requestContainer); }
protected function createApplicationContainer() { $this->app = new \TestContainer(); $this->app->singleton('config', function () { return new \Illuminate\Config\Repository(); }); $this->registerConfigure(); $eventServiceProvider = new \Illuminate\Encryption\EncryptionServiceProvider($this->app); $eventServiceProvider->register(); $eventServiceProvider = new \Illuminate\Events\EventServiceProvider($this->app); $eventServiceProvider->register(); $queueProvider = new \Illuminate\Queue\QueueServiceProvider($this->app); $queueProvider->register(); $sessionProvider = new \Illuminate\Session\SessionServiceProvider($this->app); $sessionProvider->register(); $this->registerDatabase(); $this->registerCache(); $couchbaseProvider = new \Ytake\LaravelCouchbase\CouchbaseServiceProvider($this->app); $couchbaseProvider->register(); $couchbaseProvider->boot(); $this->app->bind(\Illuminate\Container\Container::class, function () { return $this->app; }); (new \Illuminate\Events\EventServiceProvider($this->app))->register(); \Illuminate\Container\Container::setInstance($this->app); }
/** * Bind additional classes to the Container * * @param Container $app * * @return void */ public function register(Container $app) { $app->bind('slack', function ($app) { return new Client($app['config']->get('rocketeer-slack::url')); }); return $app; }
/** * Deteremine if the request passes the authorization check. * * @return bool */ protected function passesAuthorization() { if (method_exists($this, 'authorize')) { return $this->container->call([$this, 'authorize']); } return false; }
/** * Changes the set SMS driver * * @param $driver */ public function driver($driver) { $this->container['sms.sender'] = $this->container->share(function ($app) use($driver) { return (new DriverManager($app))->driver($driver); }); $this->driver = $this->container['sms.sender']; }
/** * Call the given seeder. * * @param \Closure|string $seeder * @return void */ protected function call($seeder) { if ($seeder instanceof Closure) { return $this->container->call($seeder); } $this->container->call($seeder, [], 'seed'); }
/** * Setup the IoC container instance. * * @param \Illuminate\Container\Container|null $container * @return void */ protected function setupContainer($container) { $this->container = $container ?: new Container(); if (!$this->container->bound('config')) { $this->container->instance('config', new Fluent()); } }
/** * Execute the required command against the command handler. * * @param Command $command * @return mixed */ public function execute(Command $command) { $handler = $this->commandTranslator->getCommandHandler($command); $commandName = $this->getCommandName($command); $this->log->info("New command [{$commandName}]", get_object_vars($command)); return $this->app->make($handler)->handle($command); }
/** * Bind additional classes to the Container * * @param Container $app * * @return void */ public function register(Container $app) { $app->bind('campfire', function ($app) { return new Campfire($app['config']->get('rocketeer-campfire::config')); }); return $app; }
/** * @param Container $app * * @return AwsServiceProvider */ private function setupServiceProvider(Container $app) { // Create and register the provider. $provider = new AwsServiceProvider($app); $app->register($provider); $provider->boot(); return $provider; }
/** * @return \Illuminate\Container\Container */ public static function getContainer() { if (!self::$container) { self::$container = new \Illuminate\Container\Container(); self::$container->bind('app', self::$container); } return self::$container; }
/** * @param array $keys * @return \LW\Statistics\StatisticsProviderCollection */ protected function makeProvidersCollection($keys) { $collection = new StatisticsProviderCollection(); foreach ($keys as $name) { $collection->add($name, $this->container->make($this->providerMap[$name])); } return $collection; }
/** * Refresh modal object. * * @throws RepositoryException * * @return Model */ public function makeModel() { $model = $this->app->make($this->model()); if (!$model instanceof Model) { throw new RepositoryException("Class {$this->model()} must be an instance of Illuminate\\Database\\Eloquent\\Model"); } return $this->model = $model; }
/** * @return ContainerInterface */ private function createContainer(array $map = []) { $container = new Container(); foreach ($map as $key => $value) { $container->bind($key, $value); } return new LaravelContainer($container); }
/** * Call the given controller instance method. * * @param \Illuminate\Routing\Controller $instance * @param \Illuminate\Routing\Route $route * @param \Illuminate\Http\Request $request * @param string $method * @return mixed */ protected function callWithinStack($instance, $route, $request, $method) { $middleware = $this->getMiddleware($instance, $method); $shouldSkipMiddleware = $this->container->bound('middleware.disable') && $this->container->make('middleware.disable') === true; return (new Pipeline($this->container))->send($request)->through($shouldSkipMiddleware ? [] : $middleware)->then(function ($request) use($instance, $route, $method) { return $this->router->prepareResponse($request, $this->call($instance, $route, $method)); }); }
public function register(Container $app) { $settings = ['username' => $app['config']->get('rocketeer-slack-unofficial::config')['url'], 'channel' => $app['config']->get('rocketeer-slack-unofficial::config')['channel'], 'link_names' => true, 'icon' => ':rocket:']; $app->bind('slack', function ($app) use($settings) { return new Client($app['config']->get('rocketeer-slack-unofficial::config')['hook-url'], $settings); }); return $app; }
/** * @param $class * @param array $args * @return mixed * @throws RepositoryException */ protected function makeCriteria($class, array $args) { $criteria = $this->app->make($class, $args); if (!$criteria instanceof CriteriaContract) { throw new RepositoryException("Class {$class} must be an instance of GuilhermeGonzaga\\Repository\\Criteria\\Criteria"); } return $criteria; }
/** * 初始化,注入container * * @param Container $container */ public function __construct(Container $container) { $this->container = $container; // 初始化 DB类 TODO 应该用 事件监听的方式来初始化 因为有可能在不需要db的情况下也初始化了 $container->make('db'); if (method_exists($this, '__init__')) { return call_user_func_array(array($this, '__init__'), array()); } }
/** * Resolve an instance of the given seeder class. * * @param string $class * @return \Illuminate\Database\Seeder */ protected function resolve($class) { if (isset($this->container)) { $instance = $this->container->make($class); return $instance->setContainer($this->container)->setCommand($this->command); } else { return new $class(); } }
protected function createContainer() { $container = new Container(); $container->instance('array_iterator', new \ArrayIterator(range(1, 5))); $container->bind('error', function () { throw new \RuntimeException(); }); return new LaravelContainerAdapter($container); }
/** * Makes a request. * * @param Request $request A Request instance * @return Response A Response instance * @throws \Exception */ protected function doRequest($request) { $uses = array_flip(class_uses_recursive(get_class($this->app))); if (isset($uses[RoutesRequests::class])) { return $this->response = $this->app->prepareResponse($this->app->handle($request)); } else { throw new \Exception(sprintf('The application is not using the %s trait.', RoutesRequests::class)); } }
/** * @return $this */ protected function parseIncludes() { $request = $this->application->make('Illuminate\\Http\\Request'); $paramIncludes = Config::get('reloquent.fractal.params.include', 'include'); if ($request->has($paramIncludes)) { $this->fractal->parseIncludes($request->get($paramIncludes)); } return $this; }
/** * Bind the Warkham classes to the Container * * @param Container $app * * @return Container */ public function bindWarkhamClasses(Container $app) { $app->singleton('warkham', function ($app) { $methodDispatcher = array('Warkham\\Fields\\', Warkham::FIELDSPACE); $methodDispatcher = new MethodDispatcher($app, $methodDispatcher); return new Warkham($app, $methodDispatcher); }); return $app; }
/** @test */ public function it_can_retrieve_dynamic_objects_from_the_container() { $container = new Container(); $container->bind('foo', function () { return 'bar'; }); $handler = new EventHandlerStub($container); $this->assertSame('bar', $handler->foo); }
/** * Call the given controller instance method. * * @param \Illuminate\Routing\Controller $instance * @param \Illuminate\Routing\Route $route * @param \Illuminate\Http\Request $request * @param string $method * @return mixed */ protected function callWithinStack($instance, $route, $request, $method) { $middleware = $this->getMiddleware($instance, $method); $shouldSkipMiddleware = $this->container->bound('middleware.disable') && $this->container->make('middleware.disable') === true; // Here we will make a stack onion instance to execute this request in, which gives // us the ability to define middlewares on controllers. return (new Pipeline($this->container))->send($request)->through($shouldSkipMiddleware ? [] : $middleware)->then(function ($request) use($instance, $route, $method) { return $this->router->prepareResponse($request, $this->call($instance, $route, $method)); }); }
/** * @param Container $app * @param array $providers */ private function bindings(Container &$app, array $providers) { Collection::make($providers)->map(function ($provider) use($app) { return $app->make($provider, [$app]); })->filter(function ($object) { return is_a($object, ServiceProvider::class); })->each(function (ServiceProvider $provider) { $provider->register(); }); }
public function strip($text) { foreach ($this->getFormatters() as $formatter) { $formatter = $this->container->make($formatter); if (method_exists($formatter, 'strip')) { $text = $formatter->strip($text); } } return $text; }
public function __construct(array $attributes) { $this->encrypter = new Encrypter('088409730f085dd15e8e3a7d429dd185', 'AES-256-CBC'); $app = new Container(); $app->singleton('app', 'Illuminate\\Container\\Container'); $app->singleton('config', 'Illuminate\\Config\\Repository'); $app['config']->set('elocrypt.prefix', '__ELOCRYPT__:'); Facade::setFacadeApplication($app); parent::__construct($attributes); }
/** * Get the IoC Container * * @param string $make A dependency to fetch * * @return Container */ public static function getContainer($make = null) { if ($make) { return static::$container->make($make); } return static::$container; }