dereuromark / cakephp-dto

CakePHP DTO plugin - quickly generate useful data transfer objects for your app (mutable/immutable)
MIT License
24 stars 6 forks source link

Problem generating dto from console #63

Closed rudy1976s closed 1 year ago

rudy1976s commented 1 year ago

Good afternoon Mark I have a problem when generating / updating a dto: the namespace created seems not correct. Here there is an example:

namespace Acme/AspBologna\Dto;

while it should be

namespace Acme\AspBologna\Dto;

I have launched the following console command:

bin/cake dto generate -p Acme/AspBologna where Acme/AspBologna is one of my plugins, located in vendor.

At the same time inside all other generated files the same issues appears when the namespace of the plugin is involved:

/**
     * @throws \RuntimeException If value is not set.
     *
     * @return \Acme/AspBologna\Dto\MittenteDto
     */
    public function getMittenteOrFail(): \Acme/AspBologna\Dto\MittenteDto {
        if ($this->mittente === null) {
            throw new \RuntimeException('Value not set for field `mittente` (expected to be not null)');
        }

        return $this->mittente;
    }

What could that depends on ?

Thank you for your help

Rudy

dereuromark commented 1 year ago

Sounds like plugins with a prefix in their name have an issue with the namespace generation Would you be able to make a PR with a fix here?

dereuromark commented 1 year ago

Is it still valid? Did you find a fix for it?

dereuromark commented 1 year ago

I think I managed to fix it with https://github.com/dereuromark/cakephp-dto/commit/d5afb2a19e9f1101677691c1521e58013f1a0ca2

Please confirm

I used this to check:

    <dto name="Foo">
        <field name="foo" type="string"/>
    </dto>

    <dto name="Bar">
        <field name="foo" type="Foo"/>
        <field name="foos" type="Foo[]"/>
    </dto>
dereuromark commented 1 year ago

https://github.com/dereuromark/cakephp-dto/releases/tag/1.7.0