Added support for phar metadata
This commit is contained in:
@ -25,6 +25,8 @@ class Manifest
|
||||
protected $props = [];
|
||||
/** @var array Patterns to exclude */
|
||||
protected $excludes = [];
|
||||
/** @var array Phar metadata */
|
||||
protected $metadata = [];
|
||||
|
||||
/**
|
||||
* Read manifests from a makephar.sdl file and return all the build targets
|
||||
@ -94,6 +96,21 @@ class Manifest
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'metadata':
|
||||
foreach ($child->getChildren() as $meta) {
|
||||
if (($prop = $meta->getAttribute("prop"))) {
|
||||
if (array_key_exists($prop,$mf->props)) {
|
||||
$value = $mf->props[$prop];
|
||||
} else {
|
||||
log_warn("Property %s is not defined", $prop);
|
||||
}
|
||||
} else {
|
||||
$value = $meta->getValue();
|
||||
}
|
||||
$mf->setMetadata($meta->getTagName(), $value);
|
||||
|
||||
}
|
||||
break;
|
||||
case 'props':
|
||||
$props = [];
|
||||
if ($src = (string)$child->getValue()) {
|
||||
@ -166,6 +183,20 @@ class Manifest
|
||||
return $this->stub;
|
||||
}
|
||||
|
||||
public function setMetadata($key,$value)
|
||||
{
|
||||
$this->metadata[$key] = $value;
|
||||
}
|
||||
|
||||
public function getMetadata($key=null)
|
||||
{
|
||||
if ($key===null)
|
||||
return $this->metadata;
|
||||
if (!array_key_exists($key, $this->metadata))
|
||||
return null;
|
||||
return $this->metadata[$key];
|
||||
}
|
||||
|
||||
public function setCompression($value)
|
||||
{
|
||||
$this->compress = $value;
|
||||
@ -207,14 +238,19 @@ class Manifest
|
||||
{
|
||||
$items = [];
|
||||
foreach ($this->sources as $source) {
|
||||
if (@isset($source->opts->verbatim)) {
|
||||
$verbatim = $source->opts->verbatim;
|
||||
} else {
|
||||
$verbatim = $this->getVerbatim();
|
||||
}
|
||||
if ($source->type == 'dir') {
|
||||
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source->path));
|
||||
foreach ($it as $item) {
|
||||
if ($item->isDir()) continue;
|
||||
$items[] = (object)['src'=>realpath($item->getPathname()),'dest'=>$item->getPathname()];
|
||||
$items[] = (object)['src'=>realpath($item->getPathname()),'dest'=>$item->getPathname(),'verbatim'=>$verbatim];
|
||||
}
|
||||
} elseif ($source->type == 'file') {
|
||||
$items[] = (object)['src'=>realpath($source->path),'dest'=>$item->getPathname()];
|
||||
$items[] = (object)['src'=>realpath($source->path),'dest'=>$source->path,'verbatim'=>$verbatim];
|
||||
} else {
|
||||
log_warn("Unsupported source type: %s", $source->type);
|
||||
}
|
||||
|
Reference in New Issue
Block a user