Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

guides for writing php libraries? [closed]

Tags:

php

i have studied design patterns and want to use them to code an open source library (not an application).

but i have never coded a library before and don't know where should i include files, should i have a bootstrap file that loads everything or should every class load their own classes they are dependent on etc.

are there any tutorials for writing libraries in php from start to finnish?

thanks

like image 742
never_had_a_name Avatar asked May 07 '10 23:05

never_had_a_name


3 Answers

I can't point you to a tutorial, but the easiest way to have a plug and play library is to have one class per class file, so that the user has the option to use __autoload and simply instantiate your classes without having to change anything in their existing code. This way is most accessible to most developers.

This method still allows you to create one 'standalone' include file that includes all your other class files.

Other options include making it into a PEAR package or asking people to place your files in the include path. However this is not optimal in my opinion for people who don't have access to anything other than their own public_html folder (on shared hosting, for example).

like image 129
Lotus Notes Avatar answered Nov 02 '22 03:11

Lotus Notes


You should have a look at the Solarphp Framework. It solves like every other frameworks some standard issues like autoloading, dependeny injection etc... I learned a lot about writing good php code from it. If you have questions join #solar-talk at freenode

like image 2
kalkin Avatar answered Nov 02 '22 03:11

kalkin


I'd point you to Zend Framework. You can use it as a whole framework, but can also use selected components as you like. yes, i think to a library, autoloading is the key.

like image 1
Jim Li Avatar answered Nov 02 '22 03:11

Jim Li