/**
  * 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'));
 }
示例#2
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;
 }
示例#3
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'));
         }
     });
 }
示例#5
0
 /**
  * Filter value.
  *
  * @param  mixed   $value
  * @param  string  $filter
  *
  * @return mixed
  */
 protected function filterValue($value, $filter)
 {
     $resolver = $this->getFilterResolver($filter);
     if (method_exists($resolver[0], $resolver[1])) {
         return $this->app->call($resolver, ['value' => $value]);
     }
     return $value;
 }
示例#6
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());
 }
示例#7
0
 /**
  * Call and resolve depepndencies of a method if enabled.
  *
  * @author	Andrea Marco Sartori
  * @param	string	$method
  * @param	array	$parameters
  * @return	void
  */
 private function callIfExistsAndEnabled($method, array $parameters = [])
 {
     if (!$this->isEnabled()) {
         return;
     }
     if (method_exists($this, $method) && $this->{"{$method}IsEnabled"}()) {
         $this->container->call([$this, $method], $parameters);
     }
 }
示例#8
0
 /**
  * Resolve the target.
  *
  * @param        $target
  * @param array  $arguments
  * @param array  $options
  * @return mixed
  */
 public function resolve($target, array $arguments = [], array $options = [])
 {
     $method = array_get($options, 'method', 'handle');
     if (is_string($target) && str_contains($target, '@') || is_callable($target)) {
         $target = $this->container->call($target, $arguments);
     } elseif (is_string($target) && class_exists($target) && class_implements($target, SelfHandling::class)) {
         $target = $this->container->call($target . '@' . $method, $arguments);
     }
     return $target;
 }
 /**
  * Register field's custom validators.
  *
  * @param Factory     $factory
  * @param FormBuilder $builder
  * @param FieldType   $fieldType
  */
 protected function registerValidators(Factory $factory, FormBuilder $builder, FieldType $fieldType)
 {
     foreach ($fieldType->getValidators() as $rule => $validator) {
         $handler = array_get($validator, 'handler');
         if (is_string($handler) && !str_contains($handler, '@')) {
             $handler .= '@handle';
         }
         $factory->extend($rule, function ($attribute, $value, $parameters, Validator $validator) use($handler, $builder) {
             return $this->container->call($handler, compact('attribute', 'value', 'parameters', 'builder', 'validator'));
         }, array_get($validator, 'message'));
     }
 }
示例#10
0
 /**
  * Dispatch a command to its appropriate handler in the current process.
  *
  * @param  mixed  $command
  * @param  mixed  $handler
  * @return mixed
  */
 public function dispatchNow($command, $handler = null)
 {
     if ($handler || ($handler = $this->getCommandHandler($command))) {
         $callback = function ($command) use($handler) {
             return $handler->handle($command);
         };
     } else {
         $callback = function ($command) {
             return $this->container->call([$command, 'handle']);
         };
     }
     return $this->pipeline->send($command)->through($this->pipes)->then($callback);
 }
示例#11
0
 /**
  * Make a route.
  *
  * @param                    $route
  * @param  array             $parameters
  * @return mixed|null|string
  */
 public function make($route, array $parameters = [])
 {
     if (method_exists($this, $method = $this->str->camel(str_replace('.', '_', $route)))) {
         $parameters['parameters'] = $parameters;
         return $this->container->call([$this, $method], $parameters);
     }
     if (!str_contains($route, '.') && ($stream = $this->entry->getStreamSlug())) {
         $route = "{$stream}.{$route}";
     }
     if (!str_contains($route, '::') && ($namespace = $this->locator->locate($this->entry))) {
         $route = "{$namespace}::{$route}";
     }
     return $this->url->make($route, $this->entry, $parameters);
 }
示例#12
0
 /**
  * Run a macro.
  *
  * @param       $macro
  * @param Image $image
  * @return Image
  * @throws \Exception
  */
 public function run($macro, Image $image)
 {
     if (!($process = array_get($this->getMacros(), $macro))) {
         return $image;
     }
     if (is_array($process)) {
         foreach ($process as $method => $arguments) {
             $image->addAlteration($method, $arguments);
         }
     }
     if ($process instanceof \Closure) {
         $this->container->call($process, compact('image', 'macro'));
     }
     return $image;
 }
示例#13
0
文件: Grid.php 项目: stevebauman/html
 /**
  * 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']);
     }
 }
示例#14
0
 /**
  * Determine if the request passes the authorization check.
  *
  * @return bool
  */
 protected function passesAuthorization()
 {
     if (method_exists($this, 'authorize')) {
         return $this->container->call([$this, 'authorize']);
     }
     return false;
 }
