コード例 #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
ファイル: App.php プロジェクト: rockeinstein/library
 public function run()
 {
     try {
         $response = $this->tryRun();
     } catch (\Exception $ex) {
         $response = new \Zend\Http\Response();
         $code = $ex->getCode();
         if (is_numeric($code) && $code >= 200 && $code <= 500) {
             $response->setStatusCode($code);
         } else {
             $response->setStatusCode(500);
         }
         $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
         $response->setContent(\json_encode(array('exception' => get_class($ex), 'message' => $ex->getMessage())));
     }
     $response->getHeaders()->addHeaderLine('Access-Control-Allow-Origin', '*');
     /**
      * Imprime a resposta
      */
     $status = $response->renderStatusLine();
     header($status);
     foreach ($response->getHeaders() as $header) {
         if ($header instanceof MultipleHeaderInterface) {
             header($header->toString(), false);
             continue;
         }
         header($header->toString());
     }
     echo $response->getContent();
 }
コード例 #3
0
 public function testSearchByArea_ReturnResponse_WhenValidParams()
 {
     $response = new \Zend\Http\Response();
     $response->setContent(json_encode(array('response' => array('item' => array('title' => 'hoge')))));
     $this->_api->_request->expects($this->once())->method('request')->will($this->returnValue($response));
     $this->assertEquals(array('title' => 'hoge'), $this->_api->searchByArea('tokyo'));
 }
コード例 #4
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;
 }
コード例 #5
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;
 }
コード例 #6
0
 public function getMockedInfoResponse()
 {
     $content = '{
         "id": "500",
         "name": "John Doe",
         "first_name": "John",
         "last_name": "Doe",
         "link": "http:\\/\\/www.facebook.com\\/john.doe",
         "username": "******",
         "gender": "male",
         "timezone": 1,
         "locale": "sl_SI",
         "verified": true,
         "updated_time": "2012-09-14T12:37:27+0000"
     }';
     $response = new \Zend\Http\Response();
     $response->setContent($content);
     return $response;
 }
コード例 #7
0
ファイル: ReaderTest.php プロジェクト: bradley-holt/zf2
 /**
  * @group ZF-8330
  */
 public function testGetsFeedLinksAndNormalisesRelativeUrlsOnUriWithPath()
 {
     try {
         $currClient = Reader\Reader::getHttpClient();
         $response = new \Zend\Http\Response();
         $response->setContent('<!DOCTYPE html><html><head><link rel="alternate" type="application/rss+xml" href="../test.rss"><link rel="alternate" type="application/atom+xml" href="/test.atom"></head><body></body></html>');
         $response->setStatusCode(200);
         $testAdapter = new \Zend\Http\Client\Adapter\Test();
         $testAdapter->setResponse($response);
         Reader\Reader::setHttpClient(new \Zend\Http\Client(null, array('adapter' => $testAdapter)));
         $links = Reader\Reader::findFeedLinks('http://foo/bar');
         Reader\Reader::setHttpClient($currClient);
     } catch (\Exception $e) {
         $this->fail($e->getMessage());
     }
     $this->assertEquals('http://foo/test.rss', $links->rss);
     $this->assertEquals('http://foo/test.atom', $links->atom);
 }
コード例 #8
0
 /**
  * Test unexpected response
  *
  * @return void
  *
  * @expectedException        VuFind\Exception\Mail
  * @expectedExceptionMessage badbadbad
  */
 public function testUnexpectedResponse()
 {
     $client = $this->getMockClient();
     $expectedUri = 'https://api.clickatell.com/http/sendmsg?api_id=api_id&user=user&password=password&to=1234567890&text=hello';
     $response = new \Zend\Http\Response();
     $response->setStatusCode(200);
     $response->setContent('badbadbad');
     $client->expects($this->once())->method('setMethod')->with($this->equalTo('GET'))->will($this->returnValue($client));
     $client->expects($this->once())->method('setUri')->with($this->equalTo($expectedUri))->will($this->returnValue($client));
     $client->expects($this->once())->method('send')->will($this->returnValue($response));
     $obj = $this->getClickatell($client);
     $obj->text('Clickatell', '1234567890', '*****@*****.**', 'hello');
 }
コード例 #9
0
 public function getMockedInfoResponse()
 {
     $content = '{
         "firstName": "John",
         "lastName": "Doe",
         "headline": "Inventor",
     }';
     $response = new \Zend\Http\Response();
     $response->setContent($content);
     return $response;
 }
コード例 #10
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;
 }
コード例 #11
0
 public function getPDFResponse($template, $variables = [], $params = [])
 {
     $markup = $this->getPDFMarkup($template, $variables, $params);
     $response = new \Zend\Http\Response();
     $response->setContent($markup);
     $headers = new \Zend\Http\Headers();
     $filename = isset($params['fileName']) ? 'filename=' . $params['fileName'] . '.pdf' : 'filename=' . $this->defaultFileName;
     $headers->addHeaders(['Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; ' . $filename . '', 'Content-Transfer-Encoding' => 'binary', 'Content-Length' => strlen($markup), 'Accept-Ranges' => 'bytes']);
     $response->setHeaders($headers);
     return $response;
 }