path = $path; $this->src = $src; $this->srcset = $srcset; $this->width = $width; $this->height = $height; $this->widthAttr = $widthAttr; $this->heightAttr = $heightAttr; $this->naturalWidth = $naturalWidth; $this->naturalHeight = $naturalHeight; $this->aspectRatio = $aspectRatio; $this->alt = $alt; $this->className = $className; $this->loading = $loading; $this->decoding = $decoding; $this->sizes = $sizes; $this->computedStyle = $computedStyle; $this->optimalSizes = $optimalSizes; } /** * @param array{path: string, src: string, srcset: array, width: int, height: int, widthAttr: string, heightAttr: string, naturalWidth: int, naturalHeight: int, aspectRatio: float, alt: ?string, class: ?string, loading: string, decoding: string, sizes: ?string, computedStyle: array, optimalSizes: string} $attributes */ public static function from( array $attributes ): self { $srcset = array_map( static function ( array $entry ): SrcsetEntry { return SrcsetEntry::from( $entry ); }, $attributes['srcset'] ?? [] ); return new self( $attributes['path'] ?? '', $attributes['src'] ?? '', $srcset, $attributes['width'] ?? 0, $attributes['height'] ?? 0, $attributes['widthAttr'] ?? '', $attributes['heightAttr'] ?? '', $attributes['naturalWidth'] ?? 0, $attributes['naturalHeight'] ?? 0, $attributes['aspectRatio'] ?? null, $attributes['alt'], $attributes['class'] ?? '', $attributes['loading'], $attributes['decoding'], $attributes['sizes'], ComputedStyle::from( $attributes['computedStyle'] ), $attributes['optimalSizes'] ); } /** * @return array{path: string, src: string, srcset: array, width: int, height: int, widthAttr: string, heightAttr: string, naturalWidth: int, naturalHeight: int, aspectRatio: float, alt: ?string, class: string, loading: string, decoding: string, sizes: ?string, computedStyle: array, optimalSizes: string} */ public function toArray(): array { return [ 'path' => $this->path, 'src' => $this->src, 'srcset' => array_map( static function ( SrcsetEntry $entry ): array { return $entry->toArray(); }, $this->srcset ), 'width' => $this->width, 'height' => $this->height, 'widthAttr' => $this->widthAttr, 'heightAttr' => $this->heightAttr, 'naturalWidth' => $this->naturalWidth, 'naturalHeight' => $this->naturalHeight, 'aspectRatio' => $this->aspectRatio, 'alt' => $this->alt, 'class' => $this->className, 'loading' => $this->loading, 'decoding' => $this->decoding, 'sizes' => $this->sizes, 'computedStyle' => $this->computedStyle->toArray(), 'optimalSizes' => $this->optimalSizes, ]; } }