/**
  * Handle the command.
  *
  * @param Container $container
  */
 public function handle(Container $container)
 {
     /*
      * Set the default options handler based
      * on the builder class. Defaulting to
      * no handler.
      */
     if (!$this->builder->getRepository()) {
         $model = $this->builder->getFormModel();
         $entry = $this->builder->getEntry();
         $form = $this->builder->getForm();
         $repository = str_replace('FormBuilder', 'FormRepository', get_class($this->builder));
         if (!$this->builder->getRepository() && class_exists($repository)) {
             $this->builder->setRepository($container->make($repository, compact('form', 'model')));
         } elseif (!$this->builder->getRepository() && $model instanceof EntryModel) {
             $this->builder->setRepository($container->make(EntryFormRepository::class, compact('form', 'model')));
         } elseif (!$this->builder->getRepository() && $model instanceof EloquentModel) {
             $this->builder->setRepository($container->make(EloquentFormRepository::class, compact('form', 'model')));
         } elseif (!$this->builder->getRepository() && $entry instanceof EntryModel) {
             $this->builder->setRepository($container->make(EntryFormRepository::class, ['form' => $form, 'model' => $entry]));
         } elseif (!$this->builder->getRepository() && $entry instanceof EloquentModel) {
             $this->builder->setRepository($container->make(EloquentFormRepository::class, ['form' => $form, 'model' => $entry]));
         }
     }
 }
示例#2
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);
 }
示例#3
0
 public function make($class)
 {
     $command = $this->container->make($class);
     $command->setLaravel($this->container);
     $command->setServer($this->container->make('FluxBB\\Server\\ServerInterface'));
     return $command;
 }
示例#4
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;
 }
示例#5
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']));
     }
 }
示例#6
0
文件: Client.php 项目: huytd/core
 /**
  * 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);
 }
示例#7
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));
 }
示例#8
0
 /**
  * Get a Closure that represents a slice of the application onion.
  *
  * @return \Closure
  */
 protected function getSlice()
 {
     return function ($stack, $middleware) {
         return function ($request) use($stack, $middleware) {
             return $this->container->make($middleware)->handle($request, $stack);
         };
     };
 }
 /**
  * Make a view.
  *
  * @param  array $parameters
  * @return ViewInterface
  */
 public function make(array $parameters)
 {
     if (!class_exists(array_get($parameters, 'view'))) {
         array_set($parameters, 'view', $this->view);
     }
     $this->hydrator->hydrate($view = $this->container->make(array_get($parameters, 'view'), $parameters), $parameters);
     return $view;
 }
示例#10
0
 /**
  * Some decorators depend on others to complete their task.
  *
  * This is a helper method to easily create decorators that are available.
  *
  * @param string $class
  *
  * @throws \McCool\LaravelAutoPresenter\Exceptions\DecoratorNotFound
  *
  * @return object
  */
 public function createDecorator($class)
 {
     $decoratorClass = implode('\\', [__NAMESPACE__, $class . 'Decorator']);
     if (!class_exists($decoratorClass)) {
         throw new DecoratorNotFound($decoratorClass);
     }
     return $this->container->make($decoratorClass);
 }
 /**
  * Retrieves the validator for a specified command
  *
  * @param string $commandName
  * @return null|object
  */
 public function getValidatorForCommand($commandName)
 {
     $class_name = sprintf('%sValidator', $commandName);
     if (false === class_exists($class_name)) {
         return null;
     }
     return $this->app->make($class_name);
 }
示例#12
0
 /**
  * Resolve the current request.
  *
  * @return \Bugsnag\Request\RequestInterface
  */
 public function resolve()
 {
     if ($this->app->runningInConsole()) {
         return new NullRequest();
     }
     $request = $this->app->make(Request::class);
     return new LaravelRequest($request);
 }
示例#13
0
 /**
  * Resolve a class based on the driver configuration
  *
  * @return \Indatus\Dispatcher\Scheduling\ScheduleService
  */
 public function resolveServiceClass()
 {
     try {
         return $this->container->make($this->getDriver() . '\\ScheduleService');
     } catch (ReflectionException $e) {
         return $this->container->make('Indatus\\Dispatcher\\Drivers\\' . $this->getDriver() . '\\ScheduleService');
     }
 }
 /**
  * Returns the handler located in the same directory for a specified command.
  *
  * @param  string  $command
  * @return object
  *
  * @throws \League\Tactician\Exception\MissingHandlerException
  */
 public function getHandlerForCommand($command)
 {
     $handler = substr_replace($command, 'CommandHandler', strrpos($command, 'Command'));
     if (!class_exists($handler)) {
         throw MissingHandlerException::forCommand($command);
     }
     return $this->container->make($handler);
 }
