Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP: What should go in /Lib vs /Vendor vs /Plugin

I've been using CakePHP for a while and I still don't really understand what should go in /Lib vs /Plugin vs /Vendor. I know that plugins are basically mini apps with their own controllers, etc. But there are many situations when all three seem like ok options. Could someone shed some light on this?

like image 586
emersonthis Avatar asked Oct 02 '13 01:10

emersonthis


1 Answers

Lib

Contains 1st party libraries that do not come from 3rd parties or external vendors. This allows you to separate your organization’s internal libraries from vendor libraries.

Plugin

Contains plugin packages.

Vendor

Any third-party classes or libraries should be placed here. Doing so makes them easy to access using the App::import(‘vendor’, ‘name’) function. Keen observers will note that this seems redundant, as there is also a vendors folder at the top level of our directory structure. We’ll get into the differences between the two when we discuss managing multiple applications and more complex system setups.

Source: http://book.cakephp.org/2.0/en/getting-started/cakephp-folder-structure.html

To clarify further, Libis recommended for libraries that you write yourself. This may just be a few classes or entire libraries. Vendor is recommended for libraries or scripts that you may download from github for instance. Plugin is strictly for cakephp framework plugins.

Regarding Lib vs Vendor for you own scripts or 3rd party scripts there is no difference that I am aware of. I have put my own scripts in both as well as 3rd party scripts in both locations and it hasn't made any difference. It's just a recommended way to organize your files.

You can load your scripts from Lib or Vendor using App::import() which is the same as require_once(). To load framework files or your own scripts that follow cakephp conventions, you would use App::uses(). This uses the paths defined using App::path() or App::build() to find the files.

like image 140
Rob Avatar answered Oct 24 '22 07:10

Rob