Development

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

You must first sign up to be able to contribute.

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

Revision 11481, 2.7 kB (checked in by gregoire, 6 years ago)

Applied Dustin's changes from r9761 (closes #3711)

  • 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  * sfGeneratorConfigHandler.
13  *
14  * @package    symfony
15  * @subpackage config
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfGeneratorConfigHandler extends sfYamlConfigHandler
20 {
21   /**
22    * Executes this configuration handler.
23    *
24    * @param array An array of absolute filesystem path to a configuration file
25    *
26    * @return string Data to be written to a cache file
27    *
28    * @throws sfConfigurationException If a requested configuration file does not exist or is not readable
29    * @throws sfParseException If a requested configuration file is improperly formatted
30    * @throws sfInitializationException If a generator.yml key check fails
31    */
32   public function execute($configFiles)
33   {
34     // parse the yaml
35     $config = $this->parseYamls($configFiles);
36     if (!$config)
37     {
38       return '';
39     }
40
41     if (!isset($config['generator']))
42     {
43       throw new sfParseException(sprintf('Configuration file "%s" must specify a generator section', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0]));
44     }
45
46     $config = $config['generator'];
47
48     if (!isset($config['class']))
49     {
50       throw new sfParseException(sprintf('Configuration file "%s" must specify a generator class section under the generator section', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0]));
51     }
52
53     foreach (array('fields', 'list', 'edit') as $section)
54     {
55       if (isset($config[$section]))
56       {
57         throw new sfParseException(sprintf('Configuration file "%s" can specify a "%s" section but only under the param section', isset($configFiles[1]) ? $configFiles[1] : $configFiles[0], $section));
58       }
59     }
60
61     // generate class and add a reference to it
62     $generatorManager = new sfGeneratorManager();
63     $generatorManager->initialize();
64
65     // generator parameters
66     $generatorParam = (isset($config['param']) ? $config['param'] : array());
67
68     // hack to find the module name (look for the last /modules/ in path)
69     preg_match('#.*/'.sfConfig::get('sf_app_module_dir_name').'/([^/]+)/#', $configFiles[0], $match);
70     if ( 0 < count($match) && (0 < strlen($match[1])))
71     {
72       $generatorParam['moduleName'] = $match[1];
73     }
74
75     $data = $generatorManager->generate($config['class'], $generatorParam);
76
77     // compile data
78     $retval = "<?php\n".
79               "// auto-generated by sfGeneratorConfigHandler\n".
80               "// date: %s\n%s\n";
81     $retval = sprintf($retval, date('Y/m/d H:i:s'), $data);
82
83     return $retval;
84   }
85 }
86
Note: See TracBrowser for help on using the browser.