Support for PSR-4 namespace when exporting to ORM

+1 vote
asked Feb 16, 2016 in Feature Request by renaatdemuynck (840 points)

I have a Zend Framework 2 project with Doctrine 2 that is set up to use PSR-4 auto-loading:

"autoload": {
    "psr-4": {
        "Application\\": "module/Application/src/"
    }
}

When I configure my module's export path in Skipper, I set the 'Relative Export Path' like this: ..\..\MyApp\module\Application\src\ and set the filename format to subdirectories-by-namespace
The problem is that it exports the files to C:\...\MyApp\module\Application\src\Application\Entity\Model\User\ when I want it to be C:\...\MyApp\module\Application\src\Entity\Model\User\.

Feature request:
It would be nice to have an option in the config where I can define the namespace prefix like this:
enter image description here

commented Feb 16, 2016 by ludek.vodicka Skipper developer (140,450 points)

Hi, are you testing it on latest beta 3.2.6 or 3.2.5 stable? Because in 3.2.6 we introduced a lot of updates in export path as same as improved import for PSR-4 projects (check changelong)

http://support.skipper18.com/402/downloads-skipper-beta

In 3.2.6 version you can also use regions to define sub-directories for your entities. Also subdirectoris-by-namespace was updated to use relative paths so I suppose your problem should be solved in 3.2.6 too.

Can you please try it and let me know?

commented Feb 17, 2016 by renaatdemuynck (840 points)

I was using version 3.2.5.1283. Now I installed the latest beta but the problem still exists.
I set up a test project:

Module Application:

  • Namespace: \Application\Model\Entity
  • Relative export path: Application\src\Model\Entity
  • Filename format: subdirectories-by-namespace

Entity MyEntity1:

  • Namespace: \Application\Model\Entity\ (generated)

Entity MyEntity2:

  • Namespace: \Application\Model\Entity\ Sub\ (first part is generated)

Actual result:
The entities are exported as:

  • Application/src/Model/Entity/Application/Model/Entity/MyEntity1.php.
  • Application/src/Model/Entity/Application/Model/Entity/Sub/MyEntity2.php.

Expected result:
What I would like is that the generated part of entity's namespace (blue in the UI) is stripped before the namespace is appended to the export path defined in the module's settings:

  • Application/src/Model/Entity/MyEntity1.php.
  • Application/src/Model/Entity/Sub/MyEntity2.php.
commented Feb 17, 2016 by ludek.vodicka Skipper developer (140,450 points)

Thanks for great explanation. I have to check it but I think it shouldn't be possible to update it in this way because other user can rely on this behavior.

For your current situation the simplest solution is to switch filename-format to entityname-only and use region to define Relative export path to sub

enter image description here

This will allow you to define any subdir you need and also all sub-directories will be visually represented via regions

commented Feb 17, 2016 by renaatdemuynck (840 points)

Thanks, that is the workaround I have been using so far but it seems a bit odd to define regions for every level in the namespace hierarchy.

Couldn't the behavior I propose be implemented by adding an extra option psr-4-namespaces to filename-format which strips the generated part of the namespace before exporting?

commented Feb 17, 2016 by ludek.vodicka Skipper developer (140,450 points)

It will have to be some new switch exactly like you wrote.

I only have to discuss with my colleagues if your way is the unified way how to export PSR-4 namespaces.

I think I read from another user that they are using also PSR-4 but exporting a whole namespace path. So it will have to be something like subdirectories-by-relative-namespace but it's a damn long ;-)

Please log in or register to answer this question.

...