/** * @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 wrap($name, $model, WebRequest $dispatched, WebRequest $wrapped) { $wrapper = new Wrapper($name, $dispatched->getTarget(), $wrapped->getArguments()); if ($this->isMapping()) { $wrapper->except($this->mappedBox); } $model = $wrapper->wrap($model); $this->onLoadHandler .= $wrapper->getOnLoadHandler(); $this->heads->putAll($wrapper->getHeadElements()); return $model; }