validation for image url

This commit is contained in:
Narek Zakarian 2023-09-20 17:30:56 +04:00
parent e94c495434
commit 961a0fb3b9
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7

View file

@ -214,7 +214,7 @@ class Item {
* @return string
*/
public function image_url():string {
return $this->image_url;
return $this->validate_image_url() ? $this->image_url : '';
}
/**
@ -269,4 +269,14 @@ class Item {
return $item;
}
/**
* Validates the image url for PayPal request.
*
* @return bool true if valid, otherwise false.
*/
protected function validate_image_url(): bool {
$pattern = '/^(https:)([\/|\.|\w|\s|-])*\.(?:jpg|gif|png|jpeg|JPG|GIF|PNG|JPEG)$/';
return (bool) preg_match( $pattern, $this->image_url );
}
}