Extends
lithium\console\Command
Extract an archive into a path. If one param exists, the app.phar.gz template will be used.
If both parameters exist, then the first will be the template archive and the second will be
the name of the extracted archive
`li3 library extract myapp` : uses the command/create/template/app.phar.gz
`li3 library extract another_archive myapp`
`li3 library extract plugin li3_plugin` : uses the command/create/template/plugin.phar.gz
Parameters
- string $name if only param, command/create/template/app.phar.gz extracted to $name otherwise, the template name or full path to extract `from` phar.gz.
- string $result if exists $name is extracted to $result
Returns
booleanSource
public function extract($name = 'new', $result = null) {
$from = 'app';
$to = $name;
if ($result) {
$from = $name;
$to = $result;
}
$to = $this->_toPath($to);
if ($from[0] !== '/') {
$from = Libraries::locate('command.create.template', $from, array(
'filter' => false, 'type' => 'file', 'suffix' => '.phar.gz'
));
if (!$from || is_array($from)) {
return false;
}
}
if (file_exists($from)) {
try {
$archive = new Phar($from);
} catch (Exception $e) {
$this->error($e->getMessage());
return false;
}
if ($archive->extractTo($to)) {
$this->out(basename($to) . " created in " . dirname($to) . " from {$from}");
return $this->_replaceAfterExtract($to);
}
}
$this->error("Could not extract {$to} from {$from}");
return false;
}