Ejemplo n.º 1
0
 public function main()
 {
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'h':
             case '?':
                 return $this->usage();
                 break;
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
         }
     }
     $this->parser->listInputs($projectDirectory);
     if (empty($projectDirectory)) {
         throw new Console\Exception('The project directory must not be empty or null.', 0);
     }
     if (true === file_exists($projectDirectory)) {
         throw new Console\Exception('The project directory %s already exists, cannot create it.', 1, $projectDirectory);
     }
     $skeletonDirectory = 'hoa://Jekxyl/Resource/Skeleton';
     File\Directory::create($projectDirectory);
     (new File\Directory($skeletonDirectory))->copy($projectDirectory);
     return;
 }
Ejemplo n.º 2
0
 public function buildAssets()
 {
     $source = 'hoa://Jekxyl/Source/Public/';
     $destination = 'hoa://Jekxyl/Dist/';
     File\Directory::create($destination);
     $finder = new File\Finder();
     $finder->in($source)->files()->directories()->maxDepth(1);
     foreach ($finder as $file) {
         $file->open()->copy($destination . $file->getRelativePathname());
         $file->close();
     }
     return;
 }
Ejemplo n.º 3
0
 /**
  * Returns a principals' collection of files.
  *
  * The passed array contains principal information, and is guaranteed to
  * at least contain a uri item. Other properties may or may not be
  * supplied by the authentication backend.
  *
  * @param array $principalInfo
  * @return void
  */
 function getChildForPrincipal(array $principalInfo)
 {
     $owner = $principalInfo['uri'];
     $acl = [['privilege' => '{DAV:}read', 'principal' => $owner, 'protected' => true], ['privilege' => '{DAV:}write', 'principal' => $owner, 'protected' => true]];
     list(, $principalBaseName) = SabreUri\split($owner);
     $path = $this->storagePath . DS . $principalBaseName;
     if (!is_dir($path)) {
         HoaFile\Directory::create($path, HoaFile\Directory::MODE_CREATE_RECURSIVE);
     }
     $public = $path . DS . 'public';
     if (!is_dir($public)) {
         HoaFile\Directory::create($public, HoaFile\Directory::MODE_CREATE_RECURSIVE);
     }
     $out = new Directory($path, $acl, $owner);
     $out->setRelativePath($this->storagePath);
     return $out;
 }
Ejemplo n.º 4
0
 /**
  * The entry method.
  *
  * @return  int
  */
 public function main()
 {
     $directories = [];
     $clean = false;
     $lang = 'En';
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'd':
                 foreach ($this->parser->parseSpecialValue($v) as $directory) {
                     $directory = realpath($directory);
                     if (false === is_dir($directory)) {
                         throw new Console\Exception('Directory %s does not exist.', 0, $directory);
                     }
                     $directories[] = $directory;
                 }
                 break;
             case 'c':
                 $clean = true;
                 break;
             case 'l':
                 $lang = ucfirst(strtolower($v));
                 break;
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
             case 'h':
             case '?':
             default:
                 return $this->usage();
         }
     }
     $workspace = resolve('hoa://Library/Devtools/Resource/Documentation') . DS . 'HackBook.output';
     if (true === $clean) {
         if (true === is_dir($workspace)) {
             $directory = new File\Directory($workspace);
             $directory->delete();
             unset($directory);
         }
         return;
     }
     clearstatcache(true);
     $workspace .= DS . $lang;
     if (false === is_dir($workspace)) {
         File\Directory::create($workspace);
     }
     Console\Cursor::colorize('foreground(yellow)');
     echo 'Selected language: ', $lang, '.', "\n\n";
     Console\Cursor::colorize('normal');
     require_once 'hoa://Library/Devtools/Resource/Documentation/Router.php';
     // $router is defined.
     $finder = new File\Finder();
     foreach ($directories as $location) {
         $_location = $location . DS . 'Documentation' . DS . $lang;
         if (false === is_dir($_location)) {
             throw new Console\Exception('Directory %s does not contain documentation.', 1, $location);
         }
         $finder->in($_location);
     }
     foreach (resolve('hoa://Library', true, true) as $location) {
         $libraryFinder = new File\Finder();
         $libraryFinder->in($location)->directories()->maxDepth(1);
         foreach ($libraryFinder as $_location) {
             $_location = $_location->getPathName() . DS . 'Documentation' . DS . $lang;
             if (true === is_dir($_location)) {
                 $finder->in($_location);
             }
         }
     }
     $vendors = [];
     foreach ($finder as $entry) {
         $path = dirname(dirname($entry->getPath()));
         $vendor = ucfirst(strtolower(basename(dirname($path))));
         $library = ucfirst(strtolower(basename($path)));
         if (!isset($vendors[$vendor])) {
             $vendors[$vendor] = [];
         }
         $vendors[$vendor][$library] = ['library' => $library, 'vendor' => $vendor, 'fullname' => $vendor . '\\' . $library];
     }
     foreach ($vendors as $vendor => &$libraries) {
         $libraries = array_values($libraries);
     }
     $layout = new File\Read('hoa://Library/Devtools/Resource/Documentation/Layout.xyl');
     $xyl = new Xyl($layout, new File\Write($workspace . '/index.html'), new Xyl\Interpreter\Html(), $router);
     $xyl->setTheme('');
     $data = $xyl->getData();
     foreach ($vendors as $vendor => $libraries) {
         $data->vendors->vendor = ['name' => $vendor, 'library' => $libraries];
     }
     $xyl->addOverlay('hoa://Library/Devtools/Resource/Documentation/Index.xyl');
     $xyl->render();
     echo 'Generate', "\t";
     Console\Cursor::colorize('foreground(green)');
     echo 'index.html';
     Console\Cursor::colorize('normal');
     echo '.', "\n";
     $xyl = null;
     foreach ($vendors as $vendor => $libraries) {
         File\Directory::create($workspace . dirname($router->unroute('full', ['vendor' => $libraries[0]['vendor'], 'chapter' => $libraries[0]['library']])));
         foreach ($libraries as $library) {
             $in = 'hoa://Library/' . $library['library'] . '/Documentation/' . $lang . '/Index.xyl';
             $out = $workspace . $router->unroute('full', ['vendor' => $library['vendor'], 'chapter' => $library['library']]);
             if (true === file_exists($out) && filemtime($in) <= filemtime($out)) {
                 echo 'Skip', "\t\t";
                 Console\Cursor::colorize('foreground(green)');
                 echo $library['fullname'];
                 Console\Cursor::colorize('normal');
                 echo '.', "\n";
                 continue;
             }
             $out = new File\Write($out);
             $out->truncate(0);
             if (null === $xyl) {
                 $xyl = new Xyl($layout, $out, new Xyl\Interpreter\Html(), $router);
                 $xyl->setTheme('');
                 $xyl->addOverlay('hoa://Library/Devtools/Resource/Documentation/Chapter.xyl');
             } else {
                 $xyl->setOutputStream(new File\Write($out));
             }
             $xyl->addOverlay($in);
             $xyl->getData()->name[0] = $library['fullname'];
             $xyl->getData()->library[0] = $library['library'];
             try {
                 $xyl->render();
             } catch (\Exception $e) {
                 echo $e->getMessage(), "\n";
             }
             $xyl->removeOverlay($in);
             echo 'Generate', "\t";
             Console\Cursor::colorize('foreground(green)');
             echo $library['fullname'];
             Console\Cursor::colorize('normal');
             echo '.', "\n";
         }
     }
     echo "\n", 'Open file://', $workspace, '/index.html', '.', "\n";
     return;
 }
Ejemplo n.º 5
0
 /**
  * Set the SQLite support. If the specified database is :memory: or an
  * unexistant file, the self::createSchema() will be called.
  * If an existent file is given, it must contain the hoa_cache table
  * (please, see the self::createSchema() method). No test is done.
  * By default, the database -> host value will be choosen, but if it's
  * empty, the cache_directory will be choosen to place the database file.
  *
  * @return  void
  * @throws  \Hoa\Cache\Exception
  */
 protected function setSqlite()
 {
     if (null !== $this->_sqlite) {
         return;
     }
     $database = $this->_parameters->getParameter('sqlite.database.host');
     if (empty($database)) {
         $database = $this->_parameters->getParameter('sqlite.cache.directory');
     }
     $new = false;
     if (':memory:' === $database) {
         $new = true;
     } else {
         $new = true;
         HoaFile\Directory::create($database, HoaFile\Directory::MODE_CREATE_RECURSIVE);
     }
     if (false === ($this->_sqlite = @sqlite_open($database, 0644, $error))) {
         throw new Cache\Exception('Unable to connect to SQLite database : %s.', 2, $error);
     }
     $new and $this->createSchema();
     return;
 }
