Esempio n. 1
0
 /**
  * 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);
 }
Esempio n. 2
0
 /**
  * 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));
 }
Esempio n. 3
0
 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.');
     }
 }
Esempio n. 4
0
 /**
  * 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());
 }
Esempio n. 5
0
 /**
  * @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);
 }
 /**
  * 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');
 }
Esempio n. 7
0
 /**
  * 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']));
     }
 }
Esempio n. 8
0
 /**
  * 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;
 }
Esempio n. 9
0
 public function make($class)
 {
     $command = $this->container->make($class);
     $command->setLaravel($this->container);
     $command->setServer($this->container->make('FluxBB\\Server\\ServerInterface'));
     return $command;
 }
Esempio n. 10
0
 /**
  * @param string $class
  * @param int $priority
  * @return Storage
  */
 public function add($class, $priority = self::PRIORITY_DEFAULT) : Storage
 {
     $this->container->bind($class, $class);
     $instance = $this->container->make($class);
     $this->storage->insert($instance, $priority);
     return $this;
 }
 /**
  * Handle the filter.
  *
  * @param Builder              $query
  * @param FieldFilterInterface $filter
  * @param TableBuilder         $builder
  */
 public function handle(Builder $query, FieldFilterInterface $filter, TableBuilder $builder)
 {
     $stream = $filter->getStream();
     $fieldType = $stream->getFieldType($filter->getField());
     $fieldTypeQuery = $fieldType->getQuery();
     $this->container->call([$fieldTypeQuery, 'filter'], compact('query', 'filter', 'builder'));
 }
Esempio n. 12
0
 /**
  * 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.');
     }
 }
 public function register(Container $container)
 {
     $container->singleton(Container::class, function () use($container) {
         return $container;
     });
     $container->singleton(ContainerInterface::class, LaravelContainer::class);
 }
 /**
  * @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);
 }
Esempio n. 15
0
 /**
  * Resolve the given resource name.
  *
  * @param  string                                               $name
  * @throws \ByCedric\Allay\Exceptions\ResourceNotFoundException
  * @return mixed
  */
 public function make($name)
 {
     if ($this->contains($name)) {
         return $this->container->make($this->resources[$name]);
     }
     throw new ResourceNotFoundException($name);
 }
Esempio n. 16
0
 /**
  * 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']);
     }
 }
Esempio n. 17
0
 /**
  * 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);
 }
Esempio n. 18
0
 /**
  * Create a new command instance.
  * @param App $app
  */
 public function __construct(App $app)
 {
     parent::__construct();
     $this->public_directory = $app->basePath() . '/public/';
     $this->views_directory = $app->basePath() . '/resources/views/';
     $this->ui_directory = env('UI_PATH');
 }
 /**
  * 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);
     });
 }
 /**
  * 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);
     });
 }
 /**
  * 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());
     }
 }
Esempio n. 22
0
 /**
  * Evaluate a target entity with arguments.
  *
  * @param        $target
  * @param  array $arguments
  * @return mixed
  */
 public function evaluate($target, array $arguments = [])
 {
     /**
      * If the target is an instance of Closure then
      * call through the IoC it with the arguments.
      */
     if ($target instanceof \Closure) {
         return $this->container->call($target, $arguments);
     }
     /**
      * If the target is an array then evaluate
      * each of it's values.
      */
     if (is_array($target)) {
         foreach ($target as &$value) {
             $value = $this->evaluate($value, $arguments);
         }
     }
     /**
      * if the target is a string and is in a traversable
      * format then traverse the target using the arguments.
      */
     if (is_string($target) && !isset($arguments[$target]) && $this->isTraversable($target)) {
         $target = data_get($arguments, $target, $target);
     }
     return $target;
 }
Esempio n. 23
0
 protected function makeAndRegisterServiceProviders(Container $container, array $serviceProviderClassNames)
 {
     foreach ($serviceProviderClassNames as $providerClassName) {
         $provider = $container->make($providerClassName);
         $provider->register($container);
     }
 }
