/** * 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')); }
/** * 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; }
/** * 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')); } }); }
/** * 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; }
/** * 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 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); } }
/** * 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')); } }
/** * 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); }
/** * 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); }
/** * 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; }
/** * 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']); } }
/** * 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; }
/** * 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()}%"); } }
/** * 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); }
/** * 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); }
/** * 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); } }
/** * 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; }
/** 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']); } }
/** * 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; }
/** * 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++; } }
/** * 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); } }
/** * 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')); } }
/** * 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, '#'); } }