deletePrefix() public method

Deletes a prefix of the string.
public deletePrefix ( string $prefix ) : string
$prefix string The prefix
return string The string without prefix
 public function testDeletePrefix()
 {
     $str = new StringWrapper('Welcome to Spress');
     $this->assertEquals('to Spress', $str->deletePrefix('Welcome '));
     $this->assertEquals('Welcome to Spress', $str->deletePrefix('Hi'));
     $this->assertEquals('Welcome to Spress', $str->deletePrefix(''));
 }
Beispiel #2
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);
 }
Beispiel #3
0
 private function processAttributes(Item $item, SplFileInfo $file)
 {
     $attributes = [];
     $attributesFile = $this->getAttributesFilename($file);
     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);
     }
     $attributes['mtime'] = $this->getModifiedTime($file);
     $attributes['filename'] = $file->getFilename();
     $attributes['extension'] = $file->getExtension();
     if ($data = $this->isDateFilename($file)) {
         $attributes['title_path'] = implode(' ', explode('-', $data[3]));
         if (isset($attributes['title']) === false) {
             $attributes['title'] = $attributes['title_path'];
         }
         if (isset($attributes['date']) === false) {
             $attributes['date'] = implode('-', [$data[0], $data[1], $data[2]]);
         }
     }
     $str = new StringWrapper($file->getRelativePath());
     if ($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);
 }