UserSessions
final class UserSessions extends Model
Supports operations of the User Session model. Extends the Model class.
Traits
Creates the $created_at and $updated_at fields and performs the operation that updates timestamps.
Supports ability to validate console input.
Constants
| BLACKLIST |
Constant for blacklist. |
| WHITELIST |
Constant for whitelist. |
Properties
| protected array | $errors | An array of errors. |
from HasValidators |
| protected string | $fieldName | The name of the field to be validated. |
from HasValidators |
| protected array | $reservedKeywords | An array of reserved keywords. |
from HasValidators |
| protected array | $reservedSQLKeyWords | from HasValidators | |
| protected array | $validators | Array of validator callbacks. |
from HasValidators |
| static protected DB | $_db | The instance of the DB class. |
from Model |
| int | $id | The id for the session. |
|
| protected string | $_modelName | The name of the model. |
from Model |
| static protected bool | $_softDelete | $_softDelete value. |
from Model |
| static protected string | $_table | The name of the table. |
|
| protected bool | $_validates | Flag to indicate if validation is successful. |
from Model |
| string | $created_at | Time record was created. |
from HasTimestamps |
| string | $updated_at | Time record was updated. |
from HasTimestamps |
| string | $session | The session. |
|
| string | $user_agent | The user agent. |
|
| int | $user_id | ID of user associated with this session. |
Methods
Adds a new error message to the $errors array.
Enforce rule where input must contain only alphabetic characters.
Enforce rule where input must be alphanumeric characters.
Ensures input is between within a certain range in length.
Checks if class exists within the specified namespace.
Tests form validation with multiple fields. Used by the unique validator to test several fields for uniqueness.
Enforce rule where response and $match parameter needs to be different.
Sets name of field to be validated.
Supports includeDeleted feature for database operations.
Checks if a port on a particular host is in use. Assists in verifying if a port is available for a serve command. If the port is already in use an error message is presented to the user.
Ensure user inputs valid comma separated list of values. The user must provide the following in the $attributes parameter: 1) Class containing full namespaced path 2) Name of function that returns an array of strings or a comma separated array of strings.
Enforces rule when input must contain at least one lower case character.
Enforce rule where response and $match parameter needs to match.
Ensures input meets requirements for maximum allowable length.
Ensures input meets requirements for minimum allowable length.
Enforces rule when input must contain no special characters.
Enforce rule when reserved keywords should be avoided.
Enforce rule when reserved SQL keywords should be avoided.
Enforces rule when input must contain at least one numeric character.
Enforce rule where input must contain only numeric characters.
Parse array containing additional validators or attributes for FrameworkQuestion as strings along with any additional parameters that maybe expected.
Adds validator to array of validators to be used.
Enforces rule when input must contain at least one special character.
Split on commas (tolerate spaces), normalize to lowercase, drop empties.
Checks if value already exists in a database.
Enforces rule when input must contain at least one lower case character.
Calls validator callbacks. This function also ensures validators don't bleed into next question if instance is reused.
Update the object with an associative array.
Called before save.
Retrieves number of rows affected or returned by the last query. This is a wrapper function for the DB::count function.
Gets an associative array of field values for insert or updating.
Wrapper for the find function that is found in the DB class.
Retrieves list of all records within a table related to a user.
Performs a database query against a specified table using the same query-building logic as the default find method.
Wrapper for the findFirst function that is found in the DB class.
Returns number of records in a table. A wrapper function for findTotal function in DB class.
Checks if results of validation is true or false. If false, the $this->_validates boolean instance variable is set to false. There are two ways to provide parameters for validation. You can pass the results from chaining functions and use just one parameter. Or you can provide the value of the field's name attribute, an array of validators, and a value for how you want the name of the field represented in error messages. If this value is not provided then the name attribute is used in messaging.
Wrapper for update and insert functions. A failed form validation will cause this function to return false.
Adds to the conditions to avoid getting soft deleted rows returned
Projects model rows into a [value => label] options map for form controls.
Updates one or more rows in this model's underlying table using your framework's params-style conditions.
Function that is called on save. If validation fails the save function will not proceed. This function is just a signature and must be implemented by models that run form validation because since it is called from within this class.
Retrieves User Session information from cookie.
Details
in
HasValidators at line 127
void
addErrorMessage(string $message)
Adds a new error message to the $errors array.
in
HasValidators at line 137
HasValidators
alpha()
Enforce rule where input must contain only alphabetic characters.
in
HasValidators at line 151
HasValidators
alphaNumeric()
Enforce rule where input must be alphanumeric characters.
in
HasValidators at line 169
HasValidators
between(array $range)
Ensures input is between within a certain range in length.
in
HasValidators at line 194
HasValidators
classExists(string|array $namespace)
Checks if class exists within the specified namespace.
in
HasValidators at line 209
HasValidators
colonNotation()
Ensures response is in colon notation format.
in
HasValidators at line 231
void
compositeFieldValidation(array|string $additionalFieldData, array $conditions, array $bind)
Tests form validation with multiple fields. Used by the unique validator to test several fields for uniqueness.
in
HasValidators at line 254
HasValidators
different(mixed $data)
Enforce rule where response and $match parameter needs to be different.
in
HasValidators at line 269
void
displayErrorMessages()
Displays a list of all error messages.
in
HasValidators at line 285
HasValidators
dotNotation()
Ensures response is in dot notation format.
in
HasValidators at line 302
HasValidators
email()
Ensures input is a valid E-mail address.
in
HasValidators at line 317
HasValidators
fieldName(string|array $fieldName)
Sets name of field to be validated.
in
HasValidators at line 333
void
includeDeleted(bool|string $includeDeleted, array $queryParams)
Supports includeDeleted feature for database operations.
in
HasValidators at line 344
HasValidators
integer()
Enforce rule where input must be an integer.
in
HasValidators at line 358
HasValidators
ip()
Enforce rule where input must be a valid IP address.
in
HasValidators at line 376
HasValidators
isPortUsed(array $attributes)
Checks if a port on a particular host is in use. Assists in verifying if a port is available for a serve command. If the port is already in use an error message is presented to the user.
in
HasValidators at line 405
HasValidators
list(array $attributes)
Ensure user inputs valid comma separated list of values. The user must provide the following in the $attributes parameter: 1) Class containing full namespaced path 2) Name of function that returns an array of strings or a comma separated array of strings.
3) A string value in this array as an alias (optional).
in
HasValidators at line 443
HasValidators
lower()
Enforces rule when input must contain at least one lower case character.
in
HasValidators at line 458
HasValidators
match(mixed $match)
Enforce rule where response and $match parameter needs to match.
in
HasValidators at line 474
HasValidators
max(int|array $maxRule)
Ensures input meets requirements for maximum allowable length.
in
HasValidators at line 490
HasValidators
min(int|array $minRule)
Ensures input meets requirements for minimum allowable length.
in
HasValidators at line 505
HasValidators
negative()
Enforces rule when input must be a negative number.
in
HasValidators at line 519
HasValidators
noSpecialChars()
Enforces rule when input must contain no special characters.
in
HasValidators at line 533
HasValidators
notReservedKeyword()
Enforce rule when reserved keywords should be avoided.
in
HasValidators at line 547
HasValidators
notReservedSQLKeyword()
Enforce rule when reserved SQL keywords should be avoided.
in
HasValidators at line 561
HasValidators
number()
Enforces rule when input must contain at least one numeric character.
in
HasValidators at line 575
HasValidators
numeric()
Enforce rule where input must contain only numeric characters.
in
HasValidators at line 597
static protected void
parseAttributes(object $object, array $validators)
Parse array containing additional validators or attributes for FrameworkQuestion as strings along with any additional parameters that maybe expected.
in
HasValidators at line 618
HasValidators
required()
Ensures required input is entered.
in
HasValidators at line 631
HasValidators
positive()
Enforces rule when input must a positive number.
in
HasValidators at line 645
HasValidators
queue()
Validates if queue exists in database or redis.
in
HasValidators at line 670
HasValidators
setValidator(callable $validator)
Adds validator to array of validators to be used.
in
HasValidators at line 680
HasValidators
special()
Enforces rule when input must contain at least one special character.
in
HasValidators at line 694
HasValidators
tel()
Enforces rule where input must be a valid phone number.
in
HasValidators at line 718
HasValidators
testFilterNotation()
Ensures response is in colon notation format.
in
HasValidators at line 739
static protected array
tokens(string $data)
Split on commas (tolerate spaces), normalize to lowercase, drop empties.
Useful for cases where you have a comma separated string.
in
HasValidators at line 752
HasValidators
unique(array $attributes)
Checks if value already exists in a database.
in
HasValidators at line 796
HasValidators
upper()
Enforces rule when input must contain at least one lower case character.
in
HasValidators at line 810
HasValidators
url()
Enforce rule where input must be a valid URL.
in
HasValidators at line 826
protected bool
validate(mixed $response)
Calls validator callbacks. This function also ensures validators don't bleed into next question if instance is reused.
in
Model at line 65
__construct()
Default constructor.
in
Model at line 75
void
afterDelete()
Called before delete.
in
Model at line 82
void
afterSave()
Called before save.
in
Model at line 94
Model
assign(array $params, array $list = [], string $assignmentFilter = self::BLACKLIST)
Update the object with an associative array.
in
Model at line 117
void
beforeDelete()
This runs before delete, needs to return a boolean
at line 50
void
beforeSave()
Called before save.
in
Model at line 132
static int
count()
Retrieves number of rows affected or returned by the last query. This is a wrapper function for the DB::count function.
in
Model at line 162
bool
delete()
Wrapper for database delete function. If not softDelete we set it.
If row is set to softDelete we call the database delete function.
in
Model at line 184
static array
getColumns()
Gets columns from table.
in
Model at line 194
array
getColumnsForSave()
Gets an associative array of field values for insert or updating.
in
Model at line 236
array
getErrorMessages()
Displays error messages when form validation fails.
in
Model at line 246
static protected array
_fetchStyleParams(array $params)
Used to set default fetchStyle param.
in
Model at line 260
static array|bool
find(array $params = [])
Wrapper for the find function that is found in the DB class.
in
Model at line 276
static array
findAllByUserId(int $user_id, array $params = [])
Retrieves list of all records within a table related to a user.
in
Model at line 293
static object|bool
findById(int $id)
Get result from database by primary key ID.
in
Model at line 309
static array|bool
findByTable(string $table, array $params = [])
Performs a database query against a specified table using the same query-building logic as the default find method.
This method is useful when querying a different table than the one defined by the model's static::$_table property (e.g., joining or selecting from related tables).
in
Model at line 325
static object|bool
findFirst(array $params = [])
Wrapper for the findFirst function that is found in the DB class.
in
Model at line 340
static int
findTotal(array $params = [])
Returns number of records in a table. A wrapper function for findTotal function in DB class.
in
Model at line 355
bool
insert(array $fields)
Wrapper for database insert function.
in
Model at line 367
bool
isNew()
Checks if an object is a new insertion or an existing record.
in
Model at line 376
void
onConstruct()
Runs when the object is constructed.
in
Model at line 384
protected void
populateObjData(array|object $result)
Populates object with data.
in
Model at line 421
void
runValidation(bool|string $param, array $validators = [], string|null $fieldName = null)
Checks if results of validation is true or false. If false, the $this->_validates boolean instance variable is set to false. There are two ways to provide parameters for validation. You can pass the results from chaining functions and use just one parameter. Or you can provide the value of the field's name attribute, an array of validators, and a value for how you want the name of the field represented in error messages. If this value is not provided then the name attribute is used in messaging.
in
Model at line 444
bool
save()
Wrapper for update and insert functions. A failed form validation will cause this function to return false.
in
Model at line 485
static protected array
_softDeleteParams(array $params)
Adds to the conditions to avoid getting soft deleted rows returned
in
Model at line 527
static array
toOptions(string $valueField, string $labelField, array $conditions = [])
Projects model rows into a [value => label] options map for form controls.
This is the standard source for controls whose options are value/label pairs: select, radio groups, checkbox groups, and datalists in list (non-range) mode. Each row contributes one entry: $row->$valueField => $row->$labelField.
NOT for range inputs. A range's min/max/step are numeric params, not a map, and its datalist tick pairs are almost always developer-set literals rather than model rows — so build those inline. Only use toOptions for a range if its tick values are genuinely data-driven, which is rare.
The value field should be whatever gets stored/submitted (and matched against on populate); the label field is the display text. For ACLs, both are the name: toOptions('acl', 'acl'). For a typical lookup: toOptions('id', 'name').
in
Model at line 550
bool
update(array $fields)
Wrapper for the update function found in the DB class.
in
Model at line 580
static int
updateWhere(array $fields, array $params)
Updates one or more rows in this model's underlying table using your framework's params-style conditions.
This method delegates to the DB::updateWhere() method and allows
you to pass both the fields to update and a parameterized WHERE
clause (using conditions and bind arrays just like find/findFirst).
Example:
Queue::updateWhere(
['reserved_at' => date('Y-m-d H:i:s')],
['conditions' => 'id = ?', 'bind' => [$jobId]]
);
in
Model at line 590
bool
validationPassed()
Getter function for the $_validates boolean instance variable.
in
Model at line 601
void
validator()
Function that is called on save. If validation fails the save function will not proceed. This function is just a signature and must be implemented by models that run form validation because since it is called from within this class.
in
HasTimestamps at line 28
void
timeStamps()
Sets values for timestamp fields.
at line 61
static bool|UserSessions
getFromCookie()
Retrieves User Session information from cookie.