Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Database/PicoDataComparation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* Class PicoDataComparation
*
* This class provides various comparison operations for use in database queries.
* It allows the creation of comparison objects that can be utilized to
* compare values against specified criteria, facilitating flexible and
* It allows the creation of comparison objects that can be utilized to
* compare values against specified criteria, facilitating flexible and
* expressive database querying.
*
* The class supports a variety of comparison operators such as equality,
* inequality, inclusion, and range comparisons. Each operator can be
* The class supports a variety of comparison operators such as equality,
* inequality, inclusion, and range comparisons. Each operator can be
* applied to values of various types, including strings, booleans, and numbers.
*
* @author Kamshory
Expand Down Expand Up @@ -214,7 +214,7 @@ public function __construct($value, $comparison = self::EQUALS)
/**
* Returns the appropriate equals operator based on the value's state.
*
* If the value is null or of type null, returns the IS operator;
* If the value is null or of type null, returns the IS operator;
* otherwise, returns the standard equals operator.
*
* @return string The equals operator.
Expand All @@ -227,7 +227,7 @@ private function _equals()
/**
* Returns the appropriate not equals operator based on the value's state.
*
* If the value is null or of type null, returns the IS NOT operator;
* If the value is null or of type null, returns the IS NOT operator;
* otherwise, returns the standard not equals operator.
*
* @return string The not equals operator.
Expand Down
134 changes: 69 additions & 65 deletions src/Database/PicoDatabase.php

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/Database/PicoDatabaseCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

/**
* PicoDatabaseCredentials class
*
*
* This class encapsulates database credentials and utilizes the SecretObject to encrypt all attributes,
* ensuring the security of database configuration details from unauthorized access.
*
*
* It provides getter methods to retrieve database connection parameters such as driver, host, port,
* username, password, database name, schema, and application time zone.
*
*
* Example usage:
* ```php
* <?php
Expand All @@ -25,10 +25,10 @@
* $credentials->setPassword('password');
* $credentials->setDatabaseName('app');
* ```
*
*
* The attributes are automatically encrypted when set, providing a secure way to handle sensitive
* information within your application.
*
*
* @author Kamshory
* @package MagicObject\Database
* @link https://github.com/Planetbiru/MagicObject
Expand Down Expand Up @@ -59,7 +59,7 @@ class PicoDatabaseCredentials extends SecretObject
* @var string
*/
protected $host;

/**
* Database server port.
*
Expand Down Expand Up @@ -101,7 +101,7 @@ class PicoDatabaseCredentials extends SecretObject
* @DecryptOut
* @var string
*/
protected $databaseSchema;
protected $databaseSchema;

/**
* Application time zone.
Expand Down Expand Up @@ -131,7 +131,7 @@ class PicoDatabaseCredentials extends SecretObject
public function importFromUrl($url, $username = null, $password = null) // NOSONAR
{
$parts = parse_url($url);

if (!$parts) {
throw new InvalidArgumentException("Invalid database URL");
}
Expand Down
18 changes: 9 additions & 9 deletions src/Database/PicoDatabaseEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Class PicoDatabaseEntity
*
* Represents a database entity that manages multiple database connections.
*
*
* @author Kamshory
* @package MagicObject\Database
* @link https://github.com/Planetbiru/MagicObject
Expand All @@ -17,23 +17,23 @@ class PicoDatabaseEntity
{
/**
* An associative array of databases indexed by entity class name.
*
* @var PicoDatabase[]
*
* @var PicoDatabase[]
*/
private $databases = array();

/**
* Default database connection
*
* @var PicoDatabase
*/
private $defaultDatabase;

/**
* Adds an entity to the database.
*
* @param MagicObject $entity The entity to add.
* @param PicoDatabase|null $database The database to associate with the entity. If null,
* @param PicoDatabase|null $database The database to associate with the entity. If null,
* the current database of the entity will be used.
* @return self Returns the current instance for method chaining.
*/
Expand All @@ -51,7 +51,7 @@ public function add($entity, $database = null)
}
return $this;
}

