Merge "resourceloader: Consistently refer to the framework as ResourceLoader"
[lhc/web/wiklou.git] / includes / media / XMPValidate.php
index 0fa6011..519c420 100644 (file)
@@ -21,6 +21,9 @@
  * @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 )
         *
@@ -48,13 +64,13 @@ class XMPValidate {
         * @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;
                }
        }
@@ -66,13 +82,13 @@ class XMPValidate {
         * @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;
                }
        }
@@ -87,7 +103,7 @@ class XMPValidate {
         * @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;
@@ -95,7 +111,7 @@ class XMPValidate {
                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;
@@ -105,13 +121,13 @@ class XMPValidate {
                                // 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;
@@ -126,13 +142,13 @@ class XMPValidate {
         * @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;
                }
        }
@@ -145,13 +161,13 @@ class XMPValidate {
         * @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'] )
@@ -163,7 +179,7 @@ class XMPValidate {
                }
 
                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;
                }
        }
@@ -175,7 +191,7 @@ class XMPValidate {
         * @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;
@@ -186,7 +202,7 @@ class XMPValidate {
                        && 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' )
@@ -209,14 +225,14 @@ class XMPValidate {
         * @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;
                }
        }
@@ -238,7 +254,7 @@ class XMPValidate {
         *    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;
@@ -252,7 +268,7 @@ class XMPValidate {
                ) {
                        // @codingStandardsIgnoreEnd
 
-                       wfDebugLog( 'XMP', __METHOD__ . " Expected date but got $val" );
+                       $this->logger->info( __METHOD__ . " Expected date but got $val" );
                        $val = null;
                } else {
                        /*
@@ -270,14 +286,14 @@ class XMPValidate {
                         * 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];
@@ -290,7 +306,7 @@ class XMPValidate {
                        }
 
                        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] !== '' ) {
@@ -339,7 +355,7 @@ class XMPValidate {
         *   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;
                }
@@ -371,7 +387,7 @@ class XMPValidate {
 
                        return;
                } else {
-                       wfDebugLog( 'XMP', __METHOD__
+                       $this->logger->info( __METHOD__
                                . " Expected GPSCoordinate, but got $val." );
                        $val = null;