Implement packager and installer hooks
[pharext/pharext] / src / pharext / PeclSourceDir.php
index ab7174681c7d1fdf1cca8c67f6472ed161f17303..ca065ad21c4e142e50b521d07271513354d7a2f0 100644 (file)
@@ -25,6 +25,12 @@ class PeclSourceDir implements \IteratorAggregate, SourceDir
         */
        private $path;
        
+       /**
+        * Installer hook
+        * @var string
+        */
+       private $hook;
+       
        /**
         * @inheritdoc
         * @see \pharext\SourceDir::__construct()
@@ -48,6 +54,18 @@ class PeclSourceDir implements \IteratorAggregate, SourceDir
                        }
                }
                
+               if (($configure = $sxe->xpath("/pecl:package/pecl:extsrcrelease/pecl:configureoption"))) {
+                       $this->hook = tmpfile();
+                       ob_start(function($s) {
+                               fwrite($this->hook, $s);
+                               return null;
+                       });
+                       call_user_func(function() use ($configure) {
+                               include __DIR__."/../pharext_install.tpl.php";
+                       });
+                       ob_end_flush();
+               }
+               
                $this->cmd = $cmd;
                $this->sxe = $sxe;
                $this->path = $path;
@@ -79,6 +97,10 @@ class PeclSourceDir implements \IteratorAggregate, SourceDir
         * @return Generator
         */
        private function generateFiles() {
+               if ($this->hook) {
+                       rewind($this->hook);
+                       yield "pharext_install.php" => $this->hook;
+               }
                foreach ($this->sxe->xpath("//pecl:file") as $file) {
                        $path = $this->path ."/". $this->dirOf($file) ."/". $file["name"];
                        if ($this->cmd->getArgs()->verbose) {