~ubuntu-branches/ubuntu/quantal/php5/quantal

« back to all changes in this revision

Viewing changes to ext/phar/tests/zip/files/zipmaker.php.inc

  • Committer: Bazaar Package Importer
  • Author(s): Sean Finney
  • Date: 2009-07-01 09:12:10 UTC
  • mto: (0.9.1) (1.1.17 upstream)
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: james.westby@ubuntu.com-20090701091210-go0h6506p62on17r
Tags: upstream-5.3.0
ImportĀ upstreamĀ versionĀ 5.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// stolen from PEAR2_Pyrus_Developer_Creator_Zip by Greg Beaver, the original author, for use in unit tests
 
3
class zipmaker
 
4
{
 
5
    /**
 
6
     * Path to archive file
 
7
     *
 
8
     * @var string
 
9
     */
 
10
    protected $archive;
 
11
    /**
 
12
     * @var ZIPArchive
 
13
     */
 
14
    protected $zip;
 
15
    protected $path;
 
16
    function __construct($path)
 
17
    {
 
18
        if (!class_exists('ZIPArchive')) {
 
19
            throw new Exception(
 
20
                'Zip extension is not available');
 
21
        }
 
22
        $this->path = $path;
 
23
    }
 
24
 
 
25
    /**
 
26
     * save a file inside this package
 
27
     * @param string relative path within the package
 
28
     * @param string|resource file contents or open file handle
 
29
     */
 
30
    function addFile($path, $fileOrStream)
 
31
    {
 
32
        if (is_resource($fileOrStream)) {
 
33
            $this->zip->addFromString($path, stream_get_contents($fileOrStream));
 
34
        } else {
 
35
            $this->zip->addFromString($path, $fileOrStream);
 
36
        }
 
37
    }
 
38
 
 
39
    /**
 
40
     * Initialize the package creator
 
41
     */
 
42
    function init()
 
43
    {
 
44
        $this->zip = new ZipArchive;
 
45
        if (true !== $this->zip->open($this->path, ZIPARCHIVE::CREATE)) {
 
46
            throw new Exception(
 
47
                'Cannot open ZIP archive ' . $this->path
 
48
            );
 
49
        }
 
50
    }
 
51
 
 
52
    /**
 
53
     * Create an internal directory, creating parent directories as needed
 
54
     * 
 
55
     * This is a no-op for the tar creator
 
56
     * @param string $dir
 
57
     */
 
58
    function mkdir($dir)
 
59
    {
 
60
        $this->zip->addEmptyDir($dir);
 
61
    }
 
62
 
 
63
    /**
 
64
     * Finish saving the package
 
65
     */
 
66
    function close()
 
67
    {
 
68
        $this->zip->close();
 
69
    }
 
70
}
 
 
b'\\ No newline at end of file'