/** * Creates a new Folder entries object * * @param var... $args Either an io.Folder, an io.Path or a string * @throws lang.IllegalArgumentException */ public function __construct(...$args) { $this->base = Path::compose($args); if ($this->base->isEmpty()) { throw new IllegalArgumentException('Cannot create from empty name'); } }
/** * Determine layout, cached. * * @return xp.scriptlet.WebLayout */ private function determineLayout() { if (null === $this->layout) { $ini = new Path($this->webroot, WebConfiguration::INI); if ($ini->exists()) { $this->layout = new WebConfiguration(new Properties($ini->toString()), $this->config); } else { $ini = new Path($this->webroot, 'etc', WebConfiguration::INI); if ($ini->exists()) { $this->layout = new WebConfiguration(new Properties($ini->toString()), $this->config); } else { $this->layout = new ServeDocumentRootStatically(); } } } return $this->layout; }
public function relative_as_realpath_with_non_existant_components($components) { $current = getcwd(); $this->assertEquals($current, Path::compose($components)->asRealpath($current)->toString()); }
/** @param io.Path */ private function tempName() { return Path::compose([System::tempDir(), md5(uniqid()) . '-xp.json']); }
/** * Execute action * * @return void */ public function perform() { $this->archive->open(Archive::CREATE); $this->addAll($this->getArguments(), Path::real(getcwd())); $this->archive->create(); }
/** * Add a single file to the archive, and print out the name if verbose option is set. * * @param io.Path $target Zarh in archive * @param io.Path $source Path to source file * @return void */ protected function add($target, $source) { $name = $target->toString('/'); $this->options & Options::VERBOSE && $this->out->writeLine($name); $this->archive->addFile($name, $source->asFile()); }
/** * Entry point method * * @param string[] $args * @return int */ public static function main(array $args) { $webroot = new Path(getcwd()); $docroot = new Path($webroot, 'static'); $address = 'localhost:8080'; $profile = getenv('SERVER_PROFILE') ?: 'dev'; $mode = 'serve'; $arguments = []; $config = []; $source = '.'; for ($i = 0; $i < sizeof($args); $i++) { if ('-r' === $args[$i]) { $docroot = $webroot->resolve($args[++$i]); } else { if ('-a' === $args[$i]) { $address = $args[++$i]; } else { if ('-p' === $args[$i]) { $profile = $args[++$i]; } else { if ('-c' === $args[$i]) { $config[] = $args[++$i]; } else { if ('-m' === $args[$i]) { $arguments = explode(',', $args[++$i]); $mode = array_shift($arguments); } else { if ('-s' === $args[$i]) { $source = $args[++$i]; } else { $source = $args[$i]; break; } } } } } } } $server = self::server($mode, $address, $arguments); $server->serve($source, $profile, $webroot, $webroot->resolve($docroot), $config); return 0; }