Esempio n. 24
0
 /**
  * Handle the view query.
  *
  * @param  TableBuilder  $builder
  * @param  Builder       $query
  * @param  ViewInterface $view
  * @return mixed
  * @throws \Exception
  */
 public function handle(TableBuilder $builder, Builder $query, ViewInterface $view)
 {
     $view->fire('querying', compact('builder', 'query'));
     if (!($handler = $view->getQuery())) {
         return;
     }
     // Self handling implies @handle
     if (is_string($handler) && !str_contains($handler, '@')) {
         $handler .= '@handle';
     }
     /*
      * If the handler is a callable string or Closure
      * then call it using the IoC container.
      */
     if (is_string($handler) || $handler instanceof \Closure) {
         $this->container->call($handler, compact('builder', 'query'));
     }
     /*
      * If the handle is an instance of ViewQueryInterface
      * simply call the handle method on it.
      */
     if ($handler instanceof ViewQueryInterface) {
         $handler->handle($builder, $query);
     }
 }
 /**
  * Handle the filter.
  *
  * @param Builder               $query
  * @param SearchFilterInterface $filter
  */
 public function handle(Builder $query, TableBuilder $builder, SearchFilterInterface $filter)
 {
     $stream = $filter->getStream();
     $model = $builder->getTableModel();
     /**
      * If the model is translatable then
      * join it's translations so they
      * are filterable too.
      *
      * @var EloquentQueryBuilder $query
      */
     if ($model->getTranslationModelName() && !$query->hasJoin($model->getTranslationTableName())) {
         $query->leftJoin($model->getTranslationTableName(), $model->getTableName() . '.id', '=', $model->getTranslationTableName() . '.' . $model->getRelationKey());
     }
     $query->where(function (Builder $query) use($filter, $stream) {
         foreach ($filter->getColumns() as $column) {
             $query->orWhere($column, 'LIKE', "%{$filter->getValue()}%");
         }
         foreach ($filter->getFields() as $field) {
             $filter->setField($field);
             $fieldType = $stream->getFieldType($field);
             $fieldTypeQuery = $fieldType->getQuery();
             $fieldTypeQuery->setConstraint('or');
             $this->container->call([$fieldTypeQuery, 'filter'], compact('query', 'filter', 'builder'));
         }
     });
 }
Esempio n. 26
0
 public function test_cant_extend_with_an_invalid_class()
 {
     $this->registry->shouldReceive('getManager')->once()->with('default')->andReturn($this->em);
     $this->container->shouldReceive('make')->once()->with(InvalidDoctrineExtender::class)->andReturn(new InvalidDoctrineExtender());
     $this->setExpectedException(InvalidArgumentException::class);
     $this->manager->extend('default', InvalidDoctrineExtender::class);
 }
 /**
  * Handle the queued job.
  *
  * @param  \Illuminate\Contracts\Queue\Job  $job
  * @param  array  $data
  * @return void
  */
 public function call(Job $job, array $data)
 {
     $handler = $this->setJobInstanceIfNecessary($job, $this->container->make($data['class']));
     call_user_func_array([$handler, $data['method']], unserialize($data['data']));
     if (!$job->isDeletedOrReleased()) {
         $job->delete();
     }
 }
 /**
  * Returns the handler bound to the command's class name.
  *
  * @param  string  $command
  * @return object
  *
  * @throws \League\Tactician\Exception\MissingHandlerException
  */
 public function getHandlerForCommand($command)
 {
     $handlers = $this->config->get('tactician.handlers', []);
     if (!isset($handlers[$command]) || !class_exists($handlers[$command])) {
         throw MissingHandlerException::forCommand($command);
     }
     return $this->container->make($handlers[$command]);
 }
 /**
  * @param string $commandName
  *
  * @return mixed
  */
 public function getHandlerForCommand($commandName)
 {
     $handlerName = str_replace($this->origin, $this->target, $commandName);
     if (!class_exists($handlerName)) {
         throw MissingHandlerException::forCommand($commandName);
     }
     return $this->container->make($handlerName);
 }
 /**
  * Handle the command.
  */
 public function handle(Image $image, Container $container, Application $application)
 {
     $image->addPath('public', base_path('public'));
     $image->addPath('node', base_path('node_modules'));
     $image->addPath('asset', $application->getAssetsPath());
     $image->addPath('streams', $container->make('streams.path') . '/resources');
     $image->addPath('bower', $container->make('path.base') . '/bin/bower_components');
 }