getExtension() public method

Gets the extension of the file.
public getExtension ( ) : string
return string
Ejemplo 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);
 }
Ejemplo n.º 2
0
 public function testGetCompoundExtension()
 {
     $fileInfo = new FileInfo('foo.html.twig', $this->predefinedExtensions);
     $this->assertEquals('html.twig', $fileInfo->getExtension());
 }