当前位置: 首页>>代码示例>>PHP>>正文


PHP Uri::getScheme方法代码示例

本文整理汇总了PHP中Zend\Uri\Uri::getScheme方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::getScheme方法的具体用法?PHP Uri::getScheme怎么用?PHP Uri::getScheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Uri\Uri的用法示例。


在下文中一共展示了Uri::getScheme方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: open

 public function open($timeOut = null)
 {
     /**
      * @var $that self
      */
     $that = new FullAccessWrapper($this);
     $uri = new Uri($this->url);
     $isSecured = 'wss' === $uri->getScheme();
     $defaultPort = $isSecured ? 443 : 80;
     $connector = new Connector($this->loop, $this->dns, $this->streamOptions);
     if ($isSecured) {
         $connector = new \React\SocketClient\SecureConnector($connector, $this->loop);
     }
     $deferred = new Deferred();
     $connector->create($uri->getHost(), $uri->getPort() ?: $defaultPort)->then(function (\React\Stream\Stream $stream) use($that, $uri, $deferred, $timeOut) {
         if ($timeOut) {
             $timeOutTimer = $that->loop->addTimer($timeOut, function () use($promise, $stream, $that) {
                 $stream->close();
                 $that->logger->notice("Timeout occured, closing connection");
                 $that->emit("error");
                 $promise->reject("Timeout occured");
             });
         } else {
             $timeOutTimer = null;
         }
         $transport = new WebSocketTransportHybi($stream);
         $transport->setLogger($that->logger);
         $that->transport = $transport;
         $that->stream = $stream;
         $stream->on("close", function () use($that) {
             $that->isClosing = false;
             $that->state = WebSocket::STATE_CLOSED;
         });
         // Give the chance to change request
         $transport->on("request", function (Request $handshake) use($that) {
             $that->emit("request", func_get_args());
         });
         $transport->on("handshake", function (Handshake $handshake) use($that) {
             $that->request = $handshake->getRequest();
             $that->response = $handshake->getRequest();
             $that->emit("handshake", array($handshake));
         });
         $transport->on("connect", function () use(&$state, $that, $transport, $timeOutTimer, $deferred) {
             if ($timeOutTimer) {
                 $timeOutTimer->cancel();
             }
             $deferred->resolve($transport);
             $that->state = WebSocket::STATE_CONNECTED;
             $that->emit("connect");
         });
         $transport->on('message', function ($message) use($that, $transport) {
             $that->emit("message", array("message" => $message));
         });
         $transport->initiateHandshake($uri);
         $that->state = WebSocket::STATE_HANDSHAKE_SENT;
     }, function ($reason) use($that) {
         $that->logger->err($reason);
     });
     return $deferred->promise();
 }
开发者ID:usmanhalalit,项目名称:phpws,代码行数:60,代码来源:WebSocket.php

示例2: __construct

 /**
  * Handle incoming messages.
  *
  * Must be implemented by all extending classes
  *
  * @param $url
  * @param \React\EventLoop\LoopInterface $loop
  * @param \Zend\Log\LoggerInterface $logger
  * @throws \InvalidArgumentException
  */
 public function __construct($url, LoopInterface $loop, LoggerInterface $logger)
 {
     $uri = new Uri($url);
     if ($uri->getScheme() == 'ws') {
         $uri->setScheme('tcp');
     } elseif ($uri->getScheme() == 'wss') {
         $uri->setScheme('ssl');
     }
     if ($uri->getScheme() != 'tcp' && $uri->getScheme() != 'ssl') {
         throw new \InvalidArgumentException("Uri scheme must be one of: tcp, ssl, ws, wss");
     }
     $this->uri = $uri;
     $this->loop = $loop;
     $this->_streams = new SplObjectStorage();
     $this->_connections = new SplObjectStorage();
     $this->_context = stream_context_create();
     $this->_logger = $logger;
 }
开发者ID:devristo,项目名称:phpws,代码行数:28,代码来源:WebSocketServer.php

示例3: clearUri

 /**
  * Get clear uri.
  *
  * @static
  *
  * @param \Zend\Uri\Uri $uri
  *
  * @return boolean|\Zend\Uri\Uri False if uri is not auhorized
  */
 public static function clearUri(Uri $uri)
 {
     if ($uri->getScheme() !== 'http') {
         return false;
     }
     $uri->setHost('www.vimeo.com');
     // clear
     $uri->setPort(0);
     $uri->setUserInfo('');
     $uri->setQuery('');
     $uri->setFragment('');
     return $uri;
 }
开发者ID:pokap,项目名称:media,代码行数:22,代码来源:Vimeo.php

