Parse an option from file data structure

@param array $item

@return Option
19229
private function parseOption(array $item) : Option
    {
        $name = $item['option'];

        $characteristic = $item['characteristic'] ?? null;

        if (isset($characteristic))
        {
            $characteristic = self::optionCharacteristic($characteristic);
        }

        $type = $item['type'] ?? null;

        $default = $item['default'] ?? null;

        $description = $item['description'] ?? null;

        $fixedName = $item['name'] ?? null;

        $option = new Option($name, $characteristic, $type, $default);

        if (isset($description))
        {
            $option->setDescription($description);
        }

        if (isset($fixedName))
        {
            if ($fixedName[0] === '-')
            {
                throw new OptionLoaderException(
                    "An option's fixed name may not start with a `-`.",
                    $item
                );
            }

            $option->setFixedName($fixedName);
        }

        if (isset($item['aliases']))
        {
            foreach ($item['aliases'] as $alias)
            {
                $aliasCharacteristic = $alias['characteristic'] ?? null;

                if (isset($aliasCharacteristic))
                {
                    $aliasCharacteristic = self::optionCharacteristic(
                        $aliasCharacteristic
                    );
                }

                $aliasName = $alias['option'] ?? null;

                if ( ! isset($aliasName))
                {
                    throw new OptionLoaderException(
                        "An alias must contain its own option name.",
                        $alias
                    );
                }

                new AliasOption($aliasName, $aliasCharacteristic, $option);
            }
        }

        if (isset($fixedName))
        {
            $this->optionCatalogue[$fixedName] = $option;
        }

        $this->optionCatalogue[$option->getPrintableName()] = $option;

        return $option;
    }
305351
public function item($item = [], $options = [])
    {
        $html = '<li style="display: inline; list-style-type: none; padding-right: 20px;">';
        $html .= (key_exists('active', $item) && $item['active'] ? '<b>' : '');
        $html .= $this->Html->link(__($item['title']), $item['url']);
        $html .= (key_exists('active', $item) ? '</b>' : '');
        $html .= '</li>';
        return $html;
    }
964666
protected function instantiateConfigValues($item, array $values)
    {
        foreach ($values as $key => $value) {
            $values[$key] = $this->instantiateConfigValue($item, $value);
        }

        return $values;
    }
1163608
public function renderItem($item)
    {
        $options = ArrayHelper::getValue($item, 'options', array());
        if (isset($item['featured'])) {
            Html::addCssClass($this->htmlOptions, Enum::ClEARING_FEATURE);
            Html::addCssClass($options, Enum::CLEARING_FEATURE_IMG);
        }
        $imgOptions                 = array();
        $imgOptions['src']          = ArrayHelper::getValue($item, 'th', '#');
        $imgOptions['data-caption'] = ArrayHelper::getValue($item, 'caption', null);
        $imgOptions['class']        = 'th';
        $url                        = ArrayHelper::getValue($item, 'img', '#');

        return \CHtml::tag('li', $options, \CHtml::link(\CHtml::tag('img', $imgOptions), $url));

    }
520678
private function parseArrayToFieldEntity(array $item, $elementType)
    {
        $entity = new Field();
        $entity->set($item);
        $entity->element_type = $elementType;

        return $entity;
    }
393527
public static function extractValues($item, $key)
    {
        // Array of results
        $results = array();

        // Cast as array if object
        $item = is_object($item) ? (array) $item : $item;

        // Array of keys
        $keys = strstr($key, static::$key_split) ? explode(static::$key_split, $key) : array($key);
        $keys = array_filter($keys);

        // Key count
        $key_count = count($keys);

        // key count > 0
        if ($key_count > 0) {

                $curr_key = array_shift($keys);
                $arrayValues = array_values($item);
                $child = is_array($item) ? array_shift($arrayValues) : null;

                // it's an array
                if (is_array($item)) {
                    // Clean non-ASCII keys
                    foreach ($item as $k => $v) {
                        $sanitized = preg_replace('/[^(\x20-\x7F)]*/','', $k);
                        if ($sanitized !== $k) {
                            $item[$sanitized] = $v;
                            unset($item[$k]);
                        }
                    }

                    // it has the keys
                    if (array_key_exists($curr_key, $item)) {
                        $results = array_merge($results, static::extractValues($item[$curr_key], implode(static::$key_split, $keys)));
                    // else it's child has the key
                    } elseif ((is_array($child) || is_object($child))) {
                        if (array_key_exists($curr_key, $child)) {
                            foreach ($item as $child) {
                                $results = array_merge($results, static::extractValues($child, $key));
                            }
                        }
                    }
                }

        // no key
        } else {
            $results[] = $item;
        }
        return $results;
    }
