Skip to content

Commit

Permalink
Use tabs instead of spaces like in FileLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Nov 5, 2022
1 parent f18ec04 commit ac829d3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 64 deletions.
102 changes: 51 additions & 51 deletions src/Latte/Loaders/NamespaceLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,71 +17,71 @@
*/
class NamespaceLoader implements Latte\Loader
{
/**
* @var Latte\Loader[]
*/
private array $loaders;
/**
* @var Latte\Loader[]
*/
private array $loaders;

public function __construct(array $loaders)
{
$this->loaders = $loaders;
}
public function __construct(array $loaders)
{
$this->loaders = $loaders;
}

/**
* Returns template source code.
*/
public function getContent(string $name): string
{
[$loader, $name] = $this->extractLoaderAndName($name);
/**
* Returns template source code.
*/
public function getContent(string $name): string
{
[$loader, $name] = $this->extractLoaderAndName($name);

return $loader->getContent($name);
}
return $loader->getContent($name);
}


public function isExpired(string $file, int $time): bool
{
[$loader, $name] = $this->extractLoaderAndName($file);
public function isExpired(string $file, int $time): bool
{
[$loader, $name] = $this->extractLoaderAndName($file);

return $loader->isExpired($name, $time);
}
return $loader->isExpired($name, $time);
}


/**
* Returns referred template name.
*/
public function getReferredName(string $name, string $referringName): string
{
[$loader, $name] = $this->extractLoaderAndName($name);
/**
* Returns referred template name.
*/
public function getReferredName(string $name, string $referringName): string
{
[$loader, $name] = $this->extractLoaderAndName($name);

return $loader->getReferredName($name, $referringName);
}
return $loader->getReferredName($name, $referringName);
}


/**
* Returns unique identifier for caching.
*/
public function getUniqueId(string $name): string
{
[$loader, $name] = $this->extractLoaderAndName($name);
/**
* Returns unique identifier for caching.
*/
public function getUniqueId(string $name): string
{
[$loader, $name] = $this->extractLoaderAndName($name);

return $loader->getUniqueId($name);
}
return $loader->getUniqueId($name);
}


private function extractLoaderAndName(string $name): array
{
$namespaceParts = \explode('::', $name, 2);
private function extractLoaderAndName(string $name): array
{
$namespaceParts = \explode('::', $name, 2);

if (count($namespaceParts) === 2) {
return [
$this->loaders[$namespaceParts[0]],
$namespaceParts[1],
];
}
if (count($namespaceParts) === 2) {
return [
$this->loaders[$namespaceParts[0]],
$namespaceParts[1],
];
}

return [
$this->loaders[''],
$name,
];
}
return [
$this->loaders[''],
$name,
];
}
}
26 changes: 13 additions & 13 deletions tests/common/Loaders.NamespaceLoader.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ require __DIR__ . '/../bootstrap.php';


test('', function () {
$defaultLoader = new StringLoader(['main' => 'defaultcontent']);
$appLoader = new StringLoader(['main' => 'appcontent']);
$otherLoader = new StringLoader(['main' => 'othercontent']);

$loader = new NamespaceLoader([
'' => $defaultLoader,
'app' => $appLoader,
'other' => $otherLoader,
]);

Assert::same('defaultcontent', $loader->getContent('main'));
Assert::same('appcontent', $loader->getContent('app::main'));
Assert::same('othercontent', $loader->getContent('other::main'));
$defaultLoader = new StringLoader(['main' => 'defaultcontent']);
$appLoader = new StringLoader(['main' => 'appcontent']);
$otherLoader = new StringLoader(['main' => 'othercontent']);

$loader = new NamespaceLoader([
'' => $defaultLoader,
'app' => $appLoader,
'other' => $otherLoader,
]);

Assert::same('defaultcontent', $loader->getContent('main'));
Assert::same('appcontent', $loader->getContent('app::main'));
Assert::same('othercontent', $loader->getContent('other::main'));
});

0 comments on commit ac829d3

Please sign in to comment.