Chapter 8. HOW LIBRARY (.LIB) FILES ARE WORKING ?

Location: as source code files

Library files such nosod.lib have for goal to contain sets of functions and classes usable by the module source code. Isolating these functions and classes in a lib file provide an efficient way to avoid code redundancy.

What's the difference with a .INC file ?

The main difference is that .LIB content is managed by the framework like a source code document. This means the document is stored, versionned and extracted as the complete module code. Dot INC files are not managed by the document management engine of the framework. To benefit of the security with versionned source code, use .LIB files instead of Dot INC. Library files do not need php tags ($lt;?php ?>), .inc files need these tags.

How to manage session variables containing objects having their definition stored in a .LIB file ?

This question comes from the fact PHP regenerates objects at the session start statement. When the session starts (the php session, not the no-sod session... the session start statement is executed at every server hit) php needs to have available the class definitons of objects re-generated. If not, objects are lost. With .LIB files, the problem is that the class definition stored in a document object, are only available after the session start (as they are also session variables). In order to provide the possibility to put class definitions in .LIB files, every object of a .LIB that you want to register a session variable must be processed by the keepobject() function. So, to register an object, just call keepobject() and give the object name as argument. If you ask yourself how is it possible, the mechanism serializes all objects passed through the keepobject function before the end of the FLY execution. The FLY unserialize these serialized objects kept as session variable at the beginning of the FLY execution. Refer the FLY documentation for more details. Note that the keepobject function is a method of the session object (defined in the nsddms.inc file).

How to create a lib file for my module ?

Your module lib file name must begin with your module initials, and be a .lib extension. You must store the lib file in src/dev directory, with .src files. In order to declare your lib file to be loaded automatically by the framework, at your module login, you must put the name of your lib file (without the .lib) extension in the nsdmodule table of the system database, in the column 'libname'.