Skip to content

Commit

Permalink
Revert "Yield ready update #22 (#23)"
Browse files Browse the repository at this point in the history
This reverts commit 69c39d2.
  • Loading branch information
giorgiopogliani committed Sep 12, 2024
1 parent 69c39d2 commit 4a8d0f3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.1, 8.2, 8.3]
php: [8.0, 8.1, 8.2]
dependency-version: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
}
],
"require": {
"php": ">= 8.1 < 8.4",
"twig/twig": ">=3.9"
"php": "^7.4|^8.0",
"twig/twig": "^2.12.5 || >=3.0 <3.9"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"pestphp/pest": "^2.0",
"phpunit/phpunit": "^10.1",
"symfony/var-dumper": "^5.2"
"pestphp/pest": "^1.0",
"phpunit/phpunit": "^9.3",
"symfony/var-dumper": "^5.2",
"vimeo/psalm": "^3.11"
},
"autoload": {
"psr-4": {
Expand Down
40 changes: 29 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Digital Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Digital Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
9 changes: 3 additions & 6 deletions src/Node/ComponentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
use Performing\TwigComponents\Configuration;
use Performing\TwigComponents\View\ComponentAttributeBag;
use Performing\TwigComponents\View\ComponentSlot;
use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ConstantExpression;

use Twig\Node\IncludeNode;
use Twig\Node\Node;

#[YieldReady]
final class ComponentNode extends IncludeNode
{
const DYNAMIC_COMPONENT_NAME = 'dynamic-component';
Expand Down Expand Up @@ -45,17 +43,16 @@ public function compile(Compiler $compiler): void
->write('$slotsStack = $slotsStack ?? [];' . PHP_EOL)
->write('$slotsStack[] = $slots ?? [];' . PHP_EOL)
->write('$slots = [];' . PHP_EOL)
->write('$slot = implode("", iterator_to_array((function () use (&$slots, &$context) {' . PHP_EOL)
->write("ob_start();" . PHP_EOL)
->subcompile($this->getNode('slot'))
->write("})() ?? new \EmptyIterator()));" . PHP_EOL)
->write(sprintf('yield $%s->render(', $template));
->write('$slot = ob_get_clean();' . PHP_EOL)
->write(sprintf('$%s->display(', $template));

$this->addTemplateArguments($compiler);

$compiler
->raw(");\n")
->write('$slots = array_pop($slotsStack);' . PHP_EOL)
->write("yield '';")
->write("}\n");
}

Expand Down
7 changes: 2 additions & 5 deletions src/Node/SlotNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
namespace Performing\TwigComponents\Node;

use Performing\TwigComponents\View\ComponentSlot;
use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Node;

use Twig\Node\NodeOutputInterface;

#[YieldReady]
final class SlotNode extends Node implements NodeOutputInterface
{
public function __construct($name, $body, ?AbstractExpression $variables, int $lineno = 0)
Expand All @@ -27,10 +25,9 @@ public function compile(Compiler $compiler): void
$name = $this->getAttribute('name');

$compiler
->write('$body = (function () use (&$slots, &$context) {')
->write('ob_start();')
->subcompile($this->getNode('body'))
->write('})() ?? new \EmptyIterator();' . PHP_EOL)
->write('$body = implode("", iterator_to_array($body));' . PHP_EOL)
->write('$body = ob_get_clean();' . PHP_EOL)
->write("\$slots['$name'] = new " . ComponentSlot::class . "(\$body, ");

if ($this->hasNode('variables')) {
Expand Down

0 comments on commit 4a8d0f3

Please sign in to comment.