Getting Started with Zend Framework 2

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

Getting Started with Zend Framework 2

BullfrogBlues

Reading the getting started docs and confused by something:

"Note that as we are using Composer, as an alternative, you could not implement
getAutoloaderConfig() and instead add "Application":
"module/Application/src" to the psr-0 key in composer.json. If you go
this way, then you need to run php composer.phar update to update the
composer autoloading files."

- http://packages.zendframework.com/docs/latest/manual/en/user-guide/modules.html#autoloading-files

I don't understand what this means.

--
BB

     
Reply | Threaded
Open this post in threaded view
|

Re: Getting Started with Zend Framework 2

weierophinney
Administrator
-- Gerry - <[hidden email]> wrote
(on Friday, 03 August 2012, 01:04 PM +0100):

>
> Reading the getting started docs and confused by something:
>
> "Note that as we are using Composer, as an alternative, you could not implement
> getAutoloaderConfig() and instead add "Application":
> "module/Application/src" to the psr-0 key in composer.json. If you go
> this way, then you need to run php composer.phar update to update the
> composer autoloading files."
>
> - http://packages.zendframework.com/docs/latest/manual/en/user-guide/modules.html#autoloading-files
>
> I don't understand what this means.

It means that if your composer.json reads something like this:

    {
        "autoload": {
            "psr-0": {
                "Application": "module/Application/src"
            }
        },
        "require": {
            "php": ">=5.3.3",
            "zendframework/zendframework": "dev-master"
        }
    }

then composer will be able to autoload the classes in your Application
module once you've run "php composer.phar install".

--
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

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

RE: Getting Started with Zend Framework 2

BullfrogBlues





> Date: Fri, 3 Aug 2012 09:12:14 -0500
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [fw-general] Getting Started with Zend Framework 2
>
> -- Gerry - <[hidden email]> wrote
> (on Friday, 03 August 2012, 01:04 PM +0100):
> >
> > Reading the getting started docs and confused by something:
> >
> > "Note that as we are using Composer, as an alternative, you could not implement
> > getAutoloaderConfig() and instead add "Application":
> > "module/Application/src" to the psr-0 key in composer.json. If you go
> > this way, then you need to run php composer.phar update to update the
> > composer autoloading files."
> >
> > - http://packages.zendframework.com/docs/latest/manual/en/user-guide/modules.html#autoloading-files
> >
> > I don't understand what this means.
>
> It means that if your composer.json reads something like this:
>
>     {
>         "autoload": {
>             "psr-0": {
>                 "Application": "module/Application/src"
>             }
>         },
>         "require": {
>             "php": ">=5.3.3",
>             "zendframework/zendframework": "dev-master"
>         }
>     }
>
> then composer will be able to autoload the classes in your Application
> module once you've run "php composer.phar install".
>
> --
> 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
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>

Ok. I think I understand. I can use composer to do autoloading, thus elimating the getAutoloaderConfig() methods in modules?

--
Gerry


     
Reply | Threaded
Open this post in threaded view
|

Re: Getting Started with Zend Framework 2

Artur Bodera
On Sat, Aug 4, 2012 at 12:06 AM, Gerry - <[hidden email]> wrote:

> Ok. I think I understand. I can use composer to do autoloading, thus
> elimating the getAutoloaderConfig() methods in modules?
>

Yes - if you're talking about private modules that are used only by you, or
you commit to _always_ using composer (today and in the future)

No - if your modules will be used in other projects (yours or public) or in
the future you might stop using composer. getAutoloaderConfig() registers
spl autoloader that are shipped with ZF2, so this method will always work
in plain PHP and ZF 2.0, 2.1, 2.2 etc. and maybe even in 3.0. Also there is
no harm in having both - if you installed the module via composer, composer
autoloader will be used. If the composer autoloader is not present (or
cannot find the class), ZF2 autoloader will come in to finish the job....
all that assuming you have had getAutoloaderConfig() present.




--
      __
     /.)\   +48 695 600 936
     \(./   [hidden email]
Reply | Threaded
Open this post in threaded view
|

RE: Getting Started with Zend Framework 2

BullfrogBlues





> From: [hidden email]
> Date: Sat, 4 Aug 2012 09:31:17 +0200
> To: [hidden email]
> CC: [hidden email]
> Subject: Re: [fw-general] Getting Started with Zend Framework 2
>
> On Sat, Aug 4, 2012 at 12:06 AM, Gerry - <[hidden email]> wrote:
>
> > Ok. I think I understand. I can use composer to do autoloading, thus
> > elimating the getAutoloaderConfig() methods in modules?
> >
>
> Yes - if you're talking about private modules that are used only by you, or
> you commit to _always_ using composer (today and in the future)
>
> No - if your modules will be used in other projects (yours or public) or in
> the future you might stop using composer. getAutoloaderConfig() registers
> spl autoloader that are shipped with ZF2, so this method will always work
> in plain PHP and ZF 2.0, 2.1, 2.2 etc. and maybe even in 3.0. Also there is
> no harm in having both - if you installed the module via composer, composer
> autoloader will be used. If the composer autoloader is not present (or
> cannot find the class), ZF2 autoloader will come in to finish the job....
> all that assuming you have had getAutoloaderConfig() present.
>
>
>
>
> --
>       __
>      /.)\   +48 695 600 936
>      \(./   [hidden email]


Ok. So the recommendation is that each module ensure that it can be autoloaded by taking advantage of getAutoloaderConfig(), then autoloading will work with or without composer.

If you install composer you can configure composer to autoload modules and generally speaking, the composer autoloader will be hit first, falling back to the module autoloader, falling back to zf. I'm assuming that the zf autoloader in this case can be configured in the same way that the composer autoloader is. Nonetheless, modules should still ensure themselves that they can be autoloaded as a best practice for flexibility across different environments, etc.

So the flow of autoloading is: composer -> module (via getAutoloaderConfig()) -> zf (base/fallback).

I cloned the ZSkeletonApp rather download the zip, then ran the composer install and noticed an empty `vendor/ZF2` folder. I'm assuming that if I clone recursivly or use git to init & update the submodules zf will be cloned into that ZF2 directory and that composer installing zf in a different directory is intentional.
The directory structure for the zf install by composer is unnecessary too. Is there any reasoning to it? A shorter one would have made more sense to me i.e. `/vendor/zf/library/...` oppose to `/vendor/zendframework/zendframework/library/...`.

--
Gerry