ScriptFUSION\Porter\Porter::getProvider PHP Method

getProvider() public method

Gets the provider matching the specified class name and optionally a tag.
public getProvider ( string $name, string | null $tag = null ) : ScriptFUSION\Porter\Provider\Provider
$name string Provider class name.
$tag string | null Optional. Provider tag.
return ScriptFUSION\Porter\Provider\Provider
    public function getProvider($name, $tag = null)
    {
        if ($this->hasProvider($name, $tag)) {
            return $this->providers[$this->hashProviderName($name, $tag)];
        }
        try {
            // Tags are not supported for lazy-loaded providers because every instance would be the same.
            if ($tag === null) {
                $this->registerProvider($provider = $this->getOrCreateProviderFactory()->createProvider("{$name}"));
                return $provider;
            }
        } catch (ObjectNotCreatedException $exception) {
            // Intentionally empty.
        }
        throw new ProviderNotFoundException("No such provider registered: \"{$name}\" with tag \"{$tag}\".", isset($exception) ? $exception : null);
    }

Usage Example

Beispiel #1
0
 public function testGetStaticProviderTag()
 {
     $this->setExpectedException(ProviderNotFoundException::class);
     $this->porter->getProvider(StaticDataProvider::class, 'foo');
 }