예제 #1
0
파일: Wrapper.php 프로젝트: watoki/boxes
 /**
  * @param string $response
  * @return string
  */
 public function wrap($response)
 {
     $parser = new Parser($response);
     $root = $parser->getRoot();
     $body = $this->findBody($root);
     $this->wrapChildren($body);
     $head = $this->findElement($root, 'html/head');
     if ($head) {
         foreach ($head->getChildElements() as $headElement) {
             if (!in_array($headElement->getName(), self::$ignoredHeadElements)) {
                 $this->headElements->put($headElement);
             }
         }
     }
     $id = uniqid('box-');
     $open = '';
     $close = '';
     if ($body->getAttribute('onload') && $body->getAttribute('onload')->getValue()) {
         $handler = $body->getAttribute('onload')->getValue();
         $handler = rtrim($handler, ';') . ';';
         $handler = str_replace('top.document.body', 'document.body', $handler);
         $this->onLoadHandler = str_replace('document.body', "top.document.getElementById('{$id}')", $handler);
         $open = '<div id="' . $id . '">';
         $close = '</div>';
     }
     $printer = new Printer();
     return $open . $printer->printNodes($body->getChildren()) . $close;
 }
 private function whenIExecute($action)
 {
     $this->resource->whenIDo_With(function (ExecuteResource $resource) use($action) {
         $model = $resource->doGet($action);
         $this->resource->request->getFormats()->append('html');
         $rendered = $resource->after($model, $this->resource->request)->getBody();
         $parser = new Parser($rendered);
         $this->dom = $parser->getRoot();
         return $model;
     }, ExecuteResource::class);
 }