Description
Description
It is not possible to create an entity named “Attribute” using the maker bundle.
A message indicating that the entity exists appears when running the make:entity command.
Followed by an error:
In FileManager.php line 111:
Warning: file_get_contents(/project/path/): Failed to open stream: No such file or directory
How to reproduce
-
Create a Symfony project (version 6.4 and above):
symfony new test_project --version=6.4 cd ./test_project/
-
Install the ORM pack and the maker bundle:
symfony composer require symfony/orm-pack symfony/maker-bundle
-
Attempt to create the "Attribute" entity:
symfony console make:entity Attribute
The console will return an output like this:
Your entity already exists! So let's add some new fields!
In FileManager.php line 111:
Warning: file_get_contents(/project/path/): Failed to open stream: No such file or directory
make:entity [-a|--api-resource] [-b|--broadcast] [--regenerate] [--overwrite] [--with-uuid] [--with-ulid] [--] [<name>]
Possible Solution
The issue seems to come from line 191 of the Generator
class in the maker bundle:
<?php
// ./maker-bundle/src/Generator.php
[...]
public function createClassNameDetails(string $name, string $namespacePrefix, string $suffix = '', string $validationErrorMessage = ''): ClassNameDetails
{
(...)
Validator::classDoesNotExist($className);
(...)
}
[...]
This check verifies if the entered class already exists, but not using namespacePrefix value.
However, since PHP 8, the Attribute
class exists for managing class attributes (vs annotations).
<?php
namespace Example;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD)]
class MyAttribute
{
}
The check should be modified to verify that the class exists in the namespace.
What do you think?
Additional Context
Here is the output of the make:entity
command in verbose mode.
symfony console make:entity Attribute -vvv
Linting Generated Files With:
Bundled PHP-CS-Fixer & Bundled PHP-CS-Fixer Configuration
Your entity already exists! So let's add some new fields!
In FileManager.php line 111:
[ErrorException]
Warning: file_get_contents(/project/path/): Failed to open stream: No such file or directory
Exception trace:
at /project/path/vendor/symfony/maker-bundle/src/FileManager.php:111
Symfony/Bundle/MakerBundle/FileManager->getFileContents() at /project/path/vendor/symfony/maker-bundle/src/Maker/MakeEntity.php:851
Symfony/Bundle/MakerBundle/Maker/MakeEntity->createClassManipulator() at /project/path/vendor/symfony/maker-bundle/src/Maker/MakeEntity.php:229
Symfony/Bundle/MakerBundle/Maker/MakeEntity->generate() at /project/path/vendor/symfony/maker-bundle/src/Command/MakerCommand.php:102
Symfony/Bundle/MakerBundle/Command/MakerCommand->execute() at /project/path/vendor/symfony/console/Command/Command.php:326
Symfony/Component/Console/Command/Command->run() at /project/path/vendor/symfony/console/Application.php:1096
Symfony/Component/Console/Application->doRunCommand() at /project/path/vendor/symfony/framework-bundle/Console/Application.php:126
Symfony/Bundle/FrameworkBundle/Console/Application->doRunCommand() at /project/path/vendor/symfony/console/Application.php:324
Symfony/Component/Console/Application->doRun() at /project/path/vendor/symfony/framework-bundle/Console/Application.php:80
Symfony/Bundle/FrameworkBundle/Console/Application->doRun() at /project/path/vendor/symfony/console/Application.php:175
Symfony/Component/Console/Application->run() at /project/path/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49
Symfony/Component/Runtime/Runner/Symfony/ConsoleApplicationRunner->run() at /project/path/vendor/autoload_runtime.php:29
require_once() at /project/path/bin/console:15
make:entity [-a|--api-resource] [-b|--broadcast] [--regenerate] [--overwrite] [--with-uuid] [--with-ulid] [--] [<name>]