This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/ContainerInterface.php

158 lines
3.7 KiB
PHP
Raw Normal View History

2010-01-04 14:26:20 +00:00
<?php
/*
* This file is part of the Symfony package.
2010-01-04 14:26:20 +00:00
*
* (c) Fabien Potencier <fabien@symfony.com>
2010-01-04 14:26:20 +00:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2010-01-04 14:26:20 +00:00
*/
namespace Symfony\Component\DependencyInjection;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2010-01-04 14:26:20 +00:00
/**
* ContainerInterface is the interface implemented by service container classes.
*
* @author Fabien Potencier <fabien@symfony.com>
2011-01-17 22:28:59 +00:00
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*
* @api
2010-01-04 14:26:20 +00:00
*/
interface ContainerInterface
{
2010-06-27 17:28:29 +01:00
const EXCEPTION_ON_INVALID_REFERENCE = 1;
2014-10-22 19:27:13 +01:00
const NULL_ON_INVALID_REFERENCE = 2;
const IGNORE_ON_INVALID_REFERENCE = 3;
const SCOPE_CONTAINER = 'container';
const SCOPE_PROTOTYPE = 'prototype';
2010-06-27 17:28:29 +01:00
/**
* Sets a service.
*
* @param string $id The service identifier
* @param object $service The service instance
2011-01-17 22:28:59 +00:00
* @param string $scope The scope of the service
*
* @api
2010-06-27 17:28:29 +01:00
*/
2012-07-09 13:50:58 +01:00
public function set($id, $service, $scope = self::SCOPE_CONTAINER);
2010-06-27 17:28:29 +01:00
/**
* Gets a service.
*
2012-05-15 21:19:31 +01:00
* @param string $id The service identifier
* @param int $invalidBehavior The behavior when the service does not exist
2010-06-27 17:28:29 +01:00
*
* @return object The associated service
*
* @throws ServiceCircularReferenceException When a circular reference is detected
2014-11-30 13:33:44 +00:00
* @throws ServiceNotFoundException When the service is not defined
2010-06-27 17:28:29 +01:00
*
* @see Reference
*
* @api
2010-06-27 17:28:29 +01:00
*/
2012-07-09 13:50:58 +01:00
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE);
2010-06-27 17:28:29 +01:00
/**
* Returns true if the given service is defined.
*
2012-05-15 21:19:31 +01:00
* @param string $id The service identifier
2010-06-27 17:28:29 +01:00
*
2014-11-30 13:33:44 +00:00
* @return bool true if the service is defined, false otherwise
*
* @api
2010-06-27 17:28:29 +01:00
*/
2012-07-09 13:50:58 +01:00
public function has($id);
2011-01-17 22:28:59 +00:00
/**
* Gets a parameter.
*
2012-05-15 21:19:31 +01:00
* @param string $name The parameter name
*
2014-11-30 13:33:44 +00:00
* @return mixed The parameter value
*
* @throws InvalidArgumentException if the parameter is not defined
*
* @api
*/
2012-07-09 13:50:58 +01:00
public function getParameter($name);
/**
* Checks if a parameter exists.
*
2012-05-15 21:19:31 +01:00
* @param string $name The parameter name
*
2014-11-30 13:33:44 +00:00
* @return bool The presence of parameter in container
*
* @api
*/
2012-07-09 13:50:58 +01:00
public function hasParameter($name);
/**
* Sets a parameter.
*
2011-04-23 16:05:44 +01:00
* @param string $name The parameter name
* @param mixed $value The parameter value
*
* @api
*/
2012-07-09 13:50:58 +01:00
public function setParameter($name, $value);
2011-01-17 22:28:59 +00:00
/**
2014-12-21 17:00:50 +00:00
* Enters the given scope.
2011-01-17 22:28:59 +00:00
*
* @param string $name
*
* @api
2011-01-17 22:28:59 +00:00
*/
2012-07-09 13:50:58 +01:00
public function enterScope($name);
2011-01-17 22:28:59 +00:00
/**
2014-12-21 17:00:50 +00:00
* Leaves the current scope, and re-enters the parent scope.
2011-01-17 22:28:59 +00:00
*
* @param string $name
*
* @api
2011-01-17 22:28:59 +00:00
*/
2012-07-09 13:50:58 +01:00
public function leaveScope($name);
2011-01-17 22:28:59 +00:00
/**
2014-12-21 17:00:50 +00:00
* Adds a scope to the container.
2011-01-17 22:28:59 +00:00
*
* @param ScopeInterface $scope
*
* @api
2011-01-17 22:28:59 +00:00
*/
2012-07-09 13:50:58 +01:00
public function addScope(ScopeInterface $scope);
2011-01-17 22:28:59 +00:00
/**
2014-12-21 17:00:50 +00:00
* Whether this container has the given scope.
2011-01-17 22:28:59 +00:00
*
* @param string $name
2011-12-13 07:50:54 +00:00
*
2014-04-16 11:30:19 +01:00
* @return bool
*
* @api
2011-01-17 22:28:59 +00:00
*/
2012-07-09 13:50:58 +01:00
public function hasScope($name);
2011-01-17 22:28:59 +00:00
/**
* Determines whether the given scope is currently active.
*
* It does however not check if the scope actually exists.
*
2011-02-13 18:06:41 +00:00
* @param string $name
2011-12-13 07:50:54 +00:00
*
2014-04-16 11:30:19 +01:00
* @return bool
*
* @api
2011-01-17 22:28:59 +00:00
*/
2012-07-09 13:50:58 +01:00
public function isScopeActive($name);
2010-01-04 14:26:20 +00:00
}