Merge "Rewrite pref cleanup script"
[lhc/web/wiklou.git] / includes / clientpool / SquidPurgeClient.php
index 24b8b8e..be802f9 100644 (file)
@@ -44,7 +44,7 @@ class SquidPurgeClient {
        protected $writeBuffer = '';
 
        /** @var array */
-       protected $requests = array();
+       protected $requests = [];
 
        /** @var mixed */
        protected $currentRequestIndex;
@@ -70,7 +70,7 @@ class SquidPurgeClient {
         * @param string $server
         * @param array $options
         */
-       public function __construct( $server, $options = array() ) {
+       public function __construct( $server, $options = [] ) {
                $parts = explode( ':', $server, 2 );
                $this->host = $parts[0];
                $this->port = isset( $parts[1] ) ? $parts[1] : 80;
@@ -116,13 +116,13 @@ class SquidPurgeClient {
         */
        public function getReadSocketsForSelect() {
                if ( $this->readState == 'idle' ) {
-                       return array();
+                       return [];
                }
                $socket = $this->getSocket();
                if ( $socket === false ) {
-                       return array();
+                       return [];
                }
-               return array( $socket );
+               return [ $socket ];
        }
 
        /**
@@ -131,13 +131,13 @@ class SquidPurgeClient {
         */
        public function getWriteSocketsForSelect() {
                if ( !strlen( $this->writeBuffer ) ) {
-                       return array();
+                       return [];
                }
                $socket = $this->getSocket();
                if ( $socket === false ) {
-                       return array();
+                       return [];
                }
-               return array( $socket );
+               return [ $socket ];
        }
 
        /**
@@ -197,7 +197,7 @@ class SquidPurgeClient {
        public function queuePurge( $url ) {
                global $wgSquidPurgeUseHostHeader;
                $url = CdnCacheUpdate::expand( str_replace( "\n", '', $url ) );
-               $request = array();
+               $request = [];
                if ( $wgSquidPurgeUseHostHeader ) {
                        $url = wfParseUrl( $url );
                        $host = $url['host'];
@@ -304,40 +304,40 @@ class SquidPurgeClient {
         */
        protected function processReadBuffer() {
                switch ( $this->readState ) {
-               case 'idle':
-                       return 'done';
-               case 'status':
-               case 'header':
-                       $lines = explode( "\r\n", $this->readBuffer, 2 );
-                       if ( count( $lines ) < 2 ) {
+                       case 'idle':
                                return 'done';
-                       }
-                       if ( $this->readState == 'status' ) {
-                               $this->processStatusLine( $lines[0] );
-                       } else { // header
-                               $this->processHeaderLine( $lines[0] );
-                       }
-                       $this->readBuffer = $lines[1];
-                       return 'continue';
-               case 'body':
-                       if ( $this->bodyRemaining !== null ) {
-                               if ( $this->bodyRemaining > strlen( $this->readBuffer ) ) {
-                                       $this->bodyRemaining -= strlen( $this->readBuffer );
-                                       $this->readBuffer = '';
+                       case 'status':
+                       case 'header':
+                               $lines = explode( "\r\n", $this->readBuffer, 2 );
+                               if ( count( $lines ) < 2 ) {
                                        return 'done';
+                               }
+                               if ( $this->readState == 'status' ) {
+                                       $this->processStatusLine( $lines[0] );
+                               } else { // header
+                                       $this->processHeaderLine( $lines[0] );
+                               }
+                               $this->readBuffer = $lines[1];
+                               return 'continue';
+                       case 'body':
+                               if ( $this->bodyRemaining !== null ) {
+                                       if ( $this->bodyRemaining > strlen( $this->readBuffer ) ) {
+                                               $this->bodyRemaining -= strlen( $this->readBuffer );
+                                               $this->readBuffer = '';
+                                               return 'done';
+                                       } else {
+                                               $this->readBuffer = substr( $this->readBuffer, $this->bodyRemaining );
+                                               $this->bodyRemaining = 0;
+                                               $this->nextRequest();
+                                               return 'continue';
+                                       }
                                } else {
-                                       $this->readBuffer = substr( $this->readBuffer, $this->bodyRemaining );
-                                       $this->bodyRemaining = 0;
-                                       $this->nextRequest();
-                                       return 'continue';
+                                       // No content length, read all data to EOF
+                                       $this->readBuffer = '';
+                                       return 'done';
                                }
-                       } else {
-                               // No content length, read all data to EOF
-                               $this->readBuffer = '';
-                               return 'done';
-                       }
-               default:
-                       throw new MWException( __METHOD__ . ': unexpected state' );
+                       default:
+                               throw new MWException( __METHOD__ . ': unexpected state' );
                }
        }