Frage

I've been using a tiny and neat caching library on my projects, but I realize that "Cache" is a very generic name and it's easy to get a collision when using it in large projects.

Also, I would like to publish it in Github in order to share it with colleagues and make it easy for all of us to install using composer.

The problem is that I don't really get all this PSR-4 recommendations.

How should I structure my folders? How should I namespace the library? And how should I autoload it from within my projects?

What I need is probably a very comprehensive composer tutorial, that I wasn't able to find yet...

War es hilfreich?

Lösung

As GordonM mentioned in the comment, you should break it up to something along the lines of

\Vendor\Package\ClassName

So maybe for your cache library it would be something along the lines of

\SG\Cache\CacheClass

Directory structures usually mirror the above. So it'd be located in /SG/Cache/CacheClass.php of your root directory. If you're using a particular framework there should be some documentation on namespace usage for the framework.

Lizenziert unter: CC-BY-SA mit Zuschreibung
scroll top