24use Psr\Log\LoggerInterface;
25use Psr\Log\LoggerAwareInterface;
26use Wikimedia\Timestamp\ConvertibleTimestamp;
73 if ( $val !==
'True' && $val !==
'False' ) {
74 $this->logger->info( __METHOD__ .
" Expected True or False but got $val" );
91 if ( !preg_match(
'/^(?:-?\d+)\/(?:\d+[1-9]|[1-9]\d*)$/D', $val ) ) {
92 $this->logger->info( __METHOD__ .
" Expected rational but got $val" );
108 if ( !$standalone ) {
112 if ( !preg_match(
'/^[-+]?\d*(?:\.?\d*)$/D', $val )
113 || !is_numeric( $val )
115 $this->logger->info( __METHOD__ .
" Expected rating but got $val" );
125 $this->logger->info( __METHOD__ .
" Rating too low, setting to -1 (Rejected)" );
131 $this->logger->info( __METHOD__ .
" Rating too high, setting to 5" );
147 if ( !$standalone ) {
151 if ( !preg_match(
'/^[-+]?\d+$/D', $val ) ) {
152 $this->logger->info( __METHOD__ .
" Expected integer but got $val" );
166 if ( !$standalone ) {
173 if ( isset( $info[
'rangeLow'] )
174 && isset( $info[
'rangeHigh'] )
175 && is_numeric( $val )
176 && ( intval( $val ) <= $info[
'rangeHigh'] )
177 && ( intval( $val ) >= $info[
'rangeLow'] )
182 if ( !isset( $info[
'choices'][$val] ) && !$inRange ) {
183 $this->logger->info( __METHOD__ .
" Expected closed choice, but got $val" );
200 if ( !( isset( $val[
'Fired'] )
201 && isset( $val[
'Function'] )
202 && isset( $val[
'Mode'] )
203 && isset( $val[
'RedEyeMode'] )
204 && isset( $val[
'Return'] )
206 $this->logger->info( __METHOD__ .
" Flash structure did not have all the required components" );
209 $val = ( 0 | ( $val[
'Fired'] ===
'True' )
210 | ( intval( $val[
'Return'] ) << 1 )
211 | ( intval( $val[
'Mode'] ) << 3 )
212 | ( ( $val[
'Function'] ===
'True' ) << 5 )
213 | ( ( $val[
'RedEyeMode'] ===
'True' ) << 6 ) );
231 if ( !$standalone ) {
235 if ( !preg_match(
'/^[-A-Za-z0-9]{2,}$/D', $val ) ) {
237 $this->logger->info( __METHOD__ .
" Expected Lang code but got $val" );
260 if ( !$standalone ) {
268 '/^([0-3]\d{3})(?:-([01]\d)(?:-([0-3]\d)(?:T([0-2]\d):([0-6]\d)(?::([0-6]\d)(?:\.\d+)?)?([-+]\d{2}:\d{2}|Z)?)?)?)?$/D',
271 $this->logger->info( __METHOD__ .
" Expected date but got $val" );
288 if (
$res[1] ===
'0000' ) {
289 $this->logger->info( __METHOD__ .
" Invalid date (year 0): $val" );
295 if ( !isset(
$res[4] ) ) {
298 if ( isset(
$res[2] ) ) {
299 $val .=
':' .
$res[2];
301 if ( isset(
$res[3] ) ) {
302 $val .=
':' .
$res[3];
308 if ( !isset(
$res[7] ) ||
$res[7] ===
'Z' ) {
312 if ( isset(
$res[6] ) &&
$res[6] !==
'' ) {
313 $val .=
':' .
$res[6];
320 $stripSeconds =
false;
321 if ( !isset(
$res[6] ) ||
$res[6] ===
'' ) {
323 $stripSeconds =
true;
331 $unix = ConvertibleTimestamp::convert( TS_UNIX,
334 $offset = intval( substr(
$res[7], 1, 2 ) ) * 60 * 60;
335 $offset += intval( substr(
$res[7], 4, 2 ) ) * 60;
336 if ( substr(
$res[7], 0, 1 ) ===
'-' ) {
339 $val = ConvertibleTimestamp::convert( TS_EXIF, $unix + $offset );
341 if ( $stripSeconds ) {
343 $val = substr( $val, 0, -3 );
361 if ( !$standalone ) {
367 '/(\d{1,3}),(\d{1,2}),(\d{1,2})([NWSE])/D',
370 $coord = intval( $m[1] );
371 $coord += intval( $m[2] ) * ( 1 / 60 );
372 $coord += intval( $m[3] ) * ( 1 / 3600 );
373 if ( $m[4] ===
'S' || $m[4] ===
'W' ) {
379 } elseif ( preg_match(
380 '/(\d{1,3}),(\d{1,2}(?:.\d*)?)([NWSE])/D',
383 $coord = intval( $m[1] );
384 $coord += floatval( $m[2] ) * ( 1 / 60 );
385 if ( $m[3] ===
'S' || $m[3] ===
'W' ) {
392 $this->logger->info( __METHOD__
393 .
" Expected GPSCoordinate, but got $val." );
This contains some static methods for validating XMP properties.
validateRating( $info, &$val, $standalone)
function to validate rating properties -1, 0-5
validateInteger( $info, &$val, $standalone)
function to validate integers
validateClosed( $info, &$val, $standalone)
function to validate properties with a fixed number of allowed choices.
setLogger(LoggerInterface $logger)
validateBoolean( $info, &$val, $standalone)
Function to validate boolean properties ( True or False )
validateDate( $info, &$val, $standalone)
function to validate date properties, and convert to (partial) Exif format.
validateGPS( $info, &$val, $standalone)
function to validate, and more importantly translate the XMP DMS form of gps coords to the decimal fo...
__construct(LoggerInterface $logger)
validateRational( $info, &$val, $standalone)
function to validate rational properties ( 12/10 )
validateFlash( $info, &$val, $standalone)
function to validate and modify flash structure
validateLangCode( $info, &$val, $standalone)
function to validate LangCode properties ( en-GB, etc )