本文整理汇总了PHP中Illuminate\Contracts\Container\Container::bound方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::bound方法的具体用法?PHP Container::bound怎么用?PHP Container::bound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Contracts\Container\Container
的用法示例。
在下文中一共展示了Container::bound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
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.');
}
}
示例2: getConverterFor
/**
* 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;
}
示例3: boot
/**
* 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.');
}
}
示例4: setupContainer
/**
* 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());
}
}
示例5: has
/**
* {@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;
}
示例6: handleException
/**
* 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);
}
示例7: addConnection
/**
* @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;
}
}
示例8: boot
/**
* 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.');
}
}
示例9: setMailerDependencies
/**
* 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']);
}
}
示例10: validate
/**
* 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);
}
}
示例11: resolve
/**
* {@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);
}
示例12: getDefaultPayload
/**
* 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;
}
示例13: createConnection
/**
* 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}]");
}
示例14: getTranslator
/**
* 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();
}
示例15: runCommandInForeground
/**
* 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'));
}
}