/** * Attempts to determine a files programming language and returns * a parser instance for this language. * * @param Luxor_Files $files An instance of Luxor_Files to use for file * operations and path name resolution. * @param string $pathname The path name of the file to create a * parser for. * * @return mixed The created concrete Luxor_Lang instance, or false * on error. */ function builder($files, $pathname) { global $languages; $languages = Horde::loadConfiguration('languages.php', 'languages', 'luxor'); /* First, check the 'filetype' hash for a matching file extension. */ foreach ($languages['filetype'] as $type) { if (preg_match('/' . $type[1] . '/', $pathname)) { return Luxor_Lang::factory($type[2], $type); } } /* Next, try to detect the shebang line. */ $fh = $files->getFileHandle($pathname); if (!$fh || is_a($fh, 'PEAR_Error')) { return $fh; } $line = fgets($fh); if (!preg_match('/^\\#!\\s*(\\S+)/s', $line, $match)) { return false; } if (isset($languages['interpreters'][$match[1]])) { $lang = $languages['filetype'][$languages['interpreters'][$match[1]]]; return Luxor_Lang::factory($lang[2], $lang); } return false; }
/** * Initial app setup code. */ public static function initialize() { global $sources, $sourceid, $source, $files, $index, $pathname; require LUXOR_BASE . '/config/backends.php'; /* Default to the first source; overridden elsewhere if necessary. */ $sourceid = Horde_Util::getFormData('source'); if (!isset($sources[$sourceid])) { $sourceid = key($sources); } $source = $sources[$sourceid]; $files = Luxor_Files::factory($source['driver'], $source); $index = Luxor_Driver::factory($sourceid); $pathname = Luxor::fixPaths(Horde_Util::getFormData('f')); }