3ev / repoman

此包已被废弃,不再维护。未建议替代包。

轻量级仓库模式实现

v1.0.0 2015-05-14 15:49 UTC

This package is not auto-updated.

Last update: 2024-02-17 14:06:28 UTC


README

#Repoman

轻量级仓库模式接口和实现。

参见这篇文章了解Laravel中的仓库模式。

##安装

$ composer require "3ev/repoman:~1.0"

##用法

Repoman提供了一个仓库的基本接口。您可以自行实现,或利用提供的实现之一。您可以扩展接口以适应您自己的特定仓库类。

有关API和错误的详细信息,请参阅源文件中的phpdoc。

###基本实现

<?php
namespace Entity\Repositories;

use Tev\Repoman\Repositories\RepositoryInterface;

class Repository implements RepositoryInterface
{
    public function getAll()
    {
        // ...
    }

    public function chunk($size, $callback)
    {
        // ...
    }

    public function find($id)
    {
        // ...
    }

    public function create(array $data)
    {
        // ...
    }

    public function update($id, array $data)
    {
        // ...
    }

    public function delete($id)
    {
        // ...
    }
}

###Eloquent

<?php
namespace Entity\Repositories\Eloquent;

use Entity\Models\ExampleModel;
use Tev\Repoman\Repositories\Eloquent\Repository;

class ExampleModelRepository extends Repository
{
    public function __construct()
    {
        $this->model = new ExampleModel;
    }
}

##许可证

MIT