fzaninotto / Faker

Faker is a PHP library that generates fake data for you
MIT License
26.79k stars 3.57k forks source link

Adding an autoloader #5

Closed willdurand closed 12 years ago

willdurand commented 12 years ago

Hi,

What about adding an autoloader for this lib ? And to set a "standard" directory structure as below:

 Faker
    |_ src/
    |    |_  Faker/
    |        |_ Provider/
    |        |_ Factory.php
    |        |_ Generator.php
    |_ tests/
         |_  Faker/
             |_ Provider/
             |_ FactoryTest.php
             |_ GeneratorTest.php

That will follow the PSR-0 standard and will ease integration in other projects. You won't have to provide a dependency with ClassLoader except for unit test or standalone usage (which is more or less the same thing).

See: https://github.com/knplabs/Gaufrette Note: Propel2 will follow the same standard.

fzaninotto commented 12 years ago

Yeah, not sure about that. The factory will work if you add an autoloaded Provider. But I'm not sure I'll add Yet Another Autoloader - or a dependency to PSR-0 autoloader.

willdurand commented 12 years ago

You should avoid require() methods too. And a PSR-0 autoloader is a standard, I guess you want to follow conventions for this lib :)

Le 15 oct. 2011 à 14:15, Francois Zaninottoreply@reply.github.com a écrit :

Yeah, not sure about that. The factory will work if you add an autoloaded Provider. But I'm not sure I'll add Yet Another Autoloader - or a dependency to PSR-0 autoloader.

Reply to this email directly or view it on GitHub: https://github.com/fzaninotto/Faker/issues/5#issuecomment-2415259

fzaninotto commented 12 years ago

Why should I avoid require()? Not way to to otherwise if I don't want to use an autoloader.

A PSR-0 autoloader is a dependency. For now, this project has none, and therefore is very easy to install. I'd like to keep that.

Besides, there are a lot of good libs that don't feel obliged to use an autoloader. See, for instance:

https://github.com/fabpot/yaml

2011/10/15 William DURAND < reply@reply.github.com>

You should avoid require() methods too. And a PSR-0 autoloader is a standard, I guess you want to follow conventions for this lib :)

Le 15 oct. 2011 14:15, Francois Zaninottoreply@reply.github.com a crit :

Yeah, not sure about that. The factory will work if you add an autoloaded Provider. But I'm not sure I'll add Yet Another Autoloader - or a dependency to PSR-0 autoloader.

Reply to this email directly or view it on GitHub: https://github.com/fzaninotto/Faker/issues/5#issuecomment-2415259

Reply to this email directly or view it on GitHub: https://github.com/fzaninotto/Faker/issues/5#issuecomment-2415796

ruudk commented 12 years ago

+1 for this.. I can't use this in my Symfony2 application because you don't have the "Faker" directory inside the src/ dir.

ruudk commented 12 years ago

Btw, the fabpot/yaml library is made for PHP 5.2 not 5.3

fzaninotto commented 12 years ago

So now we have a standard directory structure. But do we need an autoloader?

willdurand commented 12 years ago

If you want to avoid require and add use instead, probably yes. Otherwise no but I don't know if it will work fine.

fzaninotto commented 12 years ago

We already use use. And the Factory has some sort of autoloading for Providers with a cascade to default locale, that an autoloader won't allow. So I think we don't need a PSR-0 autoloader, and I think Faker works fine in projects that already have an autoloader.

I'll wait for more feedback, but I'll probably close this one.

willdurand commented 12 years ago

Mmmmh I meant to avoid this kind of statement: https://github.com/fzaninotto/Faker/blob/master/src/Faker/Factory.php#L5

fzaninotto commented 12 years ago

Yes, I got you loud and clear. But require isn't a bad word per se. There, requires allow any developer to start using the library without installing a third-party autoloader - right away.

yohang commented 12 years ago

Why not add a small autoload.php file (like the autoload function in https://wiki.php.net/rfc/splclassloader) for people that doesn't use an autoloader or use a not PSR-0 compatible autoloader ?

It could be a compromise beetween the requires and the dependency to an autoloader...

fzaninotto commented 12 years ago

Fixed by #13

willdurand commented 12 years ago

\o/