| Server IP : 89.39.208.18 / Your IP : 216.73.217.74 Web Server : LiteSpeed System : User : ( ) PHP Version : 7.4.33 Disable Function : eval,./,ln,passthru,dl,system,exec,popen,shell_exec,posix_getpwuid,posix_uname,ftp_exec,posix_uname,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,get_current_user,getmyuid,getmygid,listen,chgrp,apache_note,apache_setenv,apache_child_terminate,closelog,debugger_off,debugge_on,ini_restore,netscript,escapeshellarg,cmd,backtick,virtual,show_sourc,show_source,pclose,pcntl_exec,datasec,old_offset,ctrl_dir,ini_alter,leak,listen,chgrp,apache_setenv,define_syslog_variables,root,diskfreespace,disk_free_space,disk_total_space,posix_kill,getmyuid,getmygid,apache_child_terminate,php_ini_scanned_files,ls,ps_aux,chown,getrusage,posixc,posame,chgrp,posix_setuid,posix_setsid,posix_setgid,apache_note,apache_setenv,x_getuid,e_ini_file,nfo,SQL,mysql_li,t_dbs,filegroup,highlight_file,ilegetcontents,get_dir,popen,popens,pfsockopen,dos_conv,apache_get_modules,crack_check,crack_closedict,rar_open,bzopen,bzread,bzwrite,shellcode,posix_isatty,posix_getservbyname,escapeshellarg,hypot,pg_host,pos,posix_access,inurl,posix_times,posix_mknod,pclose,ps_fill,symlink,id,escapeshellcmd,php_uname,phpinfo MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home3/mahyarcake/www/wp-content/plugins/wordpress-seo/vendor/yoast/whip/src/ |
Upload File : |
<?php
namespace Yoast\WHIPv2;
use Yoast\WHIPv2\Exceptions\EmptyProperty;
use Yoast\WHIPv2\Exceptions\InvalidOperatorType;
use Yoast\WHIPv2\Exceptions\InvalidType;
use Yoast\WHIPv2\Exceptions\InvalidVersionComparisonString;
use Yoast\WHIPv2\Interfaces\Requirement;
/**
* A value object containing a version requirement for a component version.
*/
class VersionRequirement implements Requirement {
/**
* The component name.
*
* @var string
*/
private $component;
/**
* The component version.
*
* @var string
*/
private $version;
/**
* The operator to use when comparing version.
*
* @var string
*/
private $operator;
/**
* Requirement constructor.
*
* @param string $component The component name.
* @param string $version The component version.
* @param string $operator The operator to use when comparing version.
*/
public function __construct( $component, $version, $operator = '=' ) {
$this->validateParameters( $component, $version, $operator );
$this->component = $component;
$this->version = $version;
$this->operator = $operator;
}
/**
* Retrieves the component name defined for the requirement.
*
* @return string The component name.
*/
public function component() {
return $this->component;
}
/**
* Gets the components version defined for the requirement.
*
* @return string
*/
public function version() {
return $this->version;
}
/**
* Gets the operator to use when comparing version numbers.
*
* @return string The comparison operator.
*/
public function operator() {
return $this->operator;
}
/**
* Creates a new version requirement from a comparison string.
*
* @param string $component The component for this version requirement.
* @param string $comparisonString The comparison string for this version requirement.
*
* @return VersionRequirement The parsed version requirement.
*
* @throws InvalidVersionComparisonString When an invalid version comparison string is passed.
*/
public static function fromCompareString( $component, $comparisonString ) {
$matcher = '`
(
>=? # Matches >= and >.
|
<=? # Matches <= and <.
)
([^>=<\s]+) # Matches anything except >, <, =, and whitespace.
`x';
if ( ! \preg_match( $matcher, $comparisonString, $match ) ) {
throw new InvalidVersionComparisonString( $comparisonString );
}
$version = $match[2];
$operator = $match[1];
return new VersionRequirement( $component, $version, $operator );
}
/**
* Validates the parameters passed to the requirement.
*
* @param string $component The component name.
* @param string $version The component version.
* @param string $operator The operator to use when comparing version.
*
* @return void
*
* @throws EmptyProperty When any of the parameters is empty.
* @throws InvalidOperatorType When the $operator parameter is invalid.
* @throws InvalidType When any of the parameters is not of the expected type.
*/
private function validateParameters( $component, $version, $operator ) {
if ( empty( $component ) ) {
throw new EmptyProperty( 'Component' );
}
if ( ! \is_string( $component ) ) {
throw new InvalidType( 'Component', $component, 'string' );
}
if ( empty( $version ) ) {
throw new EmptyProperty( 'Version' );
}
if ( ! \is_string( $version ) ) {
throw new InvalidType( 'Version', $version, 'string' );
}
if ( empty( $operator ) ) {
throw new EmptyProperty( 'Operator' );
}
if ( ! \is_string( $operator ) ) {
throw new InvalidType( 'Operator', $operator, 'string' );
}
$validOperators = array( '=', '==', '===', '<', '>', '<=', '>=' );
if ( ! \in_array( $operator, $validOperators, true ) ) {
throw new InvalidOperatorType( $operator, $validOperators );
}
}
}