private function getCommandsInDirectory($path, $relativePath)
{
$commands = array();
if (false !== ($d = opendir($path))) {
while (false !== ($f = readdir($d))) {
$new_path = $path . '/' . $f;
$new_relative_path = $relativePath . '/' . $f;
if ('.amCommand' == substr($f, -10) || is_dir($new_path) && 0 != strncmp('.', $f, 1)) {
if (is_dir($new_path) && file_exists($new_path . '/group.amGroup')) {
$yaml = YAML::load($new_path . '/group.amGroup');
$yaml['filename'] = $f;
$yaml['is_collection'] = '1';
$yaml['path'] = $relativePath;
$commands[] = $yaml;
$commands = array_merge($commands, $this->getCommandsInDirectory($new_path, $new_relative_path));
continue;
}
$def_file = $new_path . 'Def';
if (!file_exists($def_file)) {
throw new Exception('Missing command definition file `' . $def_file . '`.');
}
$yaml = YAML::load($new_path);
$yaml['code'] = file_get_contents($def_file);
$yaml['filename'] = substr($f, 0, -10);
$yaml['path'] = $relativePath;
$commands[] = $yaml;
}
}
closedir($d);
}
return $commands;
}