|
Hi,
I wonder if there is any recommended structure for a module below the /src path. If we think of a news module with a more complex model structure we might have a couple of classes: entity, mapper, table, filter, interfaces, service... I can think of a couple of reasonable module structures: Structure 1: /module/News/src/News/Model/News.php /module/News/src/News/Model/NewsFilter.php /module/News/src/News/Model/NewsInterface.php /module/News/src/News/Model/NewsMapper.php /module/News/src/News/Model/NewsService.php /module/News/src/News/Model/NewsTable.php Structure 2: /module/News/src/News/Entity/News.php /module/News/src/News/Entity/NewsInterface.php /module/News/src/News/Filter/NewsFilter.php /module/News/src/News/Mapper/NewsMapper.php /module/News/src/News/Service/NewsService.php /module/News/src/News/Table/NewsTable.php Structure 3: /module/News/src/News/Entity/News.php /module/News/src/News/Entity/NewsInterface.php /module/News/src/News/Filter/News.php /module/News/src/News/Mapper/News.php /module/News/src/News/Service/News.php /module/News/src/News/Table/News.php Which one would you recommended? Or are there other structures you would prefer and why? Thanks and best regards, Ralf -- Ralf Eggert Geschäftsführer Travello GmbH An der Eiche 15 25421 Pinneberg Geschäftsführer: Ralf Eggert Amtsgericht Pinneberg HRB 6112 PI Tel: 04101/8529401 Fax: 04101/8529402 E-Mail: [hidden email] Web: http://www.travello.de |
|
/module/News/src/News/Entity/News.php
/module/News/src/News/Entity/NewsInterface.php
/module/News/src/News/Form/NewsFilter.php /module/News/src/News/Mapper/News.php /module/News/src/News/Mapper/NewsHydrator.php
/module/News/src/News/Mapper/NewsInterface.php
/module/News/src/News/Service/News.php On Tue, Aug 14, 2012 at 12:42 AM, Ralf Eggert <[hidden email]> wrote: Hi, |
|
I like structure 2, else you will end up with name collisions. You cannot reference the class News\Entity\News from you service class that has the same name unless you reference it like Entity\News:
<?php namespace News\Service; use News\Entity\News; class News // <-- Error, already in use. { public function persist(News $newsItem) // a possible solution for this would be to type hint like this: Entity\News { }} From: [hidden email] Date: Tue, 14 Aug 2012 01:33:09 -0400 To: [hidden email] CC: [hidden email] Subject: Re: [zf-contributors] Recommended module structure /module/News/src/News/Entity/News.php
/module/News/src/News/Entity/NewsInterface.php
/module/News/src/News/Form/NewsFilter.php /module/News/src/News/Mapper/News.php /module/News/src/News/Mapper/NewsHydrator.php
/module/News/src/News/Mapper/NewsInterface.php /module/News/src/News/Service/News.php On Tue, Aug 14, 2012 at 12:42 AM, Ralf Eggert <[hidden email]> wrote: Hi, |
|
I would use NewsInterface, not the class.
On Tue, Aug 14, 2012 at 3:36 AM, Walter Tamboer <[hidden email]> wrote:
|
|
In reply to this post by Walter Tamboer
To resolve your naming-colsisions you can always rename the used entity like
use News\Entity\News as NewsEntity Am 14.08.12 09:36, schrieb Walter Tamboer: > I like structure 2, else you will end up with name collisions. You > cannot reference the class News\Entity\News from you service class that > has the same name unless you reference it like Entity\News: > > > <?php > > > namespace News\Service; > > > use News\Entity\News; > > > class News // <-- Error, already in use. > { > > public function persist(News $newsItem) // a possible solution for > this would be to type hint like this: Entity\News > > { > > } > > } ,,, (o o) +---------------------------------------------------------ooO-(_)-Ooo-+ | Andreas Heigl | | mailto:[hidden email] N 50°22'59.5" E 08°23'58" | | http://andreas.heigl.org http://hei.gl/wiFKy7 | +---------------------------------------------------------------------+ | http://hei.gl/root-ca | +---------------------------------------------------------------------+ |
|
In reply to this post by Ryan Hutchison
Hi Ryan,
interesting. But what is the job of the NewsHydrator? Could you clarify? Thanks and best regards, Ralf |
|
In reply to this post by Ralf Eggert
Hi again,
could we use the ZendSkeletonModule to include a set of recommended subdirectories for the /src directory? https://github.com/zendframework/ZendSkeletonModule This would help to understand an unknown module much easier as if every module uses another structure. Best regards, Ralf |
|
On Tue, Aug 14, 2012 at 10:04 PM, Ralf Eggert <[hidden email]> wrote:
> Hi again, > > could we use the ZendSkeletonModule to include a set of recommended > subdirectories for the /src directory? > > https://github.com/zendframework/ZendSkeletonModule > > This would help to understand an unknown module much easier as if every > module uses another structure. No, the skeleton is really just meant to be a functional starting point for a new module, not an "example" module. Also, under src/, I'd argue there really is no "recommended" structure. You could follow the lead set by ZF-Commons modules if you want a specific structure to follow, I suppose. The recommendation for src/ is simply that under it you follow PSR-0, and preferably lead with a namespace matching your module namespace (though you can also have additional namespaces in your module if necessary). That's it. We've had too many discussions about structure, directory names, class names hierarchy, etc, on the ML in the past and it's clear there is really no agreement and everyone has their own opinions -- nothing constructive ever comes from the discussion. Anyway, my only opinion here is that no, the skeleton module is not the place to put any sort of recommended structure under src/ beyond what's already there to make it a functional starting point. There are places in the documentation for talking about the module structure: http://zf2.readthedocs.org/en/latest/modules/zend.mvc.intro.html#basic-module-structure Feel free to propose a change to that page in the documentation if you have some specific recommendation you want to propose. (PS: Git does not support empty directories, so we'd end up with a bunch of empty .gitignore files or shell classes for no reason anyway -- yet another reason not to do this in the skeleton module.) -- Evan Coury. |
|
Hi Evan,
thanks for clarifying. Makes sense to me. So it is really up to me how to handle this structure. > http://zf2.readthedocs.org/en/latest/modules/zend.mvc.intro.html#basic-module-structure This leads me to another question. I see the public/ directory in the module structure. I remember a discussion about providing mechanisms to copy or link these module public directories to the main public/ of the Application. From the manual: How these are exposed is left to the developer. Does mean, that there are no mechanisms yet? If not, how do others do this? Best regards, Ralf |
|
2012/8/15 Ralf Eggert <[hidden email]> -- This leads me to another question. I see the public/ directory in the You could use rewrite rules (for Apache or nginx) to link from your webroot to the modules public directories. You could also copy the contents into the webroot when you deploy your application. A third option (and as far as I see, the most preferred one) is to use symlinks to link into your module public directory.
It's up to your personal preference what you like the most. Jurian Sluiman |
|
Hi Jurian,
I would also prefer the symlinks, though, when it comes to reusable modules, it might not work properly for the poor souls that a stuck with Windows XP on there development machine. Regards, Ralf |
|
Administrator
|
-- Ralf Eggert <[hidden email]> wrote
(on Wednesday, 15 August 2012, 11:16 AM +0200): > I would also prefer the symlinks, though, when it comes to reusable > modules, it might not work properly for the poor souls that a stuck with > Windows XP on there development machine. True -- but considering that Microsoft stopped supporting XP quite some time ago, I also don't know that it makes sense for us to support it, either. -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
I'd like to state that symlinks are FAR from being common on shared hostings (at least in Czech Republic, not sure how about other countries).
On Wed, Aug 15, 2012 at 6:16 PM, Matthew Weier O'Phinney <[hidden email]> wrote: -- Ralf Eggert <[hidden email]> wrote |
|
On Wed, Aug 15, 2012 at 10:09 AM, Tomáš Fejfar <[hidden email]> wrote:
> I'd like to state that symlinks are FAR from being common on shared hostings > (at least in Czech Republic, not sure how about other countries). This is actually news to me -- Admittedly it's been well over 5 years since I've used shared hosting, but AFIAK every shared host I've ever used has supported symlinks just fine. Interesting to hear that symlink support in shared hosting is the exception, not the rule. -- Evan Coury |
|
the same is in Slovak republic (on many shared hostings)
On 08/15/2012 07:25 PM, Evan Coury wrote: > On Wed, Aug 15, 2012 at 10:09 AM, Tomáš Fejfar <[hidden email]> wrote: >> I'd like to state that symlinks are FAR from being common on shared hostings >> (at least in Czech Republic, not sure how about other countries). > This is actually news to me -- Admittedly it's been well over 5 years > since I've used shared hosting, but AFIAK every shared host I've ever > used has supported symlinks just fine. Interesting to hear that > symlink support in shared hosting is the exception, not the rule. > > -- > Evan Coury |
|
I accidentally send it only to Evan. There is a symlink function, that works probably everywhere (I never used it and I was not aware it even exists - I'm on windows where it doesn't work or needs elevated privledges). I created a quick test script. Try to run it. It lists files, create symlink of file, lists again, unlink it, lists again. I tested it on UNIHOST.cz and TOJEONO.cz and works fine.
<?php ini_set('display_errors', 'on'); error_reporting(E_ALL); echo __LINE__ . PHP_EOL; var_dump(glob('*.php')); symlink('test.php', 'target.php');
echo __LINE__ . PHP_EOL; var_dump(glob('*.php')); unlink('target.php'); echo __LINE__ . PHP_EOL; var_dump(glob('*.php'));
On Wed, Aug 15, 2012 at 8:35 PM, Lukas Vlk <[hidden email]> wrote: the same is in Slovak republic (on many shared hostings) |
|
Sorry to cut in, but thought I'd add some info as well. Personally I
love the symlink idea. With that said, Apache has to be setup to follow symlinks for this to work for the public folder. As this is an option that is not turned on by default symlinks should be not be considered universal. Just my .02 Westin On Wed, 2012-08-15 at 13:39 -0500, Tomáš Fejfar wrote: > I accidentally send it only to Evan. There is a symlink function, that > works probably everywhere (I never used it and I was not aware it even > exists - I'm on windows where it doesn't work or needs elevated > privledges). I created a quick test script. Try to run it. It lists > files, create symlink of file, lists again, unlink it, lists again. I > tested it on UNIHOST.cz and TOJEONO.cz and works fine. > > > <?php > ini_set('display_errors', 'on'); > error_reporting(E_ALL); > echo __LINE__ . PHP_EOL; > var_dump(glob('*.php')); > symlink('test.php', 'target.php'); > echo __LINE__ . PHP_EOL; > var_dump(glob('*.php')); > unlink('target.php'); > echo __LINE__ . PHP_EOL; > var_dump(glob('*.php')); > > On Wed, Aug 15, 2012 at 8:35 PM, Lukas Vlk <[hidden email]> wrote: > the same is in Slovak republic (on many shared hostings) > > On 08/15/2012 07:25 PM, Evan Coury wrote: > On Wed, Aug 15, 2012 at 10:09 AM, Tomáš Fejfar > <[hidden email]> wrote: > I'd like to state that symlinks are FAR from > being common on shared hostings > (at least in Czech Republic, not sure how > about other countries). > This is actually news to me -- Admittedly it's been > well over 5 years > since I've used shared hosting, but AFIAK every shared > host I've ever > used has supported symlinks just fine. Interesting to > hear that > symlink support in shared hosting is the exception, > not the rule. > > -- > Evan Coury > > |
|
Administrator
|
-- Westin Shafer <[hidden email]> wrote
(on Thursday, 16 August 2012, 08:06 AM -0500): > Sorry to cut in, but thought I'd add some info as well. Personally I > love the symlink idea. With that said, Apache has to be setup to follow > symlinks for this to work for the public folder. As this is an option > that is not turned on by default symlinks should be not be considered > universal. That's the problem in a nutshell -- there's no real universal solution available short of copying the files from the module into the public tree -- which either (a) inflates the size of your repository, and/or (b) requires an additional deployment step (though symlinks do as well, to a degree). > On Wed, 2012-08-15 at 13:39 -0500, Tomáš Fejfar wrote: > > I accidentally send it only to Evan. There is a symlink function, that > > works probably everywhere (I never used it and I was not aware it even > > exists - I'm on windows where it doesn't work or needs elevated > > privledges). I created a quick test script. Try to run it. It lists > > files, create symlink of file, lists again, unlink it, lists again. I > > tested it on UNIHOST.cz and TOJEONO.cz and works fine. > > > > > > <?php > > ini_set('display_errors', 'on'); > > error_reporting(E_ALL); > > echo __LINE__ . PHP_EOL; > > var_dump(glob('*.php')); > > symlink('test.php', 'target.php'); > > echo __LINE__ . PHP_EOL; > > var_dump(glob('*.php')); > > unlink('target.php'); > > echo __LINE__ . PHP_EOL; > > var_dump(glob('*.php')); > > > > On Wed, Aug 15, 2012 at 8:35 PM, Lukas Vlk <[hidden email]> wrote: > > the same is in Slovak republic (on many shared hostings) > > > > On 08/15/2012 07:25 PM, Evan Coury wrote: > > On Wed, Aug 15, 2012 at 10:09 AM, Tomáš Fejfar > > <[hidden email]> wrote: > > I'd like to state that symlinks are FAR from > > being common on shared hostings > > (at least in Czech Republic, not sure how > > about other countries). > > This is actually news to me -- Admittedly it's been > > well over 5 years > > since I've used shared hosting, but AFIAK every shared > > host I've ever > > used has supported symlinks just fine. Interesting to > > hear that > > symlink support in shared hosting is the exception, > > not the rule. > > > > -- > > Evan Coury > > > > > -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
On Thursday, August 16, 2012 at 4:12 PM, Matthew Weier O'Phinney wrote: > -- Westin Shafer <[hidden email] (mailto:[hidden email])> wrote > (on Thursday, 16 August 2012, 08:06 AM -0500): > > Sorry to cut in, but thought I'd add some info as well. Personally I > > love the symlink idea. With that said, Apache has to be setup to follow > > symlinks for this to work for the public folder. As this is an option > > that is not turned on by default symlinks should be not be considered > > universal. > > > > That's the problem in a nutshell -- there's no real universal solution > available short of copying the files from the module into the public > tree -- which either (a) inflates the size of your repository, and/or > (b) requires an additional deployment step (though symlinks do as well, > to a degree). If the symlinks are not an option I'd probably use a build tool locally (just to avoid the manual steps of copying and forgetting half of it) before you upload to your shared host. Another option could be setting up a 404 handler via a ZF controller and piping everything through PHP. This is neither pretty or "even" fast, but it works well. ;-) Till |
|
I'm in the camp of "there is more than one way to do it" and as the
thread has already shown there is a number of options available. personally I prefer an alias in my vhost and am not a fan of symlinks but thats neither here nor there. Push come to shove we shouldn't be enforcing one specific option on people and merely provide a list of possible solutions for individual developers to select the one that suits them best. The one thing we should be asking developers to document the method that needs to be implemented (or even document multiple ways to implement to suit all possible methods i.e. symlinks, alias, copy, etc) when others install a module that they have developed. Matt On 8/16/12, till <[hidden email]> wrote: > > > On Thursday, August 16, 2012 at 4:12 PM, Matthew Weier O'Phinney wrote: > >> -- Westin Shafer <[hidden email] (mailto:[hidden email])> >> wrote >> (on Thursday, 16 August 2012, 08:06 AM -0500): >> > Sorry to cut in, but thought I'd add some info as well. Personally I >> > love the symlink idea. With that said, Apache has to be setup to follow >> > symlinks for this to work for the public folder. As this is an option >> > that is not turned on by default symlinks should be not be considered >> > universal. >> >> >> >> That's the problem in a nutshell -- there's no real universal solution >> available short of copying the files from the module into the public >> tree -- which either (a) inflates the size of your repository, and/or >> (b) requires an additional deployment step (though symlinks do as well, >> to a degree). > > > If the symlinks are not an option I'd probably use a build tool locally > (just to avoid the manual steps of copying and forgetting half of it) before > you upload to your shared host. > > Another option could be setting up a 404 handler via a ZF controller and > piping everything through PHP. This is neither pretty or "even" fast, but it > works well. ;-) > > Till > -- Matt Cockayne *Zucchi ! Digital Perfection* Managing Director *e:* [hidden email] *t:* +44 (0) 843 557 1751 *m:* +44 (0) 773 836 4766 *w:* zucchi.co.uk *a:* 26 Avon Rd / Cheadle / Cheshire / SK8 3LS *sk:* matt.cockayne *tw:* @mattcockayne <http://twitter.com/#!/mattcockayne> *in:* matthewcockayne <http://www.linkedin.com/in/matthewcockayne> Click for Email Disclaimer <http://zucchi.co.uk/legals/email-disclaimer> |
| Powered by Nabble | Edit this page |
