English Yacs handbook Developer's guide

Static and dynamic PHP classes

YACS relies heavily on object-oriented programmation. However, the number of object instances is rather small. Why?

This is quite a complex question, but generally speaking dynamic classes make sense only if you have to maintain internal data. Else static classes make the fit for less overhead, without the need for instanciation, etc.

So YACS is built with a simple rule of thumb: if there are some information to take care of, create an object instance, else, use a static library.

In YACS all data libraries can be invoked as static classes. For example, to get a list of most recent articles you would write:
$items Articles::list_by_date(010);


By the way, all scripts related to database management is named after its module. For example, the script articles/articles.php is the static class used to save articles in the database, or to retrieve them.

Data and operations related to the surfer, meaning, the person (or the dog) that is browsing your site, have been grouped in a static class as well. For example, to assert if the surfer has been authenticated as a valid associates of the site, you would write:
if(Surfer::is_associate()) {
   ...


Several global resources of this kind are available. Most of the rendering engine is accessible through the Skin class. For example, to build a link, you would write:
$link Skin::build_link('www.cisco.com''Cisco');


If you have to purge the cache, just write:
Cache::clear();


On the other hand, YACS uses object instances mostly to handle contextual resources. For example, to get the container of an article, you would write:
$anchor get_anchor('article:123');


From there, as usual with object instances, you can use member functions to proceed. For example, to print the title of the container of an article, you would say:
echo $anchor->get_title();


Object instances in YACS are quite easy to locate, because they are all derivated from a reduced set of core interfaces. Most important include: - anchor - defined in shared/anchor.php- overlay - defined in overlays/overlay.php- behavior - defined in behaviors/behavior.php By convention, anchor implementations are scripts placed in their respective modules. For example articles/article.php is the anchor implementation for articles.

You also have to know that all overlay implementations are placed into the directory overlays, and that all behavior implementations are under behaviors.