Development

/branches/1.1/lib/generator/sfGenerator.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/generator/sfGenerator.class.php

Revision 17858, 4.2 kB (checked in by FabianLange, 5 years ago)

[1.1, 1.2, 1.3] fixed some codeing standards (fixes #6376 - patch from gimler)

  • 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  * sfGenerator is the abstract base class for all generators.
13  *
14  * @package    symfony
15  * @subpackage generator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 abstract class sfGenerator
20 {
21   protected
22     $generatorClass      = '',
23     $generatorManager    = null,
24     $generatedModuleName = '',
25     $theme               = 'default',
26     $moduleName          = '';
27
28   /**
29    * Class constructor.
30    *
31    * @see initialize()
32    */
33   public function __construct(sfGeneratorManager $generatorManager)
34   {
35     $this->initialize($generatorManager);
36   }
37
38   /**
39    * Initializes the current sfGenerator instance.
40    *
41    * @param sfGeneratorManager $generatorManager A sfGeneratorManager instance
42    */
43   public function initialize(sfGeneratorManager $generatorManager)
44   {
45     $this->generatorManager = $generatorManager;
46   }
47
48   /**
49    * Generates classes and templates.
50    *
51    * @param array $params An array of parameters
52    *
53    * @return string The cache for the configuration file
54    */
55   abstract public function generate($params = array());
56
57   /**
58    * Generates PHP files for a given module name.
59    *
60    * @param string $generatedModuleName The name of module name to generate
61    * @param array  $files               A list of template files to generate
62    */
63   protected function generatePhpFiles($generatedModuleName, $files = array())
64   {
65     foreach ($files as $file)
66     {
67       $this->getGeneratorManager()->save($generatedModuleName.'/'.$file, $this->evalTemplate($file));
68     }
69   }
70
71   /**
72    * Evaluates a template file.
73    *
74    * @param string $templateFile The template file path
75    *
76    * @return string The evaluated template
77    */
78   protected function evalTemplate($templateFile)
79   {
80     $templateFile = $this->generatorManager->getConfiguration()->getGeneratorTemplate($this->getGeneratorClass(), $this->getTheme(), $templateFile);
81
82     // eval template file
83     ob_start();
84     require($templateFile);
85     $content = ob_get_clean();
86
87     // replace [?php and ?]
88     return $this->replacePhpMarks($content);
89   }
90
91   /**
92    * Replaces PHP marks by <?php ?>.
93    *
94    * @param string $text The PHP code
95    *
96    * @return string The converted PHP code
97    */
98   protected function replacePhpMarks($text)
99   {
100     // replace [?php and ?]
101     return str_replace(array('[?php', '[?=', '?]'), array('<?php', '<?php echo', '?>'), $text);
102   }
103
104   /**
105    * Gets the generator class.
106    *
107    * @return string The generator class
108    */
109   public function getGeneratorClass()
110   {
111     return $this->generatorClass;
112   }
113
114   /**
115    * Sets the generator class.
116    *
117    * @param string $generatorClass The generator class
118    */
119   public function setGeneratorClass($generatorClass)
120   {
121     $this->generatorClass = $generatorClass;
122   }
123
124   /**
125    * Gets the sfGeneratorManager instance.
126    *
127    * @return string The sfGeneratorManager instance
128    */
129   protected function getGeneratorManager()
130   {
131     return $this->generatorManager;
132   }
133
134   /**
135    * Gets the module name of the generated module.
136    *
137    * @return string The module name
138    */
139   public function getGeneratedModuleName()
140   {
141     return $this->generatedModuleName;
142   }
143
144   /**
145    * Sets the module name of the generated module.
146    *
147    * @param string $moduleName The module name
148    */
149   public function setGeneratedModuleName($moduleName)
150   {
151     $this->generatedModuleName = $moduleName;
152   }
153
154   /**
155    * Gets the module name.
156    *
157    * @return string The module name
158    */
159   public function getModuleName()
160   {
161     return $this->moduleName;
162   }
163
164   /**
165    * Sets the module name.
166    *
167    * @param string $moduleName The module name
168    */
169   public function setModuleName($moduleName)
170   {
171     $this->moduleName = $moduleName;
172   }
173
174   /**
175    * Gets the theme name.
176    *
177    * @return string The theme name
178    */
179   public function getTheme()
180   {
181     return $this->theme;
182   }
183
184   /**
185    * Sets the theme name.
186    *
187    * @param string $theme The theme name
188    */
189   public function setTheme($theme)
190   {
191     $this->theme = $theme;
192   }
193 }
194
Note: See TracBrowser for help on using the browser.