Development

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

You must first sign up to be able to contribute.

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

Revision 23810, 3.0 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  * 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     $basePath      = null;
24
25   /**
26    * Class constructor.
27    *
28    * @param sfProjectConfiguration $configuration A sfProjectConfiguration instance
29    * @param string                 $basePath      The base path for file generation
30    *
31    * @see initialize()
32    */
33   public function __construct(sfProjectConfiguration $configuration, $basePath = null)
34   {
35     $this->configuration = $configuration;
36     $this->basePath = $basePath;
37   }
38
39   /**
40    * Initializes the sfGeneratorManager instance.
41    *
42    * @param sfProjectConfiguration $configuration A sfProjectConfiguration instance
43    * @deprecated
44    */
45   public function initialize(sfProjectConfiguration $configuration)
46   {
47     // DEPRECATED
48   }
49
50   /**
51    * Returns the current configuration instance.
52    *
53    * @return sfProjectConfiguration A sfProjectConfiguration instance
54    */
55   public function getConfiguration()
56   {
57     return $this->configuration;
58   }
59
60   /**
61    * Gets the base path to use when generating files.
62    *
63    * @return string The base path
64    */
65   public function getBasePath()
66   {
67     if (null === $this->basePath)
68     {
69       // for BC
70       $this->basePath = sfConfig::get('sf_module_cache_dir');
71     }
72
73     return $this->basePath;
74   }
75
76   /**
77    * Sets the base path to use when generating files.
78    *
79    * @param string $basePath The base path
80    */
81   public function setBasePath($basePath)
82   {
83     $this->basePath = $basePath;
84   }
85
86   /**
87    * Saves some content.
88    *
89    * @param string $path    The relative path
90    * @param string $content The content
91    */
92   public function save($path, $content)
93   {
94     $path = $this->getBasePath().DIRECTORY_SEPARATOR.$path;
95
96     if (!is_dir(dirname($path)))
97     {
98       $current_umask = umask(0000);
99       if (false === @mkdir(dirname($path), 0777, true))
100       {
101         throw new sfCacheException(sprintf('Failed to make cache directory "%s".', dirname($path)));
102       }
103       umask($current_umask);
104     }
105
106     if (false === $ret = @file_put_contents($path, $content))
107     {
108       throw new sfCacheException(sprintf('Failed to write cache file "%s".', $path));
109     }
110
111     return $ret;
112   }
113
114   /**
115    * Generates classes and templates for a given generator class.
116    *
117    * @param string $generatorClass The generator class name
118    * @param array  $param          An array of parameters
119    *
120    * @return string The cache for the configuration file
121    */
122   public function generate($generatorClass, $param)
123   {
124     $generator = new $generatorClass($this);
125
126     return $generator->generate($param);
127   }
128 }
129
Note: See TracBrowser for help on using the browser.