https://github.com/irfan-dahir/php-mom
PHP Model Object Management
https://github.com/irfan-dahir/php-mom
generator helper json management model object php php-library php-model php-object psr2 psr4 schema
Last synced: 13 days ago
JSON representation
PHP Model Object Management
- Host: GitHub
- URL: https://github.com/irfan-dahir/php-mom
- Owner: irfan-dahir
- License: mit
- Created: 2019-02-08T17:58:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-12T07:07:15.000Z (almost 7 years ago)
- Last Synced: 2025-06-10T00:11:14.566Z (8 months ago)
- Topics: generator, helper, json, management, model, object, php, php-library, php-model, php-object, psr2, psr4, schema
- Language: PHP
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Model Object Management
[](https://packagist.org/packages/irfan-dahir/php-mom) [](http://isitmaintained.com/project/irfan-dahir/php-mom "Average time to resolve an issue") [](http://isitmaintained.com/project/irfan-dahir/php-mom "Average time to resolve an issue") []() [](https://img.shields.io/github/license/irfan-dahir/php-mom.svg?style=flat)
PHP-MOM is a stupid simple PHP Model object generator and helper.
## Installation
```composer require irfan-dahir/php-mom --no-dev```
## Example
```php
require_once __DIR__ . '/vendor/autoload.php';
// Create the object
$schema = \MOM\Schema::create();
// Create an object from JSON
$schema = \MOM\Schema::fromJSON("[]");
// Adding Properties
$schema->add('prop1'); // will assign value NULL
$schema->add('prop1', 5); // will assign value `5`
// PHP's default syntax
$schema->prop1 = 5;
// Bulk adding
$schema->add([
'prop2',
'prop3' => 5,
'prop4' => 3.142,
'prop5' => 'foo',
'prop_unedit' => true
]);
// Works with pre-made models/objects too
// Only copies public properties for now
// Anonymous properties do NOT get copied (there might be a workaround)
$schema->add(new class {
public $foo = "bar";
public $baz = false;
});
// Removing properties
$schema->remove('prop2');
// Bulk removal
$schema->remove([
'prop2','prop3'
]);
// PHP's default syntax
unset($schema->prop2, ...);
// Updating Properties; aka renaming
$schema->update('prop1', 'prop1_edit'); // renames `prop1` to `prop1_edit` (copies the value as well)
// Bulk update
$schema->update([
'prop5' => 'prop5_edit',
'prop_unedit' => 'prop_edited'
]);
// Helper Methods
$schema->toArray(); // Model to Array
$schema->toJSON(); // Model to JSON
```
### Running tests
1. `composer require irfan-dahir/php-mom --dev`
2. `composer vendor/bin/phpunit tests`
### Dependencies
- PHP 7.1+
### Issues
Please create an issue for any bugs/security risks/etc