示例4: write

 /**
  * Send request to the proxy server with streaming support
  *
  * @param string        $method
  * @param \Zend\Uri\Uri $uri
  * @param string        $http_ver
  * @param array         $headers
  * @param string        $body
  * @return string Request as string
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     // If no proxy is set, throw an error
     if (!$this->config['proxy_host']) {
         throw new Adapter\Exception('No proxy host set!');
     }
     // Make sure we're properly connected
     if (!$this->socket) {
         throw new Adapter\Exception('Trying to write but we are not connected');
     }
     $host = $this->config['proxy_host'];
     $port = $this->config['proxy_port'];
     if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) {
         throw new Adapter\Exception('Trying to write but we are connected to the wrong proxy ' . 'server');
     }
     // Add Proxy-Authorization header
     if ($this->config['proxy_user'] && !isset($headers['proxy-authorization'])) {
         $headers['proxy-authorization'] = \Zend\Http\Client::encodeAuthHeader($this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']);
     }
     // if we are proxying HTTPS, preform CONNECT handshake with the proxy
     if ($uri->getScheme() == 'https' && !$this->negotiated) {
         $this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
         $this->negotiated = true;
     }
     // Save request method for later
     $this->method = $method;
     // Build request headers
     $request = "{$method} {$uri->toString()} HTTP/{$http_ver}\r\n";
     // Add all headers to the request string
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = "{$k}: {$v}";
         }
         $request .= "{$v}\r\n";
     }
     $request .= "\r\n";
     // Send the request headers
     if (!@fwrite($this->socket, $request)) {
         throw new Adapter\Exception('Error writing request to proxy server');
     }
     //read from $body, write to socket
     while ($body->hasData()) {
         if (!@fwrite($this->socket, $body->read(self::CHUNK_SIZE))) {
             throw new Adapter\Exception('Error writing request to server');
         }
     }
     return 'Large upload, request is not cached.';
 }
开发者ID:rafalwrzeszcz,项目名称:zf2,代码行数:58,代码来源:HttpAdapterStreamingProxy.php

示例5: write

    /**
     * Send request to the remote server with streaming support.
     *
     * @param string        $method
     * @param \Zend\Uri\Uri $uri
     * @param string        $http_ver
     * @param array         $headers
     * @param string        $body
     * @return string Request as string
     */
    public function write($method, $uri, $http_ver = '1.1', $headers = array(),
        $body = '')
    {
        // Make sure we're properly connected
        if (! $this->socket) {
            throw new Adapter\Exception(
                'Trying to write but we are not connected');
        }

        $host = $uri->getHost();
        $host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
        if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
            throw new Adapter\Exception(
                'Trying to write but we are connected to the wrong host');
        }

        // Save request method for later
        $this->method = $method;

        // Build request headers
        $path = $uri->getPath();
        if ($uri->getQuery()) $path .= '?' . $uri->getQuery();
        $request = "{$method} {$path} HTTP/{$http_ver}\r\n";
        foreach ($headers as $k => $v) {
            if (is_string($k)) $v = ucfirst($k) . ": $v";
            $request .= "$v\r\n";
        }

        // Send the headers over
        $request .= "\r\n";
        if (! @fwrite($this->socket, $request)) {
            throw new Adapter\Exception(
                'Error writing request to server');
        }


        //read from $body, write to socket
        $chunk = $body->read(self::CHUNK_SIZE);
        while ($chunk !== FALSE) {
            if (! @fwrite($this->socket, $chunk)) {
                throw new Adapter\Exception(
                    'Error writing request to server');
            }
            $chunk = $body->read(self::CHUNK_SIZE);
        }
        $body->closeFileHandle();
        return 'Large upload, request is not cached.';
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:58,代码来源:HttpAdapterStreamingSocket.php

示例6: clearUri

 /**
  * Get clear uri.
  *
  * @static
  *
  * @param \Zend\Uri\Uri $uri
  *
  * @return boolean|\Zend\Uri\Uri False if uri is not auhorized
  */
 public static function clearUri(Uri $uri)
 {
     if ($uri->getScheme() !== 'http') {
         return false;
     }
     $query = $uri->getQueryAsArray();
     if (empty($query['v'])) {
         return false;
     }
     $uri->setQuery(array('v' => $query['v']));
     $uri->setHost('www.youtube.com');
     $uri->setPath('/watch');
     // clear
     $uri->setPort(0);
     $uri->setUserInfo('');
     $uri->setFragment('');
     return $uri;
 }
开发者ID:pokap,项目名称:media,代码行数:27,代码来源:Youtube.php