925980
protected function convertItemToHash(Item $item)
    {
        $hash = array();

        foreach ($item->getState() as $propName => $propValue) {
            switch ($propName) {
                case 'blockId':
                case 'contentId':
                case 'locationId':
                case 'priority':
                case 'movedTo':
                case 'action':
                    if ($propValue !== null) {
                        $hash[$propName] = $propValue;
                    }
                    break;
                case 'attributes':
                    if ($propValue !== null && $propValue !== array()) {
                        $hash['attributes'] = $propValue;
                    }
                    break;
                case 'publicationDate':
                case 'visibilityDate':
                case 'hiddenDate':
                case 'rotationUntilDate':
                    if ($propValue !== null) {
                        /* @var $propValue \DateTime */
                        $hash[$propName] = $propValue->format(\DateTime::RFC850);
                    }
                    break;
            }
        }

        return $hash;
    }
1211317
protected function renderItem($item)
    {
        $item['label'] = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];

        $options = ArrayHelper::getValue($item, 'options', $this->itemOptions);
        Html::addCssClass($options, 'section');

        if (isset($item['url'])) {
            $link = Html::a($item['label'], $item['url'], $options);
        } else {
            Html::addCssClass($options, 'active');
            $link = Html::tag('div', $item['label'], $options);
        }
        return $link;
    }
333253
public function parse(array $item): array
    {
        $transform = new AssetTransform();

        foreach ($item as $k => $v) {
            $transform->$k = $v;
        }

        return [$transform, null];
    }
1089663
protected function itemToArray($item)
    {
        if (is_array($item)) {
            return $item;
        } elseif (method_exists($item, 'toArray')) {
            return $item->toArray();
        } elseif (method_exists($item, 'getArrayCopy')) {
            return $item->getArrayCopy();
        }

        throw new Exception\RuntimeException(sprintf(
            'Items as part of this DataSource, with type "%s" cannot be cast to an array',
            is_object($item) ? get_class($item) : gettype($item)
        ));
    }
255329
public function createResourceViewData(array $options, $item)
    {
        if ($item->getType() === Setting::SETTING_TYPE_TEXT) {
            return $item->getValue();
        }

        if ($item->getType() === Setting::SETTING_TYPE_BOOLEAN) {
            $booleanWidget = $this->container->get('enhavo_app.table.boolean');
            $options['property'] = 'value';
            return $booleanWidget->createResourceViewData($options, $item);
        }

        if ($item->getType() === Setting::SETTING_TYPE_FILE) {
            $pictureWidget = $this->container->get('enhavo_media.table.picture_widget');
            $options['property'] = 'file';
            return $pictureWidget->createResourceViewData($options, $item);
        }

        if ($item->getType() === Setting::SETTING_TYPE_FILES) {
            $pictureWidget = $this->container->get('enhavo_media.table.picture_widget');
            $options['property'] = 'files';
            return $pictureWidget->createResourceViewData($options, $item);
        }

        if ($item->getType() === Setting::SETTING_TYPE_WYSIWYG) {
            return $item->getValue();
        }

        if ($item->getType() === Setting::SETTING_TYPE_DATE) {
            $date = $item->getDate();
            if($date instanceof \DateTime) {
                return $date->format('d.m.y');
            }
            return '';
        }

        if ($item->getType() === Setting::SETTING_TYPE_DATETIME) {
            $date = $item->getDate();
            if($date instanceof \DateTime) {
                return $date->format('d.m.y H:i');
            }
            return '';
        }
        
        return '';
    }
