Skip to content

Instantly share code, notes, and snippets.

@fleeting
Last active August 29, 2015 14:18
Show Gist options
  • Save fleeting/ffbf82230c721de10050 to your computer and use it in GitHub Desktop.
Save fleeting/ffbf82230c721de10050 to your computer and use it in GitHub Desktop.
public function get_templates() {
$dir = new Folder(ROOT . '/MbCmsPlugin/AbcPages/View/Pages/Templates');
$files = $dir->find('.*\.ctp', true);
$templates = array();
foreach ($files as $k => $file) {
$file = new File($dir->pwd() . DS . $file);
$name = $file->name();
$contents = $file->read();
$file->close();
$tokens = token_get_all($contents);
$comment = array(
T_COMMENT, // All comments since PHP5
T_DOC_COMMENT // PHPDoc comments
);
foreach($tokens as $token) {
if(!in_array($token[0], $comment))
continue;
$templates[$name] = str_replace(array('/* ', ' */'), '', $token[1]);
}
}
return $templates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment