Guidelines for writing php libraries?

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 I don’t know where I should include the files, should I have a boot file that loads everything, or each class loads its own classes on which they depend, etc.

Are there any tutorials for writing libraries in php from start to Finnish?

thanks

+4
source share
5 answers

I cannot point you to a tutorial, but the easiest way to have a plug and play library is to have one class for each class file so that the user can use __autoload and just instantiate your classes without having to change anything in their existing code . This method is most accessible to most developers.

This method still allows you to create one standalone include file that includes all of your files from other classes.

Other options include including it in a PEAR package or requesting the placement of files in the include path. However, this is not optimal, in my opinion, for people who do not have access to anything other than their own public_html folder (for example, on shared hosting).

+4
source

You should take a look at the Solarphp Framework . It solves, like any other structure, some standard problems, such as startup, dependency on injections, etc. .... I learned a lot about writing good PHP code. If you have questions, join # solar-talk on freenode

+2
source

I would point you to the Zend Framework. You can use it as a whole, but you can also use the selected components as you wish. yes, I think autoload is the key to the library.

+1
source

If your library performs any checks or string manipulations, consider whether they should be byte strings or strings of text characters, and if the latter use only a multibyte string, it works with them, and not with ordinary PHP string strings. Otherwise, your library will not be used for people who need to work with Unicode text.

+1
source

There are many PHP frameworks that can help you create library files. But I always prefer MVC models with a lot of hook functions with common formats. A few of the examples below ...

  # o = Object
 # r = Return
 # a = Array
 # e = Element
 # g = Global declaration
 # hook = a function which can be used for hooking with other functions
 # call = a function which can be used for making call from client to server system
 # sync = a function which can be used for SYNC
-1
source

Source: https://habr.com/ru/post/1309158/


All Articles