Exemple #1
1
 /**
  * Show/return documentation
  *
  * Returns a ContentNegotiation view model to allow for multiple
  * representations of documentation.
  *
  * @return ViewModel
  */
 public function showAction()
 {
     $apiName = $this->params()->fromRoute('api');
     $apiVersion = $this->params()->fromRoute('version', '1');
     $serviceName = $this->params()->fromRoute('service');
     $viewModel = new ViewModel();
     $viewModel->setTemplate('zf-apigility-documentation/show');
     $viewModel->setVariable('baseUrl', $this->serverUrlViewHelper->__invoke());
     if (!$apiName) {
         $apiList = $this->apiFactory->createApiList();
         $viewModel->setVariable('apis', $apiList);
         $viewModel->setVariable('type', 'apiList');
         return $viewModel;
     }
     $api = $this->apiFactory->createApi($apiName, $apiVersion);
     if (!$serviceName) {
         $viewModel->setVariable('documentation', $api);
         $viewModel->setVariable('type', 'api');
         return $viewModel;
     }
     $service = $this->apiFactory->createService($api, $serviceName);
     $viewModel->setVariable('documentation', $service);
     $viewModel->setVariable('type', 'service');
     return $viewModel;
 }
Exemple #2
0
 public function __invoke($tld = null)
 {
     $currentServerUrl = parent::__invoke(null);
     if (!$tld) {
         return $currentServerUrl;
     }
     $tld = str_replace('.', '', $tld);
     $tld = '.' . $tld;
     $uri = parse_url($currentServerUrl);
     $uri['host'] = preg_replace('#\\.([a-z]+)$#', $tld, $uri['host'], 1);
     return $uri['scheme'] . '://' . $uri['host'];
 }
Exemple #3
0
 public function testServerUrlWithObject()
 {
     $_SERVER['HTTPS'] = 'off';
     $_SERVER['HTTP_HOST'] = 'example.com';
     $_SERVER['REQUEST_URI'] = '/foo.html';
     $url = new Helper\ServerUrl();
     $this->assertEquals('http://example.com', $url->__invoke(new \stdClass()));
 }
 /**
  * Retorna a url atual.
  * 
  * @return String
  */
 public function getCurrentUrl()
 {
     $serverUrl = new ServerUrl();
     $currentUrl = $serverUrl->__invoke(true);
     return $currentUrl;
 }
Exemple #5
0
 /**
  * @group ZF2-508
  */
 public function testServerUrlWithMultipleProxies()
 {
     $_SERVER['HTTP_HOST'] = 'proxyserver.com';
     $_SERVER['HTTP_X_FORWARDED_HOST'] = 'www.firsthost.org, www.secondhost.org';
     $url = new Helper\ServerUrl();
     $this->assertEquals('http://www.secondhost.org', $url->__invoke());
 }
 public function testCanUseXForwardedPortIfProvided()
 {
     $_SERVER['HTTP_HOST'] = 'proxyserver.com';
     $_SERVER['HTTP_X_FORWARDED_HOST'] = 'www.firsthost.org, www.secondhost.org';
     $_SERVER['HTTP_X_FORWARDED_PORT'] = '8888';
     $url = new Helper\ServerUrl();
     $url->setUseProxy(true);
     $this->assertEquals('http://www.secondhost.org:8888', $url->__invoke());
 }
Exemple #7
0
 /**
  * @group ZF-9919
  */
 public function testServerUrlWithPort()
 {
     $_SERVER['SERVER_PORT'] = 443;
     $_SERVER['HTTP_HOST'] = 'example.com';
     $url = new Helper\ServerUrl();
     $this->assertEquals('https://example.com', $url->__invoke());
 }
 /**
  * Get Base Host Url.
  *
  *
  * @return string
  */
 private function getBaseUrl()
 {
     $helper = new ServerUrl();
     return $helper->__invoke(false);
 }