explicit "unsetter" methods which seems to be a cleaner way.
Signed-off-by: Roland Häder <roland@mxchange.org>
* @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;
}
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
*
*
* @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('');
* @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()));
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);
*/
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;
}
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
*
} // END - while
// Close the file
- $fileInstance->closeFile();
+ unset($fileInstance);
}
/**
} // END - while
// Close directory handle
- $fileInstance->closeFile();
+ unset($fileInstance);
// Convert it into an array
$inputBuffer = explode(chr(10), $inputBuffer);
// 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);
$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();
}
// 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();
* @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;
}