Exemplo n.º 1
0
 public function testGetConfig()
 {
     $instance = Teleport::instance(array('foo' => 'bar'));
     $config = $instance->getConfig();
     $this->assertInstanceOf('Teleport\\Config', $config);
     $this->assertEquals('bar', $config->get('foo'));
 }
Exemplo n.º 2
0
 /**
  * Get a MODX reference to operate on.
  *
  * @param \stdClass $profile An object describing properties of a MODX
  * instance.
  *
  * @return \modX A reference to a MODX instance.
  */
 public function &getMODX($profile)
 {
     if (!$this->modx instanceof \modX) {
         $results = $this->request->getResults();
         $this->modx = Teleport::instance()->getMODX($profile, $this->request->args(), $results);
     }
     return $this->modx;
 }
Exemplo n.º 3
0
 public function handle(array $arguments)
 {
     $this->parseArguments($arguments);
     $start = microtime(true);
     $loop = \React\EventLoop\Factory::create();
     $process = new \React\ChildProcess\Process($this->getCLICommand());
     $message = '';
     $request =& $this;
     $teleport = \Teleport\Teleport::instance();
     $process->on('exit', function ($exitCode, $termSignal) use($teleport, $request, $start, &$message) {
         $request->results = explode(PHP_EOL, rtrim($message, PHP_EOL));
         if ($request->args('debug') || $request->args('verbose')) {
             array_push($request->results, sprintf("request finished with exit code {$exitCode} in %2.4f seconds" . PHP_EOL, microtime(true) - $start));
         }
         if ($teleport->getConfig()->get('verbose', null, false) || $teleport->getConfig()->get('debug', null, false)) {
             echo sprintf("process finished with exit code {$exitCode} in %2.4f seconds" . PHP_EOL, microtime(true) - $start);
         }
     });
     $loop->addTimer(0.001, function ($timer) use($teleport, $request, $process, &$message) {
         if ($teleport->getConfig()->get('verbose', null, false) || $teleport->getConfig()->get('debug', null, false)) {
             echo "process started using cmd: {$process->getCommand()}" . PHP_EOL;
         }
         $process->start($timer->getLoop());
         $process->stdout->on('data', function ($output) use($teleport, $request, &$message) {
             $message .= $output;
             if ($teleport->getConfig()->get('verbose', null, false) || $teleport->getConfig()->get('debug', null, false)) {
                 echo $output;
             }
         });
         $process->stderr->on('data', function ($output) use($teleport, $request, &$message) {
             $message .= $output;
             if ($teleport->getConfig()->get('verbose', null, false) || $teleport->getConfig()->get('debug', null, false)) {
                 echo $output;
             }
         });
     });
     $loop->run();
 }
Exemplo n.º 4
0
        // Increase memory_limit if it is lower than 512M
        if ($memoryInBytes($memoryLimit) < 512 * 1024 * 1024) {
            @ini_set('memory_limit', '512M');
        }
        unset($memoryInBytes);
    }
    unset($memoryLimit);
}
try {
    require_once __DIR__ . '/../src/bootstrap.php';
    define('TELEPORT_BASE_PATH', rtrim(getcwd(), '/') . '/');
    $options = array('debug' => $debug);
    if (is_readable('config.php')) {
        $options = (include 'config.php');
    }
    $teleport = \Teleport\Teleport::instance($options);
    $request = $teleport->getRequest();
    array_shift($argv);
    $request->handle($argv);
    $results = implode(PHP_EOL, $request->getResults());
    echo trim($results) . PHP_EOL;
    if ($debug) {
        printf("execution finished with exit code 0 in %2.4f seconds" . PHP_EOL, microtime(true) - $start);
    }
    exit(0);
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL;
    if ($debug) {
        printf("execution failed with exit code {$e->getCode()} in %2.4f seconds" . PHP_EOL, microtime(true) - $start);
    }
    exit($e->getCode());