Current Path : /storage/v11800/lifespanstoresnew/public_html/wp-content/plugins/google-listings-and-ads/src/Value/ |
Linux v11800 5.3.0-1023-aws #25~18.04.1-Ubuntu SMP Fri Jun 5 15:19:18 UTC 2020 aarch64
|
Current File : /storage/v11800/lifespanstoresnew/public_html/wp-content/plugins/google-listings-and-ads/src/Value/EnumeratedValues.php |
<?php
declare( strict_types=1 );
namespace Automattic\WooCommerce\GoogleListingsAndAds\Value;
use Automattic\WooCommerce\GoogleListingsAndAds\Exception\InvalidType;
defined( 'ABSPATH' ) || exit;
/**
* Class EnumeratedValues
*
* @package Automattic\WooCommerce\GoogleListingsAndAds\Value
*/
abstract class EnumeratedValues {
/** @var string */
protected $value;
/**
* Array of possible valid values.
*
* Data will be validated to ensure it is one of these values.
*
* @var array
*/
protected $valid_values = [];
/**
* EnumeratedValues constructor.
*
* @param string $value
*/
public function __construct( string $value ) {
$this->validate_value( $value );
$this->value = $value;
}
/**
* Validate the that value we received is one of the valid types.
*
* @param string $value
*
* @throws InvalidType When the value is not valid.
*/
protected function validate_value( string $value ) {
if ( ! array_key_exists( $value, $this->valid_values ) ) {
throw InvalidType::from_type( $value, array_keys( $this->valid_values ) );
}
}
}