/** * Make a field type. * * @param array $parameters * @param StreamInterface $stream * @param null $entry * @return FieldType */ public function make(array $parameters, StreamInterface $stream = null, $entry = null) { /* @var EntryInterface $entry */ if ($stream && $entry instanceof EntryInterface && $entry->hasField(array_get($parameters, 'field'))) { $field = clone $entry->getFieldType(array_get($parameters, 'field')); $modifier = $field->getModifier(); $value = array_pull($parameters, 'value'); /* @var EntryInterface $entry */ $field->setValue(!is_null($value) ? $modifier->restore($value) : $entry->getAttribute($field->getField())); } elseif (is_object($entry)) { $field = $this->builder->build($parameters); $modifier = $field->getModifier(); $value = array_pull($parameters, 'value'); $field->setValue(!is_null($value) ? $modifier->restore($value) : $entry->{$field->getField()}); } else { $field = $this->builder->build($parameters); $modifier = $field->getModifier(); $field->setValue($modifier->restore(array_pull($parameters, 'value'))); } // Set the entry. $field->setEntry($entry); // Merge in rules and validators. $field->mergeRules(array_pull($parameters, 'rules', []))->mergeConfig(array_pull($parameters, 'config', []))->mergeMessages(array_pull($parameters, 'messages', []))->mergeValidators(array_pull($parameters, 'validators', [])); // Hydrate the field with parameters. $this->hydrator->hydrate($field, $parameters); return $field; }
/** * 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; }
/** * Make the widget from the parameters. * * @param array $parameters */ public function make(array $parameters) { if (!($widget = $this->widgets->find(array_get($parameters, 'widget')))) { $widget = app()->make(array_get($parameters, 'widget')); } $this->hydrator->hydrate($widget, $parameters); return $widget; }
/** * Make a filter. * * @param array $parameters * @return FilterInterface */ public function make(array $parameters) { if ($filter = $this->filters->get(array_get($parameters, 'filter'))) { $parameters = array_replace_recursive($filter, array_except($parameters, 'filter')); } $filter = app()->make(array_get($parameters, 'filter', $this->filter), $parameters); $this->hydrator->hydrate($filter, $parameters); return $filter; }
/** * Return a stream entry form. * * @param array $parameters * @return $this */ public function form(array $parameters = []) { if (!($builder = array_get($parameters, 'builder'))) { $builder = 'Anomaly\\SlackInviterExtension\\Invite\\Form\\InviteFormBuilder'; } /* @var FormBuilder $builder */ $builder = $this->container->make($builder); $this->hydrator->hydrate($builder, $parameters); $builder->make(); return $builder->getFormPresenter(); }
/** * Handle the command. * * @param Hydrator $hydrator */ public function handle(Hydrator $hydrator) { if (!($definition = $this->dispatch(new GetValueDefinition($this->tree)))) { return; } $hydrator->hydrate($this->tree, $definition); }
/** * Handle the command. * * @param Hydrator $hydrator */ public function handle(Hydrator $hydrator) { if (!($definition = $this->dispatch(new GetLookupDefinition($this->table)))) { return; } $hydrator->hydrate($this->table, $definition); }
/** * Build the builder. * * @return FormBuilder */ public function build() { /* * Hide breadcrumbs by default. */ array_set($this->parameters, 'options.breadcrumb', array_get($this->parameters, 'options.breadcrumb', false)); /* * Cache and hash! */ array_set($this->parameters, 'key', md5(json_encode($this->parameters))); /* * Set the forms URL after obtaining * our parameter hash for the form. */ array_set($this->parameters, 'options.url', array_get($this->parameters, 'options.url', $this->builder->getOption('url', 'form/handle/' . array_get($this->parameters, 'key')))); $this->cache->remember('form::' . array_get($this->parameters, 'key'), 30, function () { return $this->parameters; }); if (is_array(array_get($this->parameters, 'options'))) { foreach (array_pull($this->parameters, 'options') as $key => $value) { $this->builder->setOption($key, $value); } } return $this->hydrator->hydrate($this->builder, $this->parameters); }
/** * Make a button. * * @param array $parameters * @return ButtonInterface */ public function make(array $parameters) { $button = array_get($parameters, 'button'); if ($button && ($registered = $this->buttons->get($button))) { $parameters = array_replace_recursive($registered, array_except($parameters, 'button')); } $parameters = $this->translator->translate($parameters); if (!array_get($parameters, 'button') || !class_exists(array_get($parameters, 'button'))) { array_set($parameters, 'button', $this->button); } /* @var ButtonInterface $button */ $button = app()->make(array_get($parameters, 'button'), $parameters); $this->hydrator->hydrate($button, $parameters); if (($permission = $button->getPermission()) && !$this->authorizer->authorize($permission)) { $button->setEnabled(false); } return $button; }
/** * Build a field type. * * @param array $parameters * @return FieldType */ public function build(array $parameters) { $type = array_get($parameters, 'type'); /** * If the field type is a string and * starts with the root namespace for * streams then it's a class path and * we can resolve it from the container. */ if (is_string($type) && starts_with($type, 'Anomaly') && class_exists($type)) { $type = clone $this->container->make($type); } /** * If the field type is a dot format * namespace then we can also resolve * the field type from the container. */ if (is_string($type) && str_is('*.*.*', $type)) { $type = $this->fieldTypes->get($type); } /** * If we have gotten this far then it's * likely a simple slug and we can try * returning the first match for the slug. */ if (is_string($type)) { $type = $this->fieldTypes->findBySlug($type); } /** * If we don't have a field type let em know. */ if (!$type) { throw new \Exception("Field type [{$type}] not found."); } $type->mergeRules(array_pull($parameters, 'rules', [])); $type->mergeConfig(array_pull($parameters, 'config', [])); $this->hydrator->hydrate($type, $parameters); return $type; }
/** * Make a column. * * @param array $parameters * @return ColumnInterface */ public function make(array $parameters) { $column = app()->make(array_get($parameters, 'column', $this->column), $parameters); $this->hydrator->hydrate($column, $parameters); return $column; }
/** * Make an action. * * @param array $parameters * @return ActionInterface */ public function make(array $parameters) { $action = $this->container->make(array_get($parameters, 'action', Action::class), $parameters); $this->hydrator->hydrate($action, $parameters); return $action; }
/** * Make the navigation link. * * @param array $parameters * @return NavigationLinkInterface */ public function make(array $parameters) { $link = $this->container->make(array_get($parameters, 'link', $this->link), $parameters); $this->hydrator->hydrate($link, $parameters); return $link; }
/** * Make an item. * * @param array $parameters * @return ItemInterface */ public function make(array $parameters) { $item = $this->container->make(Item::class, $parameters); $this->hydrator->hydrate($item, $parameters); return $item; }
/** * Make the section from it's parameters. * * @param array $parameters * @return mixed */ public function make(array $parameters) { $section = $this->container->make(array_get($parameters, 'section', $this->section), $parameters); $this->hydrator->hydrate($section, $parameters); return $section; }
/** * Make a row. * * @param array $parameters * @return RowInterface */ public function make(array $parameters) { $row = $this->container->make(Row::class, $parameters); $this->hydrator->hydrate($row, $parameters); return $row; }
/** * Make a header. * * @param array $parameters * @return HeaderInterface */ public function make(array $parameters) { $header = $this->container->make(Header::class, $parameters); $this->hydrator->hydrate($header, $parameters); return $header; }
/** * Return the hydrated builder. * * @return FormBuilder */ public function builder() { $this->hydrator->hydrate($this->builder, $this->parameters); return $this->builder; }
/** * Make an action. * * @param array $parameters * @return ActionInterface */ public function make(array $parameters) { $parameters = $this->translator->translate($parameters); $this->hydrator->hydrate($action = app()->make(array_get($parameters, 'action', $this->action), $parameters), $parameters); return $action; }
/** * Make a segment. * * @param array $parameters * @return SegmentInterface */ public function make(array $parameters) { $segment = app()->make(array_get($parameters, 'segment', $this->segment), $parameters); $this->hydrator->hydrate($segment, $parameters); return $segment; }