Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 5, 2023. It is now read-only.

imba28/symfony-enum-array-parameters-bug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to reproduce

  1. Start application and go to http:127.0.0.1:8888

If the container behaved like expected, the application would not print the following warning

Warning: Undefined array key "app.another_parameter"

Quick fix

  1. Replace Symfony\Component\DependencyInjection\Dumper\PhpDumper::dumpParameter with the following method:
private function dumpParameter(string $name): string
{
    if ($this->container->hasParameter($name)) {
        $value = $this->container->getParameter($name);
        $dumpedValue = $this->dumpValue($value, false);

        if (!$value || !\is_array($value)) {
            return $dumpedValue;
        }

        $hasEnum = array_filter($value, fn ($v) => $v instanceof \UnitEnum) !== [];

        if (!$hasEnum && !preg_match("/\\\$this->(?:getEnv\('(?:[-.\w\\\\]*+:)*+\w++'\)|targetDir\.'')/", $dumpedValue)) {
            return sprintf('$this->parameters[%s]', $this->doExport($name));
        }
    }

    return sprintf('$this->getParameter(%s)', $this->doExport($name));
}
  1. Clear Symfony's cache
  2. Reload browser
  3. You should now see the two dumped parameters.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published