]> git.mxchange.org Git - core.git/commitdiff
Don't "abuse" setters for actually "unsetting" (closing) instances. Better use
authorRoland Haeder <roland@mxchange.org>
Wed, 18 Mar 2015 00:31:09 +0000 (01:31 +0100)
committerRoland Haeder <roland@mxchange.org>
Wed, 18 Mar 2015 00:31:09 +0000 (01:31 +0100)
explicit "unsetter" methods which seems to be a cleaner way.

Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/file_directories/class_BaseAbstractFile.php
inc/classes/main/file_directories/class_BaseFileIo.php
inc/classes/main/file_directories/directory/class_FrameworkDirectoryPointer.php
inc/classes/main/file_directories/io_stream/class_FileIoStream.php
inc/classes/main/filter/payment/class_PaymentDiscoveryFilter.php
inc/classes/main/helper/captcha/web/class_GraphicalCodeCaptcha.php
inc/classes/main/helper/web/forms/class_WebFormHelper.php

index cf0e5da7d4f96653cd13b68bd8bb49e4d6971152..c5226fed87530797370d1acee063116bb7bba829 100644 (file)
@@ -1038,7 +1038,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @param       $protocolInstance       An instance of an HandleableProtocol
         * @return      void
         */
-       public final function setProtocolInstance (HandleableProtocol $protocolInstance = NULL) {
+       public final function setProtocolInstance (HandleableProtocol $protocolInstance) {
                $this->protocolInstance = $protocolInstance;
        }
 
@@ -1322,6 +1322,22 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->pointerInstance;
        }
 
+       /**
+        * Unsets pointer instance which triggers a call of __destruct() if the
+        * instance is still there. This is surely not fatal on already "closed"
+        * file pointer instances.
+        *
+        * I don't want to mess around with above setter by giving it a default
+        * value NULL as setter should always explicitly only set (existing) object
+        * instances and NULL is NULL.
+        *
+        * @return      void
+        */
+       protected final function unsetPointerInstance () {
+               // Simply it to NULL
+               $this->pointerInstance = NULL;
+       }
+
        /**
         * Setter for Indexable instance
         *
index 382ea6fac356c42528bc0606fff36e4ca8dc0fa0..3f4869e416029dde018bcb0feeff333672be780f 100644 (file)
@@ -133,10 +133,13 @@ class BaseAbstractFile extends BaseFrameworkSystem {
         *
         * @return      void
         */
-       public function closeFile () {
+       private function closeFile () {
                // Debug message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: fileName=%s - CALLED!', __METHOD__, __LINE__, $this->getFileName()));
 
+               // Close down pointer instance as well by unsetting it
+               $this->unsetPointerInstance();
+
                // Remove file name
                $this->setFileName('');
 
index 9b762693b34658dfb6e74f08f03f5ca16f380b62..df6d0321c52f5473bf6b0526d733a4531e2a1a2d 100644 (file)
@@ -67,7 +67,7 @@ class BaseFileIo extends BaseFrameworkSystem {
         * @throws      NullPointerException    If the file pointer instance is not set by setPointer()
         * @throws      InvalidResourceException        If there is being set
         */
-       public function closeFile () {
+       private function closeFile () {
                // Debug message
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: fileName=%s - CALLED!', __METHOD__, __LINE__, $this->getFileName()));
 
@@ -79,6 +79,9 @@ class BaseFileIo extends BaseFrameworkSystem {
                        throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
                }
 
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: Closing file %s ...', __METHOD__, __LINE__, $this->getFileName()));
+
                // Close the file pointer and reset the instance variable
                @fclose($this->getPointer());
                $this->setPointer(NULL);
index 3d824272257fff01c74fd27e0cbc98a01f39d48c..42380fd142469c9834e39a3abf9878f167383e90 100644 (file)
@@ -196,18 +196,18 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
         */
        public function closeDirectory () {
                // Close the directory by unsetting it
-               $this->setDirectoryIteratorInstance(NULL);
+               $this->unsetDirectoryIteratorInstance();
                $this->setPathName('');
        }
 
        /**
         * Setter for the directory pointer
         *
-        * @param       $iteratorInstance       An instanceof a DirectoryIterator class or NULL to unset ("close") it.
+        * @param       $iteratorInstance       An instanceof a DirectoryIterator class
         * @return      void
         */
-       protected final function setDirectoryIteratorInstance (DirectoryIterator $iteratorInstance = NULL) {
-               // Set instance (or NULL)
+       protected final function setDirectoryIteratorInstance (DirectoryIterator $iteratorInstance) {
+               // Set instance
                $this->iteratorInstance = $iteratorInstance;
        }
 
@@ -220,6 +220,19 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem implements Framework
                return $this->iteratorInstance;
        }
 
+       /**
+        * Remove directory iterator instance (effectively closing it) by setting
+        * it to NULL. This will trigger a call on the destructor which will then
+        * "close" the iterator.
+        *
+        * @param       $iteratorInstance       An instanceof a DirectoryIterator class
+        * @return      void
+        */
+       protected final function unsetDirectoryIteratorInstance (e) {
+               // "Unset" the instance
+               $this->iteratorInstance = NULL;
+       }
+
        /**
         * Setter for path name
         *
index a7470073fdd3c4679af4471c7036e508120ec08d..9d1bc1a1b0d6dcbfa3b61218da74bad0d3a9072a 100644 (file)
@@ -130,7 +130,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
                } // END - while
 
                // Close the file
-               $fileInstance->closeFile();
+               unset($fileInstance);
        }
 
        /**
@@ -166,7 +166,7 @@ class FileIoStream extends BaseFrameworkSystem implements FileInputStreamer, Fil
                } // END - while
 
                // Close directory handle
-               $fileInstance->closeFile();
+               unset($fileInstance);
 
                // Convert it into an array
                $inputBuffer = explode(chr(10), $inputBuffer);
index 2d3fe83b957b6c33e5f358f20ef491d8016e636d..7a016ece8c46f2b0cda6b287191615d884a0c394 100644 (file)
@@ -101,7 +101,7 @@ class PaymentDiscoveryFilter extends BaseFilter implements Filterable {
                // Try to get real discovery class
                try {
                        // Get an instance from the object factory
-                       $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName().'_payment_discovery', array($this));
+                       $discoveryInstance = ObjectFactory::createObjectByConfiguredName($this->getActionName() . '_payment_discovery', array($this));
 
                        // Call the discovery method
                        $discoveryInstance->discover($requestInstance);
index 7b068da759e3c05cfb928aa1f20e16db55abec62..3d097bdb14969bc9726bbb186a87adb468b5fc86 100644 (file)
@@ -137,13 +137,13 @@ class GraphicalCodeCaptcha extends BaseCaptcha implements SolveableCaptcha {
                $templateInstance->loadCodeTemplate('captch_graphic_code');
 
                // Rename variable
-               $templateInstance->renameVariable('captcha_code', $helperInstance->getFormName().'_captcha');
-               $templateInstance->renameVariable('captcha_hash', $helperInstance->getFormName().'_hash');
-               $templateInstance->renameVariable('encrypted_code', $helperInstance->getFormName().'_encrypt');
+               $templateInstance->renameVariable('captcha_code', $helperInstance->getFormName() . '_captcha');
+               $templateInstance->renameVariable('captcha_hash', $helperInstance->getFormName() . '_hash');
+               $templateInstance->renameVariable('encrypted_code', $helperInstance->getFormName() . '_encrypt');
 
                // Assign variables
-               $templateInstance->assignVariable($helperInstance->getFormName().'_encrypt', urlencode(base64_encode($this->encryptedString)));
-               $templateInstance->assignVariable($helperInstance->getFormName().'_hash', $this->hashedString);
+               $templateInstance->assignVariable($helperInstance->getFormName() . '_encrypt', urlencode(base64_encode($this->encryptedString)));
+               $templateInstance->assignVariable($helperInstance->getFormName() . '_hash', $this->hashedString);
 
                // Compile the template
                $templateInstance->compileTemplate();
index 2498006a0e64c0dafac6583cf4538c524ce02029..f7c8fa1d2b137f3c6d2dab8df6a2918c35d162f1 100644 (file)
@@ -684,7 +684,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
                }
 
                // Get a configured instance
-               $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName().'_captcha', array($this, $extraInstance));
+               $captchaInstance = ObjectFactory::createObjectByConfiguredName($this->getFormName() . '_captcha', array($this, $extraInstance));
 
                // Initiate the CAPTCHA
                $captchaInstance->initiateCaptcha();
@@ -751,7 +751,7 @@ class WebFormHelper extends BaseWebHelper implements HelpableTemplate {
         * @return      $isSecured      Whether this form is secured by a CAPTCHA
         */
        public function ifFormSecuredWithCaptcha () {
-               $isSecured = ($this->getConfigInstance()->getConfigEntry($this->getFormName().'_captcha_secured') == 'Y');
+               $isSecured = ($this->getConfigInstance()->getConfigEntry($this->getFormName() . '_captcha_secured') == 'Y');
                return $isSecured;
        }