getFirstEndMatch() public method

Gets the first element of the argument matching with the ends of the string.
public getFirstEndMatch ( array $strings ) : string
$strings array List of strings
return string The first element or empty string if no matching found
示例#1
0
 public function testGetFirstEndMatch()
 {
     $extensions = ['html.twig', 'md', 'md', 'html'];
     $str = new StringWrapper('about.html.twig');
     $this->assertEquals('html.twig', $str->getFirstEndMatch($extensions));
     $str = new StringWrapper('about.html');
     $this->assertEquals('html', $str->getFirstEndMatch($extensions));
     $str = new StringWrapper('about.xml');
     $this->assertEquals('', $str->getFirstEndMatch($extensions));
 }
示例#2
0
 /**
  * Converts an item. This method uses the SNAPSHOT_PATH_RELATIVE of Item path.
  *
  * @param Yosymfony\Spress\Core\DataSource\ItemInterface $item The item
  *
  * @return Yosymfony\Spress\Core\ContentManager\Converter\ConverterResult
  *
  * @throws RuntimeException If there's no converter for the extension passed
  */
 public function convertItem(ItemInterface $item)
 {
     $path = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE);
     $str = new StringWrapper($path);
     $extension = $str->getFirstEndMatch($this->textExtensions);
     if ($extension === '') {
         $extension = pathinfo($path, PATHINFO_EXTENSION);
     }
     return $this->convertContent($item->getContent(), $extension);
 }