Development

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

You must first sign up to be able to contribute.

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

Revision 3203, 3.2 kB (checked in by fabien, 8 years ago)
  • added phpdoc to the config/ files
  • renamed sfLoader::getConfigDirs() to sfLoader::getConfigPaths()
  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
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 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 = $this->parseYamls($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         $error = sprintf('Configuration file "%s" specifies category "%s" with missing class key', $configFiles[0], $category);
64         throw new sfParseException($error);
65       }
66
67       $class = $keys['class'];
68
69       if (isset($keys['file']))
70       {
71         // we have a file to include
72         $file = $this->replaceConstants($keys['file']);
73         $file = $this->replacePath($file);
74
75         if (!is_readable($file))
76         {
77           // handler file doesn't exist
78           $error = sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s"', $configFiles[0], $class, $file);
79           throw new sfParseException($error);
80         }
81
82         // append our data
83         $includes[] = sprintf("require_once('%s');", $file);
84       }
85
86       // parse parameters
87       $parameters = (isset($keys['param']) ? var_export($keys['param'], true) : null);
88
89       // append new data
90       $data[] = sprintf("\$this->handlers['%s'] = new %s();", $category, $class);
91
92       // initialize the handler with parameters
93       $data[] = sprintf("\$this->handlers['%s']->initialize(%s);", $category, $parameters);
94     }
95
96     // compile data
97     $retval = sprintf("<?php\n" .
98                       "// auto-generated by sfRootConfigHandler\n".
99                       "// date: %s\n%s\n%s\n",
100                       date('Y/m/d H:i:s'), implode("\n", $includes), implode("\n", $data));
101
102     return $retval;
103   }
104 }
105
Note: See TracBrowser for help on using the browser.