/** * Data provider for testExamples method. * * Assumes that an `examples` directory exists inside parent directory. * This examples directory should contain any number of subdirectories, each of which contains * three files: one Mustache class (.php), one Mustache template (.mustache), and one output file * (.txt). * * This whole mess will be refined later to be more intuitive and less prescriptive, but it'll * do for now. Especially since it means we can have unit tests :) * * @access public * @return array */ public function getExamples() { $basedir = dirname(__FILE__) . '/../examples/'; $ret = array(); $files = new RecursiveDirectoryIterator($basedir); while ($files->valid()) { if ($files->hasChildren() && ($children = $files->getChildren())) { $example = $files->getSubPathname(); $class = null; $template = null; $output = null; foreach ($children as $file) { if (!$file->isFile()) { continue; } $filename = $file->getPathInfo(); $info = pathinfo($filename); switch ($info['extension']) { case 'php': $class = $info['filename']; include_once $filename; break; case 'mustache': $template = file_get_contents($filename); break; case 'txt': $output = file_get_contents($filename); break; } } $ret[$example] = array($class, $template, $output); } $files->next(); } return $ret; }
/** * parse this directory * * @return none */ protected function parseDir() { $this->clear(); $iter = new RecursiveDirectoryIterator($this->getPath()); while ($iter->valid()) { $curr = (string) $iter->getSubPathname(); if (!$iter->isDot() && $curr[0] != '.') { $this->addItem(Varien_Directory_Factory::getFactory($iter->current(), $this->getRecursion(), $this->getRecursionLevel())); } $iter->next(); } }