766736
public function itemToString(\stdClass $item)
    {

    	$attributes = (array) $item;

        if (isset($attributes['type']) &&
                (($attributes['type'] == 'text/css') || ($attributes['type'] == 'text/less'))) {

            // This is a stylesheet, consider extension and compile .less to .css
            if (($attributes['type'] == 'text/less') || \MUtil_String::endsWith($attributes['href'], '.less', true)) {
                $this->compile($this->view, $attributes['href'], false);

                // Modify object, not the derived array
                $item->type = 'text/css';
                $item->href = substr($attributes['href'], 0, -4) . 'css';
            }
        }

        if (isset($this->view->currentVersion)) {
            $version = $this->view->currentVersion;

            if (property_exists($item, 'href')) {
                $item->href = $item->href . '?' . $version;
            }
        }
        
        return \Zend_View_Helper_HeadLink::itemToString($item);
    }
124716
public function fromItem(Item $item)
    {
        return Comment::createFromArray(array_filter([
            'id' => $item->getId(),
            'source' => $item->get('source'),
            'parent' => $item->get('parent'),
            'author_uuid' => $item->get('author_uuid'),
            'author_name' => $item->get('author_name'),
            'author_email' => $item->get('author_email'),
            'author_avatar' => $item->get('author_avatar'),
            'author_role' => $item->get('author_role'),
            'thumb' => $item->get('thumb'),
            'rating' => $item->get('rating'),
            'content' => $item->get('content'),
            'state' => $item->get('state'),
            'created_at' =>  $item->get('created_at'),
        ]));
    }
616029
private static function splitToken($item)
    {
        if (is_array($item)) {
            $tokenName = $item[0];
            $tokenData = $item[1];
        } else {
            $tokenName = null;
            $tokenData = $item;
        }

        return [$tokenName, $tokenData];
    }
479192
public function attach($item, array $options = [])
    {
        // Merge in default options
        $options += [
            'key'           => '',
            'title'         => '',
            'description'   => '',
            'user_id'       => Auth::id()
        ];

        // Determine the type
        $type = Filer::checkType($item);

        // Create the appropriate model for the item if it doesn't already exist
        $itemToAttach = null;
        switch ($type) {
            case Type::URL:
                $itemToAttach = Url::firstOrCreate(['url' => $item]);
                break;
            case Type::FILEPATH:
                $item = new File(config('filer.path.absolute') . "/{$item}");
            case Type::FILE:
                $itemToAttach = LocalFile::firstOrNew([
                    'filename'  => $item->getFilename(),
                    'path'      => Filer::getRelativeFilepath($item)
                ]);
                $itemToAttach->fill([
                    'mimetype'  => $item->getMimeType(),
                    'size'      => $item->getSize()
                ])->save();
                break;
        }

        if (is_null($itemToAttach)) {
            return false;
        }

        // Create/update and save the attachment
        $attributes = [
            'user_id' => $options['user_id'],
            'model_id' => $this->id
        ];

        if (!is_null($options['key'])) {
            $attributes['key'] = $options['key'];
        }

        $attachment = Attachment::firstOrNew($attributes);

        if (!is_null($options['title'])) {
            $attachment->title = $options['title'];
        }

        if (!is_null($options['description'])) {
            $attachment->description = $options['description'];
        }

        $attachment->save();

        // Save the attachment to the model
        $this->attachments()->save($attachment);

        // Save the attachment to the item
        $itemToAttach->attachment()->save($attachment);

        return $attachment;
    }
957921
public function getValue(ArrayAccess $item): string
    {
        $value = $item->offsetExists($this->name)
            ? $item->offsetGet($this->name)
            : '';

        if (is_callable($this->filter)) {
            if ($this->filter instanceof ContextAwareFilterInterface) {
                $this->filter->setContext(clone $item);
            }

            $value = call_user_func($this->filter, $value);
        }

        return $value;
    }
937698
public function line(array $item)
	{
		$val = print_r($item['var'], true);
		$val = preg_replace('/\[(.+?)\] =>/i', '<code class="ky">[$1]</code> <code class="op">=></code>', $val);
		return '<pre>' . $val . '</pre>';
	}