Skip to content

Releases: Planetbiru/MagicObject

3.21.2

30 Dec 03:49
03a20a9

Choose a tag to compare

What's Changed

Full Changelog: 3.21.1...3.21.2

3.21.1

29 Dec 00:05
6140bf1

Choose a tag to compare

What's Changed

Full Changelog: 3.21.0...3.21.1

3.21.0

10 Dec 01:07
fa4510a

Choose a tag to compare

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

09 Dec 15:33
01679fc

Choose a tag to compare

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

  1. Complex Numbers
  2. Matrix Operations
  3. Geometry Utilities

Migration

These classes are not discontinued, but have been moved into a new dedicated repository:

👉 Planetbiru/MagicMath

Developers who rely on these math utilities should install the new package separately:

composer require planetbiru/magic-math

New 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 when PDO::getAttribute(PDO::ATTR_CONNECTION_STATUS)
    is not supported by the active PDO driver (e.g., SQLite).

  • Graceful Fallback
    Introduced an optional $databaseCredentials parameter, 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 populated SecretObject with connection details.
    If extraction fails, either the provided $databaseCredentials is returned,
    or a new empty SecretObject is 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

Full Changelog: 3.19.0...3.20.0

3.19.0

19 Sep 11:55
bec60f8

Choose a tag to compare

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 null instead 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 curl extension is available.
  • Falls back to PHP streams (file_get_contents + stream context) when curl is 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 CurlException on 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 curl extension 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

Full Changelog: 3.18.0...3.19.0

3.18.0

16 Sep 17:23
f47cf31

Choose a tag to compare

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

Full Changelog: 3.17.0...3.18.0

3.17.1

23 Aug 12:54

Choose a tag to compare

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

  • PostgreSQL & SQLite Export: Removed unnecessary double quotes (`"… by @kamshory in #141

Full Changelog: 3.17.0...3.17.1

3.17.0

16 Aug 00:35
7ab0bf6

Choose a tag to compare

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.yml or 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: 10

Impact
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

  • Enhancement: Configurable Database Connection Timeout by @kamshory in #140

Full Changelog: 3.16.8...3.17.0

3.16.8

09 Aug 15:43
99a13f7

Choose a tag to compare

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:

  • TRUE1
  • FALSE0

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 NULL when 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

Full Changelog: 3.16.7...3.16.8

3.16.7

31 Jul 14:05
938adf4

Choose a tag to compare

What's Changed

Full Changelog: 3.16.4...3.16.7