url = $url; $this->headers = $headers; } /** * Creates the value object. * * @param array{url: string, headers: Header|array} $data The meta data. * * @throws InvalidArgumentException If the $url argument is empty. * * @return self */ public static function from( array $data ): self { $headers = $data['headers']; if ( ! $headers instanceof Header ) { $headers = ( new Header() )->replace( $headers ); } return new self( $data['url'], $headers ); } /** * Convert the value object to an array. * * @return array{url: string, headers: array} */ public function to_array(): array { return [ 'url' => $this->url, 'headers' => $this->headers->all(), ]; } }