| 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 |
$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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|