-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from tomaj/api-link-extension
Added support for latte/latte ^3.0 (Added Latte extension for ApiLink)
- Loading branch information
Showing
5 changed files
with
113 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tomaj\NetteApi\Link; | ||
|
||
use Latte\Extension; | ||
|
||
final class ApiLinkExtension extends Extension | ||
{ | ||
public function getTags(): array | ||
{ | ||
return [ | ||
'apiLink' => [ApiLinkNode::class, 'create'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tomaj\NetteApi\Link; | ||
|
||
use Latte\Compiler\Nodes\Php\Expression\ArrayNode; | ||
use Latte\Compiler\Nodes\StatementNode; | ||
use Latte\Compiler\PrintContext; | ||
use Latte\Compiler\Tag; | ||
|
||
final class ApiLinkNode extends StatementNode | ||
{ | ||
/** @var ArrayNode $endpointArgs */ | ||
public $endpointArgs; | ||
|
||
/** @var ArrayNode $endpointParams */ | ||
public $endpointParams; | ||
|
||
public static function create(Tag $tag): ?ApiLinkNode | ||
{ | ||
$tag->expectArguments(); | ||
$node = new self(); | ||
|
||
$tag->parser->stream->tryConsume(','); | ||
$args = $tag->parser->parseArguments(); | ||
|
||
$allParameters = $args->items; | ||
$node->endpointArgs = new ArrayNode(array_slice($allParameters, 0, 4)); | ||
$node->endpointParams = new ArrayNode(array_slice($allParameters, 4)); | ||
|
||
return $node; | ||
} | ||
|
||
public function print(PrintContext $context): string | ||
{ | ||
return $context->format('echo ($this->filters->apiLink)(new Tomaj\NetteApi\EndpointIdentifier(%args), %args);', $this->endpointArgs, $this->endpointParams); | ||
} | ||
|
||
|
||
public function &getIterator(): \Generator | ||
{ | ||
yield $this->endpointArgs; | ||
yield $this->endpointParams; | ||
} | ||
} |