Merge "Made User generally use DB_SLAVE by default"
[lhc/web/wiklou.git] / includes / media / XMPValidate.php
index 4362217..55e8ce7 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;
                }
        }
@@ -142,10 +158,10 @@ class XMPValidate {
         * 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;
@@ -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;
                }
        }
@@ -172,10 +188,10 @@ class XMPValidate {
         * 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;
@@ -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' )
@@ -206,17 +222,17 @@ class XMPValidate {
         * @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->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,7 +286,7 @@ 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;
@@ -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;