コード例 #1
0
ファイル: FactoryTest.php プロジェクト: neeckeloo/AmChartsPHP
    public function testFromUrl()
    {
        $data = '<?xml version="1.0" encoding="UTF-8" ?>
<root>
    <item>
        <name>Foo</name>
        <value>1</value>
    </item>
    <item>
        <name>Bar</name>
        <value>2</value>
    </item>
    <item>
        <name>Baz</name>
        <value>3</value>
    </item>
</root>';
        $response = new \Zend\Http\Response();
        $response->setContent($data);
        $response->getHeaders()->addHeaderLine('Content-Type: text/xml');
        $client = $this->getMock('Zend\\Http\\Client', array('send'));
        $client->expects($this->once())->method('send')->will($this->returnValue($response));
        Factory::setHttpClient($client);
        $url = 'http://www.domain.com';
        $dataProvider = Factory::fromUrl($url);
        $this->assertInstanceOf('AmCharts\\Chart\\DataProvider', $dataProvider);
        $data = $dataProvider->toArray();
        $this->assertCount(3, $data);
    }
コード例 #2
0
 public function response()
 {
     $resultJson = Json::encode($this->returnEntity);
     $response = new \Zend\Http\Response();
     $response->getHeaders()->addHeaderLine('Content-Type', 'text/html; charset=utf-8');
     $response->setContent($resultJson);
     return $response;
 }
コード例 #3
0
 /**
  * Sends a request and returns a response
  *
  * @param CartRecover_Request $request
  * @return Cart_Recover_Response
  */
 public function sendRequest(CartRecover_Request $request)
 {
     $this->client->setUri($request->getUri());
     $this->client->setParameterGet($request->getParams());
     $this->client->setMethod($request->getMethod());
     $this->client->setHeaders(array('Accept' => 'application/json'));
     $this->response = $this->client->send();
     if ($this->response->getHeaders()->get('Content-Type')->getFieldValue() != 'application/json') {
         throw new CartRecover_Exception_UnexpectedValueException("Unknown response format.");
     }
     $body = json_decode($this->response->getContent(), true);
     $response = new CartRecover_Response();
     $response->setRawResponse($this->response->toString());
     $response->setBody($body);
     $response->setHeaders($this->response->getHeaders()->toArray());
     $response->setStatus($this->response->getReasonPhrase(), $this->response->getStatusCode());
     return $response;
 }
