Package Overview
When working with PEAR::Calendar, there are a total of 12 (public) classes available for you to use, depending on the particular problem you are trying to solve.
They can be grouped in date classes, tabular date classes, validation classes and decorators.
Decorators
Provide a mechanism to add functionality to the main calendar objects (the subclasses of Calendar) without needing to directly extend them (and risk overwriting fields accidentally). When you create a decorator, you pass it's constructor an instance of an existing calendar object. You can then make calls to the decorator in exactly the same way as you make calls to the original calendar object. This allows you to "overwrite" calendar methods, add new methods or even apply multiple decorators to the same calendar object. Decorators a typically either "injected" (via selection or the Calendar_Decorator_Wrapper decorator) into the loop where the calendar is rendered and / or to alter the output content (e.g. convert a numeric month into a textual month: 1 => January).
PEAR::Calendar provides some decorator implementations for you, to help with common tasks. These are not designed to suit everyone and hence are provided as optional code for you to use as needed (avoiding the performance cost associated with parsing code you're not using).
Calendar_Decorator - this is the base decorator class which you should extend with your own. It provides the same API as the calendar object it is decorating, and simply routes calls through to it. Example;
| require_once 'Calendar/Decorator.php';
class ChristmasDecorator extends Calendar_Decorator
{
function ChristmasDecorator(&$Calendar)
{
parent::Calendar_Decorator($Calendar);
}
// Some method I've added
function getDaysToChristmas()
{
$today = parent::thisDay(true);
$Christmas = new Calendar_Day(date('Y'), 12, 25);
$xmasday = $Christmas->thisDay(TRUE);
$diff = $xmasday - $today;
if ($diff < 0) {
$NextChristmas = new Calendar_Day($Christmas->nextYear(), 12, 25);
$nextxmasday = $NextChristmas->thisDay(true);
$diff = $today - $nextxmasday;
}
return ($diff / 86400);
}
} |
Calendar_Decorator_Uri - provides a decorator to help with generating URLs (for example next / prev URLs).
Include with
| require_once 'Calendar/Decorator/Uri.php'; |
.Calendar_Decorator_Textual - helps with obtaining textual month names and weekday names from a calendar object.
Include with
| require_once 'Calendar/Decorator/Textual.php'; |
.Calendar_Decorator_Wrapper - is intended to help you add decorators to the children of the calendar object you are working with. It will wrap the children in the decorator you specify at the point fetch() or fetchAll() is called, after a build build() call.
Include with
| require_once 'Calendar/Decorator/Wrapper.php'; |
.