/** * Looks on include path for specified file. * * @param string $path * * @return string File found (null if no file found). */ public static function getResourcePath($path) { if (self::$importPaths === null) { self::$importPaths = self::explodeIncludePath(); } $path = str_replace('\\', DIRECTORY_SEPARATOR, $path); $path = str_replace('/', DIRECTORY_SEPARATOR, $path); foreach (self::$importPaths as $prefix) { $testPath = $prefix . DIRECTORY_SEPARATOR . $path; if (file_exists($testPath)) { return $testPath; } } // Check for the property phing.home $homeDir = self::getProperty(self::PHING_HOME); if ($homeDir) { $testPath = $homeDir . DIRECTORY_SEPARATOR . $path; if (file_exists($testPath)) { return $testPath; } } // Check for the phing home of phar archive if (strpos(self::$importPaths[0], 'phar://') === 0) { $testPath = self::$importPaths[0] . '/../' . $path; if (file_exists($testPath)) { return $testPath; } } // If we are using this via PEAR then check for the file in the data dir // This is a bit of a hack, but works better than previous solution of assuming // data_dir is on the include_path. $dataDir = '@DATA-DIR@'; if ($dataDir[0] != '@') { // if we're using PEAR then the @ DATA-DIR @ token will have been substituted. if (!file_exists($dataDir)) { self::log("The PEAR data_dir setting is incorrect: {$dataDir}.", Project::MSG_ERR); self::log("Please edit using 'pear config-set data_dir ...' and re-install Phing.", Project::MSG_ERR); return null; } $testPath = $dataDir . DIRECTORY_SEPARATOR . $path; if (file_exists($testPath)) { return $testPath; } } else { // We're not using PEAR, so do one additional check based on path of // current file (Phing.php) $maybeHomeDir = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); $testPath = $maybeHomeDir . DIRECTORY_SEPARATOR . $path; if (file_exists($testPath)) { return $testPath; } } return null; }
/** * Looks on include path for specified file. * @return string File found (null if no file found). */ public static function getResourcePath($path) { if (self::$importPaths === null) { $paths = get_include_path(); self::$importPaths = explode(PATH_SEPARATOR, ini_get("include_path")); } $path = str_replace('\\', DIRECTORY_SEPARATOR, $path); $path = str_replace('/', DIRECTORY_SEPARATOR, $path); foreach (self::$importPaths as $prefix) { $testPath = $prefix . DIRECTORY_SEPARATOR . $path; if (file_exists($testPath)) { return $testPath; } } // Check for the property phing.home $homeDir = self::getProperty('phing.home'); if ($homeDir) { $testPath = $homeDir . DIRECTORY_SEPARATOR . $path; if (file_exists($testPath)) { return $testPath; } } // If we are using this via PEAR then check for the file in the data dir // This is a bit of a hack, but works better than previous solution of assuming // data_dir is on the include_path. $dataDir = '@DATA-DIR@'; if ($dataDir[0] != '@') { // if we're using PEAR then the @ DATA-DIR @ token will have been substituted. $testPath = $dataDir . DIRECTORY_SEPARATOR . $path; if (file_exists($testPath)) { return $testPath; } } else { // We're not using PEAR, so do one additional check based on path of // current file (Phing.php) $maybeHomeDir = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); $testPath = $maybeHomeDir . DIRECTORY_SEPARATOR . $path; if (file_exists($testPath)) { return $testPath; } } return null; }
/** * Looks on include path for specified file. * @return string File found (null if no file found). */ public static function getResourcePath($path) { if (self::$importPaths === null) { $paths = ini_get("include_path"); self::$importPaths = explode(PATH_SEPARATOR, ini_get("include_path")); } $path = str_replace('\\', DIRECTORY_SEPARATOR, $path); $path = str_replace('/', DIRECTORY_SEPARATOR, $path); foreach (self::$importPaths as $prefix) { $foo_path = $prefix . DIRECTORY_SEPARATOR . $path; if (file_exists($foo_path)) { return $foo_path; } } // Check for the property phing.home $home_dir = self::getProperty('phing.home'); if ($home_dir) { $home_path = $home_dir . DIRECTORY_SEPARATOR . $path; if (file_exists($home_path)) { return $home_path; } } // If we are using this via PEAR then check for the file in the data dir // This is a bit of a hack, but works better than previous solution of assuming // data_dir is on the include_path. $data_dir = '@DATA-DIR@'; if ($data_dir[0] != '@') { // if we're using PEAR then the @ DATA-DIR @ token will have been substituted. $data_path = $data_dir . DIRECTORY_SEPARATOR . $path; if (file_exists($data_path)) { return $data_path; } } return null; }