public static function parsePackageDescription($package, $forceremote = false) { if (strpos($package, 'http://') === 0 || strpos($package, 'https://') === 0) { if (substr($package, -4) == '.xml') { // remote package.xml file return array('Pyrus\\Package\\Xml', $package, false); } return array('Pyrus\\Package\\Remote', $package, false); } try { $test = parse_url($package); $depgroup = false; if (!$forceremote && count($test) == 2 && isset($test['fragment']) && isset($test['path'])) { // local path with dependency group? if (file_exists($test['path'])) { // yes $package = $test['path']; $depgroup = $test['fragment']; } } if (!$forceremote && @file_exists($package) && @is_file($package)) { $info = pathinfo($package); if (!isset($info['extension']) || !strlen($info['extension'])) { // guess based on first 5 characters $f = @fopen($package, 'rb'); if ($f) { $first5 = fread($f, 5); fclose($f); if ($first5 == '<?xml') { return array('Pyrus\\Package\\Xml', $package, $depgroup); } return array('Pyrus\\Package\\Phar', $package, $depgroup); } } else { if (extension_loaded('phar') && strtolower($info['extension']) != 'xml') { return array('Pyrus\\Package\\Phar', $package, $depgroup); } switch (strtolower($info['extension'])) { case 'xml': return array('Pyrus\\Package\\Xml', $package, $depgroup); default: throw new Package\Exception('Cannot read archives with phar extension'); } } } $info = Config::parsePackageName($package); return array('Pyrus\\Package\\Remote', $package, $depgroup); } catch (\Exception $e) { throw new Package\Exception('package "' . $package . '" is unknown', $e); } }