示例#1
0
文件: API.php 项目: pscheit/psc-cms
 protected function processResponse(Response $response, Request $request)
 {
     if ($response->hasHeaderField('X-MailChimp-API-Error-Code')) {
         throw Exception::fromCode($response->getHeaderField('X-MailChimp-API-Error-Code'), $request);
     }
     return $response;
 }
 public function __construct(Response $Response, CMSAcceptanceTester $acceptanceTester)
 {
     $this->setResponse($Response);
     $this->setAcceptanceTester($acceptanceTester);
     $this->testCase = $this->acceptanceTester->getTestCase();
     $this->testCase->setHTML($this->response->getRaw());
     $this->test = $this->testCase->getCodeTester();
     $this->entityMeta = clone $this->acceptanceTester->getEntityMeta();
 }
示例#3
0
 public function read(Response $response, $format = 'html', $code = 200)
 {
     //$this->logf("Dispatched CMS Request:\n%s", $dispatcher->getRequest()->debug(TRUE, FALSE));
     // versuche error meldung zu bekommen
     $msg = NULL;
     if ($response->getCode() >= 400 && $response->getHeaderField('X-Psc-Cms-Error') == 'true' && $response->getHeaderField('X-Psc-Cms-Error-Message') != NULL) {
         $msg = "\n" . 'Fehler auf der Seite: ' . $response->getHeaderField('X-Psc-Cms-Error-Message');
     }
     if ($code != $response->getCode()) {
         $e = new ResponseException('Failed asserting that Response Code is ' . $code . '. Response code is: ' . $response->getCode() . '.' . $msg);
         $e->response = $response;
         throw $e;
     }
     if ($format == 'json') {
         try {
             return JSONConverter::create()->parse($response->getRaw());
         } catch (\Psc\JS\JSONParsingException $e) {
             throw new ResponseException(sprintf("Result cannot be read as JSON. %s", mb_substr($response->getRaw(), 0, 600)), 0, $e);
         }
     } elseif ($format == 'html') {
         return $response->getDecodedRaw();
     } elseif ($format == 'text') {
         return $response->getDecodedRaw();
     } elseif ($format == 'raw') {
         return $response->getRaw();
     }
     return $response;
 }