ca065ad21c4e142e50b521d07271513354d7a2f0
6 * A PECL extension source directory containing a v2 package.xml
8 class PeclSourceDir
implements \IteratorAggregate
, SourceDir
11 * The Packager command
12 * @var pharext\Packager
18 * @var SimpleXmlElement
36 * @see \pharext\SourceDir::__construct()
38 public function __construct(Command
$cmd, $path) {
39 $sxe = simplexml_load_file("$path/package.xml");
40 $sxe->registerXPathNamespace("pecl", $sxe->getDocNamespaces()[""]);
42 $args = $cmd->getArgs();
43 if (!isset($args->name
)) {
44 $name = (string) $sxe->xpath("/pecl:package/pecl:name")[0];
45 foreach ($args->parse(2, ["--name", $name]) as $error) {
46 $cmd->error("%s\n", $error);
50 if (!isset($args->release
)) {
51 $release = (string) $sxe->xpath("/pecl:package/pecl:version/pecl:release")[0];
52 foreach ($args->parse(2, ["--release", $release]) as $error) {
53 $cmd->error("%s\n", $error);
57 if (($configure = $sxe->xpath("/pecl:package/pecl:extsrcrelease/pecl:configureoption"))) {
58 $this->hook
= tmpfile();
59 ob_start(function($s) {
60 fwrite($this->hook
, $s);
63 call_user_func(function() use ($configure) {
64 include __DIR__
."/../pharext_install.tpl.php";
76 * @see \pharext\SourceDir::getBaseDir()
78 public function getBaseDir() {
83 * Compute the path of a file by parent dir nodes
84 * @param \SimpleXMLElement $ele
87 private function dirOf($ele) {
89 while (($ele = current($ele->xpath(".."))) && $ele->getName() == "dir") {
90 $path = trim($ele["name"], "/") ."/". $path ;
92 return trim($path, "/");
96 * Generate a list of files from the package.xml
99 private function generateFiles() {
102 yield
"pharext_install.php" => $this->hook
;
104 foreach ($this->sxe
->xpath("//pecl:file") as $file) {
105 $path = $this->path
."/". $this->dirOf($file) ."/". $file["name"];
106 if ($this->cmd
->getArgs()->verbose
) {
107 $this->cmd
->info("Packaging %s\n", $path);
109 if (!($realpath = realpath($path))) {
110 $this->cmd
->error("File %s does not exist", $path);
117 * Implements IteratorAggregate
118 * @see IteratorAggregate::getIterator()
120 public function getIterator() {
121 return $this->generateFiles();