2017 © Pedro Peláez
 

library php-data-model

PHP Library that provides generic and scalable Data Models (abstract model class) for any type of data handling.

image

10quality/php-data-model

PHP Library that provides generic and scalable Data Models (abstract model class) for any type of data handling.

  • Monday, June 18, 2018
  • by amostajo
  • Repository
  • 2 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Data Model (PHP)

Latest Stable Version Total Downloads License, (*1)

PHP Library that provides generic and scalable Data Models (abstract model class) for any type of data handling., (*2)

This perfect and suitable for when developing MVC frameworks, Api clients, wrappets and/or any type of project that requires data handling., (*3)

Models inspired by Laravel and our very own Wordpress MVC., (*4)

Requires

  • PHP >= 5.4

Usage

When defining your models, extend them from the Model abstract class., (*5)

In the following example, a Product data model will be created and will extend from the Model abstract class., (*6)


use TenQuality\Data\Model; class Product extends Model { }

Then instantiate your models like this:, (*7)

$product = new Product;

Adding data

Very easy, simply add the data like an object property., (*8)

// Set data
$product->price = 19.99;
$product->name = 'My product';
$product->brandName = '10 Quality';

// Get data
echo $product->price; // Will echo 19.99
echo $product->name; // Will echo My product
echo $product->brandName; // Will echo 10 Quality

Creating aliases

Aliases are model properties that are set or get by class methods. This are defined in the model., (*9)

In the following example, an alias will be created in the model to display prices with currenty., (*10)


use TenQuality\Data\Model; class Product extends Model { /** * Method for alias property `displayPrice`. * Return `price` property concatenated with the $ (dollar) symbol */ protected function getDisplayPriceAlias() { return '$'.$this->price; } /** * Method for alias property `displayPrice`. * Sets a the price value if the alias is used. */ protected function setDisplayPriceAlias($value) { $this->price = floatval(str_replace('$', '', $value)); } }

Then use it like this:, (*11)

$product->price = 19.99;

// Get alias property
echo $product->displayPrice; // Will echo $19.99

// Set alias property
$product->displayPrice = 29.99;

// Echo property
echo $product->price; // Will echo 29.99
echo $product->displayPrice; // Will echo $29.99

Casting

Before using any casting options, the model needs to define which properties are visible and which are hidden. This is done by listing the visible ones like this:, (*12)


use TenQuality\Data\Model; class Product extends Model { protected $properties = [ 'name', 'price', 'displayPrice', ]; }

Notice that both properties and aliases can be listed. Following the samples above, property brandName will stay hidden from casting., (*13)

Cast the model like this:, (*14)

var_dump($model->toArray()); // To array
var_dump($model->__toArray()); // To array

echo (string)$model; // To json encoded string

Guidelines

PSR-2 coding standards., (*15)

MIT License - (C) 2018 10 Quality., (*16)

The Versions

18/06 2018

v1.0.x-dev

1.0.9999999.9999999-dev https://github.com/10quality/php-data-model

PHP Library that provides generic and scalable Data Models (abstract model class) for any type of data handling.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Cami M

models data

18/06 2018

v1.0.1

1.0.1.0 https://github.com/10quality/php-data-model

PHP Library that provides generic and scalable Data Models (abstract model class) for any type of data handling.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Cami M

models data

30/05 2018

dev-master

9999999-dev https://github.com/10quality/php-data-model

PHP Library that provides generic and scalable Data Models (abstract model class) for any type of data handling.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Cami M

models data

30/05 2018

v1.0.0

1.0.0.0 https://github.com/10quality/php-data-model

PHP Library that provides generic and scalable Data Models (abstract model class) for any type of data handling.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Cami M

models data