*
* @return $databaseInstance An instance of a DatabaseConnection class
*/
- public static function getDatabaseInstance (): ?DatabaseConnection {
+ public static function getDatabaseInstance (): DatabaseConnection {
// Return instance
return self::$databaseInstance;
}
*
* @return __CLASS__ This class' name
*/
- public function __toString () {
+ public function __toString (): string {
return get_class($this);
}
*
* @return $config Configuration array
*/
- public final function getConfigurationArray () {
+ public final function getConfigurationArray (): array {
// Return it
//* NOISY-DEBUG: */ printf('[%s:%d]: self::configData()=%d - EXIT!' . PHP_EOL, __METHOD__, __LINE__, count(self::$configData));
return self::$configData;
*
* @return void
*/
- public final function sortConfigurationArray () {
+ public final function sortConfigurationArray (): void {
// Resort the array
//* NOISY-DEBUG: */ printf('[%s:%d]: Sorting %d records - CALLED!' . PHP_EOL, __METHOD__, __LINE__, count(self::$configData));
ksort(self::$configData);
*
* @return $hashCode The hash code respresenting this class
*/
- public function hashCode () {
+ public function hashCode (): int {
return crc32($this->__toString());
}
*
* @return $applicationInstance An instance of a ManageableApplication class
*/
- public static final function getApplicationInstance (): ?ManageableApplication {
+ public static final function getApplicationInstance (): ManageableApplication {
return self::$applicationInstance;
}
// Import framework stuff
use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\Crypto\Cryptable;
-use Org\Mxchange\CoreFramework\Crypto\RandomNumber\RandomNumberGenerator;
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Traits\Crypto\Rng\RandomNumberGeneratorTrait;
/**
* A helper class for cryptographical things like hashing passwords and so on
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class CryptoHelper extends BaseFrameworkSystem implements Cryptable {
+ // Load traits
+ use RandomNumberGeneratorTrait;
+
// Exception constants
const EXCEPTION_ENCRYPT_MISSING = 0x1f0;
const EXCEPTION_ENCRYPT_INVALID = 0x1f1;
*/
private $salt = '';
- /**
- * Instance of a RNG
- */
- private $rngInstance = NULL;
-
/**
* Protected constructor
*
*
* @return $cryptoInstance An instance of this crypto helper class
*/
- public static final function createCryptoHelper () {
+ public static final function createCryptoHelper (): Cryptable {
// Get a new instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CRYPTO-HELPER: CALLED!');
$cryptoInstance = new CryptoHelper();
*
* @return $selfInstance An instance of this crypto helper class
*/
- public static final function getSelfInstance () {
+ public static final function getSelfInstance (): Cryptable {
// Is no instance there?
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CRYPTO-HELPER: self::selfInstance[]=%s - CALLED!', gettype(self::$selfInstance)));
if (is_null(self::$selfInstance)) {
return self::$selfInstance;
}
- /**
- * Setter for RNG instance
- *
- * @param $rngInstance An instance of a random number generator (RNG)
- * @return void
- */
- protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
- $this->rngInstance = $rngInstance;
- }
-
- /**
- * Getter for RNG instance
- *
- * @return $rngInstance An instance of a random number generator (RNG)
- */
- public final function getRngInstance () {
- return $this->rngInstance;
- }
-
/**
* Attaches a crypto stream to this crypto helper by detecting loaded
* modules.
*
* @return void
*/
- protected function attachCryptoStream () {
+ protected function attachCryptoStream (): void {
// @TODO Maybe rewrite this with DirectoryIterator, similar to Compressor thing?
// Do we have openssl loaded?
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CRYPTO-HELPER: CALLED!');
*
* @return void
*/
- protected function initHasher () {
+ protected function initHasher (): void {
// Initialize the random number generator which is required by some crypto methods
$this->setRngInstance(ObjectFactory::createObjectByConfiguredName('rng_class'));
*
* @return void
*/
- private function generateSalt () {
+ private function generateSalt (): void {
// Get a random string from the RNG
$randomString = $this->getRngInstance()->randomString() . $this->createUuid();
*
* @return $uuid UUID with leading dash or empty string
*/
- public function createUuid () {
+ public function createUuid (): string {
// Init empty UUID
$uuid = '';
* @param $withFixed Whether to include a fixed salt (not recommended in p2p applications)
* @return $hashed The hashed and salted string
*/
- public function hashString (string $str, string $oldHash = '', bool $withFixed = true) {
+ public function hashString (string $str, string $oldHash = '', bool $withFixed = true): string {
// Default is the default salt ;-)
$salt = $this->salt;
*
* @return $frontendInstance An instance of the created frontend class
*/
- public static final function createPaymentsDatabaseFrontend () {
+ public static final function createPaymentsDatabaseFrontend (): BaseDatabaseFrontend {
// Get a new instance
$frontendInstance = new PaymentsDatabaseFrontend();
*
* @return $upgradeInstance An instance of this UpgradeableDatabaseFormat class
*/
- public final static function createLocalFileDatabaseFormatVersion01To02Upgrade () {
+ public final static function createLocalFileDatabaseFormatVersion01To02Upgrade (): UpgradeableDatabaseFormat {
// Get a new instance
$upgradeInstance = new LocalFileDatabaseFormatVersion01To02Upgrade();
use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
use Org\Mxchange\CoreFramework\Helper\BaseHelper;
use Org\Mxchange\CoreFramework\Helper\Helper;
+use Org\Mxchange\CoreFramework\Traits\Crypto\Rng\RandomNumberGeneratorTrait;
use Org\Mxchange\CoreFramework\Traits\Helper\HelperTrait;
/**
abstract class BaseCaptcha extends BaseHelper implements Helper {
// Load traits
use HelperTrait;
-
- /**
- * Instance of a RNG
- */
- private $rngInstance = NULL;
+ use RandomNumberGeneratorTrait;
/**
* Protected constructor
parent::__construct($className);
}
- /**
- * Setter for RNG instance
- *
- * @param $rngInstance An instance of a random number generator (RNG)
- * @return void
- */
- protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
- $this->rngInstance = $rngInstance;
- }
-
- /**
- * Getter for RNG instance
- *
- * @return $rngInstance An instance of a random number generator (RNG)
- */
- public final function getRngInstance () {
- return $this->rngInstance;
- }
-
/**
* Initializes the random number generator (RNG)
*
*
* @return $listInstance An instance a Listable class
*/
- public static final function createListGroupList () {
+ public static final function createListGroupList (): Listable {
// Get new instance
$listInstance = new ListGroupList();
* @return void
* @todo 0% done
*/
- public function clearList () {
+ public function clearList (): void {
DebugMiddleware::getSelfInstance()->partialStub('Please implement this method.');
}
*
* @return $listInstance An instance a Listable class
*/
- public static final function createTaskList () {
+ public static final function createTaskList (): Listable {
// Get new instance
$listInstance = new TaskList();
*
* @return void
*/
- public function clearList () {
+ public function clearList (): void {
// Clear the only one group
$this->clearGroup('tasks');
}
namespace Org\Mxchange\CoreFramework\Stream\Crypto;
// Import framework stuff
-use Org\Mxchange\CoreFramework\Crypto\RandomNumber\RandomNumberGenerator;
use Org\Mxchange\CoreFramework\Stream\BaseStream;
+use Org\Mxchange\CoreFramework\Traits\Crypto\Rng\RandomNumberGeneratorTrait;
/**
* A general crypto stream class
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseCryptoStream extends BaseStream {
- /**
- * Instance of a RNG
- */
- private $rngInstance = NULL;
+ // Load traits
+ use RandomNumberGeneratorTrait;
/**
* Protected constructor
parent::__construct($className);
}
- /**
- * Setter for RNG instance
- *
- * @param $rngInstance An instance of a random number generator (RNG)
- * @return void
- */
- protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
- $this->rngInstance = $rngInstance;
- }
-
- /**
- * Getter for RNG instance
- *
- * @return $rngInstance An instance of a random number generator (RNG)
- */
- protected final function getRngInstance () {
- return $this->rngInstance;
- }
-
}
* @param $userName The username to set
* @return void
*/
- public final function setUserName (string $userName) {
+ public final function setUserName (string $userName): void {
$this->userName = $userName;
}
*
* @return $userName The username to get
*/
- public final function getUserName () {
+ public final function getUserName (): string {
return $this->userName;
}
*
* @return $userId The user id to get
*/
- public final function getUserId () {
+ public final function getUserId (): int {
return $this->userId;
}
*
* @return $email The email to get
*/
- public final function getEmail () {
+ public final function getEmail (): string {
return $this->email;
}
*
* @return $exists Whether the username exists
*/
- public function ifUsernameExists () {
+ public function ifUsernameExists (): bool {
// By default the username does not exist
$exists = false;
*
* @return $exists Whether the email exists
*/
- public function ifEmailAddressExists () {
+ public function ifEmailAddressExists (): bool {
// By default the email does not exist
$exists = false;
* @param $requestInstance A Requestable class instance
* @return $matches Whether the supplied password hash matches
*/
- public function ifPasswordHashMatches (Requestable $requestInstance) {
+ public function ifPasswordHashMatches (Requestable $requestInstance): bool {
// By default nothing matches... ;)
$matches = false;
*
* @return $passHash User's password hash from database result
*/
- public final function getPasswordHash () {
+ public final function getPasswordHash (): string {
// Default is missing password hash
$passHash = NULL;
*
* @return $primaryValue Value of the primary key based on database type
*/
- public final function getPrimaryKey () {
+ public final function getPrimaryKey (): mixed {
// Get a user database frontend
$frontendInstance = ObjectFactory::createObjectByConfiguredName('user_db_frontend_class');
* @return void
* @todo Try to make this method more generic so we can move it in BaseFrameworkSystem
*/
- public function updateDatabaseField (string $fieldName, $fieldValue) {
+ public function updateDatabaseField (string $fieldName, mixed $fieldValue): void {
// Get a critieria instance
$searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
*
* @return $isConfirmed Whether the user status is 'confirmed'
*/
- public function isConfirmed () {
+ public function isConfirmed (): bool {
// Determine it
$isConfirmed = ($this->getField(UserDatabaseFrontend::DB_COLUMN_USER_STATUS) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('user_status_confirmed'));
*
* @return $isGuest Whether the user status is 'guest'
*/
- public function isGuest () {
+ public function isGuest (): bool {
// Determine it
$isGuest = ($this->getField(UserDatabaseFrontend::DB_COLUMN_USER_STATUS) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('user_status_guest'));
*
* @return void
*/
- private function saveBackTrace () {
+ private function saveBackTrace (): void {
// Get full backtrace
$this->backTrace = debug_backtrace();
*
* @return $backTrace The full backtrace in an array
*/
- public final function getBackTrace () {
+ public final function getBackTrace (): array {
return $this->backTrace;
}
*
* @return $backTrace Backtrace for web pages
*/
- public final function getPrintableBackTrace () {
+ public final function getPrintableBackTrace (): string {
// Get the backtrace
$dbgTrace = $this->getBackTrace();
*
* @return $toString The name of the thrown exception
*/
- public function __toString() {
+ public function __toString(): string {
return get_class($this);
}
*
* @return $extraData Extra data to store
*/
- public final function getExtraData () {
+ public final function getExtraData (): string {
return $this->extraData;
}
*
* @return $compressorInstance A prepared instance of this class
*/
- public static final function createCompressorChannel () {
+ public static final function createCompressorChannel (): CompressorChannel {
// Get new instance
$compressorInstance = new CompressorChannel();
*
* @return $compressor The compressor instance
*/
- public final function getCompressor () {
+ public final function getCompressor (): Compressor {
return $this->compressor;
}
* @param $compressorInstance The compressor instance we shall use
* @return void
*/
- public final function setCompressor (Compressor $compressorInstance = NULL) {
+ public final function setCompressor (Compressor $compressorInstance = NULL): void {
$this->compressor = $compressorInstance;
}
/**
* Getter for the file extension of the current compressor
*/
- public final function getCompressorExtension () {
+ public final function getCompressorExtension (): string {
// Get compressor extension from current compressor
return $this->getCompressor()->getCompressorExtension();
}
*
* @return $ioHandlerInstance A prepared instance of FilIoHandler
*/
- public static final function createFileIoHandler () {
+ public static final function createFileIoHandler (): IoHandler {
// Get instance
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('FILE-IO-HANDLER: CALLED!');
$ioHandlerInstance = new FileIoHandler();
*
* @return $selfInstance An instance of this class
*/
- public static final function getSelfInstance () {
+ public static final function getSelfInstance (): IoHandler {
// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-HANDLER: Returning self::selfInstance[]=%s - EXIT!', gettype(self::$selfInstance)));
return self::$selfInstance;
*
* @return $cacheInstance Name of table name to set
*/
- protected final function getCacheInstance () {
+ protected final function getCacheInstance (): Cacheable {
return $this->cacheInstance;
}
*
* @return $compressorChannelInstance An instance of a CompressorChannel class
*/
- protected final function getCompressorChannelInstance () {
+ protected final function getCompressorChannelInstance (): CompressorChannel {
return $this->compressorChannelInstance;
}
*
* @return $searchInstance Searchable criteria instance
*/
- public final function getSearchInstance () {
+ public final function getSearchInstance (): LocalSearchCriteria {
return $this->searchInstance;
}
*
* @return $cryptoInstance An instance of a Cryptable class
*/
- public final function getCryptoInstance () {
+ public final function getCryptoInstance (): Cryptable {
return $this->cryptoInstance;
}
--- /dev/null
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Traits\Crypto\Rng;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Crypto\RandomNumber\RandomNumberGenerator;
+
+/**
+ * A general captcha
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+trait RandomNumberGeneratorTrait {
+
+ /**
+ * Instance of a RNG
+ */
+ private $rngInstance = NULL;
+
+ /**
+ * Setter for RNG instance
+ *
+ * @param $rngInstance An instance of a random number generator (RNG)
+ * @return void
+ */
+ protected final function setRngInstance (RandomNumberGenerator $rngInstance) {
+ $this->rngInstance = $rngInstance;
+ }
+
+ /**
+ * Getter for RNG instance
+ *
+ * @return $rngInstance An instance of a random number generator (RNG)
+ */
+ public final function getRngInstance () {
+ return $this->rngInstance;
+ }
+
+}
*
* @return $frontendInstance An instance of a DatabaseFrontend class
*/
- public final function getFrontendInstance () {
+ public final function getFrontendInstance (): DatabaseFrontend {
return $this->frontendInstance;
}
*
* @return $binaryFileInstance An instance of an BinaryFile class
*/
- public final function getBinaryFileInstance () {
+ public final function getBinaryFileInstance (): BinaryFile {
return $this->binaryFileInstance;
}
*
* @return $handlerInstance A Handleable instance
*/
- public final function getHandlerInstance () {
+ public final function getHandlerInstance (): Handleable {
return $this->handlerInstance;
}
*
* @return $fileIoInstance An instance to the file I/O sub-system
*/
- protected final function getFileIoInstance () {
+ protected final function getFileIoInstance (): IoHandler {
return $this->fileIoInstance;
}
*
* @return $helperInstance An instance of a helper class
*/
- public final function getHelperInstance () {
+ public final function getHelperInstance (): Helper {
return $this->helperInstance;
}
*
* @return $indexInstance An instance of an Indexable class
*/
- public final function getIndexInstance () {
+ public final function getIndexInstance (): Indexable {
return $this->indexInstance;
}
*
* @return $iteratorInstance An instance of an Iterator
*/
- public final function getIteratorInstance () {
+ public final function getIteratorInstance (): Iterator {
return $this->iteratorInstance;
}
*
* @return $listInstance A list of Listable
*/
- protected final function getListInstance () {
+ protected final function getListInstance (): Listable {
return $this->listInstance;
}
*
* @return $userInstance An instance of a user class
*/
- public final function getUserInstance () {
+ public final function getUserInstance (): ManageableAccount {
return $this->userInstance;
}
*
* @return $registryInstance The debug registry instance
*/
- protected final function getRegistryInstance () {
+ protected final function getRegistryInstance (): Register {
return $this->registryInstance;
}
*
* @return $resolverInstance Instance of a command resolver class
*/
- protected final function getResolverInstance () {
+ protected final function getResolverInstance (): Resolver {
return $this->resolverInstance;
}
*
* @return $resultInstance An instance of a database result class
*/
- public final function getResultInstance () {
+ public final function getResultInstance (): SearchableResult {
return $this->resultInstance;
}
*
* @return $stackInstance An instance of an stacker
*/
- public final function getStackInstance () {
+ public final function getStackInstance (): Stackable {
return $this->stackInstance;
}
*
* @return $stateInstance A Stateable instance
*/
- public final function getStateInstance () {
+ public final function getStateInstance (): Stateable {
return $this->stateInstance;
}
*
* @param $inputStreamInstance An instance of an InputStream class
*/
- protected final function getInputStreamInstance () {
+ protected final function getInputStreamInstance (): InputStream {
return $this->inputStreamInstance;
}
*
* @param $outputStreamInstance An instance of an OutputStream class
*/
- protected final function getOutputStreamInstance () {
+ protected final function getOutputStreamInstance (): OutputStream {
return $this->outputStreamInstance;
}
*
* @return $inputStreamerInstance The *real* file-input class
*/
- public final function getInputStreamerInstance () {
+ public final function getInputStreamerInstance (): FileInputStreamer {
return $this->inputStreamerInstance;
}
*
* @return $outputStreamerInstance The *real* file-output class
*/
- public final function getOutputStreamerInstance () {
+ public final function getOutputStreamerInstance (): FileOutputStreamer {
return $this->outputStreamerInstance;
}
*
* @return $outputInstance The debug output instance
*/
- protected final function getOutputInstance () {
+ protected final function getOutputInstance (): OutputStreamer {
return $this->outputInstance;
}
*
* @return $templateInstance An instance of a CompileableTemplate class
*/
- public final function getTemplateInstance () {
+ public final function getTemplateInstance (): CompileableTemplate {
return $this->templateInstance;
}
*
* @return $visitorInstance An instance of a Visitor class
*/
- protected final function getVisitorInstance () {
+ protected final function getVisitorInstance (): Visitor {
return $this->visitorInstance;
}