Development

/branches/1.4/lib/config/sfRootConfigHandler.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/config/sfRootConfigHandler.class.php

Revision 23810, 3.3 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.3] set svn:eol-style property to native and svn:keywords property to Id on all .php files

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
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  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfRootConfigHandler allows you to specify configuration handlers for the
13  * application or on a module level.
14  *
15  * @package    symfony
16  * @subpackage config
17  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
18  * @version    SVN: $Id$
19  */
20 class sfRootConfigHandler extends sfYamlConfigHandler
21 {
22   /**
23    * Executes this configuration handler
24    *
25    * @param array $configFiles An array of absolute filesystem path to a configuration file
26    *
27    * @return string Data to be written to a cache file
28    *
29    * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
30    * @throws sfParseException If a requested configuration file is improperly formatted
31    */
32   public function execute($configFiles)
33   {
34     // parse the yaml
35     $config = self::getConfiguration($configFiles);
36
37     // determine if we're loading the system config_handlers.yml or a module config_handlers.yml
38     $moduleLevel = ($this->getParameterHolder()->get('module_level') === true) ? true : false;
39
40     if ($moduleLevel)
41     {
42       // get the current module name
43       $moduleName = $this->getParameterHolder()->get('module_name');
44     }
45
46     // init our data and includes arrays
47     $data     = array();
48     $includes = array();
49
50     // let's do our fancy work
51     foreach ($config as $category => $keys)
52     {
53       if ($moduleLevel)
54       {
55         // module-level registration, so we must prepend the module
56         // root to the category
57         $category = 'modules/'.$moduleName.'/'.$category;
58       }
59
60       if (!isset($keys['class']))
61       {
62         // missing class key
63         throw new sfParseException(sprintf('Configuration file "%s" specifies category "%s" with missing class key.', $configFiles[0], $category));
64       }
65
66       $class = $keys['class'];
67
68       if (isset($keys['file']))
69       {
70         if (!is_readable($keys['file']))
71         {
72           // handler file doesn't exist
73           throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $class, $keys['file']));
74         }
75
76         // append our data
77         $includes[] = sprintf("require_once('%s');", $keys['file']);
78       }
79
80       // parse parameters
81       $parameters = (isset($keys['param']) ? var_export($keys['param'], true) : null);
82
83       // append new data
84       $data[] = sprintf("\$this->handlers['%s'] = new %s(%s);", $category, $class, $parameters);
85     }
86
87     // compile data
88     $retval = sprintf("<?php\n" .
89                       "// auto-generated by sfRootConfigHandler\n".
90                       "// date: %s\n%s\n%s\n",
91                       date('Y/m/d H:i:s'), implode("\n", $includes), implode("\n", $data));
92
93     return $retval;
94   }
95
96   /**
97    * @see sfConfigHandler
98    */
99   static public function getConfiguration(array $configFiles)
100   {
101     $config = self::replaceConstants(self::parseYamls($configFiles));
102
103     foreach ($config as $category => $keys)
104     {
105       if (isset($keys['file']))
106       {
107         $config[$category]['file'] = self::replacePath($keys['file']);
108       }
109     }
110
111     return $config;
112   }
113 }
114
Note: See TracBrowser for help on using the browser.