value ). * @param Sanitizer $sanitizer Normalises the product image. */ public function __construct( FileStore $files, callable $product_image, callable $product_type, callable $variant_attributes, Sanitizer $sanitizer ) { $this->files = $files; $this->product_image = $product_image; $this->product_type = $product_type; $this->variant_attributes = $variant_attributes; $this->sanitizer = $sanitizer; } /** * Input for one request row. * * @param array $row Request row. * @throws InputUnavailable When the photo, the product image or a supported type is missing. */ public function build( array $row ): TryOnInput { $person = $this->files->read( (string) ( $row['upload_path'] ?? '' ) ); if ( null === $person ) { throw new InputUnavailable( JobError::MISSING_UPLOAD ); } $product_id = (int) ( $row['product_id'] ?? 0 ); $type = ProductType::valid( ( $this->product_type )( $product_id ) ); if ( null === $type ) { throw new InputUnavailable( JobError::UNSUPPORTED_TYPE ); } $variation_id = (int) ( $row['variation_id'] ?? 0 ); $bytes = ( $this->product_image )( $product_id, $variation_id ); if ( ! is_string( $bytes ) || '' === $bytes ) { throw new InputUnavailable( JobError::NO_PRODUCT_IMAGE ); } try { $product = $this->sanitizer->sanitize( $bytes ); } catch ( InvalidImage $e ) { throw new InputUnavailable( JobError::NO_PRODUCT_IMAGE ); } $attributes = $variation_id > 0 ? ( $this->variant_attributes )( $variation_id ) : array(); $variant = VariantText::line( is_array( $attributes ) ? $attributes : array() ); return new TryOnInput( $person, array( new ReferenceImage( $product, $type ) ), PromptBuilder::build( $type, $variant ), self::QUALITY ); } }