2015-08-17 17:00:26 -07:00
< ? php
/*
* This file is part of the Symfony package .
*
* ( c ) Fabien Potencier < fabien @ symfony . com >
*
* For the full copyright and license information , please view the LICENSE
* file that was distributed with this source code .
*/
namespace Symfony\Component\DependencyInjection\Exception ;
2018-11-23 12:29:20 +00:00
use Psr\Container\NotFoundExceptionInterface ;
2015-08-17 17:00:26 -07:00
/**
* This exception is thrown when a non - existent service is requested .
*
* @ author Johannes M . Schmitt < schmittjoh @ gmail . com >
*/
2018-11-23 12:29:20 +00:00
class ServiceNotFoundException extends InvalidArgumentException implements NotFoundExceptionInterface
2015-08-17 17:00:26 -07:00
{
private $id ;
private $sourceId ;
2018-11-23 12:29:20 +00:00
private $alternatives ;
2015-08-17 17:00:26 -07:00
2018-11-23 12:29:20 +00:00
public function __construct ( $id , $sourceId = null , \Exception $previous = null , array $alternatives = array (), $msg = null )
2015-08-17 17:00:26 -07:00
{
2018-11-23 12:29:20 +00:00
if ( null !== $msg ) {
// no-op
} elseif ( null === $sourceId ) {
2015-08-17 17:00:26 -07:00
$msg = sprintf ( 'You have requested a non-existent service "%s".' , $id );
} else {
$msg = sprintf ( 'The service "%s" has a dependency on a non-existent service "%s".' , $sourceId , $id );
}
if ( $alternatives ) {
2018-11-23 12:29:20 +00:00
if ( 1 == \count ( $alternatives )) {
2015-08-17 17:00:26 -07:00
$msg .= ' Did you mean this: "' ;
} else {
$msg .= ' Did you mean one of these: "' ;
}
$msg .= implode ( '", "' , $alternatives ) . '"?' ;
}
parent :: __construct ( $msg , 0 , $previous );
$this -> id = $id ;
$this -> sourceId = $sourceId ;
2018-11-23 12:29:20 +00:00
$this -> alternatives = $alternatives ;
2015-08-17 17:00:26 -07:00
}
public function getId ()
{
return $this -> id ;
}
public function getSourceId ()
{
return $this -> sourceId ;
}
2018-11-23 12:29:20 +00:00
public function getAlternatives ()
{
return $this -> alternatives ;
}
2015-08-17 17:00:26 -07:00
}