示例7: clearUri

 /**
  * Get clear uri.
  *
  * @static
  *
  * @param \Zend\Uri\Uri $uri
  *
  * @return boolean|\Zend\Uri\Uri False if uri is not auhorized
  */
 public static function clearUri(Uri $uri)
 {
     if ($uri->getScheme() !== 'http') {
         return false;
     }
     $paths = explode('/', $uri->getPath());
     $pathsCount = count($paths);
     if ($pathsCount < 2) {
         return false;
     }
     $type = $paths[$pathsCount - 2];
     if (!in_array($type, self::$typesAuthorized)) {
         return false;
     }
     $uri->setHost('www.deezer.com');
     // clear
     $uri->setPort(0);
     $uri->setUserInfo('');
     $uri->setQuery('');
     $uri->setFragment('');
     return $uri;
 }
开发者ID:pokap,项目名称:media,代码行数:31,代码来源:Deezer.php

示例8: write

 /**
  * Send request to the remote server
  *
  * @param string        $method
  * @param \Zend\Uri\Uri $uri
  * @param string        $http_ver
  * @param array         $headers
  * @param string        $body
  * @return string Request as string
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     $host = $uri->getHost();
     $host = strtolower($uri->getScheme()) == 'https' ? 'sslv2://' . $host : $host;
     // Build request headers
     $path = $uri->getPath();
     if (empty($path)) {
         $path = '/';
     }
     if ($uri->getQuery()) {
         $path .= '?' . $uri->getQuery();
     }
     $request = "{$method} {$path} HTTP/{$http_ver}\r\n";
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = ucfirst($k) . ": {$v}";
         }
         $request .= "{$v}\r\n";
     }
     // Add the request body
     $request .= "\r\n" . $body;
     // Do nothing - just return the request as string
     return $request;
 }
开发者ID:nuklehed,项目名称:zf2,代码行数:34,代码来源:Test.php

示例9: write

 /**
  * Send request to the remote server
  *
  * @param string        $method
  * @param \Zend\Uri\Uri $uri
  * @param string        $httpVer
  * @param array         $headers
  * @param string        $body
  * @throws AdapterException\RuntimeException
  * @return string Request as string
  */
 public function write($method, $uri, $httpVer = '1.1', $headers = array(), $body = '')
 {
     // Make sure we're properly connected
     if (!$this->socket) {
         throw new AdapterException\RuntimeException('Trying to write but we are not connected');
     }
     $host = $uri->getHost();
     $host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
     if ($this->connectedTo[0] != $host || $this->connectedTo[1] != $uri->getPort()) {
         throw new AdapterException\RuntimeException('Trying to write but we are connected to the wrong host');
     }
     // Save request method for later
     $this->method = $method;
     // Build request headers
     $path = $uri->getPath();
     if ($uri->getQuery()) {
         $path .= '?' . $uri->getQuery();
     }
     $request = "{$method} {$path} HTTP/{$httpVer}\r\n";
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = ucfirst($k) . ": {$v}";
         }
         $request .= "{$v}\r\n";
     }
     if (is_resource($body)) {
         $request .= "\r\n";
     } else {
         // Add the request body
         $request .= "\r\n" . $body;
     }
     // Send the request
     ErrorHandler::start();
     $test = fwrite($this->socket, $request);
     $error = ErrorHandler::stop();
     if (false === $test) {
         throw new AdapterException\RuntimeException('Error writing request to server', 0, $error);
     }
     if (is_resource($body)) {
         if (stream_copy_to_stream($body, $this->socket) == 0) {
             throw new AdapterException\RuntimeException('Error writing request to server');
         }
     }
     return $request;
 }
开发者ID:leonardovn86,项目名称:zf2_basic2013,代码行数:56,代码来源:Socket.php

示例10: testSetSchemeValid

 /**
  * Test we can set different valid schemes
  *
  * @param string $scheme
  * @dataProvider validSchemeProvider
  */
 public function testSetSchemeValid($scheme)
 {
     $uri = new Uri();
     $uri->setScheme($scheme);
     $this->assertEquals($scheme, $uri->getScheme());
 }
开发者ID:navassouza,项目名称:zf2,代码行数:12,代码来源:UriTest.php

示例11: parse

 /**
  * @inheritdoc
  */
 public function parse($uri)
 {
     $uri = new Uri($uri);
     return $this->formatResults(['scheme' => $uri->getScheme(), 'userinfo' => $uri->getUserInfo(), 'host' => $uri->getHost(), 'port' => $uri->getPort(), 'path' => $uri->getPath(), 'query' => $uri->getQuery(), 'fragment' => $uri->getFragment()]);
 }
开发者ID:nyamsprod,项目名称:uri-parser-benchmarks,代码行数:8,代码来源:Zend.php

