Skip to content

Commit

Permalink
Merge branch 'feature/2.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamshory committed Dec 9, 2024
2 parents 2f4bab7 + db8e75e commit f4fac53
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 2 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,40 @@ try {
}
```

# Conclusion


MagicObject is designed to offer ease and speed in creating and managing database entities. Here are several reasons why the methods used by MagicObject can be considered intuitive:

1. **Declarative and Annotation-Based**:

- By using annotations, MagicObject allows developers to declare entity properties and metadata directly within the code. This makes it easier to understand the structure and relationships of the entities.

2. **Easy Integration with Configuration**:

- MagicObject can be easily integrated with configuration systems like ConfigApp, making database and development environment setup more straightforward and organized.

3. **Automation**:

- MagicObject automatically handles many routine tasks, such as CRUD (Create, Read, Update, Delete) operations and table relationships. Developers don’t need to write manual SQL code, reducing the potential for errors.

4. **Object-Oriented Approach**:

- MagicObject uses an object-oriented approach, allowing developers to work with entities as PHP objects, utilizing methods and properties directly on the entities.

5. **Support for Various Data Formats**:

- MagicObject can accept data in various formats, including stdClass objects, associative arrays, and form inputs from HTML. This provides flexibility in handling data from different sources.

6. **Easy Relationship Management**:

- By defining relationships between entities, such as `ManyToOne` and `OneToMany`, MagicObject makes it easy to manage complex relationships without needing to write explicit join SQL.

7. **Automatic Conversion Capabilities**:

- MagicObject has the capability to automatically convert objects to JSON, which is extremely useful for APIs and modern web applications.


# Tutorial

A tutorial is available here: https://github.com/Planetbiru/MagicObject/blob/main/tutorial.md
Expand Down
2 changes: 2 additions & 0 deletions src/Util/AttrUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private function __construct()
*
* Example:
* ```php
* <?php
* echo AttrUtil::selected($currentValue, $optionValue);
* // Outputs: selected="selected" if they match
* ```
Expand All @@ -55,6 +56,7 @@ public static function selected($param1, $param2)
*
* Example:
* ```php
* <?php
* echo AttrUtil::checked($currentValue, $inputValue);
* // Outputs: checked="checked" if they match
* ```
Expand Down
2 changes: 2 additions & 0 deletions src/Util/Dms.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Dms
*
* Example:
* ```php
* <?php
* $dms = new Dms();
* $dms->dmsToDd(34, 15, 30);
* echo $dms->printDd(); // Outputs: 34.258333
Expand Down Expand Up @@ -82,6 +83,7 @@ public function dmsToDd($deg, $min, $sec)
*
* Example:
* ```php
* <?php
* $dms = new Dms();
* $dms->ddToDms(34.258333);
* echo $dms->printDms(); // Outputs: 34:15:30
Expand Down
2 changes: 2 additions & 0 deletions src/Util/PicoArrayUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private function __construct()
*
* Example:
* ```php
* <?php
* $data = ['first_name' => 'John', 'last_name' => 'Doe'];
* $camelized = PicoArrayUtil::camelize($data);
* // $camelized is ['firstName' => 'John', 'lastName' => 'Doe']
Expand Down Expand Up @@ -58,6 +59,7 @@ public static function camelize($input)
*
* Example:
* ```php
* <?php
* $data = ['firstName' => 'John', 'lastName' => 'Doe'];
* $snakeized = PicoArrayUtil::snakeize($data);
* // $snakeized is ['first_name' => 'John', 'last_name' => 'Doe']
Expand Down
7 changes: 7 additions & 0 deletions src/Util/PicoGenericObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct($data = null)
*
* Example:
* ```php
* <?php
* $obj = new PicoGenericObject();
* $obj->loadData(['first_name' => 'John', 'last_name' => 'Doe']);
* echo $obj->get('firstName'); // Outputs: John
Expand Down Expand Up @@ -70,6 +71,7 @@ public function loadData($data)
*
* Example:
* ```php
* <?php
* $obj = new PicoGenericObject();
* $obj->set('first_name', 'John');
* echo $obj->get('firstName'); // Outputs: John
Expand All @@ -93,6 +95,7 @@ public function set($propertyName, $propertyValue)
*
* Example:
* ```php
* <?php
* $value = $obj->get('firstName'); // Retrieves the value of 'firstName'
* ```
*
Expand All @@ -112,6 +115,7 @@ public function get($propertyName)
*
* Example:
* ```php
* <?php
* $obj->firstName = 'John'; // Calls __set() internally
* ```
*
Expand All @@ -131,6 +135,7 @@ public function __set($name, $value)
*
* Example:
* ```php
* <?php
* $value = $obj->firstName; // Calls __get() internally
* ```
*
Expand All @@ -150,6 +155,7 @@ public function __get($name)
*
* Example:
* ```php
* <?php
* if ($obj->issetFirstName()) {
* // Do something
* }
Expand All @@ -168,6 +174,7 @@ public function __isset($name)
*
* Example:
* ```php
* <?php
* $obj->unsetFirstName(); // Removes the property 'firstName'
* ```
*
Expand Down
1 change: 1 addition & 0 deletions src/Util/PicoStringUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* Example usage:
* ```
* <?php
* $camelCase = PicoStringUtil::camelize('example_string');
* $kebabCase = PicoStringUtil::kebapize('exampleString');
* $isNotEmpty = PicoStringUtil::isNotNullAndNotEmpty('Some Value');
Expand Down
6 changes: 4 additions & 2 deletions src/Util/PicoYamlUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ private function __construct()
* This method recursively calculates how deep the given array is.
*
* Example:
* ```
* ```php
* <?php
* $array = [1, [2, [3, 4]]];
* $depth = PicoYamlUtil::arrayDepth($array); // Returns 3
* ```
Expand Down Expand Up @@ -72,7 +73,8 @@ public static function arrayDepth($array) {
* serialization.
*
* Example:
* ```
* ```php
* <?php
* $data = ['name' => 'John', 'age' => 30];
* $yaml = PicoYamlUtil::dump($data, null, 4, 0);
* ```
Expand Down

0 comments on commit f4fac53

Please sign in to comment.