コード例 #1
0
ファイル: SyncTask.php プロジェクト: AgenceStratis/migrator
 /**
  * @param Configuration $config
  * @throws \Exception
  */
 public function main(Configuration $config)
 {
     $remote = $config->get(array('task', 'remote'), '');
     $local = $config->get(array('task', 'local'), '');
     $delay = $config->get(array('task', 'delay'), 0);
     if (empty($remote)) {
         throw new \Exception('Task/Sync: No remote path defined.');
     }
     if (empty($local)) {
         throw new \Exception('Task/Sync: No local path defined.');
     }
     if (count($this->sources) > 1) {
         throw new \Exception('Task/Sync: This task uses only 1 source.');
     }
     // Trim slashes from paths
     $remote = rtrim($remote, '/');
     $local = rtrim($local, '/');
     // Use only one source
     reset($this->sources);
     $source = current($this->sources);
     // Download files from remote server
     foreach ($source as $record) {
         usleep($delay);
         if (!array_key_exists('file', $record)) {
             throw new \Exception('Task/Sync: The record does not have a \'file\' field!');
         }
         // No file found
         if (empty($record['file'])) {
             continue;
         }
         try {
             $file = new File\Read($remote . '/' . $record['file']);
             $file->copy($local . '/' . $record['file']);
         } catch (\Exception $e) {
             // Can't read remote file
         }
     }
     exit;
 }
コード例 #2
0
ファイル: File.php プロジェクト: Grummfy/Central
 /**
  * Remove a cache file.
  *
  * @return  void
  */
 public function remove()
 {
     $this->setId($this->getIdMd5());
     $filename = $this->_parameters->getFormattedParameter('file.cache.directory') . $this->_parameters->getFormattedParameter('file.cache.file');
     $file = new HoaFile\Read($filename);
     $file->delete();
     $file->close();
     return;
 }
コード例 #3
0
ファイル: .webserver.php プロジェクト: Hywan/Amine_and_Hamza
<?php

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Bootstrap.php';
use Hoa\Dispatcher;
use Hoa\File;
use Hoa\Mime;
use Hoa\Router;
$router = new Router\Http();
$router->any('a', '.*', function (Dispatcher\Kit $_this) {
    $uri = $_this->router->getURI();
    $file = __DIR__ . DS . $uri;
    if (!empty($uri) && true === file_exists($file)) {
        $stream = new File\Read($file);
        try {
            $mime = new Mime($stream);
            $_mime = $mime->getMime();
        } catch (Mime\Exception $e) {
            $_mime = 'text/plain';
        }
        header('Content-Type: ' . $_mime);
        echo $stream->readAll();
        return;
    }
    require 'index.php';
});
$dispatcher = new Dispatcher\Basic();
$dispatcher->dispatch($router);
コード例 #4
0
ファイル: Update.php プロジェクト: lkraav/sabre-katana
 /**
  * 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, Version::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(SABRE_KATANA_PREFIX . '/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 ', $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();
     }
 }
コード例 #5
0
ファイル: Token.php プロジェクト: Bizkaitarra/pintxobot
 /**
  * Get AST of the token representation.
  *
  * @return  \Hoa\Compiler\Llk\TreeNode
  */
 public function getAST()
 {
     if (null === static::$_regexCompiler) {
         $stream = new File\Read('hoa://Library/Regex/Grammar.pp');
         $stream->rewind();
         static::$_regexCompiler = Compiler\Llk::load($stream);
     }
     if (null === $this->_ast) {
         $this->_ast = static::$_regexCompiler->parse($this->getRepresentation());
     }
     return $this->_ast;
 }
コード例 #6
0
ファイル: Pp.php プロジェクト: lovenunu/Hoa-compiler
 /**
  * The entry method.
  *
  * @return  int
  */
 public function main()
 {
     $visitor = null;
     $tokenSequence = false;
     $trace = false;
     while (false !== ($c = $this->getOption($v))) {
         switch ($c) {
             case 'v':
                 switch (strtolower($v)) {
                     case 'dump':
                         $visitor = 'Hoa\\Compiler\\Visitor\\Dump';
                         break;
                     default:
                         return $this->usage();
                 }
                 break;
             case 'c':
                 $visitor = str_replace('.', '\\', $v);
                 break;
             case 's':
                 $tokenSequence = true;
                 break;
             case 't':
                 $trace = true;
                 break;
             case '__ambiguous':
                 $this->resolveOptionAmbiguity($v);
                 break;
             case 'h':
             case '?':
             default:
                 return $this->usage();
         }
     }
     $this->parser->listInputs($grammar, $language);
     if (empty($grammar) || empty($language) && '0' !== $language) {
         return $this->usage();
     }
     $compiler = Compiler\Llk::load(new File\Read($grammar));
     $data = new File\Read($language);
     try {
         $ast = $compiler->parse($data->readAll());
     } catch (Compiler\Exception $e) {
         if (true === $tokenSequence) {
             $this->printTokenSequence($compiler);
             echo "\n\n";
         }
         throw $e;
         return 1;
     }
     if (true === $tokenSequence) {
         $this->printTokenSequence($compiler);
         echo "\n\n";
     }
     if (true === $trace) {
         $this->printTrace($compiler);
         echo "\n\n";
     }
     if (null !== $visitor) {
         $visitor = dnew($visitor);
         echo $visitor->visit($ast);
     }
     return;
 }
コード例 #7
0
ファイル: YoutubeBot.php プロジェクト: judge2020/ChannelBot
 protected function loadConfig()
 {
     $config = new Read($this->rootDir . "/config.yaml");
     $this->config = (object) Yaml::parse($config->readAll());
 }
コード例 #8
0
ファイル: Phar.php プロジェクト: nurtext/sabre-katana
 /**
  * Get the standard stub.
  *
  * @return string
  */
 function getStubCode()
 {
     $stub = new File\Read(__FILE__);
     $stub->seek(__COMPILER_HALT_OFFSET__);
     return trim($stub->read(1 << 20)) . "\n" . '__HALT_COMPILER();';
 }