Custom libraries

In this software, there are some modules that come with libraries. These libraries perform different kinds of tasks within the software.

App module libraries

App module libraries can be found in the [app_root]\Nudasoft\App\Libraries directory.

App module libraries

  1. SymfonyMailer/BridgeExtension library

    In this software, we do not use the native CodeIgniter4 email library due to its limitations. Instead, we use the Mailer package from Symfony, installed via Composer. This library uses .twig files as view templates for email content. Since .twig files are different from standard CodeIgniter4 view files, they do not recognize native CodeIgniter4 helper methods. As a result, we have to manually introduce these methods into the .twig files. The whole purpose of this library is to enable the use of these helper methods in .twig files. This library is being used by the SymfonyMailer/SymfonyMailer library, although you will likely not need to work with it directly.

  2. SymfonyMailer/SymfonyMailer library

    Every email sent from this software has its own dedicated email class. To construct these email classes, you need to use the SymfonyMailer/SymfonyMailer library. For a better understanding of how to create these email classes, please review the SignupWelcome.php file located in [app_root]\Nudasoft\Auth\SymfonyMailerEmails.

    This library is not automatically instantiated. You need to manually create an object before using it.

    Methods
    1. send(?TransportInterface $transport = null): void

      This method is use to send the emails. to get a good idea of how to use this method, please review this event file in this directory: [app_root]\Nudasoft\Auth\Events\AfterSignupUser.php.

      For a detailed guide on creating and sending emails, refer to the dedicated Create and send emails chapter.

  3. DataFilter library

    This library includes methods related to data filtering, data cleaning.

    This library is not automatically instantiated. You need to manually create an object before using it.

    Methods
    1. trimWhitespace(array $values): array

      This method, takes an array as input and removes leading and trailing whitespace from all values within the array.

      Example usage:

                                              
                                                  // Create an instance of the DataFilter library
                                                  $app_dataFilterLibrary = new \Nudasoft\App\Libraries\DataFilter();
      
                                                  // Sample input array with only string values
                                                  $array = [
                                                      "  John Doe  ", 
                                                      "  [email protected]  ", 
                                                      "  Hello World  ", 
                                                      "  PHP Developer  "
                                                  ];
      
                                                  // Apply the trimWhitespace method
                                                  $filteredPostData = $app_dataFilterLibrary->trimWhitespace($array);
      
                                                  // Print the output
                                                  print_r($filteredPostData);
      
                                                  // Output
                                                  [
                                                      "John Doe",
                                                      "[email protected]",
                                                      "Hello World",
                                                      "PHP Developer"
                                                  ]
                                              
                                          
  4. DataView library

    This library includes methods related to data display.

    This library is not automatically instantiated. You need to manually create an object before using it.

    Methods
    1. sort(string $field, object $sortsData, string $order = 'a', bool $multiFieldSorting = true): object

      This method returns sorting data for CRUD table header fields, such as the sorting order and sorting URL. It is used to display neutral, ascending, or descending sorting links with icons for the table's field headers.

      Sorting links with icons in a crud view

      To gain a clear understanding of this method's usage, you can review any CRUD field data header file. For example, check the id.php file located in the [app_root]\Nudasoft\Users\Views\Users\FieldData\Headers directory.

  5. Mask library

    This library contains methods for data masking.

    This library is not automatically instantiated. You need to manually create an object before using it.

    Methods
    1. maskEmail(string $email): ?string

      This method can be used to mask certain parts of email addresses for privacy and security purposes, while maintaining a recognizable format for the true owners of the email addresses.

                                              
                                                  use Nudasoft\App\Libraries\Mask;
      
                                                  $mask = new Mask();
      
                                                  echo $mask->maskEmail('[email protected]');
                                                  
                                                  // Output:
                                                  // in**@n*******.***
                                              
                                          
  6. Preferences library

    This library contains methods that can be used to check system settings and user preferences.

    This library is automatically instantiated. You don’t need to manually create an object before using it.

    Let's learn how system settings and user preferences work in this software
    • What’s the difference between settings and preferences?

      In this software, settings and preferences are pretty much the same. System-related settings are referred to as system settings, while user-related settings are called user preferences.

    • Structure of settings/preferences in this software

      Structure of settings/preferences in this software

    • Why both file system based and database based settings?

      File system-based settings allow us to ship this software with zero system settings/configurations in the database, while database-based settings enable users to easily change/override the default system settings via a web interface.

    • System settings vs. user preferences

      System settings are managed through both file-system and database-based approaches. The database-based settings have their own dedicated database table and are primarily updated by system administrators via a web interface. These settings apply system-wide for all users.

      User preferences are database-based, and each user can have both system and local preferences. These preferences are stored in the users table in the database and can be updated by the particular user via a web interface. User preferences apply only to the particular user, not to others. Both system and local preferences are module-basis, meaning each module can have its own system and local preferences. system preferences can apply to the entire module or specific parts of it, while local preferences are designed for a particular part of the module.

    • Priority hierarchy of settings/preferences

      Priority hierarchy of settings/preferences

    • How to add more config class objects to this libraray

      This library will not automatically discover config classes due to performance reasons. You must manually register the config class objects you want to use. You can do this in the BaseController file located in the [app_root]\app\Controllers directory.

      Add config class objects in base controller file

    • Standards to follow when creating system/user settings/preferences keys

      When creating system settings keys and user preference keys, follow this naming convention:

      1. System settings keys: [moduleName]_settingKey. i.e., app_colorMode (If you are creating a corresponding database-based system setting key, make sure it is exactly the same as the file system-based system setting key.).
      2. User system preferences keys: [moduleName]_system_userPreferenceKey. i.e., app_system_colorMode.
      3. User local preferences keys: [moduleName]_local_userPreferenceKey. i.e., app_local_colorMode.
    Methods
    1. system(string $systemSetting): mixed

      First, this method checks if the specified system setting key exists in the database. If it does, it returns the value of that key. If it does not, it retrieves the value of the corresponding file-system-based system setting key. If that key also does not exist, the method returns the NULL. Therefore, the highest priority is given to the database-based system setting key.

                                              
                                                  echo $app_preferencesLibrary->system('app_name');
      
                                                  // Output:
                                                  // Appskull
                                              
                                          
    2. user(?string $systemSetting = null, ?string $userSystemPreference = null, ?string $userLocalPreference = null): mixed

      First this method will check if passed user local preference key exists in the database, if it does, it will return the value of that key. if it doesn't exist, it will check if the passed user system preference key exists in the database, if it does, it will return the value of that key. if it doesn't exist, it will check if the passed system setting key exists in the database, if it does, it will return the value of that key. if it doesn't exist, it will check for corresponding file system based system setting key, if it exists, it will return the value of that key. if it doesn't exist, it will return the NULL.

      This method follows the priority hierarchy of settings/preferences that we previously discussed in this chapter.

      But it's optional to pass all those 3 parameters, you can pass any combination of those 3 parameters, but make sure to pass at least one of those 3 parameters.

                                              
                                                  // Example 1: All parameters are provided
                                                  echo $app_preferencesLibrary->user('app_colorMode', 'app_system_colorMode', 'app_local_colorMode');
                                                  // Output:
                                                  // app_local_colorMode
      
                                                  // Example 2: Only $systemSetting is provided
                                                  echo $app_preferencesLibrary->user('app_colorMode', null, null);
                                                  // Output:
                                                  // app_colorMode
      
                                                  // Example 3: $systemSetting and $userSystemPreference are provided, $userLocalPreference is null
                                                  echo $app_preferencesLibrary->user('app_colorMode', 'app_system_colorMode', null);
                                                  // Output:
                                                  // app_system_colorMode
      
                                                  // Example 4: $systemSetting is null, $userSystemPreference and $userLocalPreference are provided
                                                  echo $app_preferencesLibrary->user(null, 'app_system_colorMode', 'app_local_colorMode');
                                                  // Output:
                                                  // app_local_colorMode
      
                                                  // Example 5: Only $userSystemPreference is provided
                                                  echo $app_preferencesLibrary->user(null, 'app_system_colorMode', null);
                                                  // Output:
                                                  // app_system_colorMode
      
                                                  // Example 6: Only $userLocalPreference is provided
                                                  echo $app_preferencesLibrary->user(null, null, 'app_local_colorMode');
                                                  // Output:
                                                  // app_local_colorMode
      
                                                  // Example 7: All parameters are null
                                                  echo $app_preferencesLibrary->user(null, null, null);
                                                  // Output:
                                                  // NULL
                                              
                                          
  7. URL library

    This library provides a collection of utility methods for dealing with URLs.

    This library contains a few methods that some might find challenging to understand based solely on their names, though this is not often the case with most methods. Let’s examine some commonly used segments in these method names.

    1. thisURL

      thisURL refers to the URL formed using the values of the very first two parameters accepted by these methods. Under the hood, these methods utilize CodeIgniter 4's built-in URL helper, the url_to() method. This method can generate an absolute URL using a route name or a Controller::method and also accepts additional arguments. To learn more about the url_to() method, please visit the URL Helper chapter in the official CodeIgniter 4 documentation.

    2. CurrentURL

      As the name suggests, CurrentURL refers to the URL currently displayed in the web browser's address bar.

    3. NextURL

      NextURL refers to the URL specified as a GET query parameter in the current URL, using the parameter key next.

    This library is automatically instantiated. You don’t need to manually create an object before using it.

    Methods
    1. currentURL(bool $queryString = false): string

      Returns the current URL with or without the query string.

                                              
                                                  // Example 1: Without query string
                                                  // URL: https://nudasoft.com/en/auth?q=http://google.com
                                                  echo $app_URLLibrary->currentURL();
                                                  // Output:
                                                  // https://nudasoft.com/en/auth
      
                                                  // Example 2: With query string
                                                  // URL: https://nudasoft.com/en/auth?q=http://google.com
                                                  echo $app_URLLibrary->currentURL(true);
                                                  // Output:
                                                  // https://nudasoft.com/en/auth?q=http://google.com
                                              
                                          
    2. nextURL(): ?string

      Returns the value of the next query parameter from the URL if it exists; otherwise, returns NULL.

                                              
                                                  // Example 1: 'next' query parameter exists
                                                  // URL: https://nudasoft.com/en/auth?next=http://google.com
                                                  echo $app_URLLibrary->nextURL();
                                                  // Output:
                                                  // https://google.com
      
                                                  // Example 2: 'next' query parameter does not exist
                                                  // URL: https://nudasoft.com/en/auth
                                                  echo $app_URLLibrary->nextURL();
                                                  // Output:
                                                  // NULL
                                              
                                          
    3. isNextURL(): bool

      Check whether next query parameter exists in the URL or not.

                                              
                                                  // Example 1: 'next' query parameter exists
                                                  // URL: https://nudasoft.com/en/auth?next=http://google.com
                                                  echo $app_URLLibrary->isNextURL();
                                                  // Output:
                                                  // true
      
                                                  // Example 2: 'next' query parameter does not exist
                                                  // URL: https://nudasoft.com/en/auth
                                                  echo $app_URLLibrary->isNextURL();
                                                  // Output:
                                                  // false
                                              
                                          
    4. thisURLWithCurrentURLAsNextURL(string $thisURLNamedOrReverseRoute, array $thisURLNamedOrReverseRouteArgs = []): string

      Generates a URL using the two parameters. The generated URL will have the current URL as the next query parameter value.

                                              
                                                  // Example 1: With first parameter only
                                                  // Current URL: https://nudasoft.com/en/users
                                                  echo $app_URLLibrary->thisURLWithCurrentURLAsNextURL('auth_signin');
                                                  // Output:
                                                  // https://nudasoft.com/en/auth?next=https://nudasoft.com/en/users
      
                                                  // Example 2: With both parameters
                                                  // Current URL: https://nudasoft.com/en/users
                                                  echo $app_URLLibrary->thisURLWithCurrentURLAsNextURL('auth_signin', ['social']);
                                                  // Output:
                                                  // https://nudasoft.com/en/auth/social?next=https://nudasoft.com/en/users
                                              
                                          
    5. thisURLIfNextURL(string $thisURLNamedOrReverseRoute, array $thisURLNamedOrReverseRouteArgs = [], ?string $nextURLNamedOrReverseRoute = null, array $nextURLNamedOrReverseRouteArgs = []): string

      This method returns an absolute URL, either with or without the next URL. It depends on whether you pass the relevant parameters to the method or if the next URL GET query parameter is already set in the current URL. If the next URL-related parameters are passed to the method and the current URL contains a next URL query parameter, the priority is given to the passed next URL-related method parameters.

                                              
                                                  // Example 1: Without next URL in the current URL
                                                  // Current URL: https://nudasoft.com/en/auth
                                                  echo $app_URLLibrary->thisURLIfNextURL('auth_signin');
                                                  // Output:
                                                  // https://nudasoft.com/en/auth
      
                                                  // Example 2: With next URL in the current URL
                                                  // Current URL: https://nudasoft.com/en/auth?next=https://nudasoft.com/en/users
                                                  echo $app_URLLibrary->thisURLIfNextURL('auth_signin');
                                                  // Output:
                                                  // https://nudasoft.com/en/auth?next=https://nudasoft.com/en/users
      
                                                  // Example 3: With next URL in the current URL and next URL-related parameters passed to the method
                                                  // Current URL: https://nudasoft.com/en/auth?next=https://nudasoft.com/en/users
                                                  echo $app_URLLibrary->thisURLIfNextURL('auth_signin', [], 'users_userOverview');
                                                  // Output:
                                                  // https://nudasoft.com/en/auth?next=https://nudasoft.com/en/users/overview
      
                                                  // Example 4: With next URL in the current URL and next URL-related parameters passed to the method with some arguments
                                                  // Current URL: https://nudasoft.com/en/auth?next=https://nudasoft.com/en/users
                                                  echo $app_URLLibrary->thisURLIfNextURL('auth_signin', [], 'users_userOverview', ['jane']);
                                                  // Output:
                                                  // https://nudasoft.com/en/auth?next=https://nudasoft.com/en/users/overview/jane
                                              
                                          
    6. thisURLIfNotNextURL(string $thisURLNamedOrReverseRoute, array $thisURLNamedOrReverseRouteArgs = []): string

      Return the value of the next GET query parameter if it is set in the current URL; otherwise, return the URL of the passed named/reverse route.

                                              
                                                  // Example 1: Without next URL in the current URL
                                                  // Current URL: https://nudasoft.com/en/auth
                                                  echo $app_URLLibrary->thisURLIfNotNextURL('auth_signin');
                                                  // Output:
                                                  // https://nudasoft.com/en/auth
      
                                                  // Example 2: With next URL in the current URL
                                                  // Current URL: https://nudasoft.com/en/auth?next=https://nudasoft.com/en/users
                                                  echo $app_URLLibrary->thisURLIfNotNextURL('auth_signin');
                                                  // Output:
                                                  // https://nudasoft.com/en/users
                                              
                                          
    7. canonicalURL(?int $localeSegmentIndex = null): string

      This method returns the canonical URL

      A canonical URL is the preferred version of a webpage URL, designed to prevent duplicate content issues by identifying the authoritative link for search engines. In this software, every HTTP response header includes a canonical link.

      Canonical link in the http respond header

      The $localeSegmentIndex parameter specifies the position of the locale segment in the canonical-URL. URL segments start after the domain or index.php. For example, in https://nudasoft.com/en/user/settings/profile or https://nudasoft.com/index.php/en/user/settings/profile, the first segment is en, the second is user, and so on.

                                              
                                                  // Example 1: Without $localeSegmentIndex parameter
                                                  // Current URL: https://nudasoft.com/index.php/en/user/settings/profile
                                                  echo $app_URLLibrary->canonicalURL();
                                                  // Output:
                                                  // https://nudasoft.com/index.php/en/user/settings/profile
      
                                                  // Example 2: With $localeSegmentIndex parameter
                                                  // Current URL: https://nudasoft.com/index.php/en/user/settings/profile
                                                  echo $app_URLLibrary->canonicalURL(1);
                                                  // Output:
                                                  // https://nudasoft.com/index.php/en/user/settings/profile
      
                                                  // Example 3: With $localeSegmentIndex parameter
                                                  // Current URL: https://nudasoft.com/index.php/en/user/settings/profile
                                                  echo $app_URLLibrary->canonicalURL(2);
                                                  // Output:
                                                  // https://nudasoft.com/index.php/en/en/settings/profile
      
                                                  // Example 4: With $localeSegmentIndex parameter
                                                  // Current URL: https://nudasoft.com/index.php/en/user/settings/profile
                                                  echo $app_URLLibrary->canonicalURL(3);
                                                  // Output:
                                                  // https://nudasoft.com/index.php/en/user/en/profile
                                              
                                          
    8. valueStringToArray(string $dataString): ?array

      This method converts a comma-separated values string, such as 'value1,value2,value3', into an array like ['value1', 'value2', 'value3']. If the resulting array is empty, it returns NULL.

                                              
                                                  // If the string is:
                                                  value1,value2,value3
      
                                                  // The output will be:
                                                  [
                                                      'value1',
                                                      'value2',
                                                      'value3'
                                                  ]
                                              
                                          
    9. keyValueStringToArray(string $dataString): ?array

      This method converts a string of key-value pairs in the format key1:value1,key2:value2,key3:value3 into an associative array like ['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3']. If the generated array is empty, it returns NULL.

                                              
                                                  // If the string is:
                                                  key1:value1,key2:value2,key3:value3
      
                                                  // The output will be:
                                                  [
                                                      'key1' => 'value1',
                                                      'key2' => 'value2',
                                                      'key3' => 'value3'
                                                  ]
                                              
                                          
    10. keyValuesStringToArray(string $dataString): ?array

      This method converts a string in the format like key1:value1 test|vaLue1,key2:value2 test,key3:[key4:value4 test;key5:value5 Test|value5] into a nested associative array. It handles multiple values for a key separated by a pipe (|), nested structures indicated by square brackets ([]), and key-value pairs separated by colons (:).

      In this software, we use encoded value strings for URLs to prevent them from becoming too long, which could happen if standard query strings were used.

                                              
                                                  // If the string is:
                                                  key1:value1 test|vaLue1,key2:value2 test,key3:[key4:value4 test;key5:value5 Test|value5]
      
                                                  // The output will be:
                                                  [
                                                      'key1' => [
                                                          'value1 test', 
                                                          'vaLue1'
                                                      ],
                                                      'key2' => [
                                                          'value2 test'
                                                      ],
                                                      'key3' => [
                                                          'key4' => [
                                                              'value4 test'
                                                          ],
                                                          'key5' => [
                                                              'value5 Test', 
                                                              'value5'
                                                          ]
                                                      ]
                                                  ]
                                              
                                          
    11. valueArrayToString(array $dataArray): ?string

      This method converts an array like ['value1', 'value2', 'value3'] into a comma-separated string: value1,value2,value3.

                                              
                                                  // If the array is:
                                                  [
                                                      'value1',
                                                      'value2',
                                                      'value3'
                                                  ]
      
                                                  // The output will be:
                                                  value1,value2,value3
                                              
                                          
    12. keyValueArrayToString(array $dataArray): ?string

      This method converts an associative array like ['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'] into a comma-separated string with colon-separated key-value pairs: key1:value1,key2:value2,key3:value3.

                                              
                                                  // If the array is:
                                                  [
                                                      'key1' => 'value1',
                                                      'key2' => 'value2',
                                                      'key3' => 'value3'
                                                  ]
      
                                                  // The output will be:
                                                  key1:value1,key2:value2,key3:value3
                                              
                                          
    13. keyValuesArrayToString(array $dataArray): ?string

      This PHP method converts a nested associative array like:

                                              
                                                  [
                                                      'key1' => ['value1 test', 'vaLue1'],
                                                      'key2' => ['value2 test'],
                                                      'key3' => [
                                                          'key4' => ['value4 test'],
                                                          'key5' => ['value5 Test', 'value5']
                                                      ]
                                                  ]
                                              
                                          

      into a string format with colon-separated key-value pairs, pipe (|) separating multiple values, and square brackets ([]) for nested arrays:

                                              
                                                  key1:value1 test|vaLue1,key2:value2 test,key3:[key4:value4 test;key5:value5 Test|value5]
                                              
                                          
    14. removeKeyValuesStringValuesFromURL(string $getParam, string $key, array $getParamValues, array $values): string

      This method, removes specific values from a key-value query parameter value string in the current URL. For example, given a query parameter structure such as f_a=u_c:15|12|16|4|1|5|7, it can remove specified values (i.e., 15, 16, 1) and return the updated URL with the remaining values (i.e., f_a=u_c:12|4|5|7).

                                              
                                                  // Current URL: https://nudasoft.com/users?f_a=u_c:15|12|16|4|1|5|7
                                                  // To remove values: 15, 16, 1
                                                  removeKeyValuesStringValuesFromURL('f_a', 'u_c', ["u_c" => ["15", "12", "16", "4", "1", "5", "7"]], [15, 16, 1]);
                                                  // Returns: https://nudasoft.com/users?f_a=u_c:12|4|5|7
                                              
                                          
    15. removeKeyValuesStringKeysFromURL(string $getParam, array $keys, array $getParamValues): string

      This method, removes specific keys from a key-value query parameter string in the current URL. For example, given a query parameter structure such as f_a=u_c:15|12|16|4|1|5|7,u_r:9|8|20, it can remove specified keys (i.e., u_c) and return the updated URL with the remaining keys and their associated values (i.e., f_a=u_r:9|8|20).

                                              
                                                  // Current URL: https://nudasoft.com/users?f_a=u_c:15|12|16|4|1|5|7,u_r:9|8|20
                                                  // To remove keys: u_c
                                                  removeKeyValuesStringKeysFromURL('f_a', ['u_c'], ["u_c" => ["15", "12", "16", "4", "1", "5", "7"], "u_r" => ["9", "8", "20"]]);
                                                  // Returns: https://nudasoft.com/users?f_a=u_r:9|8|20
                                              
                                          
    16. updateGetParamsAndValuesInURL(array $getParamsAndValues, ?string $URL = null): string

      This method, updates the GET parameters and their values in a given URL. For example, if the URL is https://nudasoft.com/users?f_m=active and the parameter f_m is updated to inactive, the method will return the updated URL: https://nudasoft.com/users?f_m=inactive. If no URL is provided, the method will use the current URL by default.

                                              
                                                  // URL: https://nudasoft.com/users?f_m=active
                                                  // To update: f_m=inactive
                                                  updateGetParamsAndValuesInURL(['f_m' => 'inactive'], 'https://nudasoft.com/users?f_m=active');
                                                  // Returns: https://nudasoft.com/users?f_m=inactive
                                              
                                          
    17. removeTheseKeepOthersGetParamsFromURL(array $getParams, ?string $URL = null): string

      This method, removes the specified GET parameters from a given URL while retaining all other parameters. For example, if the URL is https://nudasoft.com/users?sorts=first_name:d&page=2 and the parameter page is removed, the method will return the updated URL: https://nudasoft.com/users?sorts=first_name:d. If no URL is provided, the method will use the current URL by default.

                                              
                                                  // URL: https://nudasoft.com/users?sorts=first_name:d&page=2
                                                  // To remove: page
                                                  removeTheseKeepOthersGetParamsFromURL(['page'], 'https://nudasoft.com/users?sorts=first_name:d&page=2');
                                                  // Returns: https://nudasoft.com/users?sorts=first_name:d
                                              
                                          
    18. keepTheseRemoveOthersGetParamsFromURL(array $getParams): string

      This method, keeps the specified GET parameters in the current URL while removing all other parameters. For example, if the current URL is https://nudasoft.com/users?sorts=first_name:d&page=2 and the parameter sorts is kept, the method will return the updated URL: https://nudasoft.com/users?sorts=first_name:d.

                                              
                                                  // URL: https://nudasoft.com/users?sorts=first_name:d&page=2
                                                  // To keep: sorts
                                                  keepTheseRemoveOthersGetParamsFromURL(['sorts'], 'https://nudasoft.com/users?sorts=first_name:d&page=2');
                                                  // Returns: https://nudasoft.com/users?sorts=first_name:d
                                              
                                          

