Source for file Factory.php
Documentation is available at Factory.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* ScriptReorganizer :: Factory
* LICENSE: 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
* @package ScriptReorganizer
* @author Stefano F. Rausch <stefano@rausch-e.net>
* @copyright 2005 Stefano F. Rausch <stefano@rausch-e.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @link http://pear.php.net/package/ScriptReorganizer
* @since File available since Release 0.4.0
* Throws <kbd>ScriptReorganizer_Factory_Exception</kbd>
require_once 'ScriptReorganizer/Factory/Exception.php';
* Throws <kbd>ScriptReorganizer_Type_Decorator_Exception</kbd>
require_once 'ScriptReorganizer/Type/Decorator/Exception.php';
* Factory/Facade for easy <kbd>ScriptReorganizer_Type</kbd> object creation
* @package ScriptReorganizer
* @author Stefano F. Rausch <stefano@rausch-e.net>
* @copyright 2005 Stefano F. Rausch <stefano@rausch-e.net>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version Release: @package_version@
* @link http://pear.php.net/package/ScriptReorganizer
* @since Class available since Release 0.4.0
// {{{ public static function create( $type, $strategy [, $decorator ...] )
* Creates on object according to the specifications supplied classes-wise
* The names of the classes declared - the last differentiating part - are
* case-sensitive. E.g., <kbd>ScriptReorganizer_Type_Script</kbd> has to be
* denoted as 'Script' - on Windows boxes the case does not matter.
* @param mixed $type a string or an array representing the name of the
* <kbd>ScriptReorganizer_Type</kbd> to instantiate
* @param mixed $strategy a string representing the name or an array
* representing the name and the optional argument of the
* <kbd>ScriptReorganizer_Strategy</kbd> to instantiate
* @param mixed $decorator a variable-length argument list of strings
* representing the names and/or of arrays representing the names and the
* optional arguments of the <kbd>ScriptReorganizer_Type_Decorator</kbd>s
* @return ScriptReorganizer_Type the <kbd>ScriptReorganizer_Type</kbd> object
* @throws {@link ScriptReorganizer_Factory_Exception ScriptReorganizer_Factory_Exception}
* @throws {@link ScriptReorganizer_Type_Decorator_Exception ScriptReorganizer_Type_Decorator_Exception}
public static function create( $type, $strategy )
$classes = & self ::importAndCheck ( $arguments );
$argument = is_array( $strategy ) && isset ( $strategy[1 ] ) ? $strategy[1 ] : null;
$strategy = new $classes[1 ]( $argument );
$type = new $classes[0 ]( $strategy );
for ( $i = count( $arguments ) - 1; $i > 1; $i-- ) {
$argument = is_array( $arguments[$i] ) && isset ( $arguments[$i][1 ] ) ? $arguments[$i][1 ] : null;
$type = new $classes[$i]( $type, $argument );
// {{{ private static function & importAndCheck( & $arguments )
* Checks that the required classes are available after having imported them
* @param array &$arguments an array holding the arguments to process
* @return array an array holding the classes' names that have been imported
* @throws {@link ScriptReorganizer_Factory_Exception ScriptReorganizer_Factory_Exception}
private static function & importAndCheck ( & $arguments )
foreach ( $arguments as $argument ) {
'Argument(s) either not of type string/array or empty'
if ( !isset ( $argument[0 ] ) || !is_string( $argument[0 ] ) || empty ( $argument[0 ] ) ) {
'Array argument(s) either not of type string or empty'
$argument = $argument[0 ];
$classes[0 ] = 'ScriptReorganizer_Type_' . $classes[0 ];
$classes[1 ] = 'ScriptReorganizer_Strategy_' . $classes[1 ];
for ( $i = 2 , $j = count( $classes ); $i < $j; $i++ ) {
$classes[$i] = 'ScriptReorganizer_Type_Decorator_' . $classes[$i];
foreach ( $classes as $class ) {
@include_once $root . str_replace( '_', DIRECTORY_SEPARATOR , $class ) . '.php';
'Class ' . $class . ' not found'
* c-hanging-comment-ender-p: nil
Documentation generated on Mon, 11 Mar 2019 14:05:19 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|