views:

81

answers:

2

there are plenty of frameworks for coding MVC web applications.

this time im going to code a library (think of Doctrine or Solr) with a bunch of class files. u just include a bootstrap or a class file and you are ready to use my classes.

i have never tried to code a library before and intend to code one for learning purpose so that i can use various design patterns i have learned.

are there any great frameworks for this, how i should organize the different class files, where i can put configuration files and so on?

tutorials or other information would be great too.

thanks

UPDATE: its just in general, not something specific. im wondering if there is a "pattern" just like for web applications (MVC): should it be one file he includes and that file will include all other class files? should it be a class file he includes or a so called bootstrap file? in short, i need to know how to code a library so every developer could use it the open source way

+2  A: 

There are no general library frameworks. You will find plugin APIs, or similar, if you are developing for other software. In that case, use them. Otherwise, there are no assumptions to be made on how a library should work and therefore no framework, other than a programming language, to house it.

All libraries tend to have a bootstrap though that include all other essential files. Additional classes and files might be loaded through a registered autoloader.

erisco
+2  A: 

Library code covers so many diverse areas that it's hard to imagine a general framework for library development.

Generally speaking, you should strive to create a library that is (among other things):

  • Consistent - Your library's API should be as consistent as possible. For example: do you pass standard argument lists to constructors, or a single $config array containing name/value pairs? If you favor factory methods, implement them consistently across the whole library.

  • Efficient - avoid loading classes that aren't needed. Figure out how to manage dependencies - don't just load every class from some central bootstrap script. Consider a directory structure like that used by PEAR or Zend Framework. This can help you integrate with various autoloaders that your users may already be using.

  • Testable - a library with good tests that cover it is more valuable than one without.

  • Documented - Get cozy with PHPDocumentor, and be prepared to write additional documentation that is heavy on example client code.

timdev
are there good tutorials about how to create a library?
never_had_a_name