comparison vendor/symfony/dependency-injection/Dumper/PhpDumper.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
481 481
482 $isProxyCandidate = $this->getProxyDumper()->isProxyCandidate($definition); 482 $isProxyCandidate = $this->getProxyDumper()->isProxyCandidate($definition);
483 $instantiation = ''; 483 $instantiation = '';
484 484
485 if (!$isProxyCandidate && $definition->isShared()) { 485 if (!$isProxyCandidate && $definition->isShared()) {
486 $instantiation = "\$this->services['$id'] = ".($isSimpleInstance ? '' : '$instance'); 486 $instantiation = sprintf('$this->services[%s] = %s', $this->doExport($id), $isSimpleInstance ? '' : '$instance');
487 } elseif (!$isSimpleInstance) { 487 } elseif (!$isSimpleInstance) {
488 $instantiation = '$instance'; 488 $instantiation = '$instance';
489 } 489 }
490 490
491 $return = ''; 491 $return = '';
677 677
678 /*{$this->docStar} 678 /*{$this->docStar}
679 * Gets the $public '$id'$shared$autowired service. 679 * Gets the $public '$id'$shared$autowired service.
680 * 680 *
681 * $return 681 * $return
682 EOF;
683 $code = str_replace('*/', ' ', $code).<<<EOF
684
682 */ 685 */
683 protected function {$methodName}($lazyInitialization) 686 protected function {$methodName}($lazyInitialization)
684 { 687 {
685 688
686 EOF; 689 EOF;
691 694
692 $code .= $this->addServiceInclude($id, $definition); 695 $code .= $this->addServiceInclude($id, $definition);
693 696
694 if ($this->getProxyDumper()->isProxyCandidate($definition)) { 697 if ($this->getProxyDumper()->isProxyCandidate($definition)) {
695 $factoryCode = $asFile ? "\$this->load('%s.php', false)" : '$this->%s(false)'; 698 $factoryCode = $asFile ? "\$this->load('%s.php', false)" : '$this->%s(false)';
696 $code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName)); 699 $code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName, $this->doExport($id)));
697 } 700 }
698 701
699 if ($definition->isDeprecated()) { 702 if ($definition->isDeprecated()) {
700 $code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id))); 703 $code .= sprintf(" @trigger_error(%s, E_USER_DEPRECATED);\n\n", $this->export($definition->getDeprecationMessage($id)));
701 } 704 }
765 return $code; 768 return $code;
766 } 769 }
767 770
768 $code .= sprintf(<<<'EOTXT' 771 $code .= sprintf(<<<'EOTXT'
769 772
770 if (isset($this->%s['%s'])) { 773 if (isset($this->%s[%s])) {
771 return $this->%1$s['%2$s']; 774 return $this->%1$s[%2$s];
772 } 775 }
773 776
774 EOTXT 777 EOTXT
775 , 778 ,
776 'services', 779 'services',
777 $id 780 $this->doExport($id)
778 ); 781 );
779 782
780 return $code; 783 return $code;
781 } 784 }
782 785
1528 $conditions = []; 1531 $conditions = [];
1529 foreach (ContainerBuilder::getInitializedConditionals($value) as $service) { 1532 foreach (ContainerBuilder::getInitializedConditionals($value) as $service) {
1530 if (!$this->container->hasDefinition($service)) { 1533 if (!$this->container->hasDefinition($service)) {
1531 return 'false'; 1534 return 'false';
1532 } 1535 }
1533 $conditions[] = sprintf("isset(\$this->services['%s'])", $service); 1536 $conditions[] = sprintf('isset($this->services[%s])', $this->doExport($service));
1534 } 1537 }
1535 foreach (ContainerBuilder::getServiceConditionals($value) as $service) { 1538 foreach (ContainerBuilder::getServiceConditionals($value) as $service) {
1536 if ($this->container->hasDefinition($service) && !$this->container->getDefinition($service)->isPublic()) { 1539 if ($this->container->hasDefinition($service) && !$this->container->getDefinition($service)->isPublic()) {
1537 continue; 1540 continue;
1538 } 1541 }
1539 1542
1540 $conditions[] = sprintf("\$this->has('%s')", $service); 1543 $conditions[] = sprintf('$this->has(%s)', $this->doExport($service));
1541 } 1544 }
1542 1545
1543 if (!$conditions) { 1546 if (!$conditions) {
1544 return ''; 1547 return '';
1545 } 1548 }
1774 * 1777 *
1775 * @return string 1778 * @return string
1776 */ 1779 */
1777 private function dumpParameter($name) 1780 private function dumpParameter($name)
1778 { 1781 {
1782 $name = (string) $name;
1783
1779 if ($this->container->isCompiled() && $this->container->hasParameter($name)) { 1784 if ($this->container->isCompiled() && $this->container->hasParameter($name)) {
1780 $value = $this->container->getParameter($name); 1785 $value = $this->container->getParameter($name);
1781 $dumpedValue = $this->dumpValue($value, false); 1786 $dumpedValue = $this->dumpValue($value, false);
1782 1787
1783 if (!$value || !\is_array($value)) { 1788 if (!$value || !\is_array($value)) {
1784 return $dumpedValue; 1789 return $dumpedValue;
1785 } 1790 }
1786 1791
1787 if (!preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $dumpedValue)) { 1792 if (!preg_match("/\\\$this->(?:getEnv\('(?:\w++:)*+\w++'\)|targetDirs\[\d++\])/", $dumpedValue)) {
1788 return sprintf("\$this->parameters['%s']", $name); 1793 return sprintf('$this->parameters[%s]', $this->doExport($name));
1789 } 1794 }
1790 } 1795 }
1791 1796
1792 return sprintf("\$this->getParameter('%s')", $name); 1797 return sprintf('$this->getParameter(%s)', $this->doExport($name));
1793 } 1798 }
1794 1799
1795 /** 1800 /**
1796 * Gets a service call. 1801 * Gets a service call.
1797 * 1802 *
1811 return '$this'; 1816 return '$this';
1812 } 1817 }
1813 1818
1814 if ($this->container->hasDefinition($id) && $definition = $this->container->getDefinition($id)) { 1819 if ($this->container->hasDefinition($id) && $definition = $this->container->getDefinition($id)) {
1815 if ($definition->isSynthetic()) { 1820 if ($definition->isSynthetic()) {
1816 $code = sprintf('$this->get(\'%s\'%s)', $id, null !== $reference ? ', '.$reference->getInvalidBehavior() : ''); 1821 $code = sprintf('$this->get(%s%s)', $this->doExport($id), null !== $reference ? ', '.$reference->getInvalidBehavior() : '');
1817 } elseif (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) { 1822 } elseif (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
1818 $code = 'null'; 1823 $code = 'null';
1819 if (!$definition->isShared()) { 1824 if (!$definition->isShared()) {
1820 return $code; 1825 return $code;
1821 } 1826 }
1822 } elseif ($this->isTrivialInstance($definition)) { 1827 } elseif ($this->isTrivialInstance($definition)) {
1823 $code = substr($this->addNewInstance($definition, '', '', $id), 8, -2); 1828 $code = substr($this->addNewInstance($definition, '', '', $id), 8, -2);
1824 if ($definition->isShared()) { 1829 if ($definition->isShared()) {
1825 $code = sprintf('$this->services[\'%s\'] = %s', $id, $code); 1830 $code = sprintf('$this->services[%s] = %s', $this->doExport($id), $code);
1826 } 1831 }
1827 $code = "($code)"; 1832 $code = "($code)";
1828 } elseif ($this->asFiles && $definition->isShared() && !$this->isHotPath($definition)) { 1833 } elseif ($this->asFiles && $definition->isShared() && !$this->isHotPath($definition)) {
1829 $code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id)); 1834 $code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id));
1830 } else { 1835 } else {
1831 $code = sprintf('$this->%s()', $this->generateMethodName($id)); 1836 $code = sprintf('$this->%s()', $this->generateMethodName($id));
1832 } 1837 }
1833 } elseif (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) { 1838 } elseif (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
1834 return 'null'; 1839 return 'null';
1835 } elseif (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) { 1840 } elseif (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $reference->getInvalidBehavior()) {
1836 $code = sprintf('$this->get(\'%s\', /* ContainerInterface::NULL_ON_INVALID_REFERENCE */ %d)', $id, ContainerInterface::NULL_ON_INVALID_REFERENCE); 1841 $code = sprintf('$this->get(%s, /* ContainerInterface::NULL_ON_INVALID_REFERENCE */ %d)', $this->doExport($id), ContainerInterface::NULL_ON_INVALID_REFERENCE);
1837 } else { 1842 } else {
1838 $code = sprintf('$this->get(\'%s\')', $id); 1843 $code = sprintf('$this->get(%s)', $this->doExport($id));
1839 } 1844 }
1840 1845
1841 // The following is PHP 5.5 syntax for what could be written as "(\$this->services['$id'] ?? $code)" on PHP>=7.0 1846 // The following is PHP 5.5 syntax for what could be written as "(\$this->services['$id'] ?? $code)" on PHP>=7.0
1842 1847
1843 return "\${(\$_ = isset(\$this->services['$id']) ? \$this->services['$id'] : $code) && false ?: '_'}"; 1848 return sprintf("\${(\$_ = isset(\$this->services[%s]) ? \$this->services[%1\$s] : %s) && false ?: '_'}", $this->doExport($id), $code);
1844 } 1849 }
1845 1850
1846 /** 1851 /**
1847 * Initializes the method names map to avoid conflicts with the Container methods. 1852 * Initializes the method names map to avoid conflicts with the Container methods.
1848 * 1853 *