protected function getPhar(&$pharName) { $finder = new Finder(); $finder->files()->in(Protocol::realPath('katana://data/lib/composer'))->in(Protocol::realPath('katana://data/lib/hoa/core'))->in(Protocol::realPath('katana://data/lib/hoa/console'))->in(Protocol::realPath('katana://data/lib/hoa/iterator'))->in(Protocol::realPath('katana://data/lib/hoa/router'))->in(Protocol::realPath('katana://data/lib/sabre/uri'))->in(Protocol::realPath('katana://data/lib/ircmaxell/password-compat'))->name('/\\.php$/')->notIn('/^\\.git$/'); $pharName = $this->helper->temporaryFile('.phar'); $phar = new CUT($pharName); $phar->buildFromIterator($finder, SABRE_KATANA_PREFIX); $phar['bootstrap.php'] = '<?php require \'vendor/autoload.php\';'; $phar['vendor/autoload.php'] = file_get_contents('katana://data/lib/autoload.php'); $phar->setStub($phar->getStubCode()); return $phar; }
/** * Overload the parent constructor. * The username and password might come from the configuration file. Thus, * if not set, their values are an empty string. PDO needs no value instead * of an empty string. We fix that. * * @param string $dsn DSN. * @param string $username Username. * @param string $password Password. * @return void */ function __construct($dsn, $username = null, $password = null) { if ('sqlite:katana://' === substr($dsn, 0, 16)) { $dsn = 'sqlite:' . Protocol::realPath(substr($dsn, 7), false); } if (empty($username)) { parent::__construct($dsn); } elseif (empty($password)) { parent::__construct($dsn, $username); } else { parent::__construct($dsn, $username, $password); } }
/** * Main method. * * @return int */ function main() { $format = 0; while (false !== ($c = $this->getOption($v))) { switch ($c) { case '__ambiguous': $this->resolveOptionAmbiguity($v); break; case 'z': $format = static::FORMAT_ZIP; break; case 'p': $format = static::FORMAT_PHAR; break; case 'h': case '?': default: return $this->usage(); break; } } $archiveName = null; $finder = new Finder(); $finder->files()->in(SABRE_KATANA_PREFIX)->notIn('/^\\.git$/'); if (0 === $format) { return $this->usage(); } elseif (static::FORMAT_ZIP === $format) { $pathName = 'katana.zip'; $finder->notIn('/^' . preg_quote($pathName, '/') . '$/'); $archiveName = $pharPathname = Protocol::realPath('katana://data/share/' . $pathName, false); if (true === file_exists($pharPathname)) { unlink($pharPathname); } $zip = new Zip($pharPathname); $zip->buildFromIterator($finder, SABRE_KATANA_PREFIX); } elseif (static::FORMAT_PHAR === $format) { if (false === Phar::canWrite()) { throw new Exception\Console('Cannot create the PHAR. ' . 'Retry with `php -d phar.readonly=0 ' . $_SERVER['argv'][0] . ' stub --phar'); } $pathName = 'katana.phar'; $finder->notIn('/^' . preg_quote($pathName, '/') . '$/'); $archiveName = $pharPathname = Protocol::realPath('katana://data/share/' . $pathName, false); if (true === file_exists($pharPathname)) { unlink($pharPathname); } $phar = new Phar($pharPathname); $phar->buildFromIterator($finder, SABRE_KATANA_PREFIX); $phar->setStub($phar->getStubCode()); } echo $archiveName, "\n"; }
/** * Main method. * * @return int */ function main() { $operation = 0; $location = null; $updateServer = Updater::DEFAULT_UPDATE_SERVER; while (false !== ($c = $this->getOption($v))) { switch ($c) { case '__ambiguous': $this->resolveOptionAmbiguity($v); break; case 'f': $operation = static::OPERATION_FETCH | Updater::FORMAT_PHAR; break; case 'z': $operation = static::OPERATION_FETCH | Updater::FORMAT_ZIP; break; case 'a': $operation = static::OPERATION_APPLY; $location = $v; break; case 's': $updateServer = $v; break; case 'h': case '?': default: return $this->usage(); break; } } $updateServer = rtrim($updateServer, '/') . '/'; if (0 !== (static::OPERATION_FETCH & $operation)) { $updatesDotJson = Updater::getUpdateUrl($updateServer); $versions = @file_get_contents($updatesDotJson); if (empty($versions)) { throw new Exception\Console('Oh no! We are not able to check if a new version exists… ' . 'Contact us at http://sabre.io/ ' . '(tried URL %s).', 0, $updatesDotJson); } $versions = json_decode($versions, true); /** * Expected format: * { * "1.0.1": { * "phar": "https://…", * "zip" : "https://…" * }, * "1.0.0": { * "phar": "https://…", * "zip" : "https://…" * }, * … * } */ $versionsToFetch = Updater::filterVersions($versions, SABRE_KATANA_VERSION, $operation); $windowWidth = Window::getSize()['x']; $progress = function ($percent) use($windowWidth) { Cursor::clear('↔'); $message = 'Downloading… '; $barWidth = $windowWidth - mb_strlen($message); if ($percent <= 0) { $color = '#c74844'; } elseif ($percent <= 25) { $color = '#cb9a3d'; } elseif ($percent <= 50) { $color = '#dcb11e'; } elseif ($percent <= 75) { $color = '#aed633'; } else { $color = '#54b455'; } echo $message; Cursor::colorize('foreground(' . $color . ') background(' . $color . ')'); echo str_repeat('|', $percent * $barWidth / 100); Cursor::colorize('normal'); }; foreach ($versionsToFetch as $versionNumber => $versionUrl) { list(, $versionUrlBasename) = Uri\split($versionUrl); $fileIn = new File\Read($versionUrl, File::MODE_READ, null, true); $fileOut = new File\Write('katana://data/share/update/' . $versionUrlBasename); echo "\n", 'Fetch version ', $versionNumber, ' from ', $versionUrl, "\n", 'Waiting…', "\n"; $fileIn->on('connect', function () { Cursor::clear('↔'); echo 'Downloading… '; }); $fileIn->on('progress', function (Core\Event\Bucket $bucket) use($progress) { static $previousPercent = 0; $data = $bucket->getData(); $current = $data['transferred']; $max = $data['max']; $percent = $current * 100 / $max; $delta = $percent - $previousPercent; if (1 <= $delta) { $previousPercent = $percent; $progress($percent); } }); $fileIn->open(); $fileOut->writeAll($fileIn->readAll()); echo "\n", 'Fetched at ', Protocol::realPath($fileOut->getStreamName()), '.', "\n"; } return 0; } elseif (static::OPERATION_APPLY === $operation) { if (false === file_exists($location)) { throw new Exception\Console('Update %s is not found.', 1, $location); } $processus = new Console\Processus(Core::getPHPBinary(), [$location, '--extract' => SABRE_KATANA_PREFIX, '--overwrite']); $processus->on('input', function () { return false; }); $processus->on('output', function (Core\Event\Bucket $bucket) { echo $bucket->getData()['line'], "\n"; }); $processus->run(); if (true === $processus->isSuccessful()) { echo 'sabre/katana updated!', "\n"; } else { echo 'Something wrong happened!', "\n"; } return $processus->getExitCode(); } else { return $this->usage(); } }
/** * Initialize WebDAV. * * @param DavACl\Principal\Backend $principalBackend The principal backend. * @return void */ protected function initializeWebDAV(DavAcl\Principal\Backend $principalBackend) { $storagePath = Protocol::realPath('katana://data/home'); $collection = new DavAcl\File\Home($principalBackend, $storagePath, 'principals'); $collection->collectionName = 'files'; $this->getServer()->tree->getNodeForPath('')->addChild($collection); $this->getServer()->addPlugin(new DavAcl\File\Plugin($storagePath)); $database = $this->getDatabase(); $backend = new SabreDav\Locks\Backend\PDO($database); $plugin = new SabreDav\Locks\Plugin($backend); $this->getServer()->addPlugin($plugin); }
function case_data_root() { $this->given($path = 'katana://data/')->when($result = CUT::realPath($path))->then->string($result)->isEqualTo(realpath(__DIR__ . DS . '..' . DS . '..' . DS . 'data') . DS); }