Development

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

You must first sign up to be able to contribute.

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

Revision 10135, 2.3 kB (checked in by FabianLange, 6 years ago)

1.1: fixed notice. fixed #3918

  • 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  * sfGeneratorManager helps generate classes, views and templates for scaffolding, admin interface, ...
13  *
14  * @package    symfony
15  * @subpackage generator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfGeneratorManager
20 {
21   protected
22     $configuration = null;
23
24   /**
25    * Class constructor.
26    *
27    * @param sfProjectConfiguration $configuration A sfProjectConfiguration instance
28    *
29    * @see initialize()
30    */
31   public function __construct(sfProjectConfiguration $configuration)
32   {
33     $this->initialize($configuration);
34   }
35
36   /**
37    * Initializes the sfGeneratorManager instance.
38    *
39    * @param sfProjectConfiguration $configuration A sfProjectConfiguration instance
40    */
41   public function initialize(sfProjectConfiguration $configuration)
42   {
43     $this->configuration = $configuration;
44   }
45
46   /**
47    * Returns the current configuration instance.
48    *
49    * @return sfProjectConfiguration A sfProjectConfiguration instance
50    */
51   public function getConfiguration()
52   {
53     return $this->configuration;
54   }
55
56   public function save($path, $content)
57   {
58     $path = sfConfig::get('sf_module_cache_dir').DIRECTORY_SEPARATOR.$path;
59
60     if (!is_dir(dirname($path)))
61     {
62       $current_umask = umask(0000);
63       if (false === @mkdir(dirname($path), 0777, true))
64       {
65         throw new sfCacheException(sprintf('Failed to make cache directory "%s".', dirname($path)));
66       }
67       umask($current_umask);
68     }
69
70     if (false === $ret = @file_put_contents($path, $content))
71     {
72       throw new sfCacheException(sprintf('Failed to write cache file "%s".', $path));
73     }
74
75     return $ret;
76   }
77
78   /**
79    * Generates classes and templates for a given generator class.
80    *
81    * @param string $generatorClass    The generator class name
82    * @param array  $param             An array of parameters
83    *
84    * @return string The cache for the configuration file
85    */
86   public function generate($generatorClass, $param)
87   {
88     $generator = new $generatorClass($this);
89
90     return $generator->generate($param);
91   }
92 }
93
Note: See TracBrowser for help on using the browser.