/** * load flavor * * @param string $name flavor name * @return FlavirDirectory object. */ public function load($name) { foreach ($this->dirs as $dir) { $flavor = new FlavorDirectory($dir . DIRECTORY_SEPARATOR . $name); if ($flavor->exists()) { return $flavor; } } throw new Exception("Flavor {$name} not found."); }
function testFunc() { $fl = new FlavorDirectory('flavors/command'); ok($fl->getResourceDir()); ok($fl->hasResourceDir()); ok($fl->hasGeneratorClassFile()); ok($fl->getGeneratorClassFile()); ok($fl->exists()); is('command', $fl->getName()); is('\\command\\Generator', $fl->getGeneratorClass()); ok($fl->createGenericGenerator()); }
/** * 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); } } }