Sculpin\Core\Permalink\SourcePermalinkFactory::create PHP Метод

create() публичный Метод

public create ( Sculpin\Core\Source\SourceInterface $source )
$source Sculpin\Core\Source\SourceInterface
    public function create(SourceInterface $source)
    {
        if ($source->canBeFormatted()) {
            $relativeFilePath = $this->generatePermalinkPathname($source);
            // TODO: Make this configurable... not all index files are named index.*
            if (strpos(basename($relativeFilePath), 'index.') === false) {
                $relativeUrlPath = $relativeFilePath;
            } else {
                $relativeUrlPath = dirname($relativeFilePath);
            }
            if ($relativeUrlPath == '/.') {
                $relativeUrlPath = '/';
            }
        } else {
            $relativeFilePath = $relativeUrlPath = $source->relativePathname();
        }
        if (0 !== strpos($relativeUrlPath, '/')) {
            $relativeUrlPath = '/' . $relativeUrlPath;
        }
        return new Permalink($relativeFilePath, $relativeUrlPath);
    }

Usage Example

 /**
  * @test
  * @dataProvider provideCreateData
  * @param string $defaultPermalink
  * @param SourceInterface $source
  * @param Permalink $expectedPermalink
  */
 public function testCreate($defaultPermalink, SourceInterface $source, Permalink $expectedPermalink)
 {
     $sourcePermalinkFactory = new SourcePermalinkFactory($defaultPermalink);
     $permalink = $sourcePermalinkFactory->create($source);
     $this->assertEquals($expectedPermalink, $permalink);
 }