/**
  * The deserialize method is called during xml parsing.
  *
  * This method is called statictly, this is because in theory this method
  * may be used as a type of constructor, or factory method.
  *
  * Often you want to return an instance of the current class, but you are
  * free to return other data as well.
  *
  * You are responsible for advancing the reader to the next element. Not
  * doing anything will result in a never-ending loop.
  *
  * If you just want to skip parsing for this element altogether, you can
  * just call $reader->next();
  *
  * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  * the next element.
  *
  * @param Reader $reader
  * @return mixed
  */
 static function xmlDeserialize(Reader $reader)
 {
     $elems = $reader->parseInnerTree(['{urn:ietf:params:xml:ns:carddav}address-data' => 'Sabre\\CardDAV\\Xml\\Filter\\AddressData', '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue']);
     $newProps = ['hrefs' => [], 'properties' => []];
     foreach ($elems as $elem) {
         switch ($elem['name']) {
             case '{DAV:}prop':
                 $newProps['properties'] = array_keys($elem['value']);
                 if (isset($elem['value']['{' . Plugin::NS_CARDDAV . '}address-data'])) {
                     $newProps += $elem['value']['{' . Plugin::NS_CARDDAV . '}address-data'];
                 }
                 break;
             case '{DAV:}href':
                 $newProps['hrefs'][] = Uri\resolve($reader->contextUri, $elem['value']);
                 break;
         }
     }
     $obj = new self();
     foreach ($newProps as $key => $value) {
         $obj->{$key} = $value;
     }
     return $obj;
 }
Пример #2
0
 /**
  * Returns the full url based on the given url (which may be relative). All
  * urls are expanded based on the base url as given by the server.
  *
  * @param string $url
  * @return string
  */
 function getAbsoluteUrl($url)
 {
     return Uri\resolve($this->baseUri, $url);
 }
Пример #3
0
 /**
  * Generates a 'full' url based on a relative one.
  *
  * For relative urls, the base of the application is taken as the reference
  * url, not the 'current url of the current request'.
  *
  * Absolute urls are left alone.
  *
  * @param string $path
  * @return string
  */
 function fullUrl($path)
 {
     return Uri\resolve($this->baseUri, $path);
 }
Пример #4
0
 /**
  * Sends a request to a HTTP server, and returns a response.
  *
  * @param RequestInterface $request
  * @return ResponseInterface
  */
 function send(RequestInterface $request)
 {
     $this->emit('beforeRequest', [$request]);
     $retryCount = 0;
     $redirects = 0;
     do {
         $doRedirect = false;
         $retry = false;
         try {
             $response = $this->doRequest($request);
             $code = (int) $response->getStatus();
             // We are doing in-PHP redirects, because curl's
             // FOLLOW_LOCATION throws errors when PHP is configured with
             // open_basedir.
             //
             // https://github.com/fruux/sabre-http/issues/12
             if (in_array($code, [301, 302, 307, 308]) && $redirects < $this->maxRedirects) {
                 $oldLocation = $request->getUrl();
                 // Creating a new instance of the request object.
                 $request = clone $request;
                 // Setting the new location
                 $request->setUrl(Uri\resolve($oldLocation, $response->getHeader('Location')));
                 $doRedirect = true;
                 $redirects++;
             }
             // This was a HTTP error
             if ($code >= 400) {
                 $this->emit('error', [$request, $response, &$retry, $retryCount]);
                 $this->emit('error:' . $code, [$request, $response, &$retry, $retryCount]);
             }
         } catch (ClientException $e) {
             $this->emit('exception', [$request, $e, &$retry, $retryCount]);
             // If retry was still set to false, it means no event handler
             // dealt with the problem. In this case we just re-throw the
             // exception.
             if (!$retry) {
                 throw $e;
             }
         }
         if ($retry) {
             $retryCount++;
         }
     } while ($retry || $doRedirect);
     $this->emit('afterRequest', [$request, $response]);
     if ($this->throwExceptions && $code >= 400) {
         throw new ClientHttpException($response);
     }
     return $response;
 }
Пример #5
0
 /**
  * Function to get all link url, css and js from a url
  *
  * @param  array  $currentUrl []
  * @param  array  $lists []
  * @param  array  $siteLink []
  * @param  int    $recursive []
  *
  * @return void
  */
 protected function getAllLink($currentUrl, $lists, &$siteLink, $recursive = 0)
 {
     foreach ($lists as $list) {
         if (!$list || !$this->checkIfCrawlable($list)) {
             continue;
         }
         $list = $this->encodeUrl(preg_replace('/(\\.\\.\\/)+/', '/', $list));
         $list = Uri\resolve($currentUrl, $list);
         if ($this->checkIfExternal($list) || !$this->checkNotInList($list, $siteLink)) {
             continue;
         }
         if (!$recursive && $this->getExtension($list)) {
             $responseUrl = $this->client->get($list);
             array_push($siteLink, ['type' => $this->getExtension($list), 'url' => $list, 'bodyContent' => gzdeflate($responseUrl->getBody()->getContents())]);
         } elseif (!in_array($list, $this->unvisitedUrl)) {
             $this->unvisitedUrl[] = $list;
         }
     }
 }
Пример #6
0
 /**
  * The xmlSerialize metod is called during xml writing.
  *
  * Use the $writer argument to write its own xml serialization.
  *
  * An important note: do _not_ create a parent element. Any element
  * implementing XmlSerializble should only ever write what's considered
  * its 'inner xml'.
  *
  * The parent of the current element is responsible for writing a
  * containing element.
  *
  * This allows serializers to be re-used for different element names.
  *
  * If you are opening new elements, you must also close them again.
  *
  * @param Writer $writer
  * @return void
  */
 function xmlSerialize(Writer $writer)
 {
     foreach ($this->getHrefs() as $href) {
         $href = Uri\resolve($writer->contextUri, $href);
         $writer->writeElement('{DAV:}href', $href);
     }
 }