Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. diff --git a/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Configuration/ConfigResolver.php b/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Configuration/ConfigResolver.php
  2. index 9b1e713e7..ff3443e41 100644
  3. --- a/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Configuration/ConfigResolver.php
  4. +++ b/eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Configuration/ConfigResolver.php
  5. @@ -14,6 +14,7 @@ use eZ\Publish\Core\MVC\Symfony\SiteAccess\SiteAccessAware;
  6. use eZ\Publish\Core\MVC\Exception\ParameterNotFoundException;
  7. use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  8. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  9. +use Symfony\Component\DependencyInjection\ContainerBuilder;
  10.  
  11. /**
  12. * This class will help you get settings for a specific scope.
  13. @@ -165,6 +166,10 @@ class ConfigResolver implements VersatileScopeInterface, SiteAccessAware, Contai
  14. */
  15. public function getParameter($paramName, $namespace = null, $scope = null)
  16. {
  17. + if (!$this->container instanceof ContainerBuilder && $this->siteAccess->matchingType === 'uninitialized') {
  18. + $this->triggerEarlyUseError($paramName);
  19. + }
  20. +
  21. $namespace = $namespace ?: $this->defaultNamespace;
  22. $scope = $scope ?: $this->getDefaultScope();
  23. $triedScopes = array();
  24. @@ -214,6 +219,43 @@ class ConfigResolver implements VersatileScopeInterface, SiteAccessAware, Contai
  25. }
  26. }
  27.  
  28. + private function triggerEarlyUseError($paramName)
  29. + {
  30. + // Try to extract service name of service asking for this parameter
  31. + $service = '??';
  32. + foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 9) as $t) {
  33. + if (!isset($t['function']) || $t['function'] === 'getParameter' || $t['function'] === __FUNCTION__) {
  34. + continue;
  35. + }
  36. +
  37. + // We can only really reverse engineer traditional service name, namspace is stripped from autowired / class name based services
  38. + if (strpos($t['function'], 'get') === 0 && strpos($t['function'], 'Service') === strlen($t['function']) -7) {
  39. + $serviceName = strtolower(preg_replace('/\B([A-Z])/', '_$1', str_replace('_', '.', substr($t['function'], 3, -7))));
  40. + if ($this->container->has($serviceName)) {
  41. + $service = $serviceName;
  42. + } else {
  43. + $service = '->' . $t['function'] . '()';
  44. + }
  45. + break;
  46. + }
  47. + }
  48. +
  49. + // Error breaks loading of services, & commands that depend on them
  50. + // Also this is so early in request warning/deprecated/logger does not show up anywhere
  51. + /*@trigger_error(
  52. + sprintf(
  53. + 'ConfigResolver was used by "%s" to read "%s" parameter before SiteAccess was loaded. This should be avoided, '
  54. + . (PHP_SAPI == 'cli' ? 'make sure your commands are lazy loaded, ' : '')
  55. + . 'if nothing else helps make sure the service is marked as lazy.',
  56. + $service,
  57. + $paramName
  58. + );
  59. + E_USER_ERROR
  60. + );*/
  61. +
  62. + echo "Parameter '$paramName' was loaded by '$service' service\n";
  63. + }
  64. +
  65. /**
  66. * Changes the default namespace to look parameter into.
  67. *
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement