Code Monkey home page Code Monkey logo

php-mom's Introduction

PHP Model Object Management

Version Average time to resolve an issue Average time to resolve an issue stable MIT License

PHP-MOM is a stupid simple PHP Model object generator and helper.

Installation

composer require irfan-dahir/php-mom --no-dev

Example

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

php-mom's People

Contributors

irfan-dahir avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.