monooso/base-model

This package is abandoned and no longer maintained. No replacement package was suggested.

The world's simplest base model, with support for custom getters and setters.

0.1.0 2016-09-21 15:19 UTC

This package is auto-updated.

Last update: 2021-11-03 19:32:27 UTC


README

The world's simplest base model, with support for custom getters and setters.

Installation

Install Base Model using Composer, as follows:

$ composer require monooso/base-model

Usage

In the following example model, the simple property will be set and retrieved directly, and the fancy property will be set and retrieved using the custom getter and setter methods.

<?php namespace MyProject

use InvalidArgumentException;
use Monooso\BaseModel\Model;

class Example extends Model
{
    protected $fancy;
    protected $simple;

    /**
     * Prepends a string to the 'fancy' property, before returning it.
     *
     * @return string
     */
    public function getFancy()
    {
        return 'fancy-' . $this->fancy;
    }

    /**
     * Validates that the 'fancy' property is a string.
     *
     * @param mixed $val
     *
     * @throws InvalidArgumentException
     */
    public function setFancy($val)
    {
        if (!is_string($val)) {
            throw new InvalidArgumentException('Value must be a string');
        }

        $this->fancy = $val;
    }
}