示例#15
0
 /**
  * @param $class
  * @return $this
  */
 public function add($class)
 {
     $this->container->bind($class, $class);
     $subscriber = $this->container->make($class);
     $this->subscribers[] = $subscriber;
     $subscriber->handle();
     return $this;
 }
 /**
  * @param $requestClass
  * @return RequestHandlerInterface
  */
 private function requestHandler($requestClass)
 {
     $handler = $this->container->make($requestClass);
     if (!$handler instanceof RequestHandlerInterface) {
         throw new RuntimeException("Class {$requestClass} is not a request handler.");
     }
     return $handler;
 }
示例#17
0
 /**
  * Get the validator instance for the request.
  *
  * @return \Illuminate\Contracts\Validation\Validator
  */
 protected function getValidatorInstance()
 {
     $factory = $this->container->make(ValidationFactory::class);
     if (method_exists($this, 'validator')) {
         return $this->container->call([$this, 'validator'], compact('factory'));
     }
     return $factory->make($this->all(), $this->container->call([$this, 'rules']), $this->messages(), $this->attributes());
 }
 /**
  * Call the failed method on the job instance.
  *
  * The event instance and the exception will be passed.
  *
  * @param  array  $data
  * @param  \Exception  $e
  * @return void
  */
 public function failed(array $data, $e)
 {
     $handler = $this->container->make($data['class']);
     $parameters = array_merge(unserialize($data['data']), [$e]);
     if (method_exists($handler, 'failed')) {
         call_user_func_array([$handler, 'failed'], $parameters);
     }
 }
 /**
  * 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]);
 }
示例#21
0
 /**
  * Create the VersionFactory for the Version
  *
  * @return \LaraPackage\Api\Contracts\Factory\VersionFactory
  * @internal param $version
  *
  */
 protected function createVersionFactory()
 {
     $version = $this->requestParser->version();
     $factory = $this->apiVersion->factory($version);
     $instance = $this->app->make($factory);
     $this->app->instance(\LaraPackage\Api\Contracts\Factory\VersionFactory::class, $instance);
     return $instance;
 }
 /**
  * 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');
 }
 /**
  * @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);
 }
 /**
  * Retrieves the handler for a specified command
  *
  * @param string $commandName
  * @return object
  *
  * @throws \DeSmart\CommandBus\Exceptions\MissingHandlerException
  */
 public function getHandlerForCommand($commandName)
 {
     $class_name = sprintf('%sHandler', $commandName);
     if (false === class_exists($class_name)) {
         throw new MissingHandlerException("Class {$class_name} does not exist!");
     }
     return $this->app->make($class_name);
 }
示例#25
0
 /**
  * @param string $class
  * @return ControllerInterface
  */
 protected function resolveController($class)
 {
     $controller = $this->container->make($class);
     if (!$controller instanceof ControllerInterface) {
         throw new InvalidArgumentException('Controller must be an instance of ' . ControllerInterface::class);
     }
     return $controller;
 }
示例#26
0
 /**
  * Get instance of the empty form which can be modified
  *
  * @param array $options
  * @param array $data
  * @return Form
  */
 public function plain(array $options = [], array $data = [])
 {
     return $this->container
         ->make('Kris\LaravelFormBuilder\Form')
         ->setFormHelper($this->formHelper)
         ->setFormBuilder($this)
         ->setFormOptions($options)
         ->addData($data);
 }
 /**
  * Dynamically pass calls to tracker instances.
  *
  * @param $name
  * @param array $arguments
  * @return \BoxedCode\Tracking\Contracts\Tracker
  */
 public function __call($name, $arguments = [])
 {
     if (array_key_exists($name, $this->trackers)) {
         $tracker = $this->container->make($this->trackers[$name]);
         $attr = $tracker->getModelAttributes($arguments);
         $tracker->setModel(TrackableResourceModel::create($attr));
         return $tracker;
     }
 }
 /**
  * @param $name
  *
  * @throws LogicException
  * @return Sidebar
  */
 public function resolve($name)
 {
     $sidebar = $this->container->make($name);
     if (!$sidebar instanceof Sidebar) {
         throw new LogicException('Your sidebar should implement the Sidebar interface');
     }
     $sidebar->build();
     return $sidebar;
 }
示例#29
0
 /**
  * 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);
 }
 public function register(Container $container)
 {
     $container->bind(Relay::class, function (Container $container) {
         /** @var RelayBuilder $relayBuilder */
         $relayBuilder = $container->make(RelayBuilder::class);
         $queue = array_merge([$container->make(ResponseSender::class), $container->make(NikicFastRoute::class, ['actionAttributeName' => App::DEFAULT_ACTION_ATTRIBUTE_NAME, 'parametersAttributeName' => App::DEFAULT_PARAMETERS_ATTRIBUTE_NAME])], $container->tagged('middleware.error_handler'), $container->tagged('middleware.early'), $container->tagged('middleware'), $container->tagged('middleware.late'), [$container->make(ActionHandler::class, ['actionAttributeName' => App::DEFAULT_ACTION_ATTRIBUTE_NAME])]);
         return $relayBuilder->newInstance($queue);
     });
 }