SessionManager: Add SessionBackend::setProviderMetadata()
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 22 Jan 2016 16:09:32 +0000 (11:09 -0500)
committerBrad Jorsch <bjorsch@wikimedia.org>
Fri, 22 Jan 2016 16:10:42 +0000 (11:10 -0500)
Providers might need to update their metadata at times other than when
they're creating the SessionInfo.

Bug: T124409
Change-Id: Ia9d113c93726205de85df65bf85faef74c73c949

includes/session/SessionBackend.php

index 5743b12..3c0f692 100644 (file)
@@ -408,12 +408,31 @@ final class SessionBackend {
        /**
         * Fetch provider metadata
         * @protected For use by SessionProvider subclasses only
-        * @return mixed
+        * @return array|null
         */
        public function getProviderMetadata() {
                return $this->providerMetadata;
        }
 
+       /**
+        * Set provider metadata
+        * @protected For use by SessionProvider subclasses only
+        * @param array|null $metadata
+        */
+       public function setProviderMetadata( $metadata ) {
+               if ( $metadata !== null && !is_array( $metadata ) ) {
+                       throw new \InvalidArgumentException( '$metadata must be an array or null' );
+               }
+               if ( $this->providerMetadata !== $metadata ) {
+                       $this->providerMetadata = $metadata;
+                       $this->metaDirty = true;
+                       $this->logger->debug(
+                               "SessionBackend $this->id metadata dirty due to provider metadata change"
+                       );
+                       $this->autosave();
+               }
+       }
+
        /**
         * Fetch the session data array
         *