Continued:
[core.git] / framework / main / classes / user / class_BaseUser.php
index d4e1d511676747462aa428cf66558f96571908ec..920127ed6cacf5c6767ede07182e12e0bf1fc48c 100644 (file)
@@ -3,19 +3,21 @@
 namespace Org\Mxchange\CoreFramework\User;
 
 // Import framework stuff
-use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseWrapper;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Database\Frontend\User\UserDatabaseFrontend;
 use Org\Mxchange\CoreFramework\Database\Updateable;
-use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 use Org\Mxchange\CoreFramework\Request\Requestable;
 use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
+use Org\Mxchange\CoreFramework\Traits\Result\Search\SearchableResultTrait;
 
 /**
  * A general user class
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @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
  *
@@ -33,6 +35,9 @@ use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
+       // Load traits
+       use SearchableResultTrait;
+
        // Exception constances
        const EXCEPTION_USERNAME_NOT_FOUND   = 0x150;
        const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x151;
@@ -60,7 +65,7 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
         * @param       $className      Name of the class
         * @return      void
         */
-       protected function __construct ($className) {
+       protected function __construct (string $className) {
                // Call parent constructor
                parent::__construct($className);
        }
@@ -71,8 +76,8 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
         * @param       $userName       The username to set
         * @return      void
         */
-       public final function setUserName ($userName) {
-               $this->userName = (string) $userName;
+       public final function setUserName (string $userName) {
+               $this->userName = $userName;
        }
 
        /**
@@ -91,7 +96,7 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
         * @return      void
         * @todo        Find a way of casting here. "(int)" might destroy the user id > 32766
         */
-       public final function setUserId ($userId) {
+       public final function setUserId (int $userId) {
                $this->userId = $userId;
        }
 
@@ -110,8 +115,8 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
         * @param       $email  The email to set
         * @return      void
         */
-       protected final function setEmail ($email) {
-               $this->email = (string) $email;
+       protected final function setEmail (string $email) {
+               $this->email = $email;
        }
 
        /**
@@ -134,34 +139,34 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
 
                // Is a previous result there?
                if (!$this->getResultInstance() instanceof SearchableResult) {
-                       // Get a UserDatabaseWrapper instance
-                       $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+                       // Get a UserDatabaseFrontend instance
+                       $frontendInstance = ObjectFactory::createObjectByConfiguredName('user_db_frontend_class');
 
                        // Create a search criteria
                        $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                        // Add the username as a criteria and set limit to one entry
-                       $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+                       $criteriaInstance->addCriteria(UserDatabaseFrontend::DB_COLUMN_USERNAME, $this->getUserName());
                        $criteriaInstance->setLimit(1);
 
                        // Get a search result
-                       $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+                       $resultInstance = $frontendInstance->doSelectByCriteria($criteriaInstance);
 
                        // Set the index "solver"
-                       $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
+                       $resultInstance->solveResultIndex(UserDatabaseFrontend::DB_COLUMN_USERID, $frontendInstance, array($this, 'setUserId'));
 
                        // And finally set it
                        $this->setResultInstance($resultInstance);
-               } // END - if
+               }
 
                // Rewind it
                $this->getResultInstance()->rewind();
 
                // Search for it
-               if ($this->getResultInstance()->next()) {
+               if ($this->getResultInstance()->valid()) {
                        // Entry found
                        $exists = true;
-               } // END - if
+               }
 
                // Return the status
                return $exists;
@@ -178,31 +183,31 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
 
                // Is a previous result there?
                if (!$this->getResultInstance() instanceof SearchableResult) {
-                       // Get a UserDatabaseWrapper instance
-                       $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+                       // Get a UserDatabaseFrontend instance
+                       $frontendInstance = ObjectFactory::createObjectByConfiguredName('user_db_frontend_class');
 
                        // Create a search criteria
                        $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                        // Add the username as a criteria and set limit to one entry
-                       $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_EMAIL, $this->getEmail());
+                       $criteriaInstance->addCriteria(UserDatabaseFrontend::DB_COLUMN_EMAIL, $this->getEmail());
                        $criteriaInstance->setLimit(1);
 
                        // Get a search result
-                       $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+                       $resultInstance = $frontendInstance->doSelectByCriteria($criteriaInstance);
 
                        // Set the index "solver"
-                       $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
+                       $resultInstance->solveResultIndex(UserDatabaseFrontend::DB_COLUMN_USERID, $frontendInstance, array($this, 'setUserId'));
 
                        // And finally set it
                        $this->setResultInstance($resultInstance);
-               } // END - if
+               }
 
                // Rewind it
                $this->getResultInstance()->rewind();
 
                // Search for it
-               if ($this->getResultInstance()->next()) {
+               if ($this->getResultInstance()->valid()) {
                        // Entry found
                        $exists = true;
 
@@ -213,8 +218,8 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
 
                                // Set the username
                                $this->setUserName($currEntry['username']);
-                       } // END - if
-               } // END - if
+                       }
+               }
 
                // Return the status
                return $exists;
@@ -233,25 +238,25 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
 
                // Is a previous result there?
                if ((!$this->getResultInstance() instanceof SearchableResult) || ($this->getResultInstance()->count() == 0)) {
-                       // Get a UserDatabaseWrapper instance
-                       $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+                       // Get a UserDatabaseFrontend instance
+                       $frontendInstance = ObjectFactory::createObjectByConfiguredName('user_db_frontend_class');
 
                        // Create a search criteria
                        $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                        // Add the username as a criteria and set limit to one entry
-                       $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+                       $criteriaInstance->addCriteria(UserDatabaseFrontend::DB_COLUMN_USERNAME, $this->getUserName());
                        $criteriaInstance->setLimit(1);
 
                        // Get a search result
-                       $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+                       $resultInstance = $frontendInstance->doSelectByCriteria($criteriaInstance);
 
                        // Set the index "solver"
-                       $resultInstance->solveResultIndex(UserDatabaseWrapper::DB_COLUMN_USERID, $wrapperInstance, array($this, 'setUserId'));
+                       $resultInstance->solveResultIndex(UserDatabaseFrontend::DB_COLUMN_USERID, $frontendInstance, array($this, 'setUserId'));
 
                        // And finally set it
                        $this->setResultInstance($resultInstance);
-               } // END - if
+               }
 
                // Rewind it and advance to first entry
                $this->getResultInstance()->rewind();
@@ -264,7 +269,7 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
                        // So does the hashes match?
                        //* DEBUG: */ echo $requestInstance->getRequestElement('pass_hash') . '<br />' . $this->getResultInstance()->getFoundValue() . '<br />';
                        $matches = ($requestInstance->getRequestElement('pass_hash') === $this->getResultInstance()->getFoundValue());
-               } // END - if
+               }
 
                // Return the status
                return $matches;
@@ -286,7 +291,7 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
                if (isset($entry['pass_hash'])) {
                        // Get it
                        $passHash = $entry['pass_hash'];
-               } // END - if
+               }
 
                // And return the hash
                return $passHash;
@@ -298,11 +303,11 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
         * @return      $primaryValue   Value of the primary key based on database type
         */
        public final function getPrimaryKey () {
-               // Get a user database wrapper
-               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+               // Get a user database frontend
+               $frontendInstance = ObjectFactory::createObjectByConfiguredName('user_db_frontend_class');
 
-               // Get the primary key back from the wrapper
-               $primaryKey = $wrapperInstance->getPrimaryKeyValue();
+               // Get the primary key back from the frontend
+               $primaryKey = $frontendInstance->generatePrimaryKey();
 
                // Get that field
                $primaryValue = $this->getField($primaryKey);
@@ -319,12 +324,12 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
         * @return      void
         * @todo        Try to make this method more generic so we can move it in BaseFrameworkSystem
         */
-       public function updateDatabaseField ($fieldName, $fieldValue) {
+       public function updateDatabaseField (string $fieldName, $fieldValue) {
                // Get a critieria instance
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
 
                // Add search criteria
-               $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+               $searchInstance->addCriteria(UserDatabaseFrontend::DB_COLUMN_USERNAME, $this->getUserName());
                $searchInstance->setLimit(1);
 
                // Now get another criteria
@@ -336,8 +341,8 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
                // Add the search criteria for searching for the right entry
                $updateInstance->setSearchInstance($searchInstance);
 
-               // Set wrapper class name
-               $updateInstance->setWrapperConfigEntry('user_db_wrapper_class');
+               // Set frontend class name
+               $updateInstance->setFrontendConfigEntry('user_db_frontend_class');
 
                // Remember the update in database result
                $this->getResultInstance()->add2UpdateQueue($updateInstance);
@@ -350,7 +355,7 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
         */
        public function isConfirmed () {
                // Determine it
-               $isConfirmed = ($this->getField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS) == $this->getConfigInstance()->getConfigEntry('user_status_confirmed'));
+               $isConfirmed = ($this->getField(UserDatabaseFrontend::DB_COLUMN_USER_STATUS) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('user_status_confirmed'));
 
                // Return it
                return $isConfirmed;
@@ -363,7 +368,7 @@ abstract class BaseUser extends BaseFrameworkSystem implements Updateable {
         */
        public function isGuest () {
                // Determine it
-               $isGuest = ($this->getField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS) == $this->getConfigInstance()->getConfigEntry('user_status_guest'));
+               $isGuest = ($this->getField(UserDatabaseFrontend::DB_COLUMN_USER_STATUS) == FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('user_status_guest'));
 
                // Return it
                return $isGuest;