Auth module libraries

App module libraries can be found in the [app_root]\Nudasoft\Auth\Libraries directory.

Auth module libraries

  1. Gates library

    We previously discussed this library in the Authentication chapter. It contains methods specifically related to authentication gates.

    This library is not automatically instantiated. You need to manually create an object before using it.

    Methods
    1. toGate(string $gate, string $preOrPost, string $gateRequestNamedOrReverseRoute, array $gateRequestNamedOrReverseRouteArgs = [], ?array $preGatePostData = null): ?string

      This method sets the gate request and returns a URL that can be used to redirect the user to the auth gate. Otherwise return the NULL.

                                              
                                                  // Example 1:
                                                  // Auth gate type: password pre
                                                  // Gate request named or reverse route: users_emailUserSettings
                                                  // Gate request named or reverse route args: none
                                                  // Pre gate post data: none
                                                  echo $auth_gatesLibrary->toGate('password', 'pre', 'users_emailUserSettings');
                                                  // Output:
                                                  // https://nudasoft.com/en/auth/gate/password
      
                                                  // Example 2:
                                                  // Auth gate type: password post
                                                  // Gate request named or reverse route: users_emailUserSettings
                                                  // Gate request named or reverse route args: none
                                                  // Pre gate post data: Post data array
                                                  echo $auth_gatesLibrary->toGate('password', 'pre', 'users_emailUserSettings', [], $postDataArray);
                                                  // Output:
                                                  // https://nudasoft.com/en/auth/gate/password
                                              
                                          
    2. validateGate(string $gate = '', string $preOrPost = ''): void

      This method validates the authentication gate for a specific duration, which can be modified in the Gates configuration file within the Auth module. This file is located in the [app_root]\Nudasoft\Auth\Config directory.

                                              
                                                  // Example 1:
                                                  // Auth gate type: password pre
                                                  $auth_gatesLibrary->validateGate('password', 'pre');
      
                                                  // Example 2:
                                                  // Auth gate type: password post
                                                  $auth_gatesLibrary->validateGate('password', 'post');
                                              
                                          
    3. isValidateGate(string $gate, string $preOrPost): bool

      This method checks whether the auth gates are validated or not.

                                              
                                                  // Example 1:
                                                  // Auth gate type: password pre
                                                  echo $auth_gatesLibrary->isValidateGate('password', 'pre');
                                                  // Output:
                                                  // true|false
      
                                                  // Example 2:
                                                  // Auth gate type: password post
                                                  echo $auth_gatesLibrary->isValidateGate('password', 'post');
                                                  // Output:
                                                  // true|false
                                              
                                          
    4. invalidateGate(string $gate, string $preOrPost): void

      This method is used to invalidate previously validated auth gates.

                                              
                                                  // Example 1:
                                                  // Auth gate type: password pre
                                                  $auth_gatesLibrary->invalidateGate('password', 'pre');
      
                                                  // Example 2:
                                                  // Auth gate type: password post
                                                  $auth_gatesLibrary->invalidateGate('password', 'post');
                                              
                                          
    5. gateRequest(): ?object

      This method can be used to return the gate request data set by the toGate() method.

                                              
                                                  // Example:
                                                  echo $auth_gatesLibrary->gateRequest();
                                                  // Output:
                                                  // stdClass Object
                                                  // (
                                                  //     [gate] => password
                                                  //     [preOrPost] => pre
                                                  //     [gateRequestNamedOrReverseRoute] => users_emailUserSettings
                                                  //     [gateRequestNamedOrReverseRouteArgs] => Array
                                                  //         (
                                                  //         )
                                                  //     [preGatePostData] => Array
                                                  //         (
                                                  //         )
                                                  // )
                                              
                                          
    6. isGateRequest(): bool

      This method returns whether the gate request is set or not.

                                              
                                                  // Example:
                                                  echo $auth_gatesLibrary->isGateRequest();
                                                  // Output:
                                                  // true|false
                                              
                                          
    7. invalidateGateRequest(): void

      This method invalidates the gate request set by the toGate() method.

                                              
                                                  // Example:
                                                  $auth_gatesLibrary->invalidateGateRequest();
                                              
                                          
    8. gateResponse(): ?array

      This method returns the gate response data set by the gate controller.

                                              
                                                  // Example:
                                                  echo $auth_gatesLibrary->gateResponse();
                                                  // Output:
                                                  // Array
                                                  // (
                                                  //     [gate] => password
                                                  //     [preOrPost] => pre
                                                  //     [gateResponseNamedOrReverseRoute] => users_emailUserSettings
                                                  //     [gateResponseNamedOrReverseRouteArgs] => Array
                                                  //         (
                                                  //         )
                                                  //     [preGatePostData] => Array
                                                  //         (
                                                  //         )
                                                  // )
                                              
                                          
    9. isGateResponse(): bool

      This method checks whether the gate response is set or not.

                                              
                                                  // Example:
                                                  echo $auth_gatesLibrary->isGateResponse();
                                                  // Output:
                                                  // true|false
                                              
                                          
  2. User library

    This library includes methods related to both user permissions and user authentication. Some of these methods are documented in the Authentication chapter, while others are covered in the User permissions chapter. The remaining methods are documented here.

    This library is automatically instantiated. You don’t need to manually create an object before using it.

    Methods
    1. isOnline(?string $lastActivityDateTime = null): bool

      This method checks whether the user is online or not.

                                              
                                                  // Example 1:
                                                  // Last activity date time: 2021-09-01 12:00:00
                                                  echo $auth_userLibrary->isOnline('2021-09-01 12:00:00');
                                                  // Output:
                                                  // true
      
                                                  // Example 2:
                                                  // Last activity date time: 2021-09-01 12:00:00
                                                  echo $auth_userLibrary->isOnline('2021-09-01 12:00:01');
                                                  // Output:
                                                  // false
                                              
                                          
    2. rememberMe(int $userID): void

      This method ensures the user is remembered after signing in.

                                              
                                                  // Example:
                                                  $auth_userLibrary->rememberMe(1);
                                              
                                          
    3. isEmailVerified(): bool

      This method checks if the user's email is verified.

                                              
                                                  // Example:
                                                  echo $auth_userLibrary->isEmailVerified();
                                                  // Output:
                                                  // true|false
                                              
                                          
    4. isEmailVerification(): bool

      This method checks email verification based on both system settings and user information.

                                              
                                                  // Example:
                                                  echo $auth_userLibrary->isEmailVerification();
                                                  // Output:
                                                  // true|false
                                              
                                          
Copyright © Nudasoft.