PHPackages                             planetbiru/magic-object - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. planetbiru/magic-object

ActiveLibrary

planetbiru/magic-object
=======================

MagicObject

3.22.1(2mo ago)11.8k↓100%[1 issues](https://github.com/Planetbiru/MagicObject/issues)GPL-3.0-onlyPHPPHP &gt;=5.4CI passing

Since Oct 13Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Planetbiru/MagicObject)[ Packagist](https://packagist.org/packages/planetbiru/magic-object)[ RSS](/packages/planetbiru-magic-object/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)DependenciesVersions (128)Used By (0)

MagicObject
===========

[](#magicobject)

Introduction
============

[](#introduction)

MagicObject is a powerful library for developing applications in PHP with ease. It enables the dynamic creation of classes for various intended uses. Below are some of its key features:

Features
========

[](#features)

1. **Dynamic Object Creation**: Easily create objects at runtime.
2. **Setters and Getters**: Simplify property management with automatic methods.
3. **Multi-Level Objects**: Support for nested objects.
4. **ORM**: Object-Relational Mapping support for easier interactions with databases.
5. **Filtering and Pagination**: Built-in methods for managing data display.
6. **Native Query**: Defining native queries for a function will increase flexibility and resource efficiency in accessing the database.
7. **Multiple Database Connection**: MagicObject supports the configuration of multiple database connections, allowing applications to interact with different databases simultaneously.
8. **Database Dumping**: Export database contents efficiently.
9. **Serialization/Deserialization**: Handle JSON and YAML formats seamlessly.
10. **Data Importing**: Import data even if source and destination schemas differ.
11. **File Reading**: Read INI, YAML, and JSON configuration files.
12. **Environment Variable Access**: Easily fetch environment variable values.
13. **Configuration Encryption**: Secure application settings.
14. **HTTP Data Handling**: Create objects from global request variables (POST, GET, etc.).
15. **Session Management**: Integrate with PHP sessions.
16. **Object Labeling**: Enhance object identification.
17. **Multi-Language Support**: Facilitate localization.
18. **File Uploads**: Handle file uploads efficiently.
19. **Annotations**: Add metadata to objects for better structure.
20. **Debugging**: Tools to debug and inspect objects.

This library provides a versatile toolkit for building robust PHP applications!

Installation
============

[](#installation)

Installing MagicObject
----------------------

[](#installing-magicobject)

To install MagicObject, run:

```
composer require planetbiru/magic-object

```

If Composer is not installed, use:

```
php composer.phar require planetbiru/magic-object

```

To remove MagicObject:

```
composer remove planetbiru/magic-object

```

Or if Composer is not installed:

```
php composer.phar remove planetbiru/magic-object

```

Installing Composer
-------------------

[](#installing-composer)

To install Composer on your system or download the latest `composer.phar`, visit

To see available versions of MagicObject, visit

Installing MagicObject on PHP 5
-------------------------------

[](#installing-magicobject-on-php-5)

This guide walks you through the steps to install **MagicObject** using Composer on a PHP project, particularly if you're working with a PHP version that might not meet the platform requirements for the package.

### Prerequisites:

[](#prerequisites)

- PHP installed on your system (PHP 5.x or higher)
- Composer installed globally or locally in your project

---

### Steps to Install MagicObject

[](#steps-to-install-magicobject)

#### 1. **Navigate to Your Project Directory**

[](#1-navigate-to-your-project-directory)

Open your terminal and navigate to your PHP project folder:

```
cd /path/to/your/project
```

Make sure you're in the correct directory where your PHP project resides.

#### 2. **Install MagicObject Using Composer**

[](#2-install-magicobject-using-composer)

Run the following command to require **MagicObject** in your project:

```
composer require planetbiru/magic-object
```

This command will:

- Add `planetbiru/magic-object` as a dependency to your `composer.json` file.
- Download and install the MagicObject package into your `vendor/` directory.

#### 3. **Update Dependencies with Ignored Platform Requirements**

[](#3-update-dependencies-with-ignored-platform-requirements)

If you're using a PHP version or configuration that doesn't meet the platform requirements specified by MagicObject, you can use the `--ignore-platform-reqs` flag to bypass those checks during the installation process:

```
composer update --ignore-platform-reqs
```

This command will:

- Update all dependencies listed in `composer.json`.
- Ignore platform-specific checks like PHP version or missing extensions, allowing you to proceed with the installation.

#### 4. **Autoload Composer in Your PHP Script**

[](#4-autoload-composer-in-your-php-script)

After the installation completes, include Composer's autoloader in your PHP scripts to make MagicObject available for use:

```
require 'vendor/autoload.php';
```

This ensures that all your dependencies, including MagicObject, are loaded automatically.

#### 5. **Verify Installation**

[](#5-verify-installation)

Check that MagicObject is installed by verifying its presence in the `vendor` directory:

```
ls vendor/planetbiru/magic-object
```

You should see the MagicObject files in the `vendor/planetbiru/magic-object` folder.

#### 6. **Start Using MagicObject**

[](#6-start-using-magicobject)

You can now start using MagicObject in your PHP application. Example usage:

```
use MagicObject\MagicObject;

$object = new MagicObject();
```

Replace this with your specific use cases as needed.

Advantages
==========

[](#advantages)

MagicObject is designed for ease of use and can even be used with a code generator. An example of a code generator that successfully creates MagicObject code using only parameters is **MagicAppBuilder**. MagicObject offers many flexible ways to write code, allowing users to choose the approach that best suits their needs.

In addition to prioritizing ease of use, MagicObject is also optimized for efficiency in terms of both time and resource usage, enabling applications to run smoothly even on servers with minimal specifications. This reduces costs in both development and operational phases.

Application Scaling
===================

[](#application-scaling)

For large applications, MagicObject supports database and storage scaling. You can distribute user access across multiple servers and use Redis for session storage. MagicObject integrates with Redis for cloud-based session storage, which can be secured using a password.

[![](https://github.com/Planetbiru/MagicObject/raw/main/scale-up.svg)](https://github.com/Planetbiru/MagicObject/blob/main/scale-up.svg)

Example
=======

[](#example)

Simple Object
-------------

[](#simple-object)

Yaml
----

[](#yaml)

**Yaml File**

```
result_per_page: 20
song_base_url: ${SONG_BASE_URL}
app_name: Music Production Manager
user_image:
  width: 512
  height: 512
album_image:
  width: 512
  height: 512
song_image:
  width: 512
  height: 512
database:
  time_zone_system: Asia/Jakarta
  default_charset: utf8
  driver: ${APP_DATABASE_TYPE}
  host: ${APP_DATABASE_SERVER}
  port: ${APP_DATABASE_PORT}
  username: ${APP_DATABASE_USER}
  password: ${APP_DATABASE_PASSWORD}
  database_name: ${APP_DATABASE_NAME}
  database_schema: public
  time_zone: ${APP_DATABASE_TIME_ZONE}
  salt: ${APP_DATABASE_SALT}
```

**Configuration Object**

Create class `ConfigApp` by extends `MagicObject`

```
