exportName = $exportName; return $target; } /** * @return self * @internal */ public static function fromState(array $state) { $target = GeneralUtility::makeInstance(static::class, $state['name'], $state['flags'] ?? 0); $target->exportName = $state['exportName'] ?? null; $target->items = $state['items']; return $target; } /** * @param string $name Module name */ public function __construct(string $name, int $flags) { $this->name = $name; $this->flags = $flags; } /** * @internal */ public function getState(): array { return [ 'name' => $this->name, 'exportName' => $this->exportName, 'flags' => $this->flags, 'items' => $this->items, ]; } public function jsonSerialize(): array { return $this->getState(); } public function getName(): string { return $this->name; } public function getExportName(): ?string { return $this->exportName; } public function getFlags(): int { return $this->flags; } public function getItems(): array { return $this->items; } /** * @return $this */ public function addFlags(int ...$flags): self { foreach ($flags as $flag) { $this->flags |= $flag; } return $this; } /** * @param array $assignments key-value assignments * @return static */ public function assign(array $assignments): self { $this->items[] = [ 'type' => static::ITEM_ASSIGN, 'assignments' => $assignments, ]; return $this; } /** * @param string|null $method method of JavaScript module to be invoked * @param mixed ...$args corresponding method arguments * @return static */ public function invoke(?string $method = null, ...$args): self { $this->items[] = [ 'type' => static::ITEM_INVOKE, 'method' => $method, 'args' => $args, ]; return $this; } /** * @param mixed ...$args new instance arguments * @return static */ public function instance(...$args): self { $this->items[] = [ 'type' => static::ITEM_INSTANCE, 'args' => $args, ]; return $this; } public function shallLoadImportMap(): bool { return ($this->flags & self::FLAG_LOAD_IMPORTMAP) === self::FLAG_LOAD_IMPORTMAP; } public function shallUseTopWindow(): bool { return ($this->flags & self::FLAG_USE_TOP_WINDOW) === self::FLAG_USE_TOP_WINDOW; } }