Пример #1
0
 /**
  * Hook that is called just after an object is unserialized.
  */
 public function doUnSerialize()
 {
     // Recreate fp
     list($Pos, $Contents) = $this->_fp;
     $File = new GenericFile('php://memory');
     $this->_fp = $File->createResource($this->_Flags, stream_context_create($this->_Options));
     // Restore fp
     if ($Contents) {
         $this->putContents($Contents);
         fseek($this->_fp, $Pos);
     }
 }
Пример #2
0
 /**
  * Creates a page from a HTTP Response.
  *
  * @param \BLW\Type\HTTP\IRequest $Request
  *            Request that produced response.
  * @param \BLW\Type\HTTP\IResponse $Response
  *            Response associated with request.
  * @return \BLW\Type\HTTP\IPage Generated Page.
  */
 public function createPage(IRequest $Request, IResponse $Response)
 {
     // Status of 200
     if ($Response->Status == 200 && isset($Response->Header['Content-Type'])) {
         // Test Content-Type
         $ContentType = $Response->Header['Content-Type'];
         switch (1) {
             // Text document
             case preg_match('!text/.*!', $ContentType):
                 // CreateDocument
                 $Document = new Document();
                 $Document->loadHTML(strval($Response->Body) ?: '<html><title></title><body></body></html>');
                 // Create Page
                 $Base = $Response->URI ?: $Request->URI ?: new GenericURI('about:none');
                 $Page = new HTMLPage($Document, $Base, $Request->Header, $Response->Header, $this->_Mediator);
                 // Done
                 break;
                 // File
             // File
             default:
                 // CreateFile
                 $File = new GenericFile('php://tmp');
                 $File->putContents(strval($Response->Body));
                 // Create Page
                 $Base = $Response->URI ?: $Request->URI ?: new GenericURI('about:none');
                 $Page = new FilePage($File, $Base, $Request->Header, $Response->Header, $this->_Mediator);
         }
     } elseif ($Response->isValidCode($Response->Status)) {
         $Page = $this->createStatusPage($Request, $Response);
         // Invalid Responses
     } else {
         $Page = $this->createUnknownPage();
     }
     // Done
     return $Page;
 }
Пример #3
0
 /**
  * Restarts PhantomJS process.
  *
  * @return boolean <code>TRUE</code> on success. <code>FALSE</code> on failure.
  */
 public function phantomRestart()
 {
     // Close command
     $this->_Process->close();
     // Wait a bit
     usleep(100000);
     // Create bootstrap
     $Bootstrap = new GenericFile(sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5('PhantomJS') . '.js');
     $Bootstrap->putContents(self::BOOTSTRAP);
     // Open Command
     $stdIn = '';
     $Input = new CommandInput(new StringStream($stdIn));
     $Input->Options[] = new Option('config', $this->_ConfigFile);
     $Input->Arguments[] = new Argument($Bootstrap);
     // If okay? return true.
     if ($this->_Process->open($Input)) {
         return true;
     }
     // @codeCoverageIgnoreStart
     return false;
     // @codeCoverageIgnoreEnd
 }