Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6
 * (c) 2004-2006 Sean Kerr <sean@code-box.org>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
/**
13
 * sfConfigHandler allows a developer to create a custom formatted configuration
14
 * file pertaining to any information they like and still have it auto-generate
15
 * PHP code.
16
 *
17
 * @package    symfony
18
 * @subpackage config
19
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
20
 * @author     Sean Kerr <sean@code-box.org>
21
 * @version    SVN: $Id: sfConfigHandler.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
22
 */
23
abstract class sfConfigHandler
24
{
25
  protected
26
    $parameterHolder = null;
27
 
28
  /**
29
   * Class constructor.
30
   *
31
   * @see initialize()
32
   */
33
  public function __construct($parameters = null)
34
  {
35
    $this->initialize($parameters);
36
  }
37
 
38
  /**
39
   * Initializes this configuration handler.
40
   *
41
   * @param array $parameters An associative array of initialization parameters
42
   *
43
   * @return bool true, if initialization completes successfully, otherwise false
44
   *
45
   * @throws <b>sfInitializationException</b> If an error occurs while initializing this ConfigHandler
46
   */
47
  public function initialize($parameters = null)
48
  {
49
    $this->parameterHolder = new sfParameterHolder();
50
    $this->parameterHolder->add($parameters);
51
  }
52
 
53
  /**
54
   * Executes this configuration handler
55
   *
56
   * @param array $configFiles An array of filesystem path to a configuration file
57
   *
58
   * @return string Data to be written to a cache file
59
   *
60
   * @throws <b>sfConfigurationException</b> If a requested configuration file does not exist or is not readable
61
   * @throws <b>sfParseException</b> If a requested configuration file is improperly formatted
62
   */
63
  abstract public function execute($configFiles);
64
 
65
  /**
66
   * Replaces constant identifiers in a value.
67
   *
68
   * If the value is an array replacements are made recursively.
69
   *
70
   * @param mixed $value The value on which to run the replacement procedure
71
   *
72
   * @return string The new value
73
   */
74
  static public function replaceConstants($value)
75
  {
76
    if (is_array($value))
77
    {
78
      array_walk_recursive($value, create_function('&$value', '$value = sfToolkit::replaceConstants($value);'));
79
    }
80
    else
81
    {
82
      $value = sfToolkit::replaceConstants($value);
83
    }
84
 
85
    return $value;
86
  }
87
 
88
  /**
89
   * Replaces a relative filesystem path with an absolute one.
90
   *
91
   * @param string $path A relative filesystem path
92
   *
93
   * @return string The new path
94
   */
95
  static public function replacePath($path)
96
  {
97
    if (is_array($path))
98
    {
99
      array_walk_recursive($path, create_function('&$path', '$path = sfConfigHandler::replacePath($path);'));
100
    }
101
    else
102
    {
103
      if (!sfToolkit::isPathAbsolute($path))
104
      {
105
        // not an absolute path so we'll prepend to it
106
        $path = sfConfig::get('sf_app_dir').'/'.$path;
107
      }
108
    }
109
 
110
    return $path;
111
  }
112
 
113
  /**
114
   * Gets the parameter holder for this configuration handler.
115
   *
116
   * @return sfParameterHolder A sfParameterHolder instance
117
   */
118
  public function getParameterHolder()
119
  {
120
    return $this->parameterHolder;
121
  }
122
 
123
  /**
124
   * Returns the configuration for the current config handler.
125
   *
126
   * @param array $configFiles An array of ordered configuration files
127
   * @throws LogicException no matter what
128
   */
129
  static public function getConfiguration(array $configFiles)
130
  {
131
    throw new LogicException('You must call the ::getConfiguration() method on a concrete config handler class');
132
  }
133
}