Normalize a Unix file entry.

@param string $item
@param string $base

@return array normalized file array
767673
protected function normalizeUnixObject($item, $base)
    {
        $item = \preg_replace('#\s+#', ' ', trim($item), 7);

        if (\count(\explode(' ', $item, 9)) !== 9) {
            throw new RuntimeException("Metadata can't be parsed from item '$item' , not enough parts.");
        }

        list($permissions, /* $number */, /* $owner */, /* $group */, $size, /* $month */, /* $day */, /* $time*/, $name) = explode(' ',
            $item, 9);
        $type = $this->detectType($permissions);
        $path = $base === '' ? $name : $base . $this->separator . $name;

        if ($type === 'dir') {
            return \compact('type', 'path');
        }

        $permissions = $this->normalizePermissions($permissions);
        $visibility = ($permissions & 0044) ? AdapterInterface::VISIBILITY_PUBLIC : AdapterInterface::VISIBILITY_PRIVATE;
        $size = (int) $size;

        return \compact('type', 'path', 'visibility', 'size');
    }
1157920
public function deleteItemAction(Item $item) {
        $em = $this->getDoctrine()->getManager();
        $em->remove($item);
        $em->flush();

        $view = $this->view();

        return $this->handleView($view);
    }
1078191
protected function normalizeGridFSFile(MongoGridFSFile $file, $path = null)
	{
		$result = [
			'path' => \trim($path ?: $file->getFilename(), '/'),
			'type' => 'file',
			'size' => $file->getSize(),
			'timestamp' => $file->file['uploadDate']->sec,
		];

		$result['dirname'] = Util::dirname($result['path']);

		if (isset($file->file['metadata']) && !empty($file->file['metadata']['mimetype'])) {
			$result['mimetype'] = $file->file['metadata']['mimetype'];
		}

		return $result;
	}
812651
protected function absolutePath(string $file, string $base): string
    {
        return $file[0] !== DIRECTORY_SEPARATOR && !str_contains($file, ':')
            ? $base . DIRECTORY_SEPARATOR . $file
            : $file;
    }
951039
protected function recursiveToArray($item)
    {
        if (is_array($item)) {

            foreach ($item as &$subitem) {
                $subitem = $this->recursiveToArray($subitem);
            }

            unset($subitem);

            return $item;
        }

        if ($item instanceof Arrayable) {
            return $item->toArray();
        }

        return $item;
    }
939530
protected function getAccessRootline(Item $item)
    {
        $accessRestriction = '0';
        $itemRecord = $item->getRecord();

        // TODO support access restrictions set on storage page

        if (isset($GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group'])) {
            $accessRestriction = $itemRecord[$GLOBALS['TCA'][$item->getType()]['ctrl']['enablecolumns']['fe_group']];

            if (empty($accessRestriction)) {
                // public
                $accessRestriction = '0';
            }
        }

        return 'r:' . $accessRestriction;
    }
68440
public function transform_item_values_to_json( $item ) {
		foreach ( $this->args['fields'] as $field ) {
			$true_field = $this->find_item_key( $item, $field );
			$value      = is_object( $item ) ? $item->$true_field : $item[ $true_field ];
			if ( is_array( $value ) || is_object( $value ) ) {
				if ( is_object( $item ) ) {
					$item->$true_field = json_encode( $value );
				} elseif ( is_array( $item ) ) {
					$item[ $true_field ] = json_encode( $value );
				}
			}
		}
		return $item;
	}
184979
public function writeItem(array $item)
    {
        $newNode = $this->xml->createElement($this->rowNodeName);

        //attributes
        if (isset($item['@attributes']) && is_array($item['@attributes'])) {
            foreach ($item['@attributes'] as $key => $value) {
                $attr = $this->xml->createAttribute($key);
                $attr->value = $value;
                $newNode->appendChild($attr);
            }
            unset($item['@attributes']);
        }

        //values
        foreach ($item as $key => $value) {
            $node = $this->xml->createElement($key);
            $node->nodeValue = $value;
            $newNode->appendChild($node);
        }

        $this->rootNode->appendChild($newNode);

        return $this;
    }
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;
    }
476837
public function __item($item = null)
    {
        $result = parent::__item($item);
        $result['content'] = true;
        return $result;
    }
1238379
public function removeStyle(Item $item)
    {
        $item->setIntro(preg_replace('/(<[^>]+) style=".*?"/i', '$1', $item->getIntro()));
        $item->setContent(preg_replace('/(<[^>]+) style=".*?"/i', '$1', $item->getContent()));

        return $item;
    }
546902
protected function normalizeItems($items, &$active)
    {
        foreach ($items as $i => $item) {
            if (isset($item['visible']) && !$item['visible']) {
                unset($items[$i]);
                continue;
            }
            if (!isset($item['label'])) {
                $item['label'] = '';
            }
            $encodeLabel = $item['encode'] ?? $this->encodeLabels;
            $items[$i]['label'] = $encodeLabel ? Html::encode($item['label']) : $item['label'];
            $hasActiveChild = false;
            if (isset($item['items'])) {
                $items[$i]['items'] = $this->normalizeItems($item['items'], $hasActiveChild);
                if (empty($items[$i]['items']) && $this->hideEmptyItems) {
                    unset($items[$i]['items']);
                    if (!isset($item['url'])) {
                        unset($items[$i]);
                        continue;
                    }
                }
            }
            if (!isset($item['active'])) {
                if ($this->activateParents && $hasActiveChild || $this->activateItems && $this->isItemActive($item)) {
                    $active = $items[$i]['active'] = true;
                } else {
                    $items[$i]['active'] = false;
                }
            } elseif ($item['active'] instanceof Closure) {
                $active = $items[$i]['active'] = call_user_func($item['active'], $item, $hasActiveChild, $this->isItemActive($item), $this);
            } elseif ($item['active']) {
                $active = true;
            }
        }

        return array_values($items);
    }
255071
public function camelize($base)
    {
        $callback = create_function('$c', 'return strtoupper($c[1]);');

        if (!is_array($base)) {
            return preg_replace_callback('/_([a-z])/', $callback, $base);
        }

        foreach ($base as $key => $val) {
            unset($base[$key]);
            $newKey = preg_replace_callback('/_([a-z])/', $callback, $key);
            $base[$newKey] = $val;
        }

        return $base;
    }
563081
public function setType(Item $item, $body)
    {
        $rename = [
            'Movie' => 'Feature',
            'Music' => 'Music video',
            'Special' => 'TV-special',
        ];
        $type = ucfirst($body['kind']);
        $type = isset($rename[$type]) ? $rename[$type] : $type;

        return $item->setType(
            $this
                ->doctrine
                ->getRepository('AnimeDbCatalogBundle:Type')
                ->findOneBy(['name' => $type])
        );
    }
136182
public function importItem(Item $item)
    {
        foreach ($this->data as $templateData) {
            foreach ($item->getData() as $itemData) {
                if ($itemData->getName() === $templateData->getName()) {
                    $templateData->setName($itemData->getName());
                    $templateData->setValue($itemData->getValue());
                    $templateData->setPrompt($itemData->getPrompt());
                }
            }
        }

        return $this;
    }
884629
protected function normalizeObject($item, $base)
    {
        $systemType = $this->systemType ?: $this->detectSystemType($item);

        if ($systemType === 'unix') {
            return $this->normalizeUnixObject($item, $base);
        }

        if ($systemType === 'windows') {
            return $this->normalizeWindowsObject($item, $base);
        }

        throw NotSupportedException::forFtpSystemType($systemType);
    }
55976
protected function parseSequence($item): SequenceInterface
    {
        if ($item instanceof SequenceInterface) {
            return $item;
        }

        if (is_string($item)) {
            return new CallableSequence($item);
        }

        if (is_array($item) && isset($item['command'])) {
            return new CommandSequence(
                $item['command'],
                $item['options'] ?? [],
                $item['header'] ?? '',
                $item['footer'] ?? ''
            );
        }

        if (is_array($item) && isset($item['invoke'])) {
            return new CallableSequence(
                $item['invoke'],
                $item['parameters'] ?? [],
                $item['header'] ?? '',
                $item['footer'] ?? ''
            );
        }

        throw new ConfigException(sprintf(
            "Unable to parse sequence `%s`.",
            json_encode($item)
        ));
    }