Ejemplo n.º 1
0
 /**
  * Get an iterator over all the template schemas for the active database.
  *
  * @return Finder
  */
 function getTemplateSchemaIterator()
 {
     $driverName = $this->getAttribute($this::ATTR_DRIVER_NAME);
     $finder = new Finder();
     $finder->in('katana://resource/default/database/')->name('/\\.' . $driverName . '\\.sql$/');
     return $finder;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
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.º 4
0
 /**
  * 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 = SABRE_KATANA_PREFIX . '/data/share/' . $pathName;
         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 = SABRE_KATANA_PREFIX . '/data/share/';
         if (true === file_exists($pharPathname)) {
             unlink($pharPathname);
         }
         $phar = new Phar($pharPathname);
         $phar->buildFromIterator($finder, SABRE_KATANA_PREFIX);
         $phar->setStub($phar->getStubCode());
     }
     echo $archiveName, "\n";
 }
Ejemplo n.º 5
0
 /**
  * Constructor.
  *
  * @param   int  $latency    Latency (in seconds).
  * @return  void
  */
 public function __construct($latency = null)
 {
     parent::__construct();
     $this->setListener(new Event\Listener($this, ['new', 'modify', 'move']));
     if (null !== $latency) {
         $this->setLatency($latency);
     }
     return;
 }
Ejemplo n.º 6
0
 protected function listCommands($directory)
 {
     if (is_dir($directory) === false) {
         return array();
     }
     $finder = new Finder();
     $finder->in($directory)->name('#(.*)\\.php#');
     $group = array();
     $out = array();
     $extact = function ($uri) {
         $lines = file($uri);
         $description = '';
         // Berk…
         for ($i = count($lines) - 1; $i >= 0; --$i) {
             if (strpos($lines[$i], '__halt_compiler();') === 0) {
                 $description = trim(implode('', array_slice($lines, $i + 1)));
                 break;
             }
         }
         unset($lines);
         return $description;
     };
     foreach ($finder as $cmd) {
         /**
          * @var \SplFileInfo $cmd
          */
         $path = str_replace('\\', '/', $cmd->getPath());
         $category = substr($path, strrpos($path, '/') + 1, strlen($path));
         $command = $cmd->getBasename('.php');
         $description = $extact($cmd->getPathname());
         $group[$category][$command] = $description;
     }
     foreach ($group as $category => $command) {
         $out[] = \Hoa\Console\Chrome\Text::colorize($category, 'fg(green)');
         foreach ($command as $name => $description) {
             $out[] = array('   ', \Hoa\Console\Chrome\Text::colorize($name, 'fg(blue)'), $description);
         }
     }
     echo Text::columnize($out);
 }
Ejemplo n.º 7
0
 /**
  * Clean expired cache files.
  * Note : \Hoa\Cache::CLEAN_USER is not supported, it's reserved for APC
  * backend.
  *
  * @param   int  $lifetime    Lifetime of caches.
  * @return  void
  * @throws  \Hoa\Cache\Exception
  */
 public function clean($lifetime = Cache::CLEAN_EXPIRED)
 {
     switch ($lifetime) {
         case Cache::CLEAN_ALL:
             break;
         case Cache::CLEAN_EXPIRED:
             $lifetime = $this->_parameters->getParameter('lifetime');
             break;
         case Cache::CLEAN_USER:
             throw new Cache\Exception('\\Hoa\\Cache::CLEAN_USER constant is not supported by %s.' . 2, __CLASS__);
         default:
             $lifetime = $lifetime;
     }
     $this->setId($this->getIdMd5());
     try {
         $cacheDirectory = $this->_parameters->getFormattedParameter('file.cache.directory');
         $finder = new HoaFile\Finder();
         $finder->in($cacheDirectory)->files()->modified('since ' . $lifetime . ' seconds');
         foreach ($finder as $file) {
             $file->open()->delete();
             $file->close();
         }
     } catch (HoaFile\Exception\FileDoesNotExist $e) {
     }
     return;
 }
Ejemplo n.º 8
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.º 9
0
 /**
  * Clean expired cache files.
  * Note : \Hoa\Cache::CLEAN_USER is not supported, it's reserved for APC
  * backend.
  *
  * @param   string  $lifetime    Lifetime of caches.
  * @return  void
  * @throws  \Hoa\Cache\Exception
  */
 public function clean($lifetime = Cache::CLEAN_EXPIRED)
 {
     switch ($lifetime) {
         case Cache::CLEAN_ALL:
             break;
         case Cache::CLEAN_EXPIRED:
             $lifetime = $this->_parameters->getParameter('lifetime');
             break;
         case Cache::CLEAN_USER:
             throw new \Hoa\Cache\Exception('\\Hoa\\Cache::CLEAN_USER constant is not supported by ' . 'ZendPlatform cache backend.', 3);
             break;
         default:
             $lifetime = $lifetime;
     }
     $directory = ini_get('zend_accelerator.output_cache_dir') . DS . '.php_cache_api';
     try {
         $finder = new HoaFile\Finder();
         $finder->in($directory)->files()->modified('since ' . $lifetime . ' seconds');
         foreach ($finder as $file) {
             $file->open()->delete();
             $file->close();
         }
     } catch (File\Exception\FileDoesNotExist $e) {
     }
     return;
 }
Ejemplo n.º 10
0
Archivo: Run.php Proyecto: shulard/Test
 /**
  * The entry method.
  *
  * @return  int
  */
 public function main()
 {
     $directories = [];
     $files = [];
     $namespaces = [];
     $filter = [];
     $debug = false;
     $php = null;
     $concurrentProcesses = 2;
     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();
                     if (true === Consistency::isKeyword($libraryName)) {
                         continue;
                     }
                     $pathname = resolve('hoa://Library/' . $libraryName);
                     $tests = $pathname . DS . 'Test' . DS;
                     $manualTests = $tests . 'Unit';
                     $automaticTests = $tests . 'Praspel' . DS . 'Unit';
                     if (is_dir($manualTests)) {
                         $directories[] = $manualTests;
                     }
                     if (is_dir($automaticTests)) {
                         $directories[] = $automaticTests;
                     }
                 }
                 break;
             case 'l':
                 foreach ($this->parser->parseSpecialValue($v) as $library) {
                     $libraryName = ucfirst(strtolower($library));
                     $pathname = resolve('hoa://Library/' . $libraryName);
                     $tests = $pathname . DS . 'Test';
                     if (!is_dir($tests)) {
                         throw new Console\Exception('Library %s does not exist or has no test.', 0, $libraryName);
                     }
                     $directories[] = $tests;
                     $namespaces[] = 'Hoa\\' . $libraryName;
                 }
                 break;
             case 'n':
                 foreach ($this->parser->parseSpecialValue($v) as $namespace) {
                     $namespace = str_replace('.', '\\', $namespace);
                     $parts = explode('\\', $namespace);
                     if (2 > count($parts)) {
                         throw new Console\Exception('Namespace %s is too short.', 1, $namespace);
                     }
                     $head = resolve('hoa://Library/' . $parts[1]);
                     $tail = implode(DS, array_slice($parts, 2));
                     $namespaceDirectory = $head . DS . $tail;
                     if (!is_dir($namespaceDirectory)) {
                         throw new Console\Exception('Namespace %s does not exist.', 2, $namespace);
                     }
                     $tests = $head . DS . 'Test' . DS;
                     $manualTests = $tests . 'Unit' . DS . $tail;
                     $automaticTests = $tests . 'Praspel' . DS . 'Unit' . DS . $tail;
                     if (is_dir($manualTests)) {
                         $directories[] = $manualTests;
                     }
                     if (is_dir($automaticTests)) {
                         $directories[] = $automaticTests;
                     }
                     $namespaces[] = $namespace;
                 }
                 break;
             case 'd':
                 foreach ($this->parser->parseSpecialValue($v) as $directory) {
                     if (!is_dir($directory)) {
                         throw new Console\Exception('Directory %s does not exist.', 3, $directory);
                     }
                     $directories[] = $directory;
                 }
                 break;
             case 'f':
                 foreach ($this->parser->parseSpecialValue($v) as $file) {
                     if (!file_exists($file)) {
                         throw new Console\Exception('File %s does not exist.', 4, $file);
                     }
                     $files[] = $file;
                 }
                 break;
             case 'F':
                 $filter = $v;
                 break;
             case 'D':
                 $debug = $v;
                 break;
             case 'p':
                 $php = $v;
                 break;
             case 'P':
                 $concurrentProcesses = intval($v);
                 break;
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
             case 'h':
             case '?':
             default:
                 return $this->usage();
                 break;
         }
     }
     $atoum = 'atoum';
     if (WITH_COMPOSER) {
         $atoum = __DIR__ . DS . '..' . DS . '..' . DS . '..' . DS . 'bin' . DS . 'atoum';
     } elseif (isset($_SERVER['HOA_ATOUM_BIN'])) {
         $atoum = $_SERVER['HOA_ATOUM_BIN'];
     }
     $command = $atoum . ' --configurations ' . resolve('hoa://Library/Test/.atoum.php') . ' --bootstrap-file ' . resolve('hoa://Library/Test/.bootstrap.atoum.php') . ' --force-terminal' . ' --max-children-number ' . $concurrentProcesses;
     if (true === $debug) {
         $command .= ' --debug';
     }
     if (null !== $php) {
         $command .= ' --php ' . $php;
     }
     if (!empty($directories)) {
         $command .= ' --directories ' . implode(' ', $directories);
     } elseif (!empty($files)) {
         $command .= ' --files ' . implode(' ', $files);
     } else {
         return $this->usage();
     }
     if (!empty($namespaces)) {
         $command .= ' --namespaces ' . implode(' ', $namespaces);
     }
     if (!empty($filter)) {
         $command .= ' --filter \'' . str_replace('\'', '\'"\'"\'', $filter) . '\'';
     }
     $_server = $_SERVER;
     $_server['HOA_PREVIOUS_CWD'] = getcwd();
     $processus = new Processus($command, null, null, resolve('hoa://Library/Test/'), $_server);
     $processus->on('input', function ($bucket) {
         return false;
     });
     $processus->on('output', function ($bucket) {
         $data = $bucket->getData();
         echo $data['line'], "\n";
         return;
     });
     $processus->run();
     return;
 }