コード例 #4
0
ファイル: TestController.php プロジェクト: odegroot/ers
 public function exportXlsAction()
 {
     set_time_limit(0);
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     /*$orders = $em->getRepository("ErsBase\Entity\Order")
       ->findBy(array(), array('created' => 'ASC'));*/
     $packages = $em->getRepository("ErsBase\\Entity\\Package")->findBy(array(), array('created' => 'ASC'));
     $filename = getcwd() . "/tmp/excel-" . date("m-d-Y") . ".xls";
     $realPath = realpath($filename);
     if (false === $realPath) {
         touch($filename);
         chmod($filename, 0644);
     }
     $filename = realpath($filename);
     $finalData = array();
     $finalData[] = array('code', 'participant firstname', 'participant surname', 'list of items', 'date of purchase', 'status');
     foreach ($packages as $package) {
         $order = $package->getOrder();
         $item_list = '';
         foreach ($package->getItems() as $item) {
             $item_list .= $item->getName();
             foreach ($item->getItemVariants() as $variant) {
                 $item_list .= $variant->getName() . ' ' . $variant->getValue() . '; ';
             }
             $item_list .= "\r\n";
         }
         $item_list = preg_replace('/\\r\\n$/', '', $item_list);
         $finalData[] = array(utf8_decode($package->getCode()->getValue()), utf8_decode($package->getParticipant()->getFirstname()), utf8_decode($package->getParticipant()->getSurname()), utf8_decode($item_list), utf8_decode($order->getCreated()->format('d.m.Y H:i:s')), utf8_decode($package->getStatus()));
     }
     $handle = fopen($filename, "w");
     if (!$handle) {
         $logger = $this->getServiceLocator()->get('Logger');
         $logger->warn('unable to open file ' . $filename);
         exit;
     }
     foreach ($finalData as $finalRow) {
         fputcsv($handle, $finalRow, "\t");
     }
     fclose($handle);
     #$this->_helper->layout->disableLayout();
     #$this->_helper->viewRenderer->setNoRender();
     /*$this->getResponse()->setRawHeader( "Content-Type: application/vnd.ms-excel; charset=UTF-8" )
           ->setRawHeader( "Content-Disposition: attachment; filename=excel.xls" )
           ->setRawHeader( "Content-Transfer-Encoding: binary" )
           ->setRawHeader( "Expires: 0" )
           ->setRawHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" )
           ->setRawHeader( "Pragma: public" )
           ->setRawHeader( "Content-Length: " . filesize( $filename ) )
           ->sendResponse();
       readfile( $filename ); exit();*/
     $response = new \Zend\Http\Response();
     $response->getHeaders()->addHeaderLine('Content-Type', 'application/vnd.ms-excel; charset=utf-8')->addHeaderLine('Content-Disposition', 'attachment; filename=orders-' . date('Ymd\\THis') . '.xls')->addHeaderLine('Content-Length', filesize($filename));
     $response->setContent(file_get_contents($filename));
     return $response;
 }
 public function testHandleResponseWithServerError()
 {
     $httpResponse = new \Zend\Http\Response();
     $httpResponse->setStatusCode(401);
     $httpResponse->getHeaders()->addHeaders(array('WWW-Authenticate' => 'Bearer error="server_error",foo="bar"'));
     $this->handler->handleResponse($httpResponse);
     $this->assertTrue($this->handler->isError());
     $error = $this->handler->getError();
     $this->assertInstanceOf('InoOicClient\\Oic\\Error', $error);
     $this->assertSame('server_error', $error->getCode());
 }
コード例 #6
0
ファイル: App.php プロジェクト: rockeinstein/library
 public function tryRun()
 {
     $response = new \Zend\Http\Response();
     $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
     $apiRequest = new \RockEinstein\Lib\Api\Request\ApiRequestImp();
     $resource = $apiRequest->getResource();
     $controller = $this->getRouteProvider()->getRoute($resource);
     $controller->setRequest($apiRequest);
     $controller->setResponse($response);
     $controller->setStatusCode();
     $parameters = array_merge($apiRequest->getBodyParameters(), $apiRequest->getURLParameters(), $apiRequest->getHeaderParameters());
     $mapCall = new MapCallAdapter($controller);
     $callReponse = $mapCall->callWithMapArgs($apiRequest->getMethod(), $parameters);
     if (is_array($callReponse) && !empty($callReponse['ContentType'])) {
         $response->getHeaders()->addHeaderLine('Content-Type', $callReponse['ContentType']);
         $response->setContent($callReponse['Body']);
     } else {
         $response->setContent(\json_encode($callReponse));
     }
     return $response;
 }
コード例 #7
0
ファイル: TestController.php プロジェクト: odegroot/ers
 public function encodingAction()
 {
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $order = $em->getRepository("ErsBase\\Entity\\Order")->findOneBy(array('id' => '17'));
     $viewModel = new ViewModel(array('order' => $order));
     $viewModel->setTemplate('email/purchase-info.phtml');
     $viewRender = $this->getServiceLocator()->get('ViewRenderer');
     $html = $viewRender->render($viewModel);
     $response = new \Zend\Http\Response();
     $response->getHeaders();
     #->addHeaderLine('Content-Type', 'charset=utf-8');
     #->addHeaderLine('Content-Disposition', 'attachment; filename=orders-'.date('Ymd\THis').'.xls')
     #->addHeaderLine('Content-Length', filesize($filename));
     $response->setContent($html);
     return $response;
 }