tflori/dependency-injector

View on GitHub
src/Alias.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

namespace DependencyInjector;

use Psr\Container\ContainerInterface;

class Alias implements FactoryInterface
{
    /** @var string */
    protected $origin;

    /** @var ContainerInterface */
    protected $container;

    /**
     * FactoryInterface constructor.
     *
     * @param ContainerInterface $container
     * @param string             $origin
     */
    public function __construct(ContainerInterface $container, string $origin = null)
    {
        $this->container = $container;
        $this->origin = $origin;
    }

    /**
     * Build the product of this factory and return an instance.
     *
     * Sharing has to be handled here.
     *
     * @return mixed
     */
    public function getInstance()
    {
        return $this->container->get($this->origin);
    }
}