示例#15
0
 /**
  * Determine if the request passes the authorization check.
  *
  * @return bool
  */
 protected function passesAuthorization()
 {
     $enabled = false;
     if (method_exists($this, 'authorize')) {
         $enabled = $this->container->call([$this, 'authorize']);
     }
     return (bool) $enabled;
 }
 /**
  * Handle the filter.
  *
  * @param Builder         $query
  * @param FilterInterface $filter
  */
 public function handle(Builder $query, FilterInterface $filter)
 {
     $stream = $filter->getStream();
     if ($stream && ($fieldType = $stream->getFieldType($filter->getField()))) {
         $fieldTypeQuery = $fieldType->getQuery();
         $this->container->call([$fieldTypeQuery, 'filter'], compact('query', 'filter', 'builder'));
         return;
     }
     if ($stream && ($fieldType = $stream->getFieldType($filter->getSlug()))) {
         $fieldTypeQuery = $fieldType->getQuery();
         $this->container->call([$fieldTypeQuery, 'filter'], compact('query', 'filter', 'builder'));
         return;
     }
     if ($filter->isExact()) {
         $query->where($filter->getSlug(), $filter->getValue());
     } else {
         $query->where($filter->getSlug(), 'LIKE', "%{$filter->getValue()}%");
     }
 }
示例#17
0
 /**
  * Run the given event.
  *
  * @param  \Illuminate\Contracts\Container\Container  $container
  * @return mixed
  */
 public function run(Container $container)
 {
     if ($this->description) {
         touch($this->mutexPath());
     }
     $response = $container->call($this->callback, $this->parameters);
     @unlink($this->mutexPath());
     parent::callAfterCallbacks($container);
     return $response;
 }
 /**
  * Handle the select options.
  *
  * @param SelectFieldType $fieldType
  * @return array
  */
 public function handle(SelectFieldType $fieldType, Container $container)
 {
     $options = array_get($fieldType->getConfig(), 'options', []);
     if (is_string($options)) {
         $options = $this->dispatch(new ParseOptions($options));
     }
     if ($options instanceof \Closure) {
         $options = $container->call($options);
     }
     $fieldType->setOptions($options);
 }
示例#19
0
 /**
  * Handle the event.
  *
  * @param Container $container
  */
 public function handle(Container $container)
 {
     if ($this->builder->hasFormErrors()) {
         return;
     }
     $handler = $this->builder->getHandler();
     if ($handler && !str_contains($handler, '@')) {
         $handler .= '@handle';
     }
     $container->call($handler, ['builder' => $this->builder]);
 }
 /**
  * Dispatch a command to its appropriate handler in the current process.
  *
  * @param  mixed  $command
  * @param  \Closure|null  $afterResolving
  * @return mixed
  */
 public function dispatchNow($command, Closure $afterResolving = null)
 {
     if ($command instanceof SelfHandling) {
         return $this->container->call([$command, 'handle']);
     }
     $handler = $this->resolveHandler($command);
     if ($afterResolving) {
         call_user_func($afterResolving, $handler);
     }
     return call_user_func([$handler, $this->getHandlerMethod($command)], $command);
 }
示例#21
0
 /**
  * Handle the view's table modification.
  *
  * @param TableBuilder  $builder
  * @param ViewInterface $view
  */
 public function handle(TableBuilder $builder, ViewInterface $view)
 {
     if (!($handler = $view->getHandler())) {
         return;
     }
     /*
      * 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'));
     }
     /*
      * If the handle is an instance of ViewHandlerInterface
      * simply call the handle method on it.
      */
     if ($handler instanceof ViewHandlerInterface) {
         $handler->handle($builder);
     }
 }
示例#22
0
 /**
  * Resolve database connection.
  *
  * @param  \Illuminate\Database\Eloquent\Model  $entity
  * @param  string  $database
  *
  * @return string
  */
 protected function resolveDatabaseConnection(Model $entity, $database)
 {
     $repository = $this->app->make('config');
     $connection = $this->bindWithKey($entity, $database);
     $database = Arr::get($this->config, 'database');
     $name = "database.connections.{$connection}";
     if (!is_null($database) && is_null($repository->get($name))) {
         $config = $this->app->call($database['resolver'], ['entity' => $entity, 'template' => $database['template'], 'connection' => $connection]);
         $repository->set($name, $config);
     }
     return $connection;
 }
示例#23
0
 /** Instantiates the class
  *
  * @param \Radic\Laraval\Contracts\Factory|\Radic\Laraval\Factory $factory
  * @param \Illuminate\Contracts\Container\Container               $container
  * @param \Sebwite\Support\Filesystem                        $files
  * @param \Illuminate\Contracts\View\Factory                      $viewFactory
  * @param \Illuminate\Contracts\Validation\Factory                $validationFactory
  * @param \Illuminate\Contracts\Routing\ResponseFactory           $responseFactory
  * @param array                                                   $rules
  */
 public function __construct(LaravalFactory $factory, Container $container, Filesystem $files, ViewFactory $viewFactory, array $rules = [])
 {
     $this->factory = $factory;
     $this->files = $files;
     $this->viewFactory = $viewFactory;
     $this->rules = new Collection($rules);
     $this->validatorOptions = new Collection();
     $this->embed = true;
     if (method_exists($this, 'init')) {
         $container->call([$this, 'init']);
     }
 }
