tsmsogn/attribute

0.0.1 2019-02-18 06:44 UTC

This package is auto-updated.

Last update: 2024-04-19 13:19:00 UTC


README

Requirements

  • PHP 5.4 or later

Installation

composer require tsmsogn/attribute

Usage

Make a class attribute:

Use the Attributable and implement the AttributeInterface on your class:

<?php

namespace Do\What\You\Like;


use Attribute\Attributable;
use Attribute\AttributeInterface;

class User implements AttributeInterface
{
    use Attributable;

    public $username;

    public $website;

    public function __construct($options = array())
    {
        foreach ($options as $key => $value) {
            $this->$key = $value;
        }

        $this->attributeMissing(); // Check if wheter the required attributes are missing or not.
    }

    public function getRequiredAttributes()
    {
        return array('username');
    }

    public function getOptionalAttributes()
    {
        return array('website');
    }
}

See more detail at tests.