Пример #1
0
 /**
  * Invoke a target
  *
  * @param   xp.codegen.AbstractGenerator generator
  * @param   lang.reflect.Method method
  * @param   util.collections.HashTable targets
  * @return  var result
  */
 protected static function invoke(AbstractGenerator $generator, \lang\reflect\Method $method, \lang\Object $targets)
 {
     $target = $targets->get($method);
     if ($target->containsKey('result')) {
         return $target['result'][0];
     }
     Console::writeLine('---> Target ', $method->getName(), ': ');
     // Execute dependencies
     if ($target->containsKey('depends')) {
         foreach ($target->get('depends') as $depends) {
             self::invoke($generator, $depends, $targets);
         }
     }
     // Retrieve arguments
     $arguments = array();
     if ($target->containsKey('arguments')) {
         foreach ($target->get('arguments') as $argument) {
             $arguments[] = self::invoke($generator, $argument, $targets);
         }
     }
     // Execute target itself
     $result = $method->invoke($generator, $arguments);
     $target['result'] = new \lang\types\ArrayList($result);
     Console::writeLine(null === $result ? '<ok>' : \xp::typeOf($result));
     return $result;
 }
Пример #2
0
 /**
  * Serve requests
  *
  * @param  string $source
  * @param  string $profile
  * @param  io.Path $webroot
  * @param  io.Path $docroot
  * @param  string[] $config
  */
 public function serve($source, $profile, $webroot, $docroot, $config)
 {
     $runtime = Runtime::getInstance();
     $startup = $runtime->startupOptions();
     $backing = typeof($startup)->getField('backing')->setAccessible(true)->get($startup);
     // PHP doesn't start with a nonexistant document root
     if (!$docroot->exists()) {
         $docroot = getcwd();
     }
     // Start `php -S`, the development webserver
     $arguments = ['-S', $this->host . ':' . $this->port, '-t', $docroot];
     $options = newinstance(RuntimeOptions::class, [$backing], ['asArguments' => function () use($arguments) {
         return array_merge($arguments, parent::asArguments());
     }]);
     $options->withSetting('user_dir', $source . PATH_SEPARATOR . implode(PATH_SEPARATOR, $config));
     // Pass classpath (TODO: This is fixed in XP 7.6.0, remove once
     // this becomes minimum dependency)
     $cp = [];
     foreach (ClassLoader::getLoaders() as $delegate) {
         if ($delegate instanceof FileSystemClassLoader || $delegate instanceof ArchiveClassLoader) {
             $cp[] = $delegate->path;
         }
     }
     set_include_path('');
     $options->withClassPath($cp);
     // Export environment
     putenv('DOCUMENT_ROOT=' . $docroot);
     putenv('WEB_ROOT=' . $webroot);
     putenv('SERVER_PROFILE=' . $profile);
     Console::writeLine("@", $this, "");
     Console::writeLine("Serving ", (new Source($source, new Config($config)))->layout());
     Console::writeLine("", str_repeat('═', 72), "");
     Console::writeLine();
     with($runtime->newInstance($options, 'web', '', []), function ($proc) {
         $proc->in->close();
         Console::writeLine("> Server started: ", $this->url, " (", date('r'), ')');
         Console::writeLine('  PID ', $proc->getProcessId(), '; press Ctrl+C to exit');
         Console::writeLine();
         while (is_string($line = $proc->err->readLine())) {
             Console::writeLine("  ", $line, "");
         }
     });
 }
Пример #3
0
 public function repeated_calls_to_xp_stringOf_yield_same_result()
 {
     $object = new \lang\Object();
     $stringRep = $object->toString();
     $this->assertEquals([$stringRep, $stringRep], [\xp::stringOf($object), \xp::stringOf($object)]);
 }
Пример #4
0
 public function calling_undefined_static_methods_raises_an_error()
 {
     Object::undefMethod();
 }
 /**
  * Creates a PhoneNumber object
  *
  * @param   array defaults array with default values (may be omitted)
  */
 public function __construct($params = null)
 {
     parent::__construct($params);
 }