File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/Validator.tar
GooglePriceConstraint.php 0000644 00000000655 15154600505 0011530 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Validator;
use Symfony\Component\Validator\Constraint;
defined( 'ABSPATH' ) || exit;
/**
* Class GooglePriceConstraint
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Validator
*/
class GooglePriceConstraint extends Constraint {
/**
* @var string
*/
public $message = 'Product must have a valid price and currency.';
}
GooglePriceConstraintValidator.php 0000644 00000002765 15154600505 0013402 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Validator;
use Automattic\WooCommerce\GoogleListingsAndAds\Vendor\Google\Service\ShoppingContent\Price as GooglePrice;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
defined( 'ABSPATH' ) || exit;
/**
* Class GooglePriceConstraintValidator
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Validator
*/
class GooglePriceConstraintValidator extends ConstraintValidator {
/**
* Checks if the passed value is valid.
*
* @param GooglePrice $value The value that should be validated
* @param Constraint $constraint
*
* @throws UnexpectedTypeException If invalid constraint provided.
* @throws UnexpectedValueException If invalid value provided.
*/
public function validate( $value, Constraint $constraint ) {
if ( ! $constraint instanceof GooglePriceConstraint ) {
throw new UnexpectedTypeException( $constraint, GooglePriceConstraint::class );
}
if ( null === $value || '' === $value ) {
return;
}
if ( ! $value instanceof GooglePrice ) {
throw new UnexpectedValueException( $value, GooglePrice::class );
}
if ( empty( $value->getValue() ) || empty( $value->getCurrency() ) ) {
$this->context->buildViolation( $constraint->message )
->atPath( 'value' )
->addViolation();
}
}
}
ImageUrlConstraint.php 0000644 00000000702 15154600505 0011027 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Validator;
use Symfony\Component\Validator\Constraints\Url as UrlConstraint;
defined( 'ABSPATH' ) || exit;
/**
* Class ImageUrlConstraint
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Validator
*/
class ImageUrlConstraint extends UrlConstraint {
/**
* @var string
*/
public $message = 'Product image "{{ name }}" is not a valid name.';
}
ImageUrlConstraintValidator.php 0000644 00000011436 15154600505 0012703 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Validator;
use Normalizer;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\UrlValidator as UrlConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
defined( 'ABSPATH' ) || exit;
/**
* Class ImageUrlConstraintValidator
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Validator
*/
class ImageUrlConstraintValidator extends UrlConstraintValidator {
public const IMAGE_PATTERN = '~^
(%s):// # protocol
(((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+:)?((?:[\_\.\pL\pN-]|%%[0-9A-Fa-f]{2})+)@)? # basic auth
(
(?:
(?:xn--[a-z0-9-]++\.)*+xn--[a-z0-9-]++ # a domain name using punycode
|
(?:[\pL\pN\pS\pM\-\_]++\.)+[\pL\pN\pM]++ # a multi-level domain name
|
[a-z0-9\-\_]++ # a single-level domain name
)\.?
| # or
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} # an IP address
| # or
\[
(?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]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[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
\] # an IPv6 address
)
(:[0-9]+)? # a port (optional)
(?:/ (?:[\pL\pN\-._\~!$&\'()*+,;=:@]|%%[0-9A-Fa-f]{2})* )* # a path
(?:\? (?:[\pL\pN\-._\~!$&\'\[\]()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a query (optional)
(?:\# (?:[\pL\pN\-._\~!$&\'()*+,;=:@/?]|%%[0-9A-Fa-f]{2})* )? # a fragment (optional)
$~ixuD';
/**
* Checks if the passed value is valid.
*
* @param string $value The value that should be validated
* @param Constraint $constraint
*
* @throws UnexpectedTypeException If invalid constraint provided.
* @throws UnexpectedValueException If invalid value provided.
*/
public function validate( $value, Constraint $constraint ) {
if ( ! $constraint instanceof ImageUrlConstraint ) {
throw new UnexpectedTypeException( $constraint, ImageUrlConstraint::class );
}
if ( null === $value || '' === $value ) {
return;
}
if ( ! is_scalar( $value ) && ! ( is_object( $value ) && method_exists( $value, '__toString' ) ) ) {
throw new UnexpectedValueException( $value, 'string' );
}
$value = (string) $value;
if ( '' === $value ) {
return;
}
$value = Normalizer::normalize( $value );
$pattern = sprintf( static::IMAGE_PATTERN, implode( '|', $constraint->protocols ) );
if ( ! preg_match( $pattern, $value ) ) {
$this->context->buildViolation( $constraint->message )
->setParameter( '{{ name }}', wp_basename( $value ) )
->setCode( ImageUrlConstraint::INVALID_URL_ERROR )
->addViolation();
return;
}
}
}
Validatable.php 0000644 00000000664 15154600505 0007474 0 ustar 00 <?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Validator;
use Symfony\Component\Validator\Mapping\ClassMetadata;
defined( 'ABSPATH' ) || exit;
/**
* Interface Validatable
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Validator
*/
interface Validatable {
/**
* @param ClassMetadata $metadata
*/
public static function load_validator_metadata( ClassMetadata $metadata );
}