1. sfGeneratorManager.class.php
  2. /** * sfGeneratorManager helps generate classes, views and templates for scaffolding, admin interface, ... * * @package symfony * @subpackage generator * @author Fabien Potencier * @version SVN: $Id: sfGeneratorManager.class.php 23922 2009-11-14 14:58:38Z fabien $ */
  3. class sfGeneratorManager
  4. {
  5. protected
  6. $configuration = null,
  7. $basePath = null;
  8. /**
  9. * Class constructor.
  10. *
  11. * @param sfProjectConfiguration $configuration A sfProjectConfiguration instance
  12. * @param string $basePath The base path for file generation
  13. */
  14. public function __construct(sfProjectConfiguration $configuration, $basePath = null)
  15. {
  16. $this->configuration = $configuration;
  17. $this->basePath = $basePath;
  18. }
  19. /**
  20. * Returns the current configuration instance.
  21. *
  22. * @return sfProjectConfiguration A sfProjectConfiguration instance
  23. */
  24. public function getConfiguration()
  25. {
  26. return $this->configuration;
  27. }
  28. /**
  29. * Gets the base path to use when generating files.
  30. *
  31. * @return string The base path
  32. */
  33. public function getBasePath()
  34. {
  35. if (null === $this->basePath)
  36. {
  37. // for BC
  38. $this->basePath = sfConfig::get('sf_module_cache_dir');
  39. }
  40. return $this->basePath;
  41. }
  42. /**
  43. * Sets the base path to use when generating files.
  44. *
  45. * @param string $basePath The base path
  46. */
  47. public function setBasePath($basePath)
  48. {
  49. $this->basePath = $basePath;
  50. }
  51. /**
  52. * Saves some content.
  53. *
  54. * @param string $path The relative path
  55. * @param string $content The content
  56. */
  57. public function save($path, $content)
  58. {
  59. $path = $this->getBasePath().DIRECTORY_SEPARATOR.$path;
  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. if (false === $ret = @file_put_contents($path, $content))
  70. {
  71. throw new sfCacheException(sprintf('Failed to write cache file "%s".', $path));
  72. }
  73. return $ret;
  74. }
  75. /**
  76. * Generates classes and templates for a given generator class.
  77. *
  78. * @param string $generatorClass The generator class name
  79. * @param array $param An array of parameters
  80. *
  81. * @return string The cache for the configuration file
  82. */
  83. public function generate($generatorClass, $param)
  84. {
  85. $generator = new $generatorClass($this);
  86. return $generator->generate($param);
  87. }
  88. }

Debug toolbar