Casting helper for arrays.

@param  string $name       The field name to cast.
@param  array  $data       Some data to cast.
@param  array  $options    Options for the casting.
@return mixed              The casted data.
326557
public function _castArray($name, $data, $options)
    {
        $options['type'] = isset($options['relation']) && $options['relation'] === 'hasManyThrough' ? 'through' : 'set';
        $class = ltrim($options['class'], '\\');
        $classes = $class::classes();
        $collection = $classes[$options['type']];

        if ($data instanceof $collection) {
            return $data;
        }

        $isThrough = $options['type'] === 'through';

        $isDocument = $class === Document::class;

        $config = [
            'schema'    => $isDocument ? $this : $class::definition(),
            'basePath'  => $isDocument ? $name : null,
            'meta'      => isset($options['meta']) ? $options['meta'] : [],
            'exists'    => $options['exists'],
            'defaults'  => $options['defaults']
        ];
        if (isset($options['config'])){
            $config = Set::extend($config, $options['config']);
        }

        $column = isset($this->_columns[$name]) ? $this->_columns[$name] : [];
        if (!empty($column['format']) && $data !== null) {
            $type = $column['format'];
            $data = $this->convert('cast', $type, $data, $column, $config);
        }

        if ($isThrough) {
            $config['parent'] = $options['parent'];
            $config['through'] = $options['through'];
            $config['using'] = $options['using'];
            $config['data'] = $data;
        } else {
            $config['data'] = $data ?: [];
        }
        return new $collection($config);
    }
489054
public static final function jsonDecode($data, array $options = null): array
    {
        $encoder = new JsonEncoder($options);

        return [$encoder->decode($data), $encoder->hasError()
            ? new EncoderException('JSON Error: '. $encoder->getError()) : null];
    }
968054
public function text(string $name, array $options = []): FieldTypeInterface
    {
        return (new TextType($name))
            ->setLocale($this->app->getLocale())
            ->setViewFactory($this->viewFactory)
            ->setOptions($options);
    }
665666
protected function renderElement(string $name, array $options = []) : string
    {
        return $this->config->getView()
            ->element($name, $options);
    }
1334529
public function deserialize(array $data, PanelFacet $panel, array $options = [])
    {
        $this->sipe('id', 'setUuid', $data, $panel);
        $this->sipe('title', 'setName', $data, $panel);
        $this->sipe('position', 'setPosition', $data, $panel);

        if (isset($data['roles'])) {
            $this->deserializeRoles($data['roles'], $panel);
        }

        if (isset($data['fields']) && in_array(Options::DEEP_DESERIALIZE, $options)) {
            $panel->resetFieldFacets();
            $i = 0;

            foreach ($data['fields'] as $field) {
                if (!isset($field['restrictions']['order'])) {
                    $field['restrictions']['order'] = $i;
                }
                ++$i;
                $fieldFacet = $this->_om->getObject($field, FieldFacet::class) ?? new FieldFacet();
                $fieldFacet = $this->ffSerializer->deserialize($field, $fieldFacet, $options);
                $fieldFacet->setPanelFacet($panel);
            }
        }
    }
787442
public function attachData($data, $name, array $options = [])
    {
        return $this->laravelMessage->attachData($data, $name, $options);
    }
1169267
protected function encode($data, $options = 0)
    {
        // Check is already json string.
        if (is_string($data) && strlen($data) >= 1) {
            $firstChar = $data[0];

            if (in_array($firstChar, ['[', '{', '"'])) {
                return $data;
            }
        }

        // Clear json_last_error()
        json_encode(null);

        $json = json_encode($data, $options);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new \UnexpectedValueException(sprintf('JSON encode failure: %s', json_last_error_msg()));
        }

        return $json;
    }
61707
public function createFormBuilder($data = null, array $options = array())
    {
        return $this->getContainer()->get('form.factory')->createBuilder('form', $data, $options);
    }
671450
public function createUrlListForm(
        URLListData $data = null,
        ?string $name = null,
        array $options = []
    ): FormInterface {
        $name = $name ?: StringUtil::fqcnToBlockPrefix(SearchData::class);

        return $this->formFactory->createNamed($name, URLListType::class, $data, $options);
    }
967660
public static function createFromArray($name, array $data = [])
    {
        $type = parent::createFromArray($name, $data);
        \assert($type instanceof self);
        $pos = \strpos($type->getType(), '[]');
        if ($pos !== false) {
            $type->setItems(\substr($type->getType(), 0, $pos));
        }
        $type->setType('array');

        foreach ($data as $key => $value) {
            switch ($key) {
                case 'uniqueItems':
                    $type->setUniqueItems($value);

                    break;
                case 'items':
                    if (\is_array($value) && isset($value['type'])) {
                        $type->setItems($value['type']);

                        break;
                    }
                    $type->setItems($value);

                    break;
                case 'minItems':
                    $type->setMinItems($value);

                    break;
                case 'maxItems':
                    $type->setMaxItems($value);

                    break;
            }
        }

        return $type;
    }
421807
public static final function init(string $name, array $options = null): EncoderInterface
    {
        switch ($name) {
            case self::NAME_JSON: return new JsonEncoder($options);
            case self::NAME_GZIP: return new GzipEncoder($options);
        }

        throw new EncoderException("Unimplemented encoder '{$name}' given");
    }
641808
protected function _array(array $data, $name)
    {
        $isExpanded = $this->_isExpandedLevel();

        if (0 === strpos($name, '&lt;! methods of "')) {
            $isExpanded = false;
        }
        
        ?>
        <li class="jbchild">
            <div
                class="jbelement<?php echo count((array)$data) > 0 ? ' jbexpand' : ''; ?> <?= $isExpanded ? 'jbopened' : ''; ?>"
                <?php if (count((array)$data) > 0) { ?> onClick="jbdump.toggle(this);"<?php } ?>>
                <span class="jbname"><?php echo $name; ?></span> (<span
                    class="jbtype jbtype-array">Array</span>, <?php echo count((array)$data); ?>)
            </div>
            <?php if (count((array)$data)) {
                $this->_vars($data, $isExpanded);
            } ?>
        </li>
    <?php
    }
791738
protected function makeField($name, $type = 'text', array $options = [])
    {
        $this->setupFieldOptions($name, $options);

        $fieldName = $this->getFieldName($name);

        $fieldType = $this->getFieldType($type);

        return new $fieldType($fieldName, $type, $this, $options);
    }
923134
public function email(string $name, array $options = []): FieldTypeInterface
    {
        return (new EmailType($name))
            ->setLocale($this->app->getLocale())
            ->setViewFactory($this->viewFactory)
            ->setOptions($options);
    }
1073604
public function widget($name, array $data = [], array $options = [])
    {
        $parts = explode('::', $name);
        $name = $parts[0] . 'Widgets';
        $name = empty($parts[1]) ? $name : sprintf('%s::%s', $name, $parts[1]);

        return $this->getView()->cell($name, $data, $options);
    }
873208
public function attachData($data, $name, array $options = array())
    {
        $attachment = $this->createAttachmentFromData($data, $name);

        return $this->prepAttachment($attachment, $options);
    }
1260074
public static function createFromArray($name, array $data = [])
    {
        $type = parent::createFromArray($name, $data);
        \assert($type instanceof self);

        foreach ($data as $key => $value) {
            if ($key === 'format') {
                $type->setFormat($value);
            }
        }

        return $type;
    }