/**
* Gets the database associated with an entity.
*
Expand All @@ -71,7 +71,7 @@ public function getDatabase($entity)
* Get default database connection
*
* @return PicoDatabase Default database connection
*/
*/
public function getDefaultDatabase()
{
return $this->defaultDatabase;
Expand All @@ -83,7 +83,7 @@ public function getDefaultDatabase()
* @param PicoDatabase $defaultDatabase Default database connection
*
* @return self Returns the current instance for method chaining.
*/
*/
public function setDefaultDatabase($defaultDatabase)
{
$this->defaultDatabase = $defaultDatabase;
Expand Down
4 changes: 2 additions & 2 deletions src/Database/PicoDatabasePersistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ private function getWhereWithColumns($info, $queryBuilder)
$result->whereClause = $this->whereStr;
return $result;
}

$wheres = array();
$columns = array();
foreach($info->getPrimaryKeys() as $property=>$column)
Expand All @@ -990,7 +990,7 @@ private function getWhereWithColumns($info, $queryBuilder)
{
throw new NoPrimaryKeyDefinedException("No primary key defined");
}

$result->columns = $columns;
$result->whereClause = implode(" and ", $wheres);
return $result;
Expand Down
18 changes: 9 additions & 9 deletions src/Database/PicoDatabasePersistenceExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* This class extends the functionality of the PicoDatabasePersistence
* by adding dynamic property setting through magic methods and enhanced
* record selection capabilities.
*
*
* @author Kamshory
* @package MagicObject\Database
* @link https://github.com/Planetbiru/MagicObject
Expand Down Expand Up @@ -43,7 +43,7 @@ public function with()
/**
* Sets a property value and adds it to the internal map.
*
* This method sets a value to a property of the associated object and adds the property name and value
* This method sets a value to a property of the associated object and adds the property name and value
* to an internal map for further processing.
*
* @param string $propertyName The name of the property to set.
Expand All @@ -69,7 +69,7 @@ public function set($propertyName, $propertyValue)
private function addToMap($propertyName, $propertyValue)
{
$this->map[] = array(
'property' => $propertyName,
'property' => $propertyName,
'value' => $propertyValue
);
return $this;
Expand Down Expand Up @@ -155,16 +155,16 @@ public function validate(
// Call the main validation utility only once
ValidationUtil::getInstance($messageTemplate)->validate($objectToValidate, $parentPropertyName);
}

return $this;
}

/**
* Get the current database for the specified entity.
*
* This method retrieves the database connection associated with the
* provided entity. If the entity does not have an associated database
* or if the connection is not valid, it defaults to the object's
* This method retrieves the database connection associated with the
* provided entity. If the entity does not have an associated database
* or if the connection is not valid, it defaults to the object's
* primary database connection.
*
* @param MagicObject $entity The entity for which to get the database.
Expand Down Expand Up @@ -249,7 +249,7 @@ public function selectAll()
public function __toString()
{
return json_encode(array(
'where' => (string) $this->specification,
'where' => (string) $this->specification,
'set' => $this->map
), JSON_PRETTY_PRINT);
}
Expand Down
54 changes: 27 additions & 27 deletions src/Database/PicoDatabaseQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

/**
* Class PicoDatabaseQueryBuilder
*
* A query builder for constructing SQL statements programmatically. This class
* facilitates the creation of various SQL commands including SELECT, INSERT,
*
* A query builder for constructing SQL statements programmatically. This class
* facilitates the creation of various SQL commands including SELECT, INSERT,
* UPDATE, and DELETE, while managing database-specific nuances.
*
*
* **Example:**
* ```php
* <?php
Expand All @@ -25,7 +25,7 @@
* ;
* $data = $db->fetch($query);
* echo $data['client_id']."\r\n"; // Client ID
* echo $data['name']."\r\n"; // Client name
* echo $data['name']."\r\n"; // Client name
* ```
*
* @author Kamshory
Expand Down Expand Up @@ -115,7 +115,7 @@ public function getDatabaseType()
*/
public function isMySql()
{
return strcasecmp($this->databaseType, PicoDatabaseType::DATABASE_TYPE_MYSQL) == 0 ||
return strcasecmp($this->databaseType, PicoDatabaseType::DATABASE_TYPE_MYSQL) == 0 ||
strcasecmp($this->databaseType, PicoDatabaseType::DATABASE_TYPE_MARIADB) == 0;
}

Expand All @@ -138,7 +138,7 @@ public function isSqlite()
{
return strcasecmp($this->databaseType, PicoDatabaseType::DATABASE_TYPE_SQLITE) == 0;
}

/**
* Check if the database type is SQL Server.
*
Expand Down Expand Up @@ -438,8 +438,8 @@ public function where($query)
/**
* Binds SQL parameters by replacing placeholders with actual values.
*
* This function accepts multiple arguments, where the first argument
* is expected to be a SQL string containing `?` placeholders, and
* This function accepts multiple arguments, where the first argument
* is expected to be a SQL string containing `?` placeholders, and
* subsequent arguments are the values to replace them.
*
* @return string The formatted SQL query with values replaced.
Expand Down Expand Up @@ -647,7 +647,7 @@ public function unlockTables()
*
* @return string|null The START TRANSACTION statement or null if not supported.
*/
public function startTransaction()
public function startTransaction()
{
if ($this->isMySql() || $this->isPgSql()) {
return "START TRANSACTION";
Expand Down Expand Up @@ -689,7 +689,7 @@ public function rollback()
}
return null;
}

/**
* Escapes a raw SQL query string to be safely used in an SQL statement,
* including handling of single quotes, backslashes, and line breaks,
Expand All @@ -714,7 +714,7 @@ public function escapeSQL($query) // NOSONAR
// Escape carriage return and newline for all
$query = str_replace(["\r", "\n"], ["\\r", "\\n"], $query);

if (stripos($this->databaseType, PicoDatabaseType::DATABASE_TYPE_MYSQL) !== false
if (stripos($this->databaseType, PicoDatabaseType::DATABASE_TYPE_MYSQL) !== false
|| stripos($this->databaseType, PicoDatabaseType::DATABASE_TYPE_MARIADB) !== false) {
// MySQL/MariaDB: escape both backslash and single quote
return str_replace(
Expand Down Expand Up @@ -751,19 +751,19 @@ public function escapeSQL($query) // NOSONAR
);
}


/**
* Escape a value for SQL queries.
*
* This method safely escapes different types of values (null, strings, booleans,
* numeric values, arrays, and objects) to ensure that they can be safely used in
* SQL queries. It prevents SQL injection by escaping potentially dangerous
* characters in string values and converts arrays or objects to their JSON
* This method safely escapes different types of values (null, strings, booleans,
* numeric values, arrays, and objects) to ensure that they can be safely used in
* SQL queries. It prevents SQL injection by escaping potentially dangerous
* characters in string values and converts arrays or objects to their JSON
* representation.
*
* @param mixed $value The value to be escaped. Can be null, string, boolean,
* @param mixed $value The value to be escaped. Can be null, string, boolean,
* numeric, array, or object.
* @return string The escaped value. This will be a string representation
* @return string The escaped value. This will be a string representation
* of the value, properly formatted for SQL usage.
*/
public function escapeValue($value)
Expand Down Expand Up @@ -805,7 +805,7 @@ public function escapedJSONValues($values)
{
return $this->escapeValue(json_encode($values));
}

/**
* Convert a value to its boolean representation for SQL.
*
Expand Down Expand Up @@ -1005,16 +1005,16 @@ public function addQueryParameters($query)

/**
* Adds pagination and sorting clauses to a native query string.
*
*
* This function appends the appropriate `ORDER BY` and `LIMIT $limit OFFSET $offset` or `LIMIT $offset, $limit`
* clauses to the provided SQL query string based on the given pagination and sorting parameters.
* It supports various database management systems (DBMS) and adjusts the query syntax
* It supports various database management systems (DBMS) and adjusts the query syntax
* accordingly (e.g., for PostgreSQL, SQLite, MySQL, MariaDB, etc.).
*
* @param string $queryString The original SQL query string to which pagination and sorting will be added.
* @param PicoPageable|null $pageable The pagination parameters, or `null` if pagination is not required.
* @param PicoSortable|null $sortable The sorting parameters, or `null` if sorting is not required.
*
*
* @return string The modified SQL query string with added pagination and sorting clauses.
*/
public function addPaginationAndSorting($queryString, $pageable, $sortable)
Expand All @@ -1031,8 +1031,8 @@ public function addPaginationAndSorting($queryString, $pageable, $sortable)
foreach($sortable->getSortable() as $sort)
{
$columnName = $sort->getSortBy();
$sortType = $sort->getSortType();
$sorts[] = $columnName . " " . $sortType;
$sortType = $sort->getSortType();
$sorts[] = $columnName . " " . $sortType;
}
if(!empty($sorts))
{
Expand Down Expand Up @@ -1060,10 +1060,10 @@ public function addPaginationAndSorting($queryString, $pageable, $sortable)
$queryString .= "\r\nOFFSET $offset ROWS FETCH NEXT $limit ROWS ONLY";
}
}

return $queryString;
}

/**
* Converts the current object to a string representation.
*
Expand Down
Loading