Cross package maker. DEB/RPM generation or conversion. Derived from jordansissel/fpm.

βŒˆβŒ‹ βŽ‡ branch:  cross package maker


Check-in [01f616a04b]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Separate phar plugin from php generation template, prepare for classmap building.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 01f616a04b9808c4517b9ee705054d8da0ad7e3c
User & Date: mario 2015-01-21 12:28:32
Context
2015-01-21
13:10
Implement classmap builder directly in -t phar plugin. (Original implementation and tokenizer alternative in Canonic_Autoloader.) check-in: 5c62338e56 user: mario tags: trunk
12:28
Separate phar plugin from php generation template, prepare for classmap building. check-in: 01f616a04b user: mario tags: trunk
2015-01-20
00:01
Handle tilde, caret and asterisk specifiers more concretely. Downcase version suffixes in version_rewrite(). And abstract mapping for @dependencies, @provides, @conflicts, @replaces. Debian @suggests not yet populated. (And RPM target doesn't have it.) Composer dependency version alternatives "|" get ignored. Introduce --composer-no-alt flag to disable phar-|php- alternative lists for :debs too. check-in: 593dc02107 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/fpm/package/composer.rb.

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
          when "self.version"                         # pseudo JSOX
            " = " + @version
          when /^ (=|==|>=|>|>>|<<|<|<=) (#{rx}) $/x  # >= 2.0.x
            " #{$1} #{$2}"
          when /^ (!=|<>) (#{rx}) $/x                 # conflicts
            attrs[:composer]["conflict"][k] = $1
          when /^ ([\d.]+) \.[\*x] ([~-]*.*)? $/x     # Asterisk 1.0.* and 1.0.x
          p "Asterisk"
            [" >= #{$1}.0#{$2}", " << #{next_major_ver($1+'.0')}"]
          when /^ \~  (#{rx}) $/x                     # Tilde ~2.0
            [" >= #{$1}", " << #{next_major_ver($1)}"]
          when /^ \^ (#{rx})  $/x                     # Caret ^1.2.3
            [" >= #{$1}", " << #{next_major_ver($1, 0)}"]
          when /^ #{rx} $/x                           # literal 1.0.1
            " = #{v}"







<







234
235
236
237
238
239
240

241
242
243
244
245
246
247
          when "self.version"                         # pseudo JSOX
            " = " + @version
          when /^ (=|==|>=|>|>>|<<|<|<=) (#{rx}) $/x  # >= 2.0.x
            " #{$1} #{$2}"
          when /^ (!=|<>) (#{rx}) $/x                 # conflicts
            attrs[:composer]["conflict"][k] = $1
          when /^ ([\d.]+) \.[\*x] ([~-]*.*)? $/x     # Asterisk 1.0.* and 1.0.x

            [" >= #{$1}.0#{$2}", " << #{next_major_ver($1+'.0')}"]
          when /^ \~  (#{rx}) $/x                     # Tilde ~2.0
            [" >= #{$1}", " << #{next_major_ver($1)}"]
          when /^ \^ (#{rx})  $/x                     # Caret ^1.2.3
            [" >= #{$1}", " << #{next_major_ver($1, 0)}"]
          when /^ #{rx} $/x                           # literal 1.0.1
            " = #{v}"

Changes to lib/fpm/package/phar.rb.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ phar        β”‚ Phar        β”‚ -           β”‚ -           β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ phar.gz     β”‚ Phar        β”‚ gzip        β”‚ -           β”‚ general       β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ pharΒ·bz2    β”‚ Phar        β”‚ bzip2       β”‚ -           β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ PHAZ        β”‚ Phar        β”‚ -           β”‚ gzip        β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ -           β”‚ Phar        β”‚ gzip        β”‚ gzip        β”‚ (eschew)      β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ zip         β”‚ Zip         β”‚ -           β”‚ -           β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ zip.gz      β”‚ Zip         β”‚ gzip        β”‚ -           β”‚ distribution  β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ zip…bz2     β”‚ Zip         β”‚ bzip2       β”‚ -           β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€







|

|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ phar        β”‚ Phar        β”‚ -           β”‚ -           β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ phar.gz     β”‚ Phar        β”‚ gzip        β”‚ -           β”‚ general       β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ pharΒ·bz2    β”‚ Phar        β”‚ bzip2       β”‚ -           β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ phaZ        β”‚ Phar        β”‚ -           β”‚ gzip        β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ phaZ.gz     β”‚ Phar        β”‚ gzip        β”‚ gzip        β”‚ (eschew)      β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ zip         β”‚ Zip         β”‚ -           β”‚ -           β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ zip.gz      β”‚ Zip         β”‚ gzip        β”‚ -           β”‚ distribution  β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
#  β”‚ zip…bz2     β”‚ Zip         β”‚ bzip2       β”‚ -           β”‚               β”‚
#  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65

66
67



68
69
70
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# ZIPs and TARs can be read by other languages, but contain PHP/phar-specific
# additions (.phar/stub and a signature).
#

require "fpm/package"
require "fpm/util"
require "fileutils"

require "json"

# Phar creation (output only)
class FPM::Package::Phar < FPM::Package

  option "--format", "PHAR.gz/TGZ/ZIP", "Phar package type and compression (append .gz/.bz2 for method)", :default=>"PHAR.GZ"
  option "--stub", "STUB.php", "Apply initialization/stub file", :default=>""
  #option "--nocase", :flag, "Lowercase filenames within archive", :default=>false
  option "--sign", "PEM_FILE", "Sign package with OpenSSL and key from .pem file", :default=>""

  # Invoke PHP for actual packaging process
  def output(output_path)


    # Flags



    o_nocase = attributes[:phar_nocase] || false
    o_stub = attributes[:phar_stub] || ""
    o_sign = attributes[:phar_sign] || ""
    

    # Retain package meta information, either from fpm attributes, or collected :attr hash (src module, formerly :meta)
    meta = attrs.merge({
      "id" => @name,
      "version" => @version.to_s,
      "epoch" => @epoch.to_s,
      "iteration" => @iteration.to_s,
      "architecture" => @architecture,
      "category" => @category == "none" ? nil : @category,
      "author" => @maintainer,
      "url" => @url,
      "license" => @license,
    }).delete_if{ |k,v| v.nil? || v==""}
    
    # Match format specifier/extension onto type/settings
    fmt = (attributes[:phar_format] + output_path).downcase
    fmt, enc = fmt.match(/zip|phaz|tar|t[gb]z|pz/).to_s||"phar", fmt.match(/gz|bz2/).to_s
    map2 = { "tgz" => ["tar", "gz"], "tbz" => ["tar", "bz2"], "pz" => ["phaz", ""]  }
    map = {
        # fmt,  enc          extension   format        per-file-gz   extns ← archive-compr
       ["phar", ""   ] => [ ".phar",     "Phar::PHAR", "Phar::NONE", "",     "" ],
       ["phar", "gz" ] => [ ".phar",     "Phar::PHAR", "Phar::GZ",   "",     "" ],
       ["phar", "bz2"] => [ ".phar",     "Phar::PHAR", "Phar::BZ2",  "",     "" ],
       ["zip",  ""   ] => [ ".phar.zip", "Phar::ZIP",  "Phar::NONE", "",     "" ],
       ["zip",  "gz" ] => [ ".phar.zip", "Phar::ZIP",  "Phar::GZ",   "",     "" ],
       ["zip", "bz2" ] => [ ".phar.zip", "Phar::ZIP",  "Phar::BZ2",  "",     "" ],
       ["tar",  ""   ] => [ ".phar.tar", "Phar::TAR",  "Phar::NONE", "",     "" ],
       ["tar",  "gz" ] => [ ".phar.tar", "Phar::TAR",  "Phar::GZ",   ".gz",  "(Phar::GZ)" ],
       ["tar", "bz2" ] => [ ".phar.tar", "Phar::TAR",  "Phar::BZ2",  ".bz2", "(Phar::BZ2)"],
       ["phaz", ""   ] => [ ".phar",     "Phar::PHAR", "Phar::GZ",   ".gz",  "(Phar::GZ)" ],
       ["phaz", "gz" ] => [ ".phar",     "Phar::PHAR", "Phar::GZ",   ".gz",  "(Phar::GZ)" ],
       ["phaz", "bz2"] => [ ".phar",     "Phar::PHAR", "Phar::GZ",   ".bz2", "(Phar::BZ2)"],
    }
    opt = map[[fmt,enc]] || map[map2[fmt]] || map[["phar", ""]]
    o_stdext, o_format, o_filegz, o_extout, o_hullgz = opt
    
    # Prepare output / temp filename
    output_check(output_path)
    tmp_phar = ::Dir::Tmpname.create(['_\$fpm_phar_', o_stdext]) { }

    # Have PHP generate the package
    code = <<-PHP
       #-- Create phar
       $p = new Phar('#{tmp_phar}', 0, '#{name}');
       $p->startBuffering();

       #-- Add files
       $p->buildFromDirectory('#{staging_path}');
       
       #-- Stub
       if (strlen('#{o_stub}') && file_exists('#{staging_path}/#{o_stub}')) {
          $p->setStub(file_get_contents('#{staging_path}/#{o_stub}'));
       }
       elseif (#{o_format} == Phar::PHAR) {
          $p->setDefaultStub("__init__.php", "index.php");
       }
       else {
          $p->setDefaultStub();
       }

       #-- Carry packaging info over as meta data (in particular for `fpm -s src` module)
       $p->setMetadata(json_decode($_SERVER["argv"][1]));

       #-- Per-file compression
       if (#{o_filegz}) {
          $p->compressFiles(#{o_filegz});
       }
       
       #-- Signature
       if (strlen('#{o_sign}')) {
          $p->setSignatureAlgorithm(Phar::OPENSSL, file_get_contents('#{o_sign}'));
       }
       else {
          $p->setSignatureAlgorithm(Phar::SHA256);
       }
              
       #-- Save all the things
       $p->stopBuffering();

       // Whole-archive compression; output goes to a different filename. (Cleaned up in Ruby...)
       if ("#{o_extout}") {
          $p->compress(#{o_hullgz});
       }
    PHP
    safesystem("php", "-dphar.readonly=0", "-derror_reporing=~0", "-ddisplay_errors=1", "-r", code, JSON.generate(meta))

    #-- but might end up with suffix, for whole-archive ->compress()ion
    FileUtils.mv(tmp_phar + o_extout, output_path)
    File.unlink(tmp_phar) if File.exists?(tmp_phar)
  end

end # class FPM::Package::Phar







>







|




>

|
>
>
>
|
|
|
|
>

|














|









|
|
|
|
|

<
<
|
<
<
<
|
<
<
<
<
<
|
<
<
|
<
<
<
|
<
<
<
<
<
<
|
<
<
|
<
<
<
|
|
<
<
<
<
<
<
<
|
<
<
|
<
<
<
<
<
|


|
|



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109


110



111





112


113



114






115


116



117
118







119


120





121
122
123
124
125
126
127
128
# ZIPs and TARs can be read by other languages, but contain PHP/phar-specific
# additions (.phar/stub and a signature).
#

require "fpm/package"
require "fpm/util"
require "fileutils"
require "tempfile"
require "json"

# Phar creation (output only)
class FPM::Package::Phar < FPM::Package

  option "--format", "PHAR.gz/TGZ/ZIP", "Phar package type and compression (append .gz/.bz2 for method)", :default=>"PHAR.GZ"
  option "--stub", "STUB.php", "Apply initialization/stub file", :default=>""
  #option "--nocase", :flag, "Lowercase filenames / implicit `-u lcase=*`", :default=>false
  option "--sign", "PEM_FILE", "Sign package with OpenSSL and key from .pem file", :default=>""

  # Invoke PHP for actual packaging process
  def output(output_path)
    output_check(output_path)

    # Build flags
    p = {
      :name   => name,
      :srcdir => staging_path,
      #:nocase => attributes[:phar_nocase],
      :stub   => attributes[:phar_stub_given?] ? staging_path + "/" + attributes[:phar_stub] : "",
      :sign   => attributes[:phar_sign],
    }
    
    # Retain package meta information, either from fpm attributes, or collected :attr hash (src module, formerly :meta)
    p[:meta] = attrs.merge({
      "id" => @name,
      "version" => @version.to_s,
      "epoch" => @epoch.to_s,
      "iteration" => @iteration.to_s,
      "architecture" => @architecture,
      "category" => @category == "none" ? nil : @category,
      "author" => @maintainer,
      "url" => @url,
      "license" => @license,
    }).delete_if{ |k,v| v.nil? || v==""}
    
    # Match format specifier/extension onto type/settings
    fmt = (attributes[:phar_format] + output_path).downcase
    fmt, enc = fmt.match(/zip|phaz|tar|t[gb]z|pz/).to_s||"phar", fmt.match(/gz|bz2/).to_s
    map_keys = [:stdext, :format, :filegz, :extout, :hullgz]
    map = {
        # fmt,  enc          extension   format        per-file-gz   extns ← archive-compr
       ["phar", ""   ] => [ ".phar",     "Phar::PHAR", "Phar::NONE", "",     "" ],
       ["phar", "gz" ] => [ ".phar",     "Phar::PHAR", "Phar::GZ",   "",     "" ],
       ["phar", "bz2"] => [ ".phar",     "Phar::PHAR", "Phar::BZ2",  "",     "" ],
       ["zip",  ""   ] => [ ".phar.zip", "Phar::ZIP",  "Phar::NONE", "",     "" ],
       ["zip",  "gz" ] => [ ".phar.zip", "Phar::ZIP",  "Phar::GZ",   "",     "" ],
       ["zip", "bz2" ] => [ ".phar.zip", "Phar::ZIP",  "Phar::BZ2",  "",     "" ],
       ["tar",  ""   ] => [ ".phar.tar", "Phar::TAR",  "Phar::NONE", "",     "" ],
       ["tar",  "gz" ] => [ ".phar.tar", "Phar::TAR",  "Phar::GZ",   ".gz",  "Phar::GZ" ],
       ["tar", "bz2" ] => [ ".phar.tar", "Phar::TAR",  "Phar::BZ2",  ".bz2", "Phar::BZ2"],
       ["phaz", ""   ] => [ ".phar",     "Phar::PHAR", "Phar::GZ",   ".gz",  "Phar::GZ" ],
       ["phaz", "gz" ] => [ ".phar",     "Phar::PHAR", "Phar::GZ",   ".gz",  "Phar::GZ" ],
       ["phaz", "bz2"] => [ ".phar",     "Phar::PHAR", "Phar::GZ",   ".bz2", "Phar::BZ2"],
    }


    ext2map = {  # map file extensions



       "tgz" => ["tar", "gz"],





       "tbz" => ["tar", "bz2"],


       "pz"  => ["phaz", ""]



    }






    opt = map[[fmt,enc]] || map[ext2map[fmt]] || map[["phar", ""]]


    p.merge! Hash[map_keys.zip opt]




    # Have PHP generate the package







    p[:tmpf] = ::Dir::Tmpname.create(['_\$fpm_phar_', p[:stdext]]) {}


    phargen = template_dir + "/phar.php"





    safesystem("php", "-dphar.readonly=0", "-derror_reporing=~0", "-ddisplay_errors=1", phargen, JSON.generate(p))

    #-- but might end up with suffix, for whole-archive ->compress()ion
    FileUtils.mv(p[:tmpf] + p[:extout], output_path)
    File.unlink(p[:tmpf]) if File.exists?(p[:tmpf])
  end

end # class FPM::Package::Phar

Added templates/phar.php.































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
 * api: php
 * title: Phar generation
 * description: PHP script template to get Phar assembled
 *
 * Used as template php script for -t phar building.
 * Extracts passed Ruby variables as PHP strings, so some
 * need constant(), strlen() or boolean interpretation.
 *
 */


#-- Parameters from phar.rb passed as JSON in argv[1]
extract(json_decode($_SERVER["argv"][1], TRUE));


/**
 * Create phar
 *  Β· Tempoarary filename.
 *  Β· FPM package name as Phar name.
 *  Β· Read complete staging dir.
 */
$p = new Phar($tmpf, 0, $name);
$p->startBuffering();
$p->buildFromDirectory($srcdir);


/**
 * Add stub
 *  Β· Use given file
 *  Β· Default init+index.php for native Phars.
 *  Β· Stub for zip/tar archive.
 */
if (strlen($stub) && file_exists($stub)) {
   $p->setStub(file_get_contents($stub));
}
elseif (constant($format) == Phar::PHAR) {
   $p->setDefaultStub("__init__.php", "index.php");
}
else {
   $p->setDefaultStub();
}


/**
 * Phar meta data
 *  Β· Use injected JSON blob.
 *  Β· Contains at least fpm package infos,
 *  Β· May contain additional fields - attrs{} from `-s src` or `composer` module
 *  Β· Build and include a classmap.
 */
if ($meta) {
   $p->setMetadata($meta);
}


/**
 * Complete packaging
 *  Β· Set per-file compression
 *  Β· Add signature, if any.
 *  Β· Compressed outer archive hull (tar or phar).
 */
if (constant($filegz)) {
   $p->compressFiles(constant($filegz));
}
if (strlen($sign)) {
   $p->setSignatureAlgorithm(Phar::OPENSSL, file_get_contents($sign));
}
else {
   $p->setSignatureAlgorithm(Phar::SHA256);
}
// Whole-archive compression; output goes to a different filename. (Cleaned up in Ruby...)
$p->stopBuffering();
if (strlen($extout)) {
   $p->compress(constant($hullgz));
}