Skip to content

Small path change suggestion to allow overriding your templates #2

@jimbglenn

Description

@jimbglenn

On line 48 of Doctrine/DocumentClassGenerator.php, you have the template's full paths.

        $documentPath = $this->generator->generateClass(
            $documentClassDetails->getFullName(),
            $generateEmbeddedDocument ? __DIR__.'/../Resources/skeleton/doctrine/EmbeddedDocument.tpl.php' : __DIR__.'/../Resources/skeleton/doctrine/Document.tpl.php',
            [
                'use_statements' => $useStatements,
                'repository_class_name' => $repoClassDetails->getShortName(),
                'api_resource' => $apiResource,
                'collection_name' => $collectionName,
                'embedded' => $generateEmbeddedDocument,
            ]
        );

If you drop the prefix down to the "doctrine" directory, the maker command will still find it in the skeleton directory.

$documentPath = $this->generator->generateClass(
            $documentClassDetails->getFullName(),
            $generateEmbeddedDocument ? 'doctrine/EmbeddedDocument.tpl.php' : 'doctrine/Document.tpl.php',
            [
                'use_statements' => $useStatements,
                'repository_class_name' => $repoClassDetails->getShortName(),
                'api_resource' => $apiResource,
                'collection_name' => $collectionName,
                'embedded' => $generateEmbeddedDocument,
            ]
        );

I did some quick attempts and it seems to work.
The advantage here, would be the maker command is setup to allow users to override the templates without having to override any of the rest of the code.

With the proposed change above, that means in my project, I can use your library, and put a file /doctrine/Document.tpl.php which I could use to override the template you provided.

Our team would like to add additional imports, annotations, etc on the class by overriding your template.

Here's the related question on how it works with the ORM Maker command:
https://stackoverflow.com/questions/75164548/override-symfony-makeentity-to-load-custom-columns

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions