[FEATURE] Add signal to process public URL of file
authorBenjamin Mack <benni@typo3.org>
Mon, 9 Jul 2012 21:14:57 +0000 (23:14 +0200)
committerBenjamin Mack <benni@typo3.org>
Tue, 10 Jul 2012 14:10:41 +0000 (16:10 +0200)
By using the File Abstraction Layer (FAL), resources can be put
to remote storages like Amazon S3 or WebDAV. However, in those
cases a protected URI (containing user credentials) is used for
uploading which shall not be accessible for any user of course.

This change introduces the possibility to pre-process the public
URL generation and allows i.e. to substitute by an alternative
dispatcher URL.

Example for registering the slot:
$this->getSignalSlotDispatcher()->connect(
't3lib_file_Storage',
t3lib_file_Storage::SIGNAL_PreGeneratePublicUrl,
'Tx_MyExtension_HandlerSlot',
'preGeneratePublicUrl'
);

Change-Id: I9365831208dc90427aed29cff5672cc8ba5d6261
Resolves: #38821
Releases: 6.0
Reviewed-on: http://review.typo3.org/12732
Reviewed-by: Daniel Sattler
Tested-by: Daniel Sattler
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
t3lib/file/Storage.php

index 957d6c2..eb79fc8 100644 (file)
@@ -92,6 +92,7 @@ class t3lib_file_Storage {
        const SIGNAL_PostFolderRename = 'postFolderRename';
        const SIGNAL_PreFileProcess = 'preFileProcess';
        const SIGNAL_PostFileProcess = 'postFileProcess';
+       const SIGNAL_PreGeneratePublicUrl = 'preGeneratePublicUrl';
 
        /**
         * The storage driver instance belonging to this storage.
@@ -799,7 +800,17 @@ class t3lib_file_Storage {
         * @return string
         */
        public function getPublicUrl(t3lib_file_ResourceInterface $resourceObject, $relativeToCurrentScript = FALSE) {
-               return $this->driver->getPublicUrl($resourceObject, $relativeToCurrentScript);
+               $publicUrl = NULL;
+
+                       // Pre-process the public URL by an accordant slot
+               $this->emitPreGeneratePublicUrl($resourceObject, $relativeToCurrentScript, array('publicUrl' => &$publicUrl));
+
+                       // If slot did not handle the signal, use the default way to determine public URL
+               if ($publicUrl === NULL) {
+                       $publicUrl = $this->driver->getPublicUrl($resourceObject, $relativeToCurrentScript);
+               }
+
+               return $publicUrl;
        }
 
        /**
@@ -2103,7 +2114,20 @@ class t3lib_file_Storage {
                );
        }
 
-
+       /**
+        * Emits file pre-processing signal when generating a public url for a file or folder.
+        *
+        * @param t3lib_file_ResourceInterface $resourceObject
+        * @param boolean $relativeToCurrentScript
+        * @param array $urlData
+        */
+       protected function emitPreGeneratePublicUrl(t3lib_file_ResourceInterface $resourceObject, $relativeToCurrentScript, array $urlData) {
+               $this->getSignalSlotDispatcher()->dispatch(
+                       't3lib_file_Storage',
+                       self::SIGNAL_PreGeneratePublicUrl,
+                       array($this, $this->driver, $resourceObject, $relativeToCurrentScript, $urlData)
+               );
+       }
 
        /**
         * Returns the destination path/fileName of a unique fileName/foldername in that path.