| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 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 |
|
|---|