fix packaging
[pharext/pharext.org] / app / Pharext / Package.php
1 <?php
2
3 namespace app\Pharext;
4
5 use pharext\Metadata;
6 use pharext\SourceDir;
7 use pharext\Task;
8
9 class Package
10 {
11 private $source;
12 private $file;
13 private $name;
14 private $release;
15 private $zend;
16
17 function __construct($git_url, $tag_name, $pkg_name, $options) {
18 $dir = (new Task\GitClone($git_url, $tag_name))->run();
19 $src = !empty($options["pecl"])
20 ? new SourceDir\Pecl($dir)
21 : new SourceDir\Git($dir);
22
23 /* setup defaults */
24 $this->release = $tag_name;
25 $this->name = $pkg_name;
26 $this->zend = !empty($options["zend"]);
27
28 /* override with package info from SourceDir */
29 foreach ($src->getPackageInfo() as $key => $val) {
30 switch ($key) {
31 case "name":
32 case "release":
33 case "zend":
34 $this->$key = $val;
35 break;
36 }
37 }
38
39 $this->source = $src;
40 }
41
42 function build() {
43 $meta = Metadata::all() + [
44 "name" => $this->name,
45 "release" => $this->release,
46 "license" => $this->source->getLicense(),
47 "type" => $this->zend ? "zend_extension" : "extension",
48 ];
49 /* needed for the packager, so the pharstub task can find includes */
50 set_include_path(__DIR__."/../../vendor/m6w6/pharext/src:".get_include_path());
51 $stub = __DIR__."/../../vendor/m6w6/pharext/src/pharext_installer.php";
52 $this->file = (new Task\PharBuild($this->source, $stub, $meta))->run();
53
54 return sprintf("%s-%s.ext.phar", $this->name, $this->release);
55 }
56
57 function __toString() {
58 return (string) $this->file;
59 }
60
61 function getFile() {
62 return $this->file;
63 }
64
65 function getName() {
66 return $this->name;
67 }
68
69 function getRelease() {
70 return $this->release;
71 }
72 }