function execute() { $logger = $this->getLogger(); $logger->info('Available flavors:'); $paths = Path::get_flavor_paths(); foreach ($paths as $path) { if (!file_exists($path)) { continue; } if ($handle = opendir($path)) { while (false !== ($entry = readdir($handle))) { if ($entry == '.' || $entry == '..') { continue; } $logger->info(sprintf("%-10s %s", $entry, $path), 1); } closedir($handle); } } }
/** * generate new flavor * * @param string $name flavor name, lower case, alphabets * @param string $path your code base path */ public function generate($name, $codeBasePath = null) { if (preg_match('/\\W/', $name)) { throw new Exception("{$name} is not a valid flavor name"); } $paths = Path::get_flavor_paths(); foreach ($paths as $path) { if (file_exists($path)) { $flavor = new FlavorDirectory($path . DIRECTORY_SEPARATOR . $name); $resourceDir = $flavor->getResourceDir(); $this->createDir($resourceDir); if ($codeBasePath) { if (!file_exists($codeBasePath)) { throw new Exception("{$codeBasePath} doesn't exist."); } $codeBasePath = realpath($codeBasePath) ?: $codeBasePath; $this->copyDir($codeBasePath, $resourceDir); } $this->render('Generator.php.twig', $flavor->getGeneratorClassFile(), array('name' => $name)); $this->getLogger()->info('Done'); exit(0); } } }
function __construct($dirs = null) { /* get default flavor paths */ $this->dirs = $dirs ? (array) $dirs : Path::get_flavor_paths(); }