Skip to content

Commit

Permalink
- changed the manifest search logic a little: if a directory is pass…
Browse files Browse the repository at this point in the history
…ed, it will search for package.yml, package.yaml and package.json in this order. If a file is passed, it will use the file's extension (only .yml, .yaml and .json supported) to decide the parsing method.
  • Loading branch information
kamicane committed May 9, 2010
1 parent b030758 commit abcd0b8
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions packager.php
Expand Up @@ -16,29 +16,37 @@ public static function warn($message){
private $root = null;

public function __construct($package_paths){
foreach ((array)$package_paths as $package_path)
$this->parse_manifest($package_path);
foreach ((array)$package_paths as $package_path) $this->parse_manifest($package_path);
}

private function parse_manifest($package_path){
if (is_dir($package_path))
$package_path .= '/package.yml';

$pathinfo = pathinfo($package_path);
$package_path = $pathinfo['dirname'] . '/';
$manifest_path = $package_path . $pathinfo['basename'];
$manifest_format = $pathinfo['extension'];

switch ($manifest_format){
case 'json':
$manifest = json_decode(file_get_contents($manifest_path), true);
break;
private function parse_manifest($path){
$pathinfo = pathinfo($path);

if (is_dir($path)){

$package_path = $pathinfo['dirname'] . '/' . $pathinfo['basename'] . '/';

if (file_exists($package_path . 'package.yml')){
$manifest_path = $package_path . 'package.yml';
$manifest_format = 'yaml';
} else if (file_exists($package_path . 'package.yaml')){
$manifest_path = $package_path . 'package.yaml';
$manifest_format = 'yaml';
} else if (file_exists($package_path . 'package.json')){
$manifest_path = $package_path . 'package.json';
$manifest_format = 'json';
}

default:
$manifest = YAML::decode_file($manifest_path);
} else if (file_exists($path)){
$package_path = $pathinfo['dirname'] . '/';
$manifest_path = $package_path . $pathinfo['basename'];
$manifest_format = $pathinfo['extension'];
}

if (empty($manifest)) throw new Exception(basename($manifest_path) . " not found in $package_path, or unable to parse manifest.");
if ($manifest_format == 'json') $manifest = json_decode(file_get_contents($manifest_path), true);
else if ($manifest_format == 'yaml' || $manifest_format == 'yml') $manifest = YAML::decode_file($manifest_path);

if (empty($manifest)) throw new Exception("manifest not found in $package_path, or unable to parse manifest.");

$package_name = $manifest['name'];

Expand Down

0 comments on commit abcd0b8

Please sign in to comment.