PHP code example of deefour / producer

1. Go to this page and download the library: Download deefour/producer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

deefour / producer example snippets


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

class Podcast implements Producer
{
    // ...
}

class PodcastPolicy implements Producible
{
    // ...
}

class PodcastScope implements Producible
{
    // ...
}

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

get_class($producer) . ucfirst($type)

use Deefour\Producer\Contracts\Producer;

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

namespace App;

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

class Podcast implements Producer
{
    use ResolvesProducibles;
}

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

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

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

new $producible($producer);

use Deefour\Producer\Contracts\Producer;

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