1<?php
2
3class FeatureFactory {
4  var $_features;
5
6  function FeatureFactory() {
7    $this->_features = array();
8  }
9
10  function &get($name) {
11    $instance =& FeatureFactory::get_instance();
12    return $instance->_get($name);
13  }
14
15  function &_get($name) {
16    if (!isset($this->__features[$name])) {
17      $this->_features[$name] =& $this->_load($name);
18    };
19    return $this->_features[$name];
20  }
21
22  function &_load($name) {
23    $normalized_name = strtolower(preg_replace('/[^\w\d\.]/i', '_', $name));
24    $file_name = HTML2PS_DIR.'features/'.$normalized_name.'.php';
25    $class_name = 'Feature'.join('',array_map('ucfirst',explode('.',$normalized_name)));
26
27    if (!file_exists($file_name)) {
28      $null = null;
29      return $null;
30    };
31
32    require_once($file_name);
33    $feature_object =& new $class_name;
34    return $feature_object;
35  }
36
37  function &get_instance() {
38    static $instance = null;
39    if (is_null($instance)) {
40      $instance =& new FeatureFactory();
41    };
42
43    return $instance;
44  }
45}
46
47?>