1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\DependencyInjection;
13
14use Psr\Container\ContainerInterface as PsrContainerInterface;
15use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
16use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
17use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
18
19/**
20 * ContainerInterface is the interface implemented by service container classes.
21 *
22 * @author Fabien Potencier <fabien@symfony.com>
23 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
24 */
25interface ContainerInterface extends PsrContainerInterface
26{
27    const EXCEPTION_ON_INVALID_REFERENCE = 1;
28    const NULL_ON_INVALID_REFERENCE = 2;
29    const IGNORE_ON_INVALID_REFERENCE = 3;
30    const IGNORE_ON_UNINITIALIZED_REFERENCE = 4;
31
32    /**
33     * Sets a service.
34     *
35     * @param string      $id      The service identifier
36     * @param object|null $service The service instance
37     */
38    public function set($id, $service);
39
40    /**
41     * Gets a service.
42     *
43     * @param string $id              The service identifier
44     * @param int    $invalidBehavior The behavior when the service does not exist
45     *
46     * @return object|null The associated service
47     *
48     * @throws ServiceCircularReferenceException When a circular reference is detected
49     * @throws ServiceNotFoundException          When the service is not defined
50     *
51     * @see Reference
52     */
53    public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
54
55    /**
56     * Returns true if the given service is defined.
57     *
58     * @param string $id The service identifier
59     *
60     * @return bool true if the service is defined, false otherwise
61     */
62    public function has($id);
63
64    /**
65     * Check for whether or not a service has been initialized.
66     *
67     * @param string $id
68     *
69     * @return bool true if the service has been initialized, false otherwise
70     */
71    public function initialized($id);
72
73    /**
74     * Gets a parameter.
75     *
76     * @param string $name The parameter name
77     *
78     * @return mixed The parameter value
79     *
80     * @throws InvalidArgumentException if the parameter is not defined
81     */
82    public function getParameter($name);
83
84    /**
85     * Checks if a parameter exists.
86     *
87     * @param string $name The parameter name
88     *
89     * @return bool The presence of parameter in container
90     */
91    public function hasParameter($name);
92
93    /**
94     * Sets a parameter.
95     *
96     * @param string $name  The parameter name
97     * @param mixed  $value The parameter value
98     */
99    public function setParameter($name, $value);
100}
101