Ejemplo n.º 11
0
 /**
  * Find all classes from a root.
  *
  * @param   string  $root         Root.
  * @param   string  $namespace    Namespace to prepend.
  * @return  array
  */
 protected static function findClasses($root, $namespace)
 {
     $out = [];
     $finder = new File\Finder();
     $finder->in($root)->files()->name('#^(?!\\.).+\\.php#');
     foreach ($finder as $fileinfo) {
         $out[] = $namespace . '\\' . str_replace(DS, '\\', trim(substr($fileinfo->getRelativePathname(), 0, -4), DS));
     }
     return $out;
 }
Ejemplo n.º 12
0
 /**
  * The entry method.
  *
  * @access  public
  * @return  int
  */
 public function main()
 {
     $file = null;
     $debug = false;
     $dry = false;
     $directory = null;
     $output = 'out/';
     $style_formatter = 'Cli';
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'f':
                 $file = $v;
                 break;
             case 'd':
                 $directory = $v;
                 break;
             case 'o':
                 $output = $v;
                 break;
             case 's':
                 $style_formatter = $v;
                 break;
             case 'v':
                 $debug = true;
                 break;
             case 'p':
                 $dry = true;
                 break;
             case 'h':
             case '?':
             default:
                 return $this->usage();
                 break;
         }
     }
     echo \Hoa\Console\Chrome\Text::colorize('Sohapi', 'fg(yellow)'), "\n\n";
     $root = realpath(__DIR__ . '/../../../../');
     $out = realpath($root . '/' . $output);
     // TODO : Detect relative avec absolute path !
     $formatter = '\\Sohapi\\Formatter\\' . ucfirst($style_formatter);
     if ($file !== null) {
         $file = realpath($root . '/' . $file);
     }
     if ($directory !== null) {
         $directory = realpath($root . '/' . $directory);
     }
     if ($out === false) {
         $out = $root;
     }
     if ($debug === true) {
         //\Sohapi\Parser\Ast::enableDebug();
         $a = [['ROOT', var_export($root, true)], ['Debug', var_export($debug, true)], ['Dry', var_export($dry, true)], ['Formatter', var_export($formatter, true)], ['Output', var_export($out, true)], ['File', var_export($file, true)], ['Directory', var_export($directory, true)]];
         echo \Hoa\Console\Chrome\Text::columnize($a);
     }
     $files = array();
     $this->searchLocalConfig($root, $files);
     if ($file !== null and !in_array($file, $files)) {
         $files = array($file);
     }
     if ($directory !== null) {
         if ($this->searchLocalConfig($directory, $files) === false) {
             $finder = new \Hoa\File\Finder();
             $finder->in($directory)->files()->name('#\\.php$#');
             foreach ($finder as $f) {
                 if (!in_array($this->clean($f->getPathName()), $files)) {
                     $files[] = $this->clean($f->getPathName());
                 }
             }
         }
     }
     echo 'Found ' . count($files) . ' Files' . "\n";
     foreach ($files as $i => $file) {
         echo 'Parsing : [' . ($i + 1) . '/' . count($files) . '] ' . $file . "\n";
         if ($dry === false) {
             (new \Sohapi\Parser\Reader(file_get_contents($file)))->build();
         }
     }
     $options = [];
     dnew($formatter, ['options' => ['output' => $out, 'debug' => $debug, 'dry' => $dry, 'options' => $options]])->render();
     return;
 }
Ejemplo n.º 13
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.º 14
0
 /**
  * Delete a directory.
  *
  * @return  bool
  */
 public function delete()
 {
     $from = $this->getStreamName();
     $finder = new Finder();
     $finder->in($from)->childFirst();
     foreach ($finder as $file) {
         $file->open()->delete();
         $file->close();
     }
     if (null === $this->getStreamContext()) {
         return @rmdir($from);
     }
     return @rmdir($from, $this->getStreamContext()->getContext());
 }