コード例 #1
1
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     UriFactory::registerScheme('chrome-extension', 'Zend\\Uri\\Uri');
     if (method_exists($e->getRequest(), 'getHeaders')) {
         $headers = $e->getRequest()->getHeaders();
         if ($headers->has('Origin') && $headers->has('X-Requested-With') && $headers->addHeaderLine('Access-Control-Allow-Methods: PUT, GET, POST, PATCH, DELETE, OPTIONS') && $headers->get('X-Requested-With')->getFieldValue() === 'com.ionicframework.notifycar') {
             //convert to array because get method throw an exception
             $headersArray = $headers->toArray();
             $origin = $headersArray['Origin'];
             if ($origin === 'file://') {
                 unset($headersArray['Origin']);
                 $headers->clearHeaders();
                 $headers->addHeaders($headersArray);
                 //$headers->addHeaderLine('Access-Control-Allow-Methods: PUT, GET, POST, PATCH, DELETE, OPTIONS');
                 //this is a valid uri
                 $headers->addHeaderLine('Origin', 'file://mobile');
             } else {
                 if ($origin === 'chrome-extension') {
                     unset($headersArray['Origin']);
                     $headers->clearHeaders();
                     $headers->addHeaders($headersArray);
                     //$headers->addHeaderLine('Access-Control-Allow-Methods: PUT, GET, POST, PATCH, DELETE, OPTIONS');
                     //this is a valid uri
                     $headers->addHeaderLine('Origin', 'chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop');
                     //$headers->addHeaderLine('Origin', 'chrome-extension://aicmkgpgakddgnaphhhpliifpcfhicfo');
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: Utils.php プロジェクト: robertodormepoco/zf2
 /**
  * Parses, validates and returns a valid Zend\Uri object
  * from given $input.
  *
  * @param   string|Uri\Http $input
  * @return  null|Uri\Http
  * @throws  Exception\RuntimeException
  * @static
  */
 public static function normalizeUriHttp($input)
 {
     // allow null as value
     if ($input === null) {
         return null;
     }
     $uri = $input;
     // Try to cast
     if (!$input instanceof Uri\Http) {
         try {
             $uri = Uri\UriFactory::factory((string) $input);
         } catch (\Exception $e) {
             // wrap exception under Exception object
             throw new Exception\RuntimeException($e->getMessage(), 0, $e);
         }
     }
     // allow only Zend\Uri\Http objects or child classes (not other URI formats)
     if (!$uri instanceof Uri\Http) {
         throw new Exception\RuntimeException(sprintf("%s: Invalid URL %s, only HTTP(S) protocols can be used", __METHOD__, $uri));
     }
     // Validate the URI
     if (!$uri->isValid()) {
         $caller = function () {
             $traces = debug_backtrace();
             if (isset($traces[2])) {
                 return $traces[2]['function'];
             }
             return null;
         };
         throw new Exception\RuntimeException(sprintf('%s (called by %s): invalid URI ("%s") provided', __METHOD__, $caller(), (string) $input));
     }
     return $uri;
 }
コード例 #3
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     UriFactory::registerScheme('chrome-extension', 'Zend\\Uri\\Uri');
 }
コード例 #4
0
ファイル: UriTest.php プロジェクト: thefox/phpchat
 public function testUri()
 {
     $uri1 = UriFactory::factory('tcp://192.168.241.21:25000');
     $uri2 = UriFactory::factory('tcp://192.168.241.21:25000');
     $uri3 = UriFactory::factory('tcp://192.168.241.22:25000');
     $uri4 = UriFactory::factory('');
     $uri5 = UriFactory::factory('192.168.241.22');
     $uri6 = UriFactory::factory('//192.168.241.22');
     $uri7 = UriFactory::factory('192.168.241.22:25000');
     #ve($uri7);
     $this->assertEquals($uri1, $uri2);
     $this->assertEquals('tcp://192.168.241.21:25000', $uri1);
     $this->assertEquals('tcp://192.168.241.21:25000', (string) $uri1);
     $this->assertEquals('tcp://192.168.241.22:25000', $uri3);
     $this->assertEquals('tcp://192.168.241.22:25000', (string) $uri3);
     $this->assertEquals('', (string) $uri4);
     $this->assertEquals('192.168.241.22', (string) $uri5);
     $this->assertEquals('', $uri5->getHost());
     $this->assertEquals('//192.168.241.22', (string) $uri6);
     $this->assertEquals('192.168.241.22', $uri6->getHost());
     $this->assertTrue($uri1 == $uri2);
     $this->assertFalse($uri1 == $uri3);
     $this->assertTrue($uri1 ? true : false);
     $this->assertTrue((string) $uri1 ? true : false);
     $this->assertTrue($uri4 ? true : false);
     $this->assertFalse((string) $uri4 ? true : false);
 }
コード例 #5
0
ファイル: UserAuthorization.php プロジェクト: navassouza/zf2
 /**
  * Generate a redirect URL from the allowable parameters and configured
  * values.
  *
  * @return string
  */
 public function getUrl()
 {
     $params = $this->assembleParams();
     $uri = Uri\UriFactory::factory($this->_consumer->getUserAuthorizationUrl());
     $uri->setQuery($this->_httpUtility->toEncodedQueryString($params));
     return $uri->toString();
 }
コード例 #6
0
 /**
  * discovery feed url
  * 
  * @param string $type
  * @param string|Zend\Uri\Http $baseUrl
  * @return mixed
  */
 public function discovery($type = null, $baseUrl = null)
 {
     if ($type === 'rss') {
         $xpath = self::XPATH_RSS;
     } else {
         if ($type === 'atom') {
             $xpath = self::XPATH_ATOM;
         } else {
             $xpath = self::XPATH_BOTH;
         }
     }
     if ($links = $this->getResource()->xpath($xpath)) {
         $ret = array();
         foreach ($links as $v) {
             if (isset($baseUrl)) {
                 $uri = UriFactory::factory(current($v->href));
                 $ret[] = (string) $uri->resolve($baseUrl);
             } else {
                 $ret[] = current($v->href);
             }
         }
         return $ret;
     }
     return null;
 }
コード例 #7
0
ファイル: LocationTest.php プロジェクト: pnaq57/zf2demo
 /**
  * Test that we can set a redirect to different URI-schemes via a class
  *
  * @param string $uri
  * @param string $expectedClass
  *
  * @dataProvider locationCanSetDifferentSchemeUrisProvider
  */
 public function testLocationCanSetDifferentSchemeUriObjects($uri, $expectedClass)
 {
     $uri = \Zend\Uri\UriFactory::factory($uri);
     $locationHeader = new Location();
     $locationHeader->setUri($uri);
     $this->assertAttributeInstanceof($expectedClass, 'uri', $locationHeader);
 }
コード例 #8
0
 public function onBootstrap(MvcEvent $mvcEvent)
 {
     UriFactory::registerScheme('chrome-extension', 'Zend\\Uri\\Uri');
     // add chrome-extension for API Client
     $serviceManager = $mvcEvent->getApplication()->getServiceManager();
     $eventManager = $mvcEvent->getApplication()->getEventManager();
     $sharedEventManager = $eventManager->getSharedManager();
 }
コード例 #9
0
ファイル: Frontend.php プロジェクト: violetbrick/theme
 /**
  * @param string|Uri $uri
  * @return string
  */
 protected function prepareUri($uri)
 {
     if (!$uri instanceof Uri) {
         $uri = UriFactory::factory($uri);
     }
     $uri->setScheme($this->request->getScheme());
     return $uri->toString();
 }
コード例 #10
0
ファイル: Image.php プロジェクト: bradley-holt/zf2
 /**
  * Assigns values to properties relevant to Image
  *
  * @param  DOMElement $dom
  * @return void
  */
 public function __construct(\DOMElement $dom)
 {
     $xpath = new \DOMXPath($dom->ownerDocument);
     $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05');
     $this->Url = Uri\UriFactory::factory($xpath->query('./az:URL/text()', $dom)->item(0)->data);
     $this->Height = (int) $xpath->query('./az:Height/text()', $dom)->item(0)->data;
     $this->Width = (int) $xpath->query('./az:Width/text()', $dom)->item(0)->data;
 }
コード例 #11
0
ファイル: RestClient.php プロジェクト: navtis/xerxes-pazpar2
 /**
  * Set the URI to use in the request
  *
  * @param  string|Uri\Uri $uri URI for the web service
  * @return RestClient
  */
 public function setUri($uri)
 {
     if ($uri instanceof Uri\Uri) {
         $this->_uri = $uri;
     } else {
         $this->_uri = Uri\UriFactory::factory($uri);
     }
     return $this;
 }
コード例 #12
0
 public function testSendPurgeRequestWithException()
 {
     $uris[] = UriFactory::factory('')->setHost('127.0.0.1')->setPort(8080)->setScheme('http');
     $this->cacheServer->expects($this->once())->method('getUris')->willReturn($uris);
     $this->socketAdapterMock->method('connect')->willThrowException(new \Zend\Http\Client\Adapter\Exception\RuntimeException());
     $this->loggerMock->expects($this->never())->method('execute');
     $this->loggerMock->expects($this->once())->method('critical');
     $this->assertFalse($this->model->sendPurgeRequest('tags'));
 }
コード例 #13
0
ファイル: Access.php プロジェクト: bradley-holt/zf2
 /**
  * Cast to HTTP query string
  * 
  * @param  mixed $url 
  * @param  Zend\OAuth\Config $config 
  * @param  null|array $params 
  * @return string
  */
 public function toQueryString($url, Config $config, array $params = null)
 {
     $uri = Uri\UriFactory::factory($url);
     if (!$uri->isValid() || !in_array($uri->getScheme(), array('http', 'https'))) {
         throw new OAuth\Exception('\'' . $url . '\' is not a valid URI');
     }
     $params = $this->_httpUtility->assembleParams($url, $config, $params);
     return $this->_httpUtility->toEncodedQueryString($params);
 }
コード例 #14
0
 public function setupPathController()
 {
     $request = $this->serviceManager->get('Request');
     $uri = UriFactory::factory('http://example.local/path');
     $request->setUri($uri);
     $router = $this->serviceManager->get('HttpRouter');
     $route = Router\Http\Literal::factory(array('route' => '/path', 'defaults' => array('controller' => 'path')));
     $router->addRoute('path', $route);
     $this->application->bootstrap();
 }
コード例 #15
0
ファイル: Module.php プロジェクト: n3vrax/dotkernel
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $this->services = $e->getApplication()->getServiceManager();
     $eventManager->attach(MvcAuthEvent::EVENT_AUTHENTICATION, $this->services->get('DotUser\\Authentication\\AuthenticationListener'), 100);
     $eventManager->attach(MvcEvent::EVENT_ROUTE, $this->services->get('DotUser\\Authentication\\OauthRouteGuard'));
     UriFactory::registerScheme('chrome-extension', 'Zend\\Uri\\Uri');
     $this->fixBrokenOriginHeader($e->getRequest());
 }
コード例 #16
0
ファイル: CorsService.php プロジェクト: Cyruxx/zfr-cors
 /**
  * Check if the HTTP request is a CORS request by checking if the Origin header is present and that the
  * request URI is not the same as the one in the Origin
  *
  * @param  HttpRequest $request
  * @return bool
  */
 public function isCorsRequest(HttpRequest $request)
 {
     $headers = $request->getHeaders();
     if (!$headers->has('Origin')) {
         return false;
     }
     $originUri = UriFactory::factory($headers->get('Origin')->getFieldValue());
     $requestUri = $request->getUri();
     // According to the spec (http://tools.ietf.org/html/rfc6454#section-4), we should check host, port and scheme
     return !($originUri->getHost() === $requestUri->getHost()) || !($originUri->getPort() === $requestUri->getPort()) || !($originUri->getScheme() === $requestUri->getScheme());
 }
コード例 #17
0
ファイル: UrlBuilder.php プロジェクト: ScriptFUSION/Porter
 public function buildUrl($endpoint, array $params = [], $baseUrl = null)
 {
     $uri = UriFactory::factory($endpoint);
     if ($baseUrl && !$uri->isAbsolute()) {
         // Convert relative URL to absolute URL using base URL.
         $uri->resolve($baseUrl);
     }
     // Merge query parameters.
     $uri->setQuery(array_merge($this->options->getQueryParameters(), array_merge($uri->getQueryAsArray(), $params)));
     return "{$uri}";
 }
コード例 #18
0
ファイル: Module.php プロジェクト: solcre/columnis-express
 public function onBootstrap(MvcEvent $e)
 {
     UriFactory::registerScheme('chrome-extension', 'Zend\\Uri\\Uri');
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     // get the cache listener service
     $cacheListener = $e->getApplication()->getServiceManager()->get('Columnis\\Model\\CacheListener');
     // attach the listeners to the event manager
     $e->getApplication()->getEventManager()->attach($cacheListener);
 }
コード例 #19
0
 public function __construct($url, $apiKey, $sharedSecret, ApiVersion $version, $timeout = 30)
 {
     $this->lastRequest = null;
     $this->apiKey = trim($apiKey);
     $this->signature = hash("sha256", $apiKey . trim($sharedSecret) . time());
     $this->httpClient = new Client();
     $this->httpClient->setOptions(["timeout" => $timeout]);
     UriFactory::registerScheme("https", "hotelbeds\\hotel_api_sdk\\types\\ApiUri");
     $this->apiUri = UriFactory::factory($url);
     $this->apiUri->prepare($version);
 }
コード例 #20
0
ファイル: SimpleDb.php プロジェクト: no-reply/cbpl-vufind
 /**
  * Set SimpleDB endpoint to use
  *
  * @param string|Uri\Uri $endpoint
  * @return SimpleDb
  * @throws Exception\InvalidArgumentException
  */
 public function setEndpoint($endpoint)
 {
     if (!$endpoint instanceof Uri\Uri) {
         $endpoint = Uri\UriFactory::factory($endpoint);
     }
     if (!$endpoint->isValid()) {
         throw new Exception\InvalidArgumentException("Invalid endpoint supplied");
     }
     $this->_endpoint = $endpoint;
     return $this;
 }
コード例 #21
0
ファイル: Url.php プロジェクト: bcremer/mwop.net
 public function isValid($value)
 {
     $this->setValue($value);
     if (!$value instanceof Uri) {
         $value = UriFactory::factory($value);
     }
     if (!$value->isValid()) {
         $this->error(self::INVALID_URL);
         return false;
     }
     return true;
 }
コード例 #22
0
 public function testDailyCountsResultSet()
 {
     $object = new Technorati\DailyCountsResultSet($this->dom);
     // check counts
     $this->assertInternalType('integer', $object->totalResults());
     $this->assertEquals(5, $object->totalResults());
     $this->assertInternalType('integer', $object->totalResultsAvailable());
     $this->assertEquals(5, $object->totalResultsAvailable());
     // check properties
     $this->assertInstanceOf('Zend\\Uri\\Http', $object->getSearchUrl());
     $this->assertEquals(\Zend\Uri\UriFactory::factory('http://technorati.com/search/google'), $object->getSearchUrl());
 }
コード例 #23
0
ファイル: Origin.php プロジェクト: youprofit/casebox
 public static function fromString($headerLine)
 {
     list($name, $value) = explode(': ', $headerLine, 2);
     // check to ensure proper header type for this factory
     if (strtolower($name) !== 'origin') {
         throw new Exception\InvalidArgumentException('Invalid header line for Origin string: "' . $name . '"');
     }
     $uri = UriFactory::factory($value);
     if (!$uri->isValid()) {
         throw new Exception\InvalidArgumentException('Invalid header value for Origin key: "' . $name . '"');
     }
     return new static($value);
 }
コード例 #24
0
 public function testCosmosResultSiteWeblog()
 {
     $domElements = self::getTestFileElementsAsDom('TestCosmosResultSetSiteWeblog.xml');
     $object = new Technorati\CosmosResult($domElements->item(0));
     $this->assertInstanceOf('Zend\\Service\\Technorati\\Weblog', $object->getWeblog());
     $this->assertContains('Simone Carletti', $object->getWeblog()->getName());
     $this->assertInstanceOf('Zend\\Uri\\Http', $object->getLinkUrl());
     $this->assertEquals(\Zend\Uri\UriFactory::factory('http://www.simonecarletti.com'), $object->getLinkUrl());
     // test an other element to prevent cached values
     $object = new Technorati\CosmosResult($domElements->item(1));
     $this->assertContains('Gioxx', $object->getWeblog()->getName());
     $this->assertEquals(\Zend\Uri\UriFactory::factory('http://www.simonecarletti.com'), $object->getLinkUrl());
 }
コード例 #25
0
ファイル: Loc.php プロジェクト: kingsj/core
 /**
  * Validates if a string is valid as a sitemap location
  *
  * @link http://www.sitemaps.org/protocol.php#locdef <loc>
  *
  * @param  string  $value  value to validate
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->error(self::INVALID);
         return false;
     }
     $this->setValue($value);
     $uri = Uri\UriFactory::factory($value);
     if (!$uri->isValid()) {
         $this->error(self::NOT_VALID);
         return false;
     }
     return true;
 }
コード例 #26
0
 /**
  * Get cache servers' Uris
  *
  * @return Uri[]
  */
 public function getUris()
 {
     $servers = [];
     $configuredHosts = $this->config->get(ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS);
     if (null == $configuredHosts) {
         $httpHost = $this->request->getHttpHost();
         $servers[] = $httpHost ? UriFactory::factory('')->setHost($httpHost)->setPort(self::DEFAULT_PORT)->setScheme('http') : UriFactory::factory($this->urlBuilder->getUrl('*', ['_nosid' => true]))->setScheme('http')->setPath(null)->setQuery(null);
     } else {
         foreach ($configuredHosts as $host) {
             $servers[] = UriFactory::factory('')->setHost($host['host'])->setPort(isset($host['port']) ? $host['port'] : self::DEFAULT_PORT)->setScheme('http');
         }
     }
     return $servers;
 }
コード例 #27
0
 /**
  * Normalize the base signature URL
  * 
  * @param  string $url 
  * @return string
  */
 public function normaliseBaseSignatureUrl($url)
 {
     $uri = Uri\UriFactory::factory($url);
     $uri->normalize();
     if ($uri->getScheme() == 'http' && $uri->getPort() == '80') {
         $uri->setPort('');
     } elseif ($uri->getScheme() == 'https' && $uri->getPort() == '443') {
         $uri->setPort('');
     } elseif (!in_array($uri->getScheme(), array('http', 'https'))) {
         throw new OAuthException('Invalid URL provided; must be an HTTP or HTTPS scheme');
     }
     $uri->setQuery('');
     $uri->setFragment('');
     return $uri->toString();
 }
コード例 #28
0
ファイル: ClientTest.php プロジェクト: robertodormepoco/zf2
 public function testUri()
 {
     $client = new Client\RestClient('http://framework.zend.com/rest/');
     $uri = $client->getUri();
     $this->assertTrue($uri instanceof Uri\Uri);
     $this->assertEquals('http://framework.zend.com/rest/', $uri->toString());
     $client->setUri(Uri\UriFactory::factory('http://framework.zend.com/soap/'));
     $uri = $client->getUri();
     $this->assertTrue($uri instanceof Uri\Uri);
     $this->assertEquals('http://framework.zend.com/soap/', $uri->toString());
     $client->setUri('http://framework.zend.com/xmlrpc/');
     $uri = $client->getUri();
     $this->assertTrue($uri instanceof Uri\Uri);
     $this->assertEquals('http://framework.zend.com/xmlrpc/', $uri->toString());
 }
コード例 #29
0
 public function testSearchResult()
 {
     $object = new Technorati\SearchResult($this->domElements->item(0));
     // check properties
     $this->assertInternalType('string', $object->getTitle());
     $this->assertContains('El SDK de Android', $object->getTitle());
     $this->assertInternalType('string', $object->getExcerpt());
     $this->assertContains('[ Android]', $object->getExcerpt());
     $this->assertInstanceOf('Zend\\Uri\\Http', $object->getPermalink());
     $this->assertEquals(\Zend\Uri\UriFactory::factory('http://blogs.eurielec.etsit.upm.es/miotroblog/?p=271'), $object->getPermalink());
     $this->assertInstanceOf('DateTime', $object->getCreated());
     $this->assertEquals(new DateTime('2007-11-14 22:18:04 GMT'), $object->getCreated());
     // check weblog
     $this->assertInstanceOf('ZendService\\Technorati\\Weblog', $object->getWeblog());
     $this->assertContains('Mi otro blog', $object->getWeblog()->getName());
 }
コード例 #30
0
ファイル: CallbackController.php プロジェクト: coogle/oauth2
 protected function doRequestToken()
 {
     $config = $this->getServiceLocator()->get('Config');
     $config = $config['oauth2'];
     if (is_null($config['auth']['redirect_uri'])) {
         $router = $this->getServiceLocator()->get('Router');
         $requestUri = $router->getRequestUri();
         $requestUri->setQuery(null);
         $OAuthUrl = $router->assemble(array(), array('name' => 'oauth2-callback', 'force_canonical' => true, 'uri' => $requestUri));
     } else {
         $OAuthUrl = $config['auth']['redirect_uri'];
     }
     $uri = UriFactory::factory($config['auth']['auth_uri']);
     $uri->setQuery(array('response_type' => 'code', 'client_id' => $config['auth']['client_id'], 'redirect_uri' => $OAuthUrl, 'scope' => implode(' ', $config['auth']['scopes']), 'state' => '', 'access_type' => 'offline', 'approval_prompt' => 'auto', 'include_granted_scopes' => 'true'));
     return $this->redirect()->toUrl($uri->__toString());
 }