criticalImages = $criticalImages; $this->backgroundImages = $backgroundImages; $this->sections = $sections; } /** * @param array{criticalImages: string[], backgroundImages?: string[], sections?: array} $attributes */ public static function from( array $attributes ): self { $sections = array_map( static function ( array $result ): Section { return Section::from( $result ); }, $attributes['sections'] ?? [] ); return new self( $attributes['criticalImages'], $attributes['backgroundImages'] ?? [], $sections ); } /** * @return array{criticalImages: string[], backgroundImages?: string[], sections?: array} */ public function toArray(): array { return [ 'criticalImages' => $this->criticalImages, 'backgroundImages' => $this->backgroundImages, 'sections' => array_map( static function ( Section $section ): array { return $section->toArray(); }, $this->sections ), ]; } /** * Get all the sections that are below the fold. * * @return Section[] */ public function getBelowTheFoldSections(): array { return array_filter( $this->sections, static fn( Section $section ): bool => ! $section->isAboveFold ); } }