示例#24
0
 /**
  * Run the given event.
  *
  * @param  \Illuminate\Contracts\Container\Container  $container
  * @return mixed
  *
  * @throws \Exception
  */
 public function run(Container $container)
 {
     if ($this->description) {
         $this->cache->put($this->mutexName(), true, 1440);
     }
     try {
         $response = $container->call($this->callback, $this->parameters);
     } finally {
         $this->removeMutex();
     }
     parent::callAfterCallbacks($container);
     return $response;
 }
示例#25
0
 /**
  * Run the given event.
  *
  * @param \Illuminate\Contracts\Container\Container $container        	
  * @return mixed
  *
  * @throws \Exception
  */
 public function run(Container $container)
 {
     if ($this->description) {
         touch($this->mutexPath());
     }
     try {
         $response = $container->call($this->callback, $this->parameters);
     } finally {
         $this->removeMutex();
     }
     parent::callAfterCallbacks($container);
     return $response;
 }
 /**
  * Handle the command.
  *
  * @param Container $container
  */
 public function handle(Container $container)
 {
     $step = 1;
     $total = $this->installers->count();
     /* @var Installer $installer */
     while ($installer = $this->installers->shift()) {
         if ($this->command) {
             $this->command->info("{$step}/{$total} " . trans($installer->getMessage()));
         }
         $container->call($installer->getTask());
         $step++;
     }
 }
示例#27
0
文件: Dispatcher.php 项目: rikh42/Bus
 /**
  * Dispatch a command to its appropriate handler in the current process.
  *
  * @param mixed         $command
  * @param \Closure|null $afterResolving
  *
  * @return mixed
  */
 public function dispatchNow($command, Closure $afterResolving = null)
 {
     return $this->pipeline->send($command)->through($this->pipes)->then(function ($command) use($afterResolving) {
         if (method_exists($command, 'handle')) {
             return $this->container->call([$command, 'handle']);
         }
         $handler = $this->resolveHandler($command);
         if ($afterResolving) {
             call_user_func($afterResolving, $handler);
         }
         return call_user_func([$handler, $this->getHandlerMethod($command)], $command);
     });
 }
 /**
  * Set the form response using the active action
  * form response handler.
  *
  * @param FormBuilder $builder
  * @param             $action
  */
 public function setFormResponse(FormBuilder $builder, ActionInterface $action)
 {
     $handler = $action->getHandler();
     // Self handling implies @handle
     if (is_string($handler) && !str_contains($handler, '@')) {
         $handler .= '@handle';
     }
     /*
      * If the handler is a closure or callable
      * string then call it using the service container.
      */
     if (is_string($handler) || $handler instanceof \Closure) {
         $this->container->call($handler, compact('builder'));
     }
     /*
      * If the handle is an instance of ActionHandlerInterface
      * simply call the handle method on it.
      */
     if ($handler instanceof ActionHandlerInterface) {
         $handler->handle($builder);
     }
 }
示例#29
0
 /**
  * Modify the table's query using the filters.
  *
  * @param TableBuilder    $builder
  * @param FilterInterface $filter
  * @param Builder         $query
  */
 public function filter(TableBuilder $builder, FilterInterface $filter, Builder $query)
 {
     /*
      * If the filter is self handling then let
      * it filter the query itself.
      */
     if (method_exists($filter, 'handle')) {
         $this->container->call([$filter, 'handle'], compact('builder', 'query', 'filter'));
         return;
     }
     $handler = $filter->getQuery();
     // 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', 'filter'));
     }
 }
示例#30
0
 /**
  * Handle the command.
  *
  * @param Container            $container
  * @param ViewTemplate         $template
  * @param BreadcrumbCollection $breadcrumbs
  */
 public function handle(Container $container, ViewTemplate $template, BreadcrumbCollection $breadcrumbs)
 {
     $tree = $this->builder->getTree();
     $tree->addData('tree', $tree);
     if ($handler = $tree->getOption('data')) {
         $container->call($handler, compact('tree'));
     }
     if ($layout = $tree->getOption('layout_view')) {
         $template->put('layout', $layout);
     }
     if ($title = $tree->getOption('title')) {
         $template->put('title', $title);
     }
     if ($breadcrumb = $tree->getOption('breadcrumb')) {
         $breadcrumbs->put($breadcrumb, '#');
     }
 }