public function boot() { parent::boot(); if (!$this->container->bound(JobSchedulerInterface::class)) { throw new CoreException('This module requires the Jobs component to be loaded. ' . 'Please make sure that `JobsServiceProvider` ' . 'is in your application\'s `config/app.php` file.'); } }
/** * Get the appropriate converter name for the given value. * TODO: Clean this up. A lot. * * @param mixed $value * @param bool $debug * @return string */ public function getConverterFor($value, bool $debug = false) { $type = $this->getType($value); $config = app('Illuminate\\Contracts\\Config\\Repository'); $defaults = collect($this->converterManager->getDefaultConverters())->merge($this->application['config']->get('laravel-xml.converters.defaults'))->filter(function ($item) { $item = is_array($item) ? $item['value'] : $item; return class_exists($item) or $this->container->bound($item); }); $custom = collect($this->application['config']->get('laravel-xml.converters.custom'))->filter(function ($item) { $item = is_array($item) ? $item['value'] : $item; return class_exists($item) or $this->container->bound($item); }); // if ($debug) dd($custom); // Step one: Try to find the CLASS or TYPE in $custom $class = $custom->get(is_object($value) ? get_class($value) : str_plural($type), function () use($custom, $defaults, $value, $type) { // Step two: try to find the TYPE in $custom return $custom->get(str_plural($type), function () use($defaults, $value, $type) { // Step three: Try to find the CLASS or TYPE in $defaults return $defaults->get(is_object($value) ? get_class($value) : str_plural($type), function () use($defaults, $value, $type) { // Step four: Try to find the TYPE in $defaults return $defaults->get(str_plural($type), function () { // If nothing works, throw an error. throw new NoConverterFoundException("Could not find an appropriate converter."); }); }); }); }); return is_array($class) ? isset($class['value']) ? $class['value'] : '' : $class; }
/** * Boot the module. * * @throws CoreException */ public function boot() { parent::boot(); if (!$this->container->bound(ApplicationManifestInterface::class)) { throw new CoreException('An instance of ApplicationManifest must be bound to in the ' . 'container in order to provide application reflection data.'); } }
/** * Setup the IoC container instance. * * @param \Illuminate\Contracts\Container\Container $container * @return void */ protected function setupContainer(Container $container) { $this->container = $container; if (!$this->container->bound('config')) { $this->container->instance('config', new Fluent()); } }
/** * {@inheritdoc} */ public function has($id) { if ($this->hasIsCached($id)) { return $this->hasFromCache($id); } $has = $this->container->bound($id) || $this->isInstantiable($id); $this->cacheHas($id, $has); return $has; }
/** * Handle the given exception. * * (Copy from Illuminate\Routing\Pipeline by Taylor Otwell) * * @param $passable * @param Exception $e * @return mixed * @throws Exception */ protected function handleException($passable, Exception $e) { if (!$this->container->bound(ExceptionHandler::class) || !$passable instanceof Request) { throw $e; } $handler = $this->container->make(ExceptionHandler::class); $handler->report($e); return $handler->render($passable, $e); }
/** * @param $connection */ public function addConnection($connection) { if (!$this->container->bound($this->getConnectionBindingName($connection))) { $this->container->singleton($this->getConnectionBindingName($connection), function () use($connection) { return $this->getManager($connection)->getConnection(); }); $this->connections[$connection] = $connection; } }
/** * Boot the module. * * @throws CoreException */ public function boot() { parent::boot(); if (!$this->container->bound(StructuredStatusInterface::class)) { throw new CoreException('This module requires the Structured service to be loaded. ' . 'Please make sure that `StructuredMigrationsServiceProvider` ' . 'is in your application\'s `config/app.php` file.'); } if (!$this->container->bound(Batch::class)) { throw new CoreException('While the Structured service is loaded, there isn\'t a ' . 'Batch defined at the moment. Please define a Batch class ' . 'for your application and bind it using a service provider.'); } }
/** * Set a few dependencies on the mailer instance. * * @return void */ protected function setMailerDependencies() { $this->mailer->setContainer($this->app); if ($this->app->bound('Psr\\Log\\LoggerInterface')) { $this->mailer->setLogger($this->app->make('Psr\\Log\\LoggerInterface')); } if ($this->app->bound('queue')) { $this->mailer->setQueue($this->app['queue.connection']); } }
/** * Validate the request using the checkable class. * * @throws FailedCheckException */ public function validate() { if ($this->container->bound('illuminated.skipCheckableRequest')) { return; } $check = $this->getCheckable(); $result = $check->check($this->assemble($this->request)); if ($result->failed()) { $this->handleFailure($check, $result); } }
/** * {@inheritdoc} */ public function resolve($name) { $value = $this->registrations[$name]; if (is_string($value)) { // Check for `class@method` format. if (strpos($value, '@') >= 1) { $segments = explode('@', $value, 2); if ($this->container->bound($segments[0])) { return [$this->container->make($segments[0]), $segments[1]]; } } if ($this->container->bound($name)) { return $this->container->make($name); } } return parent::resolve($name); }
/** * Get the default paylaod for the session. * * @param string $data * @return array */ protected function getDefaultPayload($data) { $payload = ['payload' => base64_encode($data), 'last_activity' => time()]; if ($this->container && $this->container->bound(Guard::class)) { $payload['user_id'] = $this->container->make(Guard::class)->id(); } if ($this->container && $this->container->bound('request')) { $payload['ip_address'] = $this->container->make('request')->ip(); } return $payload; }
/** * Create a new connection instance. * * @param string $driver * @param \PDO|\Closure $connection * @param string $database * @param string $prefix * @param array $config * @return \Illuminate\Database\Connection * * @throws \InvalidArgumentException */ protected function createConnection($driver, $connection, $database, $prefix = '', array $config = []) { if ($this->container->bound($key = "db.connection.{$driver}")) { return $this->container->make($key, [$connection, $database, $prefix, $config]); } switch ($driver) { case 'mysql': return new MySqlConnection($connection, $database, $prefix, $config); case 'pgsql': return new PostgresConnection($connection, $database, $prefix, $config); case 'sqlite': return new SQLiteConnection($connection, $database, $prefix, $config); case 'sqlsrv': return new SqlServerConnection($connection, $database, $prefix, $config); } throw new InvalidArgumentException("Unsupported driver [{$driver}]"); }
/** * Get a translator instance. * * @param \Illuminate\Contracts\Container\Container $container * @return \Symfony\Component\Translation\TranslatorInterface */ protected function getTranslator(Container $container = null) { if ($container && $container->bound('translator')) { return $container['translator']; } return new Translator(); }
/** * Run the command in the foreground. * * @param \Illuminate\Contracts\Container\Container $container * @return void */ protected function runCommandInForeground(Container $container) { (new Process(trim($this->buildCommand(), '& '), base_path(), null, null, null))->run(); if ($this->afterCallback) { $container->call($this->afterCallback); } if ($this->emailAddresses && $container->bound('Illuminate\\Contracts\\Mail\\Mailer')) { $this->emailOutput($container->make('Illuminate\\Contracts\\Mail\\Mailer')); } }
/** * {@inheritDoc} */ protected function accepts($receiver) { return $this->container->bound($receiver); }
/** * @inheritdoc */ public function hasRequest() { return $this->container->bound(RequestInterface::class); }