Skip to content

Bug: ClassReflection resource resolution system is flawed #1017

@Pierstoval

Description

@Pierstoval

Sylius version affected: 1.13.0-ALPHA.3

The \Sylius\Resource\Reflection\ClassReflection::getResourcesByPath() method is using regexes, while it could find other ways, like reflection.

I just stumbled upon a strange error today regarding this:

In ClassReflection.php line 79:

  Class "App\Entity\Field\=" does not exist

The reflection is looping over several files that are actually traits, therefore it doesn't match and doesn't add them as resources, however, one of them has this code inside it:

// ...
$class = ...
// ...

This triggers the current resolving process to actually consider this class as being a resource, and the matcher will resolve it to = (since it's what's after class . This is the cause of the error.

Can be easy-fixed by #1016 , though it's probably gonna break another app in the future.

Example that breaks after the hotfix of the aforementioned PR:

// ...

/**
 * this class is used for ...
 */
class Id
{
// ...

Same here: this will break (I tested it) but the debug message will be easier to read (it will display the beginning of the comment, so it's supposedly fine).

IMO, autoloading, leveraging PSR-4 maybe, and/or class reflection should be used, as they will be more reliable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions