PHPackages                             deefour/producer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. deefour/producer

ActiveLibrary

deefour/producer
================

Simple rule-based class resolution

1.1.1(10y ago)21.9kMITPHPPHP &gt;=5.5.0

Since Aug 5Pushed 10y ago1 watchersCompare

[ Source](https://github.com/deefour/producer)[ Packagist](https://packagist.org/packages/deefour/producer)[ Docs](https://github.com/deefour/producer)[ RSS](/packages/deefour-producer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (8)Used By (0)

Producer
========

[](#producer)

[![Build Status](https://camo.githubusercontent.com/843a7698ddedf4572ea38877ae218b2ff65ff01f20b256dfeeeaf7657b594f71/68747470733a2f2f7472617669732d63692e6f72672f646565666f75722f70726f64756365722e737667)](https://travis-ci.org/deefour/producer)[![Packagist Version](https://camo.githubusercontent.com/fb157000bdb8c72663ea00f1df2dc791255a0ab2fff4d4df16d0d61630b26d6c/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646565666f75722f70726f64756365722e737667)](https://packagist.org/packages/deefour/producer)[![Code Climate](https://camo.githubusercontent.com/3c95355100d9bffa96e7397aaf4b98101d53bc944c7e3eb88fd3c9670054086a/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f646565666f75722f70726f64756365722f6261646765732f6770612e737667)](https://codeclimate.com/github/deefour/producer)[![License](https://camo.githubusercontent.com/69743162c30028849bca4518e6ab8a5e91497905a4dd111f927e4589d12fd6e9/68747470733a2f2f706f7365722e707567782e6f72672f646565666f75722f70726f64756365722f6c6963656e7365)](https://packagist.org/packages/deefour/producer)

A small class factory.

Getting Started
---------------

[](#getting-started)

Run the following to add Producer to your project's `composer.json`. See [Packagist](https://packagist.org/packages/deefour/producer) for specific versions.

```
composer require deefour/producer
```

**`>=PHP5.5.0` is required.**

Overview
--------

[](#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
-------------------------

[](#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

[](#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

[](#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
----------

[](#contribute)

- Issue Tracker:
- Source Code:

Changelog
---------

[](#changelog)

#### 1.0.0 - October 7, 2015

[](#100---october-7-2015)

- Release 1.0.0.

#### 0.1.1 - August 8, 2015

[](#011---august-8-2015)

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

#### 0.1.0 - August 4, 2015

[](#010---august-4-2015)

- Initial release.

License
-------

[](#license)

Copyright (c) 2015 [Jason Daly](http://www.deefour.me) ([deefour](https://github.com/deefour)). Released under the [MIT License](http://deefour.mit-license.org/).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~44 days

Recently: every ~55 days

Total

6

Last Release

3712d ago

Major Versions

0.2.0 → 1.0.02015-10-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a2bddbe9f87813e53e82c1799b460513ede9f96a1d85ad7c186c0692a6f0762?d=identicon)[deefour](/maintainers/deefour)

---

Top Contributors

[![deefour](https://avatars.githubusercontent.com/u/14762?v=4)](https://github.com/deefour "deefour (21 commits)")

---

Tags

laravelproducerdeefourclass resolution

### Embed Badge

![Health badge](/badges/deefour-producer/health.svg)

```
[![Health](https://phpackages.com/badges/deefour-producer/health.svg)](https://phpackages.com/packages/deefour-producer)
```

###  Alternatives

[slowlyo/owl-admin

基于 laravel、amis 开发的后台框架~

61214.2k26](/packages/slowlyo-owl-admin)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[glhd/linen

21135.6k](/packages/glhd-linen)[deefour/presenter

Presenters/Decorators for PHP Objects

122.5k](/packages/deefour-presenter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
