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

Skip to content

PSR4 based service discovery bug on Windows #23103

Closed
@podhy

Description

@podhy
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.3.2

Hello,
I found bug on Windows when using PSR4 base service discovery.

When I've got in app/config/services.yml:

services:
  _defaults:
      autowire: true
      autoconfigure: true

  AppBundle\:
      resource: ../../src/AppBundle/**/*Controller.php

All controllers (and not only controllers) are not discovered because of backslashes. This bug is only reproducible on Windows so all tests pass.

I've found little tricky solution to change lines 136-140 in vendor/symfony/symfony/src/Symfony/Component/Config/Resource/GlobResource.php from:

foreach ($finder->followLinks()->sortByName()->in($this->prefix) as $path => $info) {
    if (preg_match($regex, substr($path, $prefixLen)) && $info->isFile()) {
        yield $path => $info;
    }
}

To:

foreach ($finder->followLinks()->sortByName()->in($this->prefix) as $path => $info) {
    $normalizedPath = str_replace(array('/', '\\'), '/', $path); // normalize directory separator to UNIX slashes
    if (preg_match($regex, substr($normalizedPath, $prefixLen)) && $info->isFile()) {
        yield $path => $info;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions