Yosymfony\Spress\Core\Support\FileInfo::getExtension PHP Method

getExtension() public method

Gets the extension of the file.
public getExtension ( ) : string
return string
    public function getExtension()
    {
        if (is_null($this->extension) === true) {
            $filename = parent::getFilename();
            $str = new StringWrapper($filename);
            $this->extension = $str->getFirstEndMatch($this->predefinedExtensions);
            $this->hasPredefinedExt = true;
            if ($this->extension === '') {
                $this->hasPredefinedExt = false;
                $this->extension = parent::getExtension();
            }
        }
        return $this->extension;
    }

Usage Example

Esempio n. 1
0
 private function processAttributes(Item $item, SplFileInfo $file)
 {
     $attributes = [];
     $attributesFile = $this->getAttributesFilename($file);
     $isItemType = $item->getType() === Item::TYPE_ITEM;
     if ($attributesFile && file_exists($attributesFile)) {
         $contentFile = file_get_contents($attributesFile);
         $attributes = $this->attributeParser->getAttributesFromString($contentFile);
     } elseif (false === $item->isBinary()) {
         $attributes = $this->attributeParser->getAttributesFromFrontmatter($item->getContent());
         $content = $this->attributeParser->getContentFromFrontmatter($item->getContent());
         $item->setContent($content, Item::SNAPSHOT_RAW);
     }
     $fileInfo = new FileInfo($file->getPathname(), $this->params['text_extensions']);
     $avoidRender = $this->avoidRenderizer($fileInfo->getExtension(), $file->getRelativePath());
     if ($isItemType && $avoidRender === true && isset($attributes['avoid_renderizer']) === false) {
         $attributes['avoid_renderizer'] = true;
     }
     $attributes['mtime'] = $this->getModifiedTime($file);
     $attributes['filename'] = $fileInfo->getFilename();
     $attributes['extension'] = $fileInfo->getExtension();
     if ($data = $this->isDateFilename($attributes['filename'])) {
         $attributes['title_path'] = $data[3];
         if (isset($attributes['title']) === false) {
             $attributes['title'] = implode(' ', explode('-', $attributes['title_path']));
         }
         if (isset($attributes['date']) === false) {
             $attributes['date'] = implode('-', [$data[0], $data[1], $data[2]]);
         }
     }
     $str = new StringWrapper($this->normalizeDirSeparator($file->getRelativePath()));
     if ($isItemType && $str->startWith('posts/') === true && array_key_exists('categories', $attributes) === false) {
         $categories = explode('/', $str->deletePrefix('posts/'));
         if ($categories[0] === '') {
             unset($categories[0]);
         }
         $attributes['categories'] = $categories;
     }
     $item->setAttributes($attributes);
 }
All Usage Examples Of Yosymfony\Spress\Core\Support\FileInfo::getExtension