Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3775ba8

Browse files
[DI] Remove synthetic services from methodMap + generated methods
1 parent7aeb31e commit3775ba8

File tree

4 files changed

+24
-54
lines changed

4 files changed

+24
-54
lines changed

‎src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php‎

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -591,15 +591,16 @@ private function addServiceConfigurator($id, Definition $definition, $variableNa
591591
*/
592592
privatefunctionaddService($id,Definition$definition)
593593
{
594+
if ($definition->isSynthetic()) {
595+
return'';
596+
}
594597
$this->definitionVariables =new \SplObjectStorage();
595598
$this->referenceVariables =array();
596599
$this->variableCount =0;
597600

598601
$return =array();
599602

600-
if ($definition->isSynthetic()) {
601-
$return[] ='@throws RuntimeException always since this service is expected to be injected dynamically';
602-
}elseif ($class =$definition->getClass()) {
603+
if ($class =$definition->getClass()) {
603604
$class =$this->container->resolveEnvPlaceholders($class);
604605
$return[] =sprintf('@return %s A %s instance',0 ===strpos($class,'%') ?'object' :'\\'.ltrim($class,'\\'),ltrim($class,'\\'));
605606
}elseif ($definition->getFactory()) {
@@ -680,26 +681,22 @@ private function addService($id, Definition $definition)
680681

681682
$code .=$isProxyCandidate ?$this->getProxyDumper()->getProxyFactoryCode($definition,$id,$methodName) :'';
682683

683-
if ($definition->isSynthetic()) {
684-
$code .=sprintf(" throw new RuntimeException('You have requested a synthetic service (\"%s\"). The DIC does not know how to construct this service.');\n }\n",$id);
685-
}else {
686-
if ($definition->isDeprecated()) {
687-
$code .=sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n",$this->export($definition->getDeprecationMessage($id)));
688-
}
689-
690-
$code .=
691-
$this->addServiceInclude($id,$definition).
692-
$this->addServiceLocalTempVariables($id,$definition).
693-
$this->addServiceInlinedDefinitions($id,$definition).
694-
$this->addServiceInstance($id,$definition).
695-
$this->addServiceInlinedDefinitionsSetup($id,$definition).
696-
$this->addServiceProperties($id,$definition).
697-
$this->addServiceMethodCalls($id,$definition).
698-
$this->addServiceConfigurator($id,$definition).
699-
$this->addServiceReturn($id,$definition)
700-
;
684+
if ($definition->isDeprecated()) {
685+
$code .=sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n",$this->export($definition->getDeprecationMessage($id)));
701686
}
702687

688+
$code .=
689+
$this->addServiceInclude($id,$definition).
690+
$this->addServiceLocalTempVariables($id,$definition).
691+
$this->addServiceInlinedDefinitions($id,$definition).
692+
$this->addServiceInstance($id,$definition).
693+
$this->addServiceInlinedDefinitionsSetup($id,$definition).
694+
$this->addServiceProperties($id,$definition).
695+
$this->addServiceMethodCalls($id,$definition).
696+
$this->addServiceConfigurator($id,$definition).
697+
$this->addServiceReturn($id,$definition)
698+
;
699+
703700
$this->definitionVariables =null;
704701
$this->referenceVariables =null;
705702

@@ -950,7 +947,8 @@ private function addNormalizedIds()
950947
*/
951948
privatefunctionaddMethodMap()
952949
{
953-
if (!$definitions =$this->container->getDefinitions()) {
950+
$definitions =$this->container->getDefinitions();
951+
if (!$definitions || !$definitions =array_filter($definitions,function ($def) {return !$def->isSynthetic(); })) {
954952
return'';
955953
}
956954

‎src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,15 @@ public function testGetCircularReference()
285285
}
286286

287287
/**
288-
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
289-
* @expectedExceptionMessage You have requested asynthetic service("request"). The DIC does not know how to construct this service.
288+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
289+
* @expectedExceptionMessage You have requested anon-existent service "request".
290290
*/
291-
publicfunctiontestGetSyntheticServiceAlwaysThrows()
291+
publicfunctiontestGetSyntheticServiceThrows()
292292
{
293293
require_once__DIR__.'/Fixtures/php/services9.php';
294294

295295
$container =new \ProjectServiceContainer();
296-
$container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE);
296+
$container->get('request');
297297
}
298298

299299
publicfunctiontestHas()

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function __construct()
5050
'method_call1' =>'getMethodCall1Service',
5151
'new_factory' =>'getNewFactoryService',
5252
'new_factory_service' =>'getNewFactoryServiceService',
53-
'request' =>'getRequestService',
5453
'service_from_static_method' =>'getServiceFromStaticMethodService',
5554
);
5655
$this->privates =array(
@@ -384,19 +383,6 @@ protected function getNewFactoryServiceService()
384383
return$instance;
385384
}
386385

387-
/**
388-
* Gets the 'request' service.
389-
*
390-
* This service is shared.
391-
* This method always returns the same instance of the service.
392-
*
393-
* @throws RuntimeException always since this service is expected to be injected dynamically
394-
*/
395-
protectedfunctiongetRequestService()
396-
{
397-
thrownewRuntimeException('You have requested a synthetic service ("request"). The DIC does not know how to construct this service.');
398-
}
399-
400386
/**
401387
* Gets the 'service_from_static_method' service.
402388
*

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function __construct()
4646
'lazy_context_ignore_invalid_ref' =>'getLazyContextIgnoreInvalidRefService',
4747
'method_call1' =>'getMethodCall1Service',
4848
'new_factory_service' =>'getNewFactoryServiceService',
49-
'request' =>'getRequestService',
5049
'service_from_static_method' =>'getServiceFromStaticMethodService',
5150
);
5251
$this->aliases =array(
@@ -377,19 +376,6 @@ protected function getNewFactoryServiceService()
377376
return$instance;
378377
}
379378

380-
/**
381-
* Gets the 'request' service.
382-
*
383-
* This service is shared.
384-
* This method always returns the same instance of the service.
385-
*
386-
* @throws RuntimeException always since this service is expected to be injected dynamically
387-
*/
388-
protectedfunctiongetRequestService()
389-
{
390-
thrownewRuntimeException('You have requested a synthetic service ("request"). The DIC does not know how to construct this service.');
391-
}
392-
393379
/**
394380
* Gets the 'service_from_static_method' service.
395381
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp