* @ingroup Media
*/
+use Psr\Log\LoggerInterface;
+use Psr\Log\LoggerAwareInterface;
+
/**
* This contains some static methods for
* validating XMP properties. See XMPInfo and XMPReader classes.
* @see http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart1.pdf starting at pg 28
* @see http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart2.pdf starting at pg 11
*/
-class XMPValidate {
+class XMPValidate implements LoggerAwareInterface {
+
+ /**
+ * @var LoggerInterface
+ */
+ private $logger;
+
+ public function __construct( LoggerInterface $logger ) {
+ $this->setLogger( $logger );
+ }
+
+ public function setLogger( LoggerInterface $logger ) {
+ $this->logger = $logger;
+ }
/**
* Function to validate boolean properties ( True or False )
*
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateBoolean( $info, &$val, $standalone ) {
+ public function validateBoolean( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
}
if ( $val !== 'True' && $val !== 'False' ) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected True or False but got $val" );
+ $this->debug->info( __METHOD__ . " Expected True or False but got $val" );
$val = null;
}
}
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateRational( $info, &$val, $standalone ) {
+ public function validateRational( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
}
if ( !preg_match( '/^(?:-?\d+)\/(?:\d+[1-9]|[1-9]\d*)$/D', $val ) ) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected rational but got $val" );
+ $this->logger->info( __METHOD__ . " Expected rational but got $val" );
$val = null;
}
}
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateRating( $info, &$val, $standalone ) {
+ public function validateRating( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
if ( !preg_match( '/^[-+]?\d*(?:\.?\d*)$/D', $val )
|| !is_numeric( $val )
) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected rating but got $val" );
+ $this->logger->info( __METHOD__ . " Expected rating but got $val" );
$val = null;
return;
// We do < 0 here instead of < -1 here, since
// the values between 0 and -1 are also illegal
// as -1 is meant as a special reject rating.
- wfDebugLog( 'XMP', __METHOD__ . " Rating too low, setting to -1 (Rejected)" );
+ $this->logger->info( __METHOD__ . " Rating too low, setting to -1 (Rejected)" );
$val = '-1';
return;
}
if ( $nVal > 5 ) {
- wfDebugLog( 'XMP', __METHOD__ . " Rating too high, setting to 5" );
+ $this->logger->info( __METHOD__ . " Rating too high, setting to 5" );
$val = '5';
return;
* @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateInteger( $info, &$val, $standalone ) {
+ public function validateInteger( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
}
if ( !preg_match( '/^[-+]?\d+$/D', $val ) ) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected integer but got $val" );
+ $this->logger->info( __METHOD__ . " Expected integer but got $val" );
$val = null;
}
}
* choices. (closed choice)
*
* @param array $info Information about current property
- * @param &$val Mixed current value to validate
+ * @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateClosed( $info, &$val, $standalone ) {
+ public function validateClosed( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
}
- //check if its in a numeric range
+ // check if its in a numeric range
$inRange = false;
if ( isset( $info['rangeLow'] )
&& isset( $info['rangeHigh'] )
}
if ( !isset( $info['choices'][$val] ) && !$inRange ) {
- wfDebugLog( 'XMP', __METHOD__ . " Expected closed choice, but got $val" );
+ $this->logger->info( __METHOD__ . " Expected closed choice, but got $val" );
$val = null;
}
}
* function to validate and modify flash structure
*
* @param array $info Information about current property
- * @param &$val Mixed current value to validate
+ * @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateFlash( $info, &$val, $standalone ) {
+ public function validateFlash( $info, &$val, $standalone ) {
if ( $standalone ) {
// this only validates flash structs, not individual properties
return;
&& isset( $val['RedEyeMode'] )
&& isset( $val['Return'] )
) ) {
- wfDebugLog( 'XMP', __METHOD__ . " Flash structure did not have all the required components" );
+ $this->logger->info( __METHOD__ . " Flash structure did not have all the required components" );
$val = null;
} else {
$val = ( "\0" | ( $val['Fired'] === 'True' )
* @see http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart1.pdf page 30 (section 8.2.2.5)
*
* @param array $info Information about current property
- * @param &$val Mixed current value to validate
+ * @param mixed &$val Current value to validate
* @param bool $standalone If this is a simple property or array
*/
- public static function validateLangCode( $info, &$val, $standalone ) {
+ public function validateLangCode( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
}
if ( !preg_match( '/^[-A-Za-z0-9]{2,}$/D', $val ) ) {
- //this is a rather naive check.
- wfDebugLog( 'XMP', __METHOD__ . " Expected Lang code but got $val" );
+ // this is a rather naive check.
+ $this->logger->info( __METHOD__ . " Expected Lang code but got $val" );
$val = null;
}
}
* 2011:04.
* @param bool $standalone If this is a simple property or array
*/
- public static function validateDate( $info, &$val, $standalone ) {
+ public function validateDate( $info, &$val, $standalone ) {
if ( !$standalone ) {
// this only validates standalone properties, not arrays, etc
return;
) {
// @codingStandardsIgnoreEnd
- wfDebugLog( 'XMP', __METHOD__ . " Expected date but got $val" );
+ $this->logger->info( __METHOD__ . " Expected date but got $val" );
$val = null;
} else {
/*
* some programs convert between metadata formats.
*/
if ( $res[1] === '0000' ) {
- wfDebugLog( 'XMP', __METHOD__ . " Invalid date (year 0): $val" );
+ $this->logger->info( __METHOD__ . " Invalid date (year 0): $val" );
$val = null;
return;
}
- if ( !isset( $res[4] ) ) { //hour
- //just have the year month day (if that)
+ if ( !isset( $res[4] ) ) { // hour
+ // just have the year month day (if that)
$val = $res[1];
if ( isset( $res[2] ) ) {
$val .= ':' . $res[2];
}
if ( !isset( $res[7] ) || $res[7] === 'Z' ) {
- //if hour is set, then minute must also be or regex above will fail.
+ // if hour is set, then minute must also be or regex above will fail.
$val = $res[1] . ':' . $res[2] . ':' . $res[3]
. ' ' . $res[4] . ':' . $res[5];
if ( isset( $res[6] ) && $res[6] !== '' ) {
* or DDD,MM.mmk form
* @param bool $standalone If its a simple prop (should always be true)
*/
- public static function validateGPS( $info, &$val, $standalone ) {
+ public function validateGPS( $info, &$val, $standalone ) {
if ( !$standalone ) {
return;
}
return;
} else {
- wfDebugLog( 'XMP', __METHOD__
+ $this->logger->info( __METHOD__
. " Expected GPSCoordinate, but got $val." );
$val = null;