1. Go to this page and download the library: Download irfan-dahir/php-mom library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
irfan-dahir / php-mom example snippets
// 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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.