定制 deefour/producer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

deefour/producer

Composer 安装命令:

composer require deefour/producer

包简介

Simple rule-based class resolution

README 文档

README

Build Status Packagist Version Code Climate License

A small class factory.

Getting Started

Run the following to add Producer to your project's composer.json. See Packagist for specific versions.

composer require deefour/producer

>=PHP5.5.0 is required.

Overview

A Producer is a class that resolves the FQCN of related Producible classes. The Factory accepts a Producer and "type", and can instantiate a concrete Producible class based on the resolved FQCN returned.

Producers and Producibles

The production factory only accepts classes that implement Deefour\Producer\Contracts\Producer. An exception will be thrown if the resolved class does not implement Deefour\Producer\Contracts\Producible.

Given the following classes

use Deefour\Producer\Contracts\Producer;
use Deefour\Producer\Contracts\Producible;

class Podcast implements Producer
{
    // ...
}

class PodcastPolicy implements Producible
{
    // ...
}

class PodcastScope implements Producible
{
    // ...
}

the production factory can produce an instance of each producible above when given a podcast and "type".

use Deefour\Producer\Factory;

$podcast = new Podcast();
$factory = new Factory();

$factory->resolve($podcast, 'policy'); //=> 'PodcastPolicy`
$factory->resolve($podcast, 'scope'); //=> 'PodcastScope`

$factory->make($podcast, 'policy'); //=> instance of PodcastPolicy

Resolving Producibles

The default producible resolver on the produciton factory looks like this

get_class($producer) . ucfirst($type)

This can be customized by implementing a resolve() method on the producer passed into the factory.

use Deefour\Producer\Contracts\Producer;

class Podcast implements Producer
{
    public function resolve($type)
    {
        // return FQCN string here
    }
}

This deefour/producer package also comes with a more opinionated resolver at Deefour\Producer\ResolvesProducibles.

namespace App;

use Deefour\Producer\ResolvesProducibles;
use Deefour\Producer\Contracts\Producer;

class Podcast implements Producer
{
    use ResolvesProducibles;
}

this will pluralize the "type" passed in and append that to the namespace of the producer doing the class resolution.

use App\Podcast;
use Deefour\Producer\Factory;

$podcast = new Podcast();
$factory = new Factory();

$factory->resolve($podcast, 'policy'); //=> 'App\Policies\PodcastPolicy`

Making Producibles

The default producible instantiator on the production factory looks like this

new $producible($producer);

This can be customized by implementing a make() method on the producer passed into the factory.

use Deefour\Producer\Contracts\Producer;

class Podcast implements Producer
{
    public function make($producible)
    {
        // instantiate the passed $producible (an FQCN)
    }
}

Note: The Deefour\Producer\ResolvesProducibles trait does not implement the make() method.

Contribute

Changelog

1.0.0 - October 7, 2015

  • Release 1.0.0.

0.1.1 - August 8, 2015

  • Added ProductionFactory interface to allow more lenient type-hinting within other packages.
  • Docblock cleanup.

0.1.0 - August 4, 2015

  • Initial release.

License

Copyright (c) 2015 Jason Daly (deefour). Released under the MIT License.

deefour/producer 适用场景与选型建议

deefour/producer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.93k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「deefour」 「producer」 「class resolution」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 deefour/producer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 deefour/producer 我们能提供哪些服务?
定制开发 / 二次开发

基于 deefour/producer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-05