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

Commit1c90d1b

Browse files
[DI] Skip hot_path tag for deprecated services as their class might also be
1 parent4baf968 commit1c90d1b

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveHotPathPass.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ protected function processValue($value, $isRoot = false)
5252
if ($valueinstanceof ArgumentInterface) {
5353
return$value;
5454
}
55-
if ($valueinstanceof Definition &&$isRoot && (isset($this->resolvedIds[$this->currentId]) || !$value->hasTag($this->tagName))) {
56-
return$value;
55+
if ($valueinstanceof Definition &&$isRoot && (isset($this->resolvedIds[$this->currentId]) || !$value->hasTag($this->tagName) ||$value->isDeprecated())) {
56+
return$value->isDeprecated() ?$value->clearTag($this->tagName) :$value;
5757
}
5858
if ($valueinstanceof Reference && ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE !==$value->getInvalidBehavior() &&$this->container->has($id = (string)$value)) {
5959
$definition =$this->container->findDefinition($id);
60-
if (!$definition->hasTag($this->tagName)) {
60+
if (!$definition->hasTag($this->tagName) && !$definition->isDeprecated()) {
6161
$this->resolvedIds[$id] =true;
6262
$definition->addTag($this->tagName);
6363
parent::processValue($definition,false);

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ private function addServiceLocalTempVariables($cId, Definition $definition, arra
271271

272272
array_unshift($inlinedDefinitions,$definition);
273273

274-
$collectLineage =$this->inlineRequires && !($this->hotPathTag &&$definition->hasTag($this->hotPathTag));
274+
$collectLineage =$this->inlineRequires && !$this->isHotPath($definition);
275275
$isNonLazyShared = !$this->getProxyDumper()->isProxyCandidate($definition) &&$definition->isShared();
276276
$lineage =$calls =$behavior =array();
277277
foreach ($inlinedDefinitionsas$iDefinition) {
278-
if ($collectLineage &&$class =is_array($factory =$iDefinition->getFactory()) &&is_string($factory[0]) ?$factory[0] :$iDefinition->getClass()) {
278+
if ($collectLineage &&!$iDefinition->isDeprecated() &&$class =is_array($factory =$iDefinition->getFactory()) &&is_string($factory[0]) ?$factory[0] :$iDefinition->getClass()) {
279279
$this->collectLineage($class,$lineage);
280280
}
281281
$this->getServiceCallsFromArguments($iDefinition->getArguments(),$calls,$behavior,$isNonLazyShared);
@@ -763,7 +763,7 @@ private function addService($id, Definition $definition, &$file = null)
763763
$lazyInitialization ='';
764764
}
765765

766-
$asFile =$this->asFiles &&$definition->isShared() && !($this->hotPathTag &&$definition->hasTag($this->hotPathTag));
766+
$asFile =$this->asFiles &&$definition->isShared() && !$this->isHotPath($definition);
767767
$methodName =$this->generateMethodName($id);
768768
if ($asFile) {
769769
$file =$methodName.'.php';
@@ -829,7 +829,7 @@ private function addServices()
829829
$definitions =$this->container->getDefinitions();
830830
ksort($definitions);
831831
foreach ($definitionsas$id =>$definition) {
832-
if ($definition->isSynthetic() || ($this->asFiles &&$definition->isShared() && !($this->hotPathTag &&$definition->hasTag($this->hotPathTag)))) {
832+
if ($definition->isSynthetic() || ($this->asFiles &&$definition->isShared() && !$this->isHotPath($definition))) {
833833
continue;
834834
}
835835
if ($definition->isPublic()) {
@@ -847,7 +847,7 @@ private function generateServiceFiles()
847847
$definitions =$this->container->getDefinitions();
848848
ksort($definitions);
849849
foreach ($definitionsas$id =>$definition) {
850-
if (!$definition->isSynthetic() &&$definition->isShared() && !($this->hotPathTag &&$definition->hasTag($this->hotPathTag))) {
850+
if (!$definition->isSynthetic() &&$definition->isShared() && !$this->isHotPath($definition)) {
851851
$code =$this->addService($id,$definition,$file);
852852
yield$file =>$code;
853853
}
@@ -1120,7 +1120,7 @@ private function addMethodMap()
11201120
$definitions =$this->container->getDefinitions();
11211121
ksort($definitions);
11221122
foreach ($definitionsas$id =>$definition) {
1123-
if (!$definition->isSynthetic() && (!$this->asFiles || !$definition->isShared() ||($this->hotPathTag &&$definition->hasTag($this->hotPathTag)))) {
1123+
if (!$definition->isSynthetic() && (!$this->asFiles || !$definition->isShared() ||$this->isHotPath($definition))) {
11241124
$code .=''.$this->export($id).' =>'.$this->export($this->generateMethodName($id)).",\n";
11251125
}
11261126
}
@@ -1139,7 +1139,7 @@ private function addFileMap()
11391139
$definitions =$this->container->getDefinitions();
11401140
ksort($definitions);
11411141
foreach ($definitionsas$id =>$definition) {
1142-
if (!$definition->isSynthetic() &&$definition->isShared() && !($this->hotPathTag &&$definition->hasTag($this->hotPathTag))) {
1142+
if (!$definition->isSynthetic() &&$definition->isShared() && !$this->isHotPath($definition)) {
11431143
$code .=sprintf(" %s => __DIR__.'/%s.php',\n",$this->export($id),$this->generateMethodName($id));
11441144
}
11451145
}
@@ -1856,7 +1856,7 @@ private function getServiceCall($id, Reference $reference = null)
18561856
if ($definition->isShared()) {
18571857
$code =sprintf('$this->services[\'%s\'] = %s',$id,$code);
18581858
}
1859-
}elseif ($this->asFiles &&$definition->isShared() && !($this->hotPathTag &&$definition->hasTag($this->hotPathTag))) {
1859+
}elseif ($this->asFiles &&$definition->isShared() && !$this->isHotPath($definition)) {
18601860
$code =sprintf("\$this->load(__DIR__.'/%s.php')",$this->generateMethodName($id));
18611861
}else {
18621862
$code =sprintf('$this->%s()',$this->generateMethodName($id));
@@ -1988,6 +1988,11 @@ private function getExpressionLanguage()
19881988
return$this->expressionLanguage;
19891989
}
19901990

1991+
privatefunctionisHotPath(Definition$definition)
1992+
{
1993+
return$this->hotPathTag &&$definition->hasTag($this->hotPathTag) && !$definition->isDeprecated();
1994+
}
1995+
19911996
privatefunctionexport($value)
19921997
{
19931998
if (null !==$this->targetDirRegex &&is_string($value) &&preg_match($this->targetDirRegex,$value,$matches,PREG_OFFSET_CAPTURE)) {

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveHotPathPassTest.php‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ public function testProcess()
3434
;
3535

3636
$container->register('lazy');
37-
$container->register('bar');
38-
$container->register('bar')->addArgument(newReference('buz'));
39-
$container->register('baz')->addArgument(newReference('lazy'));
40-
$container->register('baz')->addArgument(newReference('lazy'));
37+
$container->register('bar')
38+
->addArgument(newReference('buz'))
39+
->addArgument(newReference('deprec_ref_notag'));
40+
$container->register('baz')
41+
->addArgument(newReference('lazy'))
42+
->addArgument(newReference('lazy'));
4143
$container->register('buz');
44+
$container->register('deprec_with_tag')->setDeprecated()->addTag('container.hot_path');
45+
$container->register('deprec_ref_notag')->setDeprecated();
4246

4347
(newResolveHotPathPass())->process($container);
4448

@@ -47,5 +51,7 @@ public function testProcess()
4751
$this->assertTrue($container->getDefinition('buz')->hasTag('container.hot_path'));
4852
$this->assertFalse($container->getDefinition('baz')->hasTag('container.hot_path'));
4953
$this->assertFalse($container->getDefinition('service_container')->hasTag('container.hot_path'));
54+
$this->assertFalse($container->getDefinition('deprec_with_tag')->hasTag('container.hot_path'));
55+
$this->assertFalse($container->getDefinition('deprec_ref_notag')->hasTag('container.hot_path'));
5056
}
5157
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp