ArrayFacade example

return [
            new TwigFunction('array', $this->createArray(...)),
            new TwigFunction('version_compare', version_compare(...)),
        ];
    }

    /** * @param array<array-key, mixed> $array */
    public function createArray(array $array): ArrayFacade
    {
        return new ArrayFacade($array);
    }

    public function getTests(): array
    {
        return [
            // adds test: "var is true"             new TwigTest('true', null, ['node_class' => TrueTest::class]),
            // adds test: "var is false"             new TwigTest('false', null, ['node_class' => FalseTest::class]),
            // adds test: "var is array"             new TwigTest('array', null, ['node_class' => ArrayTest::class]),
            
private ArrayFacade $body;

    private readonly ResponseCacheConfiguration $cache;

    /** * @internal */
    public function __construct(
        private readonly ?Response $inner = null,
        private int $code = Response::HTTP_OK
    ) {
        $this->body = new ArrayFacade([]);
        $this->cache = new ResponseCacheConfiguration();
    }

    public function getCode(): int
    {
        return $this->code;
    }

    public function setCode(int $code): void
    {
        $this->code = $code;
    }
use Shopware\Core\Framework\Script\Facade\ArrayFacade;

/** * @internal */
class ArrayFacadeTest extends TestCase
{
    public function testAssignment(): void
    {
        $array = [1, 2, 3];

        $functions = new ArrayFacade($array);

        $functions[] = 4;
        $functions[] = 'string';
        $functions[] = 'string-2';
        $functions[] = true;
        $functions[] = false;
        $functions[] = 3.2;

        static::assertCount(9, $functions);
        static::assertContains(1, $functions);
        static::assertContains(2, $functions);
        

        return $this->item->getLabel();
    }

    /** * `getPayload()` returns the payload of this line-item. * * @return ArrayFacade Returns the payload as `ArrayFacade`. */
    public function getPayload(): ArrayFacade
    {
        return new ArrayFacade(
            $this->item->getPayload(),
            function Darray $payload): void {
                $this->item->setPayload($payload);
            }
        );
    }

    /** * `getChildren()` returns the child line-items of this line-item. * * @return ItemsFacade Returns the children as a `ItemsFacade`, that may be empty if no children exist. */
Home | Imprint | This part of the site doesn't use cookies.