コード例 #1
0
ファイル: Document.php プロジェクト: mekras/atompub
 /**
  * Create document.
  *
  * @param Extensions        $extensions Extension registry.
  * @param \DOMDocument|null $document   Source document.
  *
  * @throws \InvalidArgumentException If $document root node has invalid name.
  *
  * @since 1.0
  */
 public function __construct(Extensions $extensions, \DOMDocument $document = null)
 {
     parent::__construct($extensions, $document);
     if (null === $document) {
         $this->getDomDocument()->documentElement->setAttributeNS(Atom::XMLNS, 'xmlns:atom', Atom::NS);
     }
 }
コード例 #2
0
ファイル: Service.php プロジェクト: mekras/odata-client
 /**
  * Throw exception if server reports error.
  *
  * @param ResponseInterface $response
  * @param Document          $document
  *
  * @throws \Mekras\OData\Client\Exception\ClientErrorException
  * @throws \Mekras\OData\Client\Exception\ServerErrorException
  */
 private function checkResponseForErrors(ResponseInterface $response, Document $document)
 {
     if ($document instanceof ErrorDocument) {
         $message = $document->getMessage();
         $code = $document->getCode();
     } else {
         $message = $response->getReasonPhrase();
         $code = $response->getStatusCode();
     }
     switch (floor($response->getStatusCode() / 100)) {
         case 4:
             throw new ClientErrorException($message, $code);
         case 5:
             throw new ServerErrorException($message, $code);
     }
     if ($document instanceof ErrorDocument) {
         throw new ServerErrorException($message, $code);
     }
 }