本文整理汇总了PHP中Illuminate\Contracts\Container\Container类的典型用法代码示例。如果您正苦于以下问题:PHP Container类的具体用法?PHP Container怎么用?PHP Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolve
/**
* Add a command, resolving through the application.
*
* @param string $command
*
* @return \Symfony\Component\Console\Command\Command
*/
public function resolve($command)
{
if (is_null($this->container)) {
$this->container = Container::getInstance();
}
return $this->add($this->container->make($command));
}
示例2: handle
/**
* Handle the command.
*
* @param ModuleCollection $modules
* @param Decorator $decorator
* @param Repository $config
* @param Container $container
* @param Request $request
* @param Search $search
* @return LengthAwarePaginator
*/
public function handle(ModuleCollection $modules, Decorator $decorator, Repository $config, Container $container, Request $request, Search $search)
{
/* @var Query $query */
$query = $search->index($this->criteria->option('index', 'default'));
$constraint = $this->criteria->option('in');
if (!empty($constraint) && is_string($constraint)) {
$query = $query->search('stream', $constraint, ['required' => true]);
}
if (!empty($constraint) && is_array($constraint)) {
/* @var Module $module */
foreach ($modules->withConfig('search') as $module) {
foreach ($config->get($module->getNamespace('search')) as $model => $definition) {
/* @var EntryInterface $model */
$model = $container->make($model);
$stream = $model->getStreamNamespace() . '.' . $model->getStreamSlug();
if (!in_array($stream, $constraint)) {
$query = $query->search('stream', $stream, ['required' => false, 'prohibited' => true]);
}
}
}
}
foreach ($this->criteria->getOperations() as $operation) {
$query = call_user_func_array([$query, $operation['name']], $operation['arguments']);
}
$page = $request->get('page', 1);
$perPage = $this->criteria->option('paginate', $this->criteria->option('limit', 15));
$query->limit($perPage, ($page - 1) * $perPage);
$collection = new SearchCollection(array_map(function ($result) use($decorator) {
return $decorator->decorate(new SearchItem($result));
}, $query->get()));
return (new LengthAwarePaginator($collection, $query->count(), $perPage, $page))->setPath($request->path())->appends($request->all());
}
示例3: registerContainerBindings
/**
* Registers container bindings.
*
* @param Container $container
* @param ConfigRepository $config
*/
protected function registerContainerBindings(Container $container, ConfigRepository $config)
{
$container->singleton('Doctrine\\ORM\\EntityManager', function () use($config) {
return $this->createEntityManager($config);
});
$container->alias('Doctrine\\ORM\\EntityManager', 'Doctrine\\ORM\\EntityManagerInterface');
}
示例4: register
public function register(Container $container)
{
$container->singleton(Container::class, function () use($container) {
return $container;
});
$container->singleton(ContainerInterface::class, LaravelContainer::class);
}
示例5: registerBindings
/**
* @param Container $container
* @param ConfigRepository $config
*/
protected function registerBindings(Container $container, ConfigRepository $config)
{
$container->singleton(SparkPostService::class, function () use($config) {
return new SparkPostService($config[self::CONFIG_KEY]);
});
$container->alias(SparkPostService::class, SparkPostServiceContract::class);
}
示例6: __construct
/**
* Create a new Grid instance.
*
* @param \Illuminate\Contracts\Container\Container $app
*/
public function __construct(Container $app)
{
$this->app = $app;
if (method_exists($this, 'initiate')) {
$app->call([$this, 'initiate']);
}
}
示例7: handle
/**
* Execute the console command.
* @param Container The service container.
* @return mixed
*/
public function handle(Container $services)
{
$config = config('rest-scaffolding');
$namespace = $this->argument('namespace');
$prefix = $this->argument('prefix');
$services->make(Generator::class)->setProgressBar($this->output->createProgressBar())->processFiles($config, $namespace, $prefix);
}
示例8: registerContainerBindings
/**
* Registers the container bindings.
*
* @param Container $container
*/
protected function registerContainerBindings(Container $container)
{
$container->singleton('Nord\\Lumen\\Mandrill\\Mailer\\Contracts\\MandrillMailer', function () {
$config = config('mandrillmailer', []);
return new MandrillMailer($config);
});
}
示例9: registerContainerBindings
/**
* Registers container bindings.
*
* @param Container $container
* @param ConfigRepository $config
*
* @return DocumentManager
*/
protected function registerContainerBindings(Container $container, ConfigRepository $config)
{
$container->singleton('Doctrine\\ODM\\MongoDB\\DocumentManager', function () use($config) {
Config::mergeWith($config);
return $this->createDocumentManager($config);
});
}
示例10: send
/**
* Execute the given API action class, pass the input and return its response.
*
* @param User $actor
* @param string $actionClass
* @param array $input
* @return object
*/
public function send(User $actor, $actionClass, array $input = [])
{
/** @var \Flarum\Api\Actions\JsonApiAction $action */
$action = $this->container->make($actionClass);
$response = $action->handle(new Request($input, $actor));
return new Response($response);
}
示例11: 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.');
}
}
示例12: versionFactoryExpectations
/**
* @param App $app
* @param \LaraPackage\Api\Contracts\Request\Parser $requestParser
* @param \LaraPackage\Api\Contracts\Factory\VersionFactory $versionFactory
*/
protected function versionFactoryExpectations(App $app, \LaraPackage\Api\Contracts\Request\Parser $requestParser, \LaraPackage\Api\Contracts\Factory\VersionFactory $versionFactory, ApiVersion $apiVersion)
{
$requestParser->version()->shouldBeCalled()->willReturn($this->version);
$apiVersion->factory($this->version)->shouldBeCalled()->willReturn(VersionFactory::class);
$app->instance(\LaraPackage\Api\Contracts\Factory\VersionFactory::class, $versionFactory)->shouldBeCalled();
$app->make(VersionFactory::class)->shouldBeCalledTimes(1)->willReturn($versionFactory);
}
示例13: failed
/**
* Call the failed method on the job instance.
*
* @param array $data
* @return void
*/
public function failed(array $data)
{
$handler = $this->container->make($data['class']);
if (method_exists($handler, 'failed')) {
call_user_func_array([$handler, 'failed'], unserialize($data['data']));
}
}
示例14: 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;
}
示例15: make
public function make($class)
{
$command = $this->container->make($class);
$command->setLaravel($this->container);
$command->setServer($this->container->make('FluxBB\\Server\\ServerInterface'));
return $command;
}