getExpression example

use Cron\CronExpression;
use Shopware\Core\Framework\Log\Package;

#[Package('checkout')] class CronInterval extends CronExpression
{
    public const EMPTY_EXPRESSION = '* * * * *';

    public function equals(CronInterval $other): bool
    {
        return $this->getExpression() === $other->getExpression();
    }

    public function isEmpty(): bool
    {
        return $this->getExpression() === self::EMPTY_EXPRESSION;
    }

    public static function createFromCronExpression(CronExpression $cronExpression): self
    {
        return new self($cronExpression->getExpression() ?? self::EMPTY_EXPRESSION);
    }
}
public function testNotIsEmpty(): void
    {
        $cronInterval = new CronInterval('0 * * * *');
        static::assertFalse($cronInterval->isEmpty());
    }

    public function testCreateFromCronExpression(): void
    {
        $cronExpression = new CronExpression('0 * * * *');
        $cronInterval = CronInterval::createFromCronExpression($cronExpression);
        static::assertSame($cronInterval->getExpression()$cronExpression->getExpression());
    }
}
$code .= $this->renderOpts->sao .
                             "(" .
                             $this->renderOpts->sirb .
                             $this->renderNode($params) .
                             $this->renderOpts->sirb .
                             ")";
                }
                $code .= $this->renderStatementBlock($node$node->getBody(), true);
            break;
            case "ChainExpression":
            case "ExpressionStatement":
                $code .= $this->renderNode($node->getExpression());
            break;
            case "ClassExpression":
            case "ClassDeclaration":
                $code .= "class";
                if ($id = $node->getId()) {
                    $code .= " " . $this->renderNode($id);
                }
                if ($superClass = $node->getSuperClass()) {
                    $code .= " extends " . $this->renderNode($superClass);
                }
                $code .= $this->renderStatementBlock(
                    
private readonly ?string $timezone;

    public function __construct(
        private readonly CronExpression $expression = new CronExpression('* * * * *'),
        \DateTimeZone|string $timezone = null,
    ) {
        $this->timezone = $timezone instanceof \DateTimeZone ? $timezone->getName() : $timezone;
    }

    public function __toString(): string
    {
        return $this->expression->getExpression();
    }

    public static function fromSpec(string $expression = '* * * * *', string $context = null, \DateTimeZone|string $timezone = null): self
    {
        if (!class_exists(CronExpression::class)) {
            throw new LogicException(sprintf('You cannot use "%s" as the "cron expression" package is not installed. Try running "composer require dragonmantank/cron-expression".', __CLASS__));
        }

        if (!str_contains($expression, '#')) {
            return new self(new CronExpression($expression)$timezone);
        }

        

        if (!isset($this->configuration[$eventName])) {
            return;
        }

        $eventConfiguration = (array) $this->configuration[$eventName];
        foreach ($eventConfiguration as $guard) {
            if ($guard instanceof GuardExpression) {
                if ($guard->getTransition() !== $event->getTransition()) {
                    continue;
                }
                $this->validateGuardExpression($event$guard->getExpression());
            } else {
                $this->validateGuardExpression($event$guard);
            }
        }
    }

    private function validateGuardExpression(GuardEvent $event, string $expression): void
    {
        if (!$this->expressionLanguage->evaluate($expression$this->getVariables($event))) {
            $blocker = TransitionBlocker::createBlockedByExpressionGuardListener($expression);
            $event->addTransitionBlocker($blocker);
        }
/** * @throws SyntaxError */
    private function doParse(TokenStream $stream, ?array $names = []): Node\Node
    {
        $this->stream = $stream;
        $this->names = $names;

        $node = $this->parseExpression();
        if (!$stream->isEOF()) {
            throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', $stream->current->type, $stream->current->value)$stream->current->cursor, $stream->getExpression());
        }

        unset($this->stream, $this->names);

        return $node;
    }

    /** * @return Node\Node */
    public function parseExpression(int $precedence = 0)
    {
Home | Imprint | This part of the site doesn't use cookies.