Ejemplo n.º 1
0
 private function readConfiguration(InputInterface $input, OutputInterface $output)
 {
     $path = getcwd() . DIRECTORY_SEPARATOR . 'resolver-builder.json';
     if (!is_file($path) || !is_readable($path)) {
         $output->writeln(sprintf('<error>Missing configuration file "%s".</error>', $path));
         return null;
     }
     $data = file_get_contents($path);
     $config = json_decode($data, true);
     if (!$config) {
         $output->writeln(sprintf('<error>The file "%s" contains errors.</error>', $path));
         return null;
     }
     if (!array_key_exists('output', $config)) {
         $output->writeln('<error>Missing "output" configuration option.</error>');
         return null;
     }
     if (!array_key_exists('target', $config['output'])) {
         $output->writeln('<error>Missing "target" configuration option in output configuration.</error>');
         return null;
     }
     $homepage = new Uri($config['homepage']);
     if (!$homepage->isAbsolute() || $homepage->isSchemeless()) {
         $output->writeln(sprintf('<error>The homepage "%s" is invalid.</error>', $config['homepage']));
         return null;
     }
     $outputTarget = new Uri($config['output']['target']);
     if ($outputTarget->isRelative()) {
         $config['output']['target'] = getcwd() . '/' . ltrim($config['output']['target'], '/');
     }
     return $config;
 }
Ejemplo n.º 2
0
 public function build($outputPath)
 {
     FileSystem::ensureDirectory($outputPath);
     $templateUri = new Uri($this->config['output']['template']);
     if ($templateUri->isRelative()) {
         $possibleAbsoluteTemplate = getcwd() . '/' . ltrim($this->config['output']['template'], '/');
         if (is_dir($possibleAbsoluteTemplate)) {
             $this->config['output']['template'] = $possibleAbsoluteTemplate;
         } else {
             $this->config['output']['template'] = sprintf('%s/../../resources/templates/%s', __DIR__, $this->config['output']['template']);
         }
     }
     $twig = new Twig_Environment(new Twig_Loader_Filesystem($this->config['output']['template']));
     $content = $twig->render('index.html.twig', ['name' => $this->config['name'], 'description' => $this->config['description'], 'url' => rtrim($this->config['homepage'], '/'), 'packages' => $this->packages]);
     file_put_contents($outputPath . '/index.html', $content);
 }
Ejemplo n.º 3
0
 public function testRelativeAbsoluteUrls()
 {
     /**
      * So, whats happening here?
      *
      * We can put in relative and absolute URLs.
      * Relative: "otherfolder/file.html"
      * Absolute: "http://site.com/otherfolder/file.html"
      *
      * So if we put in a URL, this is what we assume:
      *
      * /hi/index.html -> Relative, no host, no user, no schema, and the path = /hi/index.html
      * //hi/index.html -> Absolute, schemaless, hi = host, /index.html = path
      *
      * If we take a relative URL, like this one; example.org/hi.html and we set the schema,
      * it should turn in a an absolute URL;
      *
      * http://example.org/hi.html
      *
      * With that in mind, the first part until the slash will be turned in to the host (example.org) and everything
      * after that is the path.
      *
      * URI: example.org/hi.html
      *  Path: example.org/hi.html
      *  Host: NULL
      *  Scheme: NULL
      *  ->getUri -> "example.org/hi.html"
      *  ->setScheme('http')
      *  Path: /hi.html
      *  Host: example.org
      *  Scheme: http
      * ->getUri -> "http://example.org/hi.html"
      */
     $uri = new Uri('relative/url/test.html?q=123#fragged');
     $this->assertSame(true, $uri->isRelative());
     $this->assertSame(false, $uri->isAbsolute());
     $this->assertSame('relative/url/test.html', $uri->getPath());
     $this->assertSame(null, $uri->getHost());
     $this->assertSame(null, $uri->getUser());
     $this->assertSame(null, $uri->getPort());
     $this->assertSame(null, $uri->getPass());
     $this->assertSame('q=123', $uri->getQuery());
     $this->assertSame('fragged', $uri->getFragment());
     $this->assertSame('relative/url/test.html?q=123#fragged', $uri->getUri());
     $uri->setScheme('http');
     $this->assertSame(false, $uri->isRelative());
     $this->assertSame(true, $uri->isAbsolute());
     $this->assertSame('/url/test.html', $uri->getPath());
     $this->assertSame('relative', $uri->getHost());
     $this->assertSame('q=123', $uri->getQuery());
     $this->assertSame('fragged', $uri->getFragment());
     $this->assertSame('http://relative/url/test.html?q=123#fragged', $uri->getUri());
     //Anohter test with some port and user stuff
     $uri = new Uri('relative/url.html');
     $this->assertSame('relative/url.html', $uri->getUri());
     $uri->setUser('Testuser');
     $this->assertSame('relative/url.html', $uri->getUri());
     $this->assertSame('relative/url.html', $uri->getPath());
     $this->assertSame(null, $uri->getHost());
     $uri->setScheme('https');
     $this->assertSame('https://Testuser@relative/url.html', $uri->getUri());
     $this->assertSame('/url.html', $uri->getPath());
     $uri = new Uri('//test.host.com/path/index.html');
     //Absolute
     $this->assertSame(true, $uri->isAbsolute());
     $this->assertSame('test.host.com', $uri->getHost());
     $this->assertSame('/path/index.html', $uri->getPath());
     $this->assertSame('//test.host.com/path/index.html', $uri->getUri());
     $uri = new Uri('/test.file.path/path/index.html');
     //Relative
     $this->assertSame(null, $uri->getHost());
     $this->assertSame(true, $uri->isRelative());
     $this->assertSame('/test.file.path/path/index.html', $uri->getPath());
     $this->assertSame('/test.file.path/path/index.html', $uri->getUri());
     $uri = new Uri('192.168.1.56/path/index.html');
     //Relative
     $this->assertSame(null, $uri->getHost());
     $this->assertSame(true, $uri->isRelative());
     $uri->setScheme('HtTpScHeaa---mmee....testscheme-isvalisd123');
     $this->assertSame('/path/index.html', $uri->getPath());
     $this->assertSame('192.168.1.56', $uri->getHost());
     $this->assertSame('httpscheaa---mmee....testscheme-isvalisd123:192.168.1.56/path/index.html', $uri->getUri());
 }