Refactoring towards ZF2 (subfolders)

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Refactoring towards ZF2 (subfolders)

dennis-fedco


I have an application where all its classes are in folder called ./class.

So, for example, I would have ./class/Device.php to host my class, because:
1) class folder holds my application's classes.  It is good to separate my classes from everything else
2) name of my class is there to differentiate in case I have more than one class

In a move towards ZF2, I moved the class elsewhere.  Specifically, here:

./module/DeviceModule/src/DeviceModule/Entity/Device.php

The path seems awfully long.  I want to check if I am doing it right.

My understanding is that:
1) module dir is to store any generic module, so it is 'needed'
2) DeviceModule is the name of *my* module, and it is there to differentiate from any other modules  I may want to create.  So this is also 'needed'.
3) src is there to separate "source code" from "other module stuff" like HTML, tests, templates.  
4) DeviceModule is there for namespace, in case I have more than one namespace in my module.  
5) Entity folder is there to store my "entity" classes
6) The name of my class
7) oh wait, there is no 7

Is there indeed the need for all these sub=folders?
Reply | Threaded
Open this post in threaded view
|

Re: Refactoring towards ZF2 (subfolders)

Ben Scholzen 'DASPRiD'
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Refactoring towards ZF2 (subfolders)

dennis-fedco
Thanks, well that's better.

I was going by ZF2 Module Structure (http://framework.zend.com/manual/2.2/en/modules/zend.mvc.intro.html.)

Right now, other developers will hate me for having to refer to my class like this:
"./module/Device/src/Device/Entity/Device.php"

because this entire 5-level-deep directory structure is set up for one class (at the moment).  Even when I have 10 classes there, the depths will remain the same.

I could instead do something like "./module/Device/src/Device/Device.php" to aid separation without too much depths, or even "./module/Device/Device/Device.php", but that's moving away from ZF2 structure and I want to go towards it.
Reply | Threaded
Open this post in threaded view
|

Re: Refactoring towards ZF2 (subfolders)

Stefano Torresi
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Refactoring towards ZF2 (subfolders)

dennis-fedco
hey

I got a little lost.
* why are there similar but different PSRs concerning paths and namespaces?
* what sis a "vendor specific prefix"?  In my case I am writing the app, so there is no 3rd party vendor.
* why is your 'Prefix' equals '/src'?  I thought a 'Prefix' is a descriptive name for a 3rd party module like '/vendor/ZfcUser/..'
* What is a Prefix?  Is that a namespace?  no... what's it for?  

So far I am thinking that I will put my classes into `module/Device` folder, but I am so confused right now I don't know what to do..  I might just leave it in 'module/Device/src/Device/Entity' like I have now, because when it will come for porting to ZF2, I will have my structure already in place.

I am not having a clear understanding on PSR-0, PSR-4 and which one to use and why.
Reply | Threaded
Open this post in threaded view
|

Re: Refactoring towards ZF2 (subfolders)

Stefano Torresi
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Refactoring towards ZF2 (subfolders)

dennis-fedco
This post was updated on .
Ah alright I think I get it a bit more.  So just to double-check

    my "module/Device/src/Device/Entity/Device.php"

will become

    "module/Device/src/Entity/Device.php"

in essence, saving me one depth level?

Alternative structures I can see are:

    module/Device/Device.php
    module/Device/src/Device.php (one I chose w/PSR-4 autoloading)

I guess the point DASPRiD made is that as long as I have module/Device/, I am ZF2-compliant, and can do whatever I want inside that folder, and answer only to developers I work with.