Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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: sfGeneratorManager.class.php 23922 2009-11-14 14:58:38Z fabien $
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
  public function __construct(sfProjectConfiguration $configuration, $basePath = null)
32
  {
33
    $this->configuration = $configuration;
34
    $this->basePath = $basePath;
35
  }
36
 
37
  /**
38
   * Returns the current configuration instance.
39
   *
40
   * @return sfProjectConfiguration A sfProjectConfiguration instance
41
   */
42
  public function getConfiguration()
43
  {
44
    return $this->configuration;
45
  }
46
 
47
  /**
48
   * Gets the base path to use when generating files.
49
   *
50
   * @return string The base path
51
   */
52
  public function getBasePath()
53
  {
54
    if (null === $this->basePath)
55
    {
56
      // for BC
57
      $this->basePath = sfConfig::get('sf_module_cache_dir');
58
    }
59
 
60
    return $this->basePath;
61
  }
62
 
63
  /**
64
   * Sets the base path to use when generating files.
65
   *
66
   * @param string $basePath The base path
67
   */
68
  public function setBasePath($basePath)
69
  {
70
    $this->basePath = $basePath;
71
  }
72
 
73
  /**
74
   * Saves some content.
75
   *
76
   * @param string $path    The relative path
77
   * @param string $content The content
78
   */
79
  public function save($path, $content)
80
  {
81
    $path = $this->getBasePath().DIRECTORY_SEPARATOR.$path;
82
 
83
    if (!is_dir(dirname($path)))
84
    {
85
      $current_umask = umask(0000);
86
      if (false === @mkdir(dirname($path), 0777, true))
87
      {
88
        throw new sfCacheException(sprintf('Failed to make cache directory "%s".', dirname($path)));
89
      }
90
      umask($current_umask);
91
    }
92
 
93
    if (false === $ret = @file_put_contents($path, $content))
94
    {
95
      throw new sfCacheException(sprintf('Failed to write cache file "%s".', $path));
96
    }
97
 
98
    return $ret;
99
  }
100
 
101
  /**
102
   * Generates classes and templates for a given generator class.
103
   *
104
   * @param string $generatorClass The generator class name
105
   * @param array  $param          An array of parameters
106
   *
107
   * @return string The cache for the configuration file
108
   */
109
  public function generate($generatorClass, $param)
110
  {
111
    $generator = new $generatorClass($this);
112
 
113
    return $generator->generate($param);
114
  }
115
}