aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/ZipArchiveTrait.php
blob: 803a5e1b1df15dbb2b93fb5a8fca21f55c35b2d8 (plain)
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
<?php
namespace Studip;

/**
 * Trait that handles the different method signatures in addFile() due to
 * changes in the Zip module since v1.18. This is the regular part.
 */
trait ZipArchiveTrait
{
    /**
     * Adds a single file.
     *
     * @param String $filename Name of the file to add
     * @param String $localname Name of the file inside the archive,
     *                          will default to $filename
     * @param int $start Unused but required (according to php doc)
     * @param int $length Unused but required (according to php doc)
     * @param int $flags Bitmask (see https://php.net/ziparchive.addfile)
     * @return false on error, $localname otherwise
     */
    public function addFile($filename, $localname = null, $start = 0, $length = 0, $flags = \ZipArchive::FL_OVERWRITE)
    {
        $localname = $this->convertLocalFilename($localname ?: basename($filename));
        return parent::addFile($filename, $localname, $start, $length, $flags)
            ? $localname
            : false;
    }
}