for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Provider;
use App\Model\Project;
use App\Provider\ProviderInterface;
use RuntimeException;
/**
* Provider factory responsible for managing provider instances
*
* @author Ronan Chilvers <[email protected]>
*/
class Factory
{
* @var array
protected $instances = [];
* Add a provider instance
* @param \App\Provider\ProviderInterface
public function addProvider(ProviderInterface $instance)
$this->instances[] = $instance;
}
* Get a suitable instance for a given project
* @param \App\Model\Project $project
* @return \App\Provider\ProviderInterface
* @throws RuntimeException If a suitable provider is not found
public function forProject(Project $project)
foreach ($this->instances as $instance) {
if ($instance->handles($project)) {
return $instance;
throw new RuntimeException('No suitable instance found for project provider ' . $project->provider);
* Get the project provider options as an array
* @return array
public function getOptions()
$options = [];
$label = $instance->getLabel();
$options[strtolower($label)] = $label;
return $options;