Ejemplo n.º 6
0
 /**
  * Move a file.
  *
  * @param   string  $name     New name.
  * @param   bool    $force    Force to move if the file $name already
  *                            exists.
  *                            Use the \Hoa\Stream\IStream\Touchable::*OVERWRITE
  *                            constants.
  * @param   bool    $mkdir    Force to make directory if does not exist.
  *                            Use the \Hoa\Stream\IStream\Touchable::*DIRECTORY
  *                            constants.
  * @return  bool
  */
 public function move($name, $force = Stream\IStream\Touchable::DO_NOT_OVERWRITE, $mkdir = Stream\IStream\Touchable::DO_NOT_MAKE_DIRECTORY)
 {
     $from = $this->getStreamName();
     if ($force === Stream\IStream\Touchable::DO_NOT_OVERWRITE && true === file_exists($name)) {
         return false;
     }
     if (Stream\IStream\Touchable::MAKE_DIRECTORY === $mkdir) {
         Directory::create(dirname($name), Directory::MODE_CREATE_RECURSIVE);
     }
     if (null === $this->getStreamContext()) {
         return @rename($from, $name);
     }
     return @rename($from, $name, $this->getStreamContext()->getContext());
 }
Ejemplo n.º 7
0
 /**
  * Triggered by a `DELETE`, `COPY` or `MOVE`. The goal is to remove the
  * home directory of the principal.
  *
  * @param  string  $path    Path.
  * @return bool
  */
 function afterUnbind($path)
 {
     list($collection, $principalName) = SabreUri\split($path);
     if ('principals' !== $collection) {
         return false;
     }
     $out = true;
     $path = $this->storagePath . DS . $principalName;
     if (is_dir($path)) {
         $directory = new HoaFile\Directory($this->storagePath . DS . $principalName);
         $out = $directory->delete();
         $directory->close();
     }
     return $out;
 }
Ejemplo n.º 8
0
 protected function computeOutputDirectory()
 {
     $outputDirectory = dirname($this->getOutputPathname());
     if (false === is_dir($outputDirectory)) {
         File\Directory::create($outputDirectory);
     }
     return;
 }
Ejemplo n.º 9
0
 /**
  * The entry method.
  *
  * @return  int
  */
 public function main()
 {
     $libraries = [];
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'a':
                 $iterator = new File\Finder();
                 $iterator->in(resolve('hoa://Library/', true, true))->directories()->maxDepth(1);
                 foreach ($iterator as $fileinfo) {
                     $libraryName = $fileinfo->getBasename();
                     $pathname = resolve('hoa://Library/' . $libraryName);
                     $automaticTests = $pathname . DS . 'Test' . DS . 'Praspel' . DS;
                     if (is_dir($automaticTests)) {
                         $libraries[] = $automaticTests;
                     }
                 }
                 if (empty($libraries)) {
                     echo 'Already clean.';
                     return;
                 }
                 break;
             case 'l':
                 foreach ($this->parser->parseSpecialValue($v) as $library) {
                     $libraryName = ucfirst(strtolower($library));
                     $pathname = resolve('hoa://Library/' . $libraryName);
                     $automaticTests = $pathname . DS . 'Test' . DS . 'Praspel' . DS;
                     if (is_dir($automaticTests)) {
                         $libraries[] = $automaticTests;
                     }
                 }
                 if (empty($libraries)) {
                     echo 'Already clean.';
                     return;
                 }
                 break;
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
             case 'h':
             case '?':
             default:
                 return $this->usage();
         }
     }
     if (empty($libraries)) {
         return $this->usage();
     }
     foreach ($libraries as $path) {
         $status = 'Clean ' . (40 < strlen($path) ? '…' . substr($path, -39) : $path);
         echo '  ⌛ ', $status;
         $directory = new File\Directory($path);
         if (false === $directory->delete()) {
             echo '  ', Console\Chrome\Text::colorize('✖︎', 'foreground(red)'), ' ', $status, "\n";
         } else {
             Console\Cursor::clear('↔');
             echo '  ', Console\Chrome\Text::colorize('✔︎', 'foreground(green)'), ' ', $status, "\n";
         }
         $directory->close();
     }
     return;
 }
Ejemplo n.º 10
0
 */
$view = function ($directoryName, $directory) {
    $user = get_current_user();
    $userId = getmyuid();
    $groupId = getmygid();
    $permissions = $directory->getReadablePermissions();
    require 'katana://resource/view/install_permissions.html';
};
$dataDirectory = new File\Directory('katana://data/');
$dataDirectory->clearStatisticCache();
if (false === $dataDirectory->isWritable()) {
    $view('data/', $dataDirectory);
    return;
}
$dataDirectory->close();
$homeDirectory = new File\Directory('katana://data/home/');
$homeDirectory->clearStatisticCache();
if (false === $homeDirectory->isWritable()) {
    $view('data/home/', $homeDirectory);
    return;
}
$homeDirectory->close();
$url = $request->getUrl();
$query = '';
/**
 * We compute asynchronous tasks from the installation page.
 * They have the following form: install?/<command>
 *
 * Else, we print the installation page.
 */
if (false !== ($pos = strpos($url, '?'))) {