<?php

declare(strict_types=1);



namespace OAuth2Framework\Component\Server\Tests\Stub;

use Psr\Container\ContainerInterface;

final class Container implements ContainerInterface
{
    /**
     * @var array
     */
    private $services = [];

    /**
     * @param $service
     *
     * @return ContainerInterface
     */
    public function add($service)
    {
        $class = get_class($service);
        $this->services[$class] = $service;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function get($id)
    {
        if ($this->has($id)) {
            return $this->services[$id];
        }
    }

    /**
     * {@inheritdoc}
     */
    public function has($id)
    {
        return array_key_exists($id, $this->services);
    }
}
