settingManager = $sm; $this->rs = $rs; $this->images = array(); $this->scripts = array(); $this->stylesheets = array(); $cookies = $rs->getCurrentRequest()->cookies; if ($cookies->has('net15_http2_ghostly')) { $data = $cookies->get('net15_http2_ghostly'); $this->gds = new GhostlyDataSet($data); } else { $this->gds = new GhostlyDataSet(); } } protected function build(){ foreach($this->scripts as $js){ if(!$this->gds->isInData($js)){ $this->gds->addToData($js); //$this->response->headers->set('link','<' . $js . '>; rel=preload; as=script',false); } } foreach($this->stylesheets as $css){ if(!$this->gds->isInData($css)){ $this->gds->addToData($css); //$this->response->headers->set('link','<' . $css . '>; rel=preload; as=style',false); } } foreach($this->images as $img){ if(!$this->gds->isInData($img)){ $this->gds->addToData($img); //$this->response->headers->set('link','<' . $img . '>; rel=preload; as=image',false); } } //die; $total = $this->gds->buildDataSet(); if(strlen($total) > 4096) $total = ""; $cookie = Cookie::create('net15_http2_ghostly', $total, strtotime('now + 24 hours')); $this->response->headers->setCookie($cookie); } /** * url of script to push * * @param string $jsAbsolutePath */ public function pushJs($jsAbsolutePath){ if(!in_array($jsAbsolutePath,$this->scripts)) $this->scripts[] = $jsAbsolutePath; } /** * url of css to push * * @param string $cssAbsolutePath */ public function pushCss($cssAbsolutePath){ if(!in_array($cssAbsolutePath,$this->stylesheets)) $this->stylesheets[] = $cssAbsolutePath; } /** * url of image to push * * @param $imgAbsolutePath */ public function pushImage($imgAbsolutePath){ if(!in_array($imgAbsolutePath,$this->images)) $this->images[] = $imgAbsolutePath; } /** * push http2 & set ghostly cookie * * @return Response */ public function buildResponse(){ $this->build(); return $this->response; } /** * @param mixed $response * @return GhostHTTP2PusherService */ public function setResponse($response) { $this->response = $response; return $this; } /** * @return mixed */ public function getResponse() { return $this->response; } }