コード例 #1
1
ファイル: Rasterizer.php プロジェクト: baiolo/RasterizeBundle
 /**
  * @param        $url
  * @param array  $arguments
  * @param string $uniqueId
  *
  * @throws \Exception
  *
  * @return string
  */
 public function rasterizeUrl($url, $arguments = array(), $uniqueId = "")
 {
     if ($uniqueId === "") {
         $uniqueId = uniqid("rasterize-");
     }
     if ($this->stopwatch instanceof Stopwatch) {
         if ($this->stopwatch->isStarted($uniqueId)) {
             $this->stopwatch->lap($uniqueId);
         } else {
             $this->stopwatch->start($uniqueId);
         }
     }
     $process = $this->configHelper->buildProcess($url, $uniqueId, $arguments);
     $exitCode = $process->run();
     if ($exitCode != 0) {
         throw new \Exception(sprintf("Rasterize script failed.\nCommandLine: %s\nExitCode: %d\nErrorOutput: %s", $process->getCommandLine(), $process->getExitCode(), $process->getErrorOutput()));
     }
     if ($this->stopwatch instanceof Stopwatch) {
         $this->stopwatch->stop($uniqueId);
     }
     $output = $this->configHelper->getOutputFilePath($uniqueId);
     $content = file_get_contents($output);
     unlink($output);
     return $content;
 }
コード例 #2
0
 /**
  * @test
  */
 public function gettersAndSetters()
 {
     $this->assertSame($this->configHelper, $this->configHelper->setConfig(array()));
     $this->assertSame(array(), $this->configHelper->getConfig());
     $context = new RequestContext();
     $this->assertSame($this->configHelper, $this->configHelper->setContext($context));
     $this->assertSame($context, $this->configHelper->getContext());
     $this->assertSame($this->configHelper, $this->configHelper->setContextBaseUrl('www.example.com'));
     $this->assertSame('www.example.com', $this->configHelper->getContextBaseUrl());
     $this->assertSame($this->configHelper, $this->configHelper->setRootDir('/test'));
     $this->assertSame('/test', $this->configHelper->getRootDir());
 }