The Library class' purpose is to simplify the inclusion of dependencies between classes. Under the covers Library uses an autoloading mechanism and some other techniques to ensure high-performance in applications that use Recess Core's functionalities. These caching and script compilation techniques will be discussed in-depth later.

Library's most useful static methods are addClassPath and import. Library maintains a list of directories it attempts to find an imported class in. The exact location of imported class files can be cached by Library to avoid hitting disk multiple times to locate single files. The order in which paths are added to Library using addClassPath is important. When attempting to import a class paths are checked from the most-recently added to the least-recently added using addClassPath. The Recess Framework uses this mechanism to allow classes defined in plugins/ to take precedence over recess/, and classes in apps/ to take precedence over plugins/.

Library's import style is inspired by Java/C# imports and is a stylistic difference from libraries like the Zend Framework. Suppose the following directory structure:

/public_html
   /foo
       ClassA.class.php
       /bar
           ClassB.class.php

These classes can be imported using Library with the following snippet of PHP:


If you ever need to use use Library and Recess classes in PHP files outside of the Recess Framework it requires setting up some environment variables and using include on Library directly. The following snippet can be placed into a php script and included by plain-old PHP files.


These directory paths may need to be tweaked depending on where you've extracted the Recess distribution. Explanations for each of these environment variables follows:

$_ENV['dir.bootstrap'] - The absolute directory that contains the bootstrap file. This is a helper variable that simplifies defining the other environment directories by reference.

$_ENV['dir.recess'] - The base directory for Recess' source files. This directory should contain two subdirectories: recess/ and test/.

$_ENV['dir.temp'] - A directory that is writable by PHP scripts. This directory is used by Recess to store temporary data such as cached data structures or compiled scripts.

$_ENV['url.base'] - This is the base URL path that relative URLs should be constructed from. Outside of the Recess Framework this is less meaningful. Recess uses it for mapping routes, and generating URLs in view helpers.