示例12: extractReview

 /**
  * Extract a single review into a review instance
  * @param  DomElement $node
  * @return Review
  */
 public function extractReview(DomElement $node)
 {
     $review = new Review();
     $doc = new DomDocument();
     $html = $node->ownerDocument->saveHtml($node);
     $doc->loadHtml('<?xml encoding="utf-8" ?>' . $html);
     $xpath = new DOMXpath($doc);
     /**
      * Author Username
      * // member_info/ * /username/span
      */
     $nodes = $xpath->query("//div[contains(@class, 'member_info')]/*/div[contains(@class, 'username')]/span");
     if ($nodes->length === 1) {
         $review->setAuthor(trim($nodes->item(0)->nodeValue));
     }
     /**
      * Author Location
      */
     $nodes = $xpath->query("//div[contains(@class, 'member_info')]/div[contains(@class, 'location')]");
     if ($nodes->length === 1) {
         $review->setAuthorLocation(trim($nodes->item(0)->nodeValue));
     }
     /**
      * Review Permalink
      */
     $nodes = $xpath->query("//div[contains(@class, 'quote')]/a");
     if ($nodes->length === 1) {
         // URL linked to from the title is an absolute path without host/scheme
         // Also, URL contains a fragment that should be removed
         $path = trim($nodes->item(0)->getAttribute('href'));
         $url = new Uri($this->getOptions()->getUrl());
         $new = sprintf('%s://%s/%s', $url->getScheme(), $url->getHost(), ltrim($path, '/'));
         $url = new Uri($new);
         $url->setFragment(null);
         $review->setUrl((string) $url);
     }
     /**
      * Title Quote
      */
     $nodes = $xpath->query("//div[contains(@class, 'quote')]/a/span[contains(@class, 'noQuotes')]");
     if ($nodes->length === 1) {
         $review->setTitle(trim($nodes->item(0)->nodeValue));
     }
     /**
      * Rating as an alt tag in an image
      */
     $nodes = $xpath->query("//div[contains(@class, 'rating')]/span[contains(@class, 'rate')]/img");
     if ($nodes->length === 1) {
         $img = $nodes->item(0);
         $alt = $img->getAttribute('alt');
         if (preg_match('/([0-9\\.]+)\\s[\\w]+\\s([0-9\\.]+)/', $alt, $match)) {
             $review->setStarRating((double) $match[1]);
             $review->setMaxStarRating((double) $match[2]);
         }
     }
     /**
      * Rating Date
      */
     $nodes = $xpath->query("//div[contains(@class, 'rating')]/span[contains(@class, 'ratingDate')]");
     if ($nodes->length === 1) {
         $span = $nodes->item(0);
         if ($span->hasAttribute('title')) {
             $dateString = $span->getAttribute('title');
             $date = DateTime::createFromFormat('d F Y', $dateString);
             if (false !== $date) {
                 $review->setDate($date);
             }
         } else {
             if (preg_match('/([0-9]{1,2}\\s[\\w]+\\s[0-9]{4})/i', trim($span->nodeValue), $match)) {
                 $date = DateTime::createFromFormat('d F Y', $match[1]);
                 if (false !== $date) {
                     $review->setDate($date);
                 }
             }
         }
     }
     /**
      * Review Excerpt
      */
     $nodes = $xpath->query("//div[contains(@class, 'entry')]/p[contains(@class, 'partial_entry')]");
     if ($nodes->length === 1) {
         // Use first child node->nodeValue to skip links for 'more...'
         $review->setExcerpt(trim($nodes->item(0)->childNodes->item(0)->nodeValue));
     }
     return $review;
 }
开发者ID:netglue,项目名称:zf2-tripadvisor-module,代码行数:91,代码来源:Scraper.php

示例13: connect

 /**
  * Connect to the remote server
  *
  * @param string|Uri $host
  * @param int    $port
  * @param bool   $secure
  *
  * @return void
  */
 public function connect($host, $port = 80, $secure = false)
 {
     if ($host instanceof Uri) {
         $port = $host->getPort();
         $secure = 'https' == $host->getScheme() ? true : false;
         $host = $host->getHost();
     }
     return $this->adapter()->connect($host, $port, $secure);
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:18,代码来源:Remote.php

示例14: testParseTwice

 public function testParseTwice()
 {
     $uri = new Uri();
     $uri->parse('http://user@example.com:1/absolute/url?query#fragment');
     $uri->parse('/relative/url');
     $this->assertNull($uri->getScheme());
     $this->assertNull($uri->getHost());
     $this->assertNull($uri->getUserInfo());
     $this->assertNull($uri->getPort());
     $this->assertNull($uri->getQuery());
     $this->assertNull($uri->getFragment());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:12,代码来源:UriTest.php

示例15: getScheme

 /**
  * Get the scheme part of the URI
  *
  * @return string|null
  */
 public function getScheme()
 {
     return $this->uri->getScheme();
 }
开发者ID:sunnyct,项目名称:silexcmf-core,代码行数:9,代码来源:Uri.php


注:本文中的Zend\Uri\Uri::getScheme方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。