What is the best place for external libraries in a PHP project?

What is the best practice for finding external libraries in a PHP project (e.g. GoogleMapAPI, Recaptcha, etc.)? Now I have all the classes in / lib or their subdirectories, and I use the Zend convention for naming (for example, the Foo class is in /lib/Foo.php, the Db_Bar class is in /lib/Db/Bar.php).

But should I separate third-party things? If so, how? Where? Inside / whether? In the other place? Note. Autoloading these classes is not a problem, because they are always included / required explicitly where necessary (unlike my own classes).

THANKS!

+4
source share
4 answers

You are on the right track by putting everything in /lib . I would suggest dividing each into its own subfolder, as many libraries will have multiple files. So /lib/googlemaps , /lib/recaptcha , etc.

If you're still not sure, you can take a look at some structures like CodeIgniter. Joomla uses the system described above. They even have /lib/joomla for the entire Joomla framework.

There is no need to think too much about it. While it’s easy to find and enable libraries, don’t worry about it.

+4
source

This is usually the structure that I adhere to organizing my applications:

 myproject/ myproject/app myproject/app/controllers myproject/app/views myproject/app/models myproject/config myproject/log myproject/lib myproject/lib/external myproject/lib/external/Zend -> symlinked to -> /whatever/libraries/zend-1.xx/ myproject/lib/external/GoogleMaps/ -> symlinked to -> /whatever/libraries/gmaps-1.x/ myproject/lib/core (to my application) myproject/lib/core/Adapters/Rest.inc myproject/lib/core/Facades/SimpleTwitterApi.inc ....etc.... 

It is useful to have lib / external, because I usually symbolize different versions of libraries (Zend, etc.) and their updating becomes more manageable. In addition, if you are using version control, it is interesting to see how many commits are in lib / core or lib / external. Alternatively, you can use something like phploc to find out if the bulk of your code is in external libraries or in your kernel.

Btw, it's nice to hear that autoload is not a problem, and you explicitly include / require files as needed :)

+2
source

Failed to map to Linux best practices, for example. / usr / share with a lib hierarchy for each type of module?

0
source

You can always store the names and locations of files in the database if you do not want to store them on your server. You can then download them as needed using the stored information. In addition, this may prevent you from changing many web pages when you need to make changes.

0
source

All Articles