lithium\console\command\Library::archive PHP Method

archive() public method

li3 library archive my_archive : archives current working directory to my_archive.phar.gz li3 library archive myapp my_archive : archives 'myapp' to 'my_archive.phar.gz'
public archive ( string $name = null, string $result = null ) : boolean
$name string if only param, the archive name for the current working directory otherwise, The library name or path to the directory to compress.
$result string if exists, The name of the resulting archive
return boolean
    public function archive($name = null, $result = null)
    {
        if (ini_get('phar.readonly') == '1') {
            throw new RuntimeException('set phar.readonly = 0 in php.ini');
        }
        $from = $name;
        $to = $name;
        if ($result) {
            $from = $name;
            $to = $result;
        }
        $path = $this->_toPath($to);
        if (file_exists("{$path}.phar")) {
            if (!$this->force) {
                $this->error(basename($path) . ".phar already exists in " . dirname($path));
                return false;
            }
            Phar::unlinkArchive("{$path}.phar");
        }
        try {
            $archive = new Phar("{$path}.phar");
        } catch (Exception $e) {
            $this->error($e->getMessage());
            return false;
        }
        $result = null;
        $from = $this->_toPath($from);
        if (is_dir($from)) {
            $result = (bool) $archive->buildFromDirectory($from, $this->filter);
        }
        if (file_exists("{$path}.phar.gz")) {
            if (!$this->force) {
                $this->error(basename($path) . ".phar.gz already exists in " . dirname($path));
                return false;
            }
            Phar::unlinkArchive("{$path}.phar.gz");
        }
        if ($result) {
            $archive->compress(Phar::GZ);
            $this->out(basename($path) . ".phar.gz created in " . dirname($path) . " from {$from}");
            return true;
        }
        $this->error("Could not create archive from {$from}");
        return false;
    }

Usage Example

Beispiel #1
0
 public function testArchiveNoLibrary()
 {
     $this->skipIf(!extension_loaded('zlib'), 'The zlib extension is not loaded.');
     $this->skipIf(ini_get('phar.readonly') == '1', 'INI setting phar.readonly = On');
     chdir('new');
     $app = new Library(array('request' => new Request(), 'classes' => $this->classes));
     $app->library = 'does_not_exist';
     $result = $app->archive();
     $this->assertTrue($result);
     $path = realpath($this->_testPath);
     $expected = "new.phar.gz created in {$path} from {$path}/new\n";
     $result = $app->response->output;
     $this->assertEqual($expected, $result);
     Phar::unlinkArchive($this->_testPath . '/new.phar');
     Phar::unlinkArchive($this->_testPath . '/new.phar.gz');
     $this->_cleanUp('tests/new');
     rmdir($this->_testPath . '/new');
 }