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;
 }
Example #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);
 }
Example #3
0
 public function testChangeScheme()
 {
     $this->assertSame('https://website.com/index.html', Uri::changeScheme('//website.com/index.html', 'https'));
     $this->assertSame('https://website.com/index.html', Uri::changeScheme('/website.com/index.html', 'https'));
     $this->assertSame('https://website.com/index.html', Uri::changeScheme('website.com/index.html', 'https'));
     $this->assertSame('https://website.com/index.html', Uri::changeScheme('http://website.com/index.html', 'https'));
 }