tsmsogn/attribute

0.0.1 2019-02-18 06:44 UTC

This package is auto-updated.

Last update: 2024-09-19 14:10:41 UTC


README

需求

  • PHP 5.4或更高版本

安装

composer require tsmsogn/attribute

使用

创建类属性

在你的类上使用Attributable并实现AttributeInterface

<?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');
    }
}

更多详细信息请查看tests