Releases: Planetbiru/MagicObject
3.21.2
3.21.1
3.21.0
MagicObject Version 3.21.0
What's New
Enhancement: Smarter Update Logic
MagicObject now automatically prevents columns used in a WHERE clause from being included in the SET part of an UPDATE statement. This avoids redundant updates (e.g., UPDATE users SET user_id = ?, name = ? WHERE user_id = ?) and improves query efficiency.
Enhancement: retrieve() Method on SecretObject
The powerful retrieve() method, which allows for easy access to nested properties, is now also available on SecretObject. This simplifies reading nested configurations from secure objects.
Example Usage:
$secretConfig->retrieve('database', 'credentials', 'username');What's Changed
- Skip column from being updated when it present in where clause by @kamshory in #172
- Update PicoDatabasePersistence.php by @kamshory in #173
- Feature/version 3.22.0 by @kamshory in #174
- Bug fix SercerObject::retrieve, add SercerObject::hasValue by @kamshory in #175
Full Changelog: 3.20.0...3.21.0
3.20.0
MagicObject Version 3.20.0
Change: Removal of Math-Related Classes
In this release, several math-related classes have been removed from MagicObject to keep the core library lightweight and focused.
Removed Modules
- Complex Numbers
- Matrix Operations
- Geometry Utilities
Migration
These classes are not discontinued, but have been moved into a new dedicated repository:
Developers who rely on these math utilities should install the new package separately:
composer require planetbiru/magic-mathNew Feature: PDO Connection Verification Method
A new method isPdoConnected() has been introduced to allow developers to verify not only the TCP-level connection, but also the ability of PHP to execute SQL statements on the database.
New Method: PicoPageData::getResultAsArray()
The new getResultAsArray() method allows users to return a list of data directly as an array, which can be immediately sent as JSON. This eliminates the need to first collect the data as an array of objects and then manually construct an array.
Bug Fix: Handle Exception in method getDatabaseCredentialsFromPdo($pdo, $driver, $dbType)
If an error occurs when executing:
$dsn = $pdo->getAttribute(PDO::ATTR_CONNECTION_STATUS);getDatabaseCredentialsFromPdo($pdo, $driver, $dbType) will return an empty instance of SecretObject.
Enhancement: Improved getDatabaseCredentialsFromPdo Handling
The method getDatabaseCredentialsFromPdo has been updated to better handle
PDO drivers that do not support certain attributes (e.g., PDO::ATTR_CONNECTION_STATUS).
Key Improvements
-
Warning Suppression
Suppresses warnings whenPDO::getAttribute(PDO::ATTR_CONNECTION_STATUS)
is not supported by the active PDO driver (e.g., SQLite). -
Graceful Fallback
Introduced an optional$databaseCredentialsparameter, which is used as a
fallback source for host, port, and database name if they cannot be extracted
from the PDO connection. -
Driver-Agnostic Behavior
Ensures compatibility across multiple database drivers (MySQL, PostgreSQL, SQLite, etc.)
without causing runtime warnings. -
Consistent Output
Always returns a populatedSecretObjectwith connection details.
If extraction fails, either the provided$databaseCredentialsis returned,
or a new emptySecretObjectis created.
Why It Matters?
- Prevents noisy PHP warnings in environments where PDO drivers expose limited attributes.
- Provides a more reliable and consistent mechanism for retrieving database credentials.
- Ensures backward compatibility while making the method more robust in multi-database environments.
What's Changed
- Move Mathematic Classes by @kamshory in #162
- Feature/version 3.20.0 by @kamshory in #163
- Handle exception by @kamshory in #164
- Feature/version 3.20.0 by @kamshory in #165
- Update CHANGELOG.md by @kamshory in #166
- Feature/version 3.20.0 by @kamshory in #167
- Update CHANGELOG.md by @kamshory in #168
- Bug fixing boolean value PHP 8 by @kamshory in #169
- Update CHANGELOG.md by @kamshory in #170
- Add method PicoPageData::getResultAsArray() by @kamshory in #171
Full Changelog: 3.19.0...3.20.0
3.19.0
MagicObject Version 3.19.0
New Feature: XmlToJsonParser Utility Class
A new utility class XmlToJsonParser has been introduced to parse XML documents into PHP arrays/JSON.
It supports:
- Custom flattener element: users can configure which XML elements should be treated as array items (e.g.,
<entry>,<item>, etc.). - Consistent output: empty XML elements are automatically converted into
nullinstead of empty arrays. - Round-trip support: arrays can also be converted back into XML, with configurable wrapper element names.
This allows developers to manage application configuration using XML files, which are less error-prone compared to YAML, especially in environments where indentation issues are common.
Example Usage:
$parser = new XmlToJsonParser(['entry', 'item']);
$config = $parser->parse(file_get_contents('config.xml'));Enhancement: PicoCurlUtil — Alternative to curl
A new class PicoCurlUtil has been added under MagicObject\Util.
This class provides an interface for making HTTP requests with automatic fallback:
- Uses cURL if the PHP
curlextension is available. - Falls back to PHP streams (
file_get_contents+ stream context) whencurlis not available.
Features
- Supports GET and POST requests (with planned extensions for PUT, DELETE, etc.).
- Allows setting headers, request body, and SSL verification options.
- Provides access to response headers, body, and HTTP status code.
- Automatically throws
CurlExceptionon error, for consistent error handling.
Example Usage:
use MagicObject\Util\PicoCurlUtil;
$http = new PicoCurlUtil();
$response = $http->get("https://example.com/api/data");
if ($http->getHttpCode() === 200) {
echo $response;
}Why It Matters?
- Greater Flexibility: Developers can now use XML configuration files instead of YAML.
- Better Portability: Applications can run even in environments where the
curlextension is not installed. - Consistent API: Whether using cURL or streams, you always interact via
PicoCurlUtil.
Enhancement: PicoSession Redis Database Parameter
PicoSession now supports specifying a Redis database index via the session save path.
This allows developers to isolate sessions in different Redis databases (e.g., separating staging and production data) without requiring additional Redis instances.
The parameter can be set using query options like db, dbindex, or database in the Redis connection string.
Example:
tcp://localhost:6379?db=3
New Feature: SqliteSessionHandler
A new SqliteSessionHandler class has been introduced under MagicObject\Session.
This provides a persistent session storage mechanism using SQLite as the backend.
Features
-
Stores sessions in a SQLite database file instead of filesystem or memory.
-
Automatically creates the session table if it does not exist.
-
Implements the full session lifecycle:
- open — Initializes session.
- read — Reads serialized session data.
- write — Writes or updates session data.
- destroy — Removes a session by ID.
- gc — Garbage collects expired sessions.
-
Ensures safe storage even when multiple PHP processes are running.
Why It Matters?
- Portability: No dependency on Redis or Memcached — only requires SQLite.
- Lightweight: Suitable for shared hosting or small applications.
- Reliability: Prevents session loss when PHP restarts, unlike file-based sessions.
What's Changed
- Feature/version 3.19.0 by @kamshory in #149
- Feature/version 3.19.0 by @kamshory in #150
- New Feature:
SqliteSessionHandlerby @kamshory in #151 - Fix Redis auth by @kamshory in #152
- Remove debug log by @kamshory in #153
- Refactor PicoSession Constructor by @kamshory in #154
- Bug fix cookie lifetime by @kamshory in #155
- Rename column of sessions table by @kamshory in #156
- Bug fix session database creation by @kamshory in #157
- Bug fix session database by @kamshory in #158
- Update SqliteSessionHandler.php by @kamshory in #159
- Bug fix refreshCookie by @kamshory in #160
- Rename max_life_time to max_lifetime by @kamshory in #161
Full Changelog: 3.18.0...3.19.0
3.18.0
MagicObject Version 3.18.0
Enhancement: Database Migration
A new parameter has been added to Database Migration to provide greater flexibility.
Previously, all migration queries had to be dumped into a SQL file before execution.
With this update, developers can now choose to run queries directly on the target database, reducing steps and improving efficiency in deployment workflows.
This makes migrations faster, easier to automate, and less error-prone—especially useful for CI/CD pipelines.
Bug Fixes: Undefined Array Index in PicoPageData::applySubqueryResult()
Fixed an issue where an undefined array index error could occur when the provided data structure did not match the expected format.
This patch ensures more robust handling of unexpected input, improving the stability and reliability of query result processing.
What's Changed
- PostgreSQL & SQLite Export: Removed unnecessary double quotes (`"… by @kamshory in #141
- Fix AUTO_INCREMENT MySQL and MariaDB by @kamshory in #142
- Add parameter to callback function database migration by @kamshory in #143
- Feature/version 3.18.1 by @kamshory in #144
- Update README.md by @kamshory in #145
- Update README.md by @kamshory in #146
- Feature/version 3.18.0 by @kamshory in #147
- HTTP Request Fallback without cURL by @kamshory in #148
Full Changelog: 3.17.0...3.18.0
3.17.1
MagicObject Version 3.17.1
What’s Changed
- PostgreSQL & SQLite Export: Removed unnecessary double quotes (
") around table names when exporting database schema.
Details
Previously, exported DDL wrapped table names in quotes:
CREATE TABLE "useraccount" (...);Starting from v3.17.1, table names are written without quotes:
CREATE TABLE useraccount (...);Why This Change?
- Cleaner SQL Output: Makes exported schema easier to read.
- Improved Compatibility: Some tools and workflows expect unquoted identifiers in both PostgreSQL and SQLite.
Notes
- No naming strategy changes were introduced. Table names remain exactly the same; only the surrounding quotes are removed.
- If your schema relies on case-sensitive identifiers or reserved keywords, you may still need to add quotes manually.
What's Changed
Full Changelog: 3.17.0...3.17.1
3.17.0
MagicObject Version 3.17.0
Enhancement: Configurable Database Connection Timeout
Added support for connection timeout configuration, retrieved directly from the database connection settings.
Details
- The timeout value is defined in the database configuration (e.g.,
core.ymlor application-specific config). - Applied when establishing a PDO connection to all supported RDBMS drivers (MySQL, PostgreSQL, SQLite, SQL Server).
- The timeout ensures that connection attempts fail gracefully if the database server does not respond within the specified time.
Example (core.yml):
database:
driver: mysql
host: localhost
port: 3306
username: app_user
password: secret
database_name: appdb
connection_timeout: 10Impact
This feature gives developers better control over database connectivity, especially in environments with slow or unreliable networks, by preventing applications from hanging indefinitely during connection attempts.
What's Changed
Full Changelog: 3.16.8...3.17.0
3.16.8
MagicObject Version 3.16.8
Bug Fix: Data Conversion on Export to SQL Server
Fixed an issue with BIT value conversion when exporting data to SQL Server.
Previously, TRUE and FALSE values were exported as literal text strings.
After this fix, they are correctly exported as numeric values:
TRUE→1FALSE→0
This ensures proper compatibility with SQL Server’s BIT data type and avoids errors when importing exported data.
Bug Fix: Default Value Handling in ALTER TABLE
Fixed an issue where DEFAULT VALUE clauses were not correctly generated when altering a table after entity changes.
The fix covers both NULL and non-null default values:
- Correctly applies
DEFAULT NULLwhen specified. - Properly formats non-null default values (e.g.,
DEFAULT 0,DEFAULT 'ACTIVE', etc.) according to the column type and target database. - Ensures compatibility with all supported database types (MySQL, PostgreSQL, SQLite, SQL Server).
Example
Before:
ALTER TABLE users MODIFY status VARCHAR(20);(Default value lost after column change)
After:
ALTER TABLE users MODIFY status VARCHAR(20) DEFAULT 'ACTIVE';or
ALTER TABLE users MODIFY last_login TIMESTAMP DEFAULT NULL;This prevents migration errors and ensures schema changes retain and apply consistent default values across databases.
What's Changed
- Bug fix data conversion to SQL Server by @kamshory in #137
- Update CHANGELOG.md by @kamshory in #138
- Bug Fix: Default Value Handling in ALTER TABLE by @kamshory in #139
Full Changelog: 3.16.7...3.16.8