<?php
//
// +--------------------------------------------------------------------+
// | Sourdough PHP Application Framework |
// +--------------------------------------------------------------------+
// | Copyright (c) 2001-2007 Philip Iezzi, phpee.com |
// | Web http://sourdough.phpee.com/ |
// | License GNU Lesser General Public License (LGPL) |
// +--------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU Lesser General Public |
// | License as published by the Free Software Foundation; either |
// | version 2.1 of the License, or (at your option) any later version. |
// +--------------------------------------------------------------------+
//
/**
* Sourdough PHP Application Framework
* @package sourdough
* @subpackage xslt
*/
/**
* SOURDOUGH XSLT object factory
*
* Static factory class to produce XSLT transformation objects.
* Detects the available libraries automatically and includes the needed class files.
*
* @static
* @package sourdough
* @subpackage xslt
* @author Philip Iezzi <pipo at phpee dot com>
* @copyright Copyright (c) 2001-2007 PHPEE.COM
* @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
* @version $Id: Sd_XsltFactory.class.php 3003 2007-12-08 11:05:17Z piezzi $
*/
class Sd_XsltFactory {
//[start] Constants
/**
* Sablotron XSLT processor
*/
const ENGINE_SABLOT = 'sablot';
/**
* DOMXML XSLT processor
*/
const ENGINE_DOM = 'dom';
/**
* XSLTPROC XSLT processor
*/
const ENGINE_XSLTPROC = 'xsltproc';
/**
* Xalan XSLT processor
*/
const ENGINE_XALAN = 'xalan';
/**
* PHP5 built-in XSLT processor
*/
const ENGINE_PHP5 = 'php5';
//[end]
//[start] Local Variables
/**
* XSLT configuration
*
* @var array
*/
private static $conf = array();
//[end]
//[start] Constructor
/**
* Protect constructor since it is a static only class.
*/
protected function __construct() {}
//[end]
//[start] Public Methods
/**
* Create a new Xslt object
*
* @param Sourdough $Sourd Sourdough framework core object
* @return Sd_Xslt Newly created Xslt object
*/
public static function getXslt(Sourdough $Sourd)
{
self::$conf = $Sourd->getConf('xslt');
if (self::$conf['force_engine']) {
if(!self::engine_available(self::$conf['engine']))
Sd_ErrorManager::raiseError(0, "Could not load XSLT engine (" . self::$conf['engine'] . ").");
$engine = self::$conf['engine'];
} else {
if (self::engine_available(self::ENGINE_PHP5)) {
$engine = self::ENGINE_PHP5;
} else if (self::engine_available(self::ENGINE_XSLTPROC)) {
$engine = self::ENGINE_XSLTPROC;
} else if (self::engine_available(self::ENGINE_DOM)) {
$engine = self::ENGINE_DOM;
} else if (self::engine_available(self::ENGINE_SABLOT)) {
$engine = self::ENGINE_SABLOT;
} else if (self::engine_available(self::ENGINE_XALAN)) {
$engine = self::ENGINE_XALAN;
} else {
Sd_ErrorManager::raiseError(0, "Could not load any XSLT engine.");
}
}
$phpext = $Sourd->getConf('php_ext');
$path = dirname(__FILE__).'/';
include_once($path.'Sd_Xslt.class.'.$phpext);
include_once($path.'Sd_Xslt_'.$engine.'.class.'.$phpext);
$class = 'Sd_Xslt_'.$engine;
return new $class($Sourd);
}
//[end]
//[start] Protected/Private Methods
/**
* Check if an engine is available
*
* @param string $engine XSLT engine
* @return boolean true if engine is available
*/
private static function engine_available($engine)
{
switch($engine) {
case self::ENGINE_PHP5:
return class_exists('xsltprocessor');
case self::ENGINE_XSLTPROC:
return @file_exists(self::$conf['xsltproc_bin']);
case self::ENGINE_DOM:
return function_exists('domxml_xslt_stylesheet');
case self::ENGINE_SABLOT:
return function_exists('xslt_create');
case self::ENGINE_XALAN:
return @file_exists(self::$conf['xalan_bin']);
default:
return false;
}
}
//[end]
}
?>