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


PHP stream_context_get_default函数代码示例

本文整理汇总了PHP中stream_context_get_default函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_context_get_default函数的具体用法?PHP stream_context_get_default怎么用?PHP stream_context_get_default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __construct

 /**
  * {@inheritDoc}
  */
 public function __construct()
 {
     $defaults = stream_context_get_options(stream_context_get_default());
     $this->adapter = $defaults[Filesystem::PROTOCOL]['adapter'];
     $this->logger = $defaults[Filesystem::PROTOCOL]['logger'];
     $this->logger->debug(__METHOD__);
 }
开发者ID:dspacelabs,项目名称:filesystem,代码行数:10,代码来源:StreamWrapper.php

示例2: embedImageURL

function embedImageURL($url)
{
    $url .= "/details/xs";
    // PHP5 befigyel!!!
    $doc = new DOMDocument();
    $opts = array('http' => array('max_redirects' => 100));
    $resource = stream_context_get_default($opts);
    $context = stream_context_create($opts);
    libxml_set_streams_context($context);
    // Pattogna kulonben a cookie miatt, kenytelenek vagyunk curl-t hasznalni
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_COOKIEFILE, "cookiefile");
    curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefile");
    # SAME cookiefile
    if (@$doc->loadHTML(curl_exec($curl))) {
        if ($retnode = $doc->getElementById("textfield-url")) {
            echo "megy";
            return "<img src=\"{$retnode->nodeValue}\">";
        } else {
            return false;
        }
    } else {
        return false;
    }
}
开发者ID:nizoo,项目名称:php-oembed,代码行数:27,代码来源:forum.php

示例3: applyInitPathHook

 public static function applyInitPathHook($url, $context = 'core')
 {
     $params = [];
     $parts = AJXP_Utils::safeParseUrl($url);
     if (!($params = self::getLocalParams(self::CACHE_KEY . $url))) {
         // Nothing in cache
         $repositoryId = $parts["host"];
         $repository = ConfService::getRepositoryById($parts["host"]);
         if ($repository == null) {
             throw new \Exception("Cannot find repository");
         }
         $configHost = $repository->getOption('HOST');
         $configPath = $repository->getOption('PATH');
         $params['path'] = $parts['path'];
         $params['basepath'] = $configPath;
         $params['itemname'] = basename($params['path']);
         // Special case for root dir
         if (empty($params['path']) || $params['path'] == '/') {
             $params['path'] = '/';
         }
         $params['path'] = dirname($params['path']);
         $params['fullpath'] = rtrim($params['path'], '/') . '/' . $params['itemname'];
         $params['base_url'] = $configHost;
         $params['keybase'] = $repositoryId . $params['fullpath'];
         $params['key'] = md5($params['keybase']);
         self::addLocalParams(self::CACHE_KEY . $url, $params);
     }
     $repoData = self::actualRepositoryWrapperData($parts["host"]);
     $repoProtocol = $repoData['protocol'];
     $default = stream_context_get_options(stream_context_get_default());
     $default[$repoProtocol]['path'] = $params;
     $default[$repoProtocol]['client']->setDefaultUrl($configHost);
     stream_context_set_default($default);
 }
开发者ID:Nanomani,项目名称:pydio-core,代码行数:34,代码来源:PathWrapper.php

示例4: choose_torrent_link

function choose_torrent_link($links)
{
    $link_best = "";
    $word_matches = 0;
    if (count($links) == 0) {
        return "";
    }
    //Check how many links has ".torrent" in them
    foreach ($links as $link) {
        if (preg_match("/\\.torrent/", $link)) {
            $link_best = $link;
            $word_matches++;
        }
    }
    //If only one had ".torrent", use that, else check http content-type for each,
    //and use the first that returns the proper torrent type
    if ($word_matches != 1) {
        foreach ($links as $link) {
            $opts = array('http' => array('timeout' => 10));
            stream_context_get_default($opts);
            $headers = get_headers($link, 1);
            if (isset($headers['Content-Disposition']) && preg_match('/filename=.+\\.torrent/i', $headers['Content-Disposition']) || isset($headers['Content-Type']) && $headers['Content-Type'] == 'application/x-bittorrent') {
                $link_best = $link;
                break;
            }
        }
    }
    //If still no match has been made, just select the first, and hope the html torrent parser can find it
    if (empty($link_best)) {
        $link_best = $links[0];
    }
    return $link_best;
}
开发者ID:thawkins,项目名称:torrentwatch-x,代码行数:33,代码来源:feeds.php

示例5: main

function main()
{
    global $ACCESS_TOKEN, $USER_AGENT;
    // Set the API sport, method, id, format, and any parameters
    $host = 'erikberg.com';
    $sport = '';
    $method = 'events';
    $id = '';
    $format = 'json';
    $parameters = array('sport' => 'nba', 'date' => '20130414');
    // Pass method, format, and parameters to build request url
    $url = buildURL($host, $sport, $method, $id, $format, $parameters);
    // Set the User Agent, Authorization header and allow gzip
    $default_opts = array('http' => array('user_agent' => $USER_AGENT, 'header' => array('Accept-Encoding: gzip', 'Authorization: Bearer ' . $ACCESS_TOKEN)));
    stream_context_get_default($default_opts);
    $file = 'compress.zlib://' . $url;
    $fh = fopen($file, 'rb');
    if ($fh && strpos($http_response_header[0], "200 OK") !== false) {
        $content = stream_get_contents($fh);
        fclose($fh);
        printResult($content);
    } else {
        // handle error, check $http_response_header for HTTP status code, etc.
        if ($fh) {
            $xmlstats_error = json_decode(stream_get_contents($fh));
            printf("Server returned %s error along with this message:\n%s\n", $xmlstats_error->error->code, $xmlstats_error->error->description);
        } else {
            print "A problem was encountered trying to connect to the server!\n";
            print_r(error_get_last());
        }
    }
}
开发者ID:jrgomez76,项目名称:nba-app,代码行数:32,代码来源:listing.php

示例6: register_stream_wrapper

 /**
  * Register the stream wrapper for s3
  */
 public function register_stream_wrapper()
 {
     if (defined('S3_UPLOADS_USE_LOCAL') && S3_UPLOADS_USE_LOCAL) {
         stream_wrapper_register('s3', 'S3_Uploads_Local_Stream_Wrapper', STREAM_IS_URL);
     } else {
         S3_Uploads_Stream_Wrapper::register($this->s3());
         stream_context_set_option(stream_context_get_default(), 's3', 'ACL', 'public-read');
     }
     stream_context_set_option(stream_context_get_default(), 's3', 'seekable', true);
 }
开发者ID:humanmade,项目名称:s3-uploads,代码行数:13,代码来源:class-s3-uploads.php

示例7: executeRequest

 /**
  * Execute an HTTP Request
  *
  * @param Google_0814_HttpRequest $request the http request to be executed
  * @return Google_0814_HttpRequest http request with the response http code,
  * response headers and response body filled in
  * @throws Google_0814_IO_Exception on curl or IO error
  */
 public function executeRequest(Google_0814_Http_Request $request)
 {
     $default_options = stream_context_get_options(stream_context_get_default());
     $requestHttpContext = array_key_exists('http', $default_options) ? $default_options['http'] : array();
     if ($request->getPostBody()) {
         $requestHttpContext["content"] = $request->getPostBody();
     }
     $requestHeaders = $request->getRequestHeaders();
     if ($requestHeaders && is_array($requestHeaders)) {
         $headers = "";
         foreach ($requestHeaders as $k => $v) {
             $headers .= "{$k}: {$v}\r\n";
         }
         $requestHttpContext["header"] = $headers;
     }
     $requestHttpContext["method"] = $request->getRequestMethod();
     $requestHttpContext["user_agent"] = $request->getUserAgent();
     $requestSslContext = array_key_exists('ssl', $default_options) ? $default_options['ssl'] : array();
     if (!array_key_exists("cafile", $requestSslContext)) {
         $requestSslContext["cafile"] = dirname(__FILE__) . '/cacerts.pem';
     }
     $options = array("http" => array_merge(self::$DEFAULT_HTTP_CONTEXT, $requestHttpContext), "ssl" => array_merge(self::$DEFAULT_SSL_CONTEXT, $requestSslContext));
     $context = stream_context_create($options);
     $url = $request->getUrl();
     if ($request->canGzip()) {
         $url = self::ZLIB . $url;
     }
     // We are trapping any thrown errors in this method only and
     // throwing an exception.
     $this->trappedErrorNumber = null;
     $this->trappedErrorString = null;
     // START - error trap.
     set_error_handler(array($this, 'trapError'));
     $fh = fopen($url, 'r', false, $context);
     restore_error_handler();
     // END - error trap.
     if ($this->trappedErrorNumber) {
         throw new Google_0814_IO_Exception(sprintf("HTTP Error: Unable to connect: '%s'", $this->trappedErrorString), $this->trappedErrorNumber);
     }
     $response_data = false;
     $respHttpCode = self::UNKNOWN_CODE;
     if ($fh) {
         if (isset($this->options[self::TIMEOUT])) {
             stream_set_timeout($fh, $this->options[self::TIMEOUT]);
         }
         $response_data = stream_get_contents($fh);
         fclose($fh);
         $respHttpCode = $this->getHttpResponseCode($http_response_header);
     }
     if (false === $response_data) {
         throw new Google_0814_IO_Exception(sprintf("HTTP Error: Unable to connect: '%s'", $respHttpCode), $respHttpCode);
     }
     $responseHeaders = $this->getHttpResponseHeaders($http_response_header);
     return array($response_data, $responseHeaders, $respHttpCode);
 }
开发者ID:nayabbukhari,项目名称:circulocristiano,代码行数:63,代码来源:Stream.php

示例8: makeRequest

 /**
  * Execute a apiHttpRequest.
  *
  * @param Google_HttpRequest $request the http request to be executed
  *
  * @throws Google_IOException on curl or IO error
  *
  * @return Google_HttpRequest http request with the response http code,
  *                            response headers and response body filled in
  */
 public function makeRequest(Google_Http_Request $request)
 {
     // First, check to see if we have a valid cached version.
     $cached = $this->getCachedRequest($request);
     if ($cached !== false) {
         if (!$this->checkMustRevalidateCachedRequest($cached, $request)) {
             return $cached;
         }
     }
     $default_options = stream_context_get_options(stream_context_get_default());
     $requestHttpContext = array_key_exists('http', $default_options) ? $default_options['http'] : [];
     if (array_key_exists($request->getRequestMethod(), self::$ENTITY_HTTP_METHODS)) {
         $request = $this->processEntityRequest($request);
     }
     if ($request->getPostBody()) {
         $requestHttpContext['content'] = $request->getPostBody();
     }
     $requestHeaders = $request->getRequestHeaders();
     if ($requestHeaders && is_array($requestHeaders)) {
         $headers = '';
         foreach ($requestHeaders as $k => $v) {
             $headers .= "{$k}: {$v}\n";
         }
         $requestHttpContext['header'] = $headers;
     }
     $requestHttpContext['method'] = $request->getRequestMethod();
     $requestHttpContext['user_agent'] = $request->getUserAgent();
     $requestSslContext = array_key_exists('ssl', $default_options) ? $default_options['ssl'] : [];
     if (!array_key_exists('cafile', $requestSslContext)) {
         $requestSslContext['cafile'] = dirname(__FILE__) . '/cacerts.pem';
     }
     $options = ['http' => array_merge(self::$DEFAULT_HTTP_CONTEXT, $requestHttpContext), 'ssl' => array_merge(self::$DEFAULT_SSL_CONTEXT, $requestSslContext)];
     $context = stream_context_create($options);
     $response_data = file_get_contents($request->getUrl(), false, $context);
     if (false === $response_data) {
         throw new Google_IOException('HTTP Error: Unable to connect');
     }
     $respHttpCode = $this->getHttpResponseCode($http_response_header);
     $responseHeaders = $this->getHttpResponseHeaders($http_response_header);
     if ($respHttpCode == 304 && $cached) {
         // If the server responded NOT_MODIFIED, return the cached request.
         $this->updateCachedRequest($cached, $responseHeaders);
         return $cached;
     }
     if (!isset($responseHeaders['Date']) && !isset($responseHeaders['date'])) {
         $responseHeaders['Date'] = date('r');
     }
     $request->setResponseHttpCode($respHttpCode);
     $request->setResponseHeaders($responseHeaders);
     $request->setResponseBody($response_data);
     // Store the request in cache (the function checks to see if the request
     // can actually be cached)
     $this->setCachedRequest($request);
     return $request;
 }
开发者ID:nabble,项目名称:ajde,代码行数:65,代码来源:Stream.php

示例9: access

 public function access($code, $options = array())
 {
     $type = isset($options['grant_type']) ? $options['grant_type'] : 'authorization_code';
     $params = array('client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'redirect_uri' => isset($options['redirect_uri']) ? $options['redirect_uri'] : $this->redirect_uri);
     switch ($type) {
         case 'authorization_code':
             $params['code'] = $code;
             $params['grant_type'] = $type;
             break;
         case 'refresh_token':
             $params['refresh_token'] = $code;
             $params['response_type'] = 'refresh_token';
             $params['UserID'] = $options['uid'];
             break;
     }
     $response = null;
     $url = $this->url_access_token();
     switch ($this->method) {
         case 'GET':
             // Need to switch to Request library, but need to test it on one that works
             $url .= '?' . http_build_query($params);
             $response = file_get_contents($url);
             $return = json_decode($response, true);
             break;
         case 'POST':
             $postdata = http_build_query($params);
             $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
             $_default_opts = stream_context_get_params(stream_context_get_default());
             $context = stream_context_create(array_merge_recursive($_default_opts['options'], $opts));
             $response = file_get_contents($url, false, $context);
             $return = json_decode($response, true);
             break;
         default:
             throw new Exception('Method \'' . $this->method . '\' must be either GET or POST');
     }
     if (isset($return['Error'])) {
         throw new Exception($return['Error'], $return['ErrorCode']);
     }
     // Converts keys to the equivalent
     $return['access_token'] = $return['AccessToken'];
     $return['expires'] = $return['Expires'];
     $return['refresh_token'] = $return['RefreshToken'];
     $return['uid'] = $return['UserID'];
     // Unsets no longer used indexes
     unset($return['AccessToken'], $return['Expires'], $return['RefreshToken'], $return['UserID']);
     switch ($type) {
         case 'authorization_code':
             return Token::factory('access', $return);
             break;
         case 'refresh_token':
             return Token::factory('refresh', $return);
             break;
     }
 }
开发者ID:dscafati,项目名称:laravel-oauth2,代码行数:54,代码来源:Ihealth.php

示例10: get_user_info

 public function get_user_info(Access $token)
 {
     $opts = array('http' => array('method' => 'GET', 'header' => 'Authorization: OAuth ' . $token->access_token));
     $_default_opts = stream_context_get_params(stream_context_get_default());
     $opts = array_merge_recursive($_default_opts['options'], $opts);
     $context = stream_context_create($opts);
     $url = 'http://api-yaru.yandex.ru/me/?format=json';
     $user = json_decode(file_get_contents($url, false, $context));
     preg_match("/\\d+\$/", $user->id, $uid);
     return array('uid' => $uid[0], 'nickname' => isset($user->name) ? $user->name : null, 'name' => isset($user->name) ? $user->name : null, 'first_name' => isset($user->first_name) ? $user->first_name : null, 'last_name' => isset($user->last_name) ? $user->last_name : null, 'email' => isset($user->email) ? $user->email : null, 'location' => isset($user->hometown->name) ? $user->hometown->name : null, 'description' => isset($user->bio) ? $user->bio : null, 'image' => $user->links->userpic);
 }
开发者ID:rocketyang,项目名称:mincms,代码行数:11,代码来源:Yandex.php

示例11: register_stream_wrapper

 /**
  * Register the stream wrapper for s3
  */
 public function register_stream_wrapper()
 {
     if (defined('S3_UPLOADS_USE_LOCAL') && S3_UPLOADS_USE_LOCAL) {
         require_once dirname(__FILE__) . '/class-s3-uploads-local-stream-wrapper.php';
         stream_wrapper_register('s3', 'S3_Uploads_Local_Stream_Wrapper', STREAM_IS_URL);
     } else {
         $s3 = $this->s3();
         S3_Uploads_Stream_Wrapper::register($s3);
         stream_context_set_option(stream_context_get_default(), 's3', 'ACL', 'public-read');
     }
     stream_context_set_option(stream_context_get_default(), 's3', 'seekable', true);
 }
开发者ID:bdurette,项目名称:S3-Uploads,代码行数:15,代码来源:class-s3-uploads.php

示例12: __construct

 /**
  * @param string $prefix
  */
 public function __construct(S3Client $client)
 {
     $protocol = 'dspace';
     $this->client = $client;
     $default = stream_context_get_options(stream_context_get_default());
     $default[$protocol]['client'] = $client;
     if (!isset($default[$protocol]['cache'])) {
         // Set a default cache adapter.
         $default[$protocol]['cache'] = new LruArrayCache();
     }
     stream_context_set_default($default);
 }
开发者ID:dspacelabs,项目名称:filesystem,代码行数:15,代码来源:AmazonS3Adapter.php

示例13: testDefaultContextOptionsAreRemoved

 public function testDefaultContextOptionsAreRemoved()
 {
     return;
     $this->markTestSkipped('Skipped until I find a way to remove eys from default context options');
     stream_context_set_default(array('someContext' => array('a' => 'b')));
     $fs = new FileSystem();
     $scheme = $fs->scheme();
     unset($fs);
     //provoking __destruct
     $options = stream_context_get_options(stream_context_get_default());
     $this->assertArrayNotHasKey($scheme, $options, 'FS Context option present');
     $this->assertArrayHasKey('someContext', $options, 'Previously existing context option present');
 }
开发者ID:mathroc,项目名称:php-vfs,代码行数:13,代码来源:VirtualFilesystemTest.php

示例14: links_from_site

 /**	Load the page, parse for iconic links, and add them to icon list if
 		they are valid.
 	*/
 protected function links_from_site()
 {
     /*
     	Quietly fetch the site contents into a DOM
     */
     $dom = new DOMDocument();
     $dom->recover = true;
     $dom->strictErrorChecking = false;
     $default_context = stream_context_get_default();
     $stream_context = stream_context_create($this->stream_context_options);
     libxml_set_streams_context($stream_context);
     $libxml_err_state = libxml_use_internal_errors(true);
     $dom_result = @$dom->loadHTMLFile($this->site_url);
     libxml_clear_errors();
     libxml_use_internal_errors($libxml_err_state);
     libxml_set_streams_context($default_context);
     if ($dom_result === false) {
         $status = self::header_findr($http_response_header, null);
         @(list(, $status, ) = explode(' ', $status, 3));
         $status = (int) $status;
         trigger_error('site \'' . $this->site_url . '\' returned ' . $status, E_USER_NOTICE);
         return false;
     }
     /*
     	If we followed any redirects, rewrite the site_url with the current
     	location, so that relative urls may be correctly converted into
     	their absolute form.
     */
     $location = self::header_findr($http_response_header, 'Location');
     if ($location !== null) {
         $this->site_url = $location;
     }
     /* check all the links which relate to icons */
     foreach ($dom->getElementsByTagName('link') as $link) {
         $relations = explode(' ', $link->getAttribute('rel'));
         if (in_array('icon', array_map('strtolower', $relations))) {
             $href = $link->getAttribute('href');
             $href_absolute = $this->absolutize_url($href);
             $icon = $this->validate_icon($href_absolute);
             if ($icon !== null) {
                 if (empty($icon['type'])) {
                     $icon['type'] = $link->getAttribute('type');
                 }
                 if (empty($icon['sizes'])) {
                     $icon['sizes'] = $link->getAttribute('sizes');
                 }
                 $this->favicons[] = $icon;
             }
         }
     }
 }
开发者ID:RomanSixty,项目名称:Feed-on-Feeds,代码行数:54,代码来源:favicon.php

示例15: get_user_info

 public function get_user_info(OAuth2_Token_Access $token)
 {
     $url = 'https://api.renren.com/restserver.do';
     $params = array('access_token' => $token->access_token, 'format' => 'JSON', 'v' => '1.0', 'call_id' => time(), 'method' => 'users.getInfo');
     $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($params)));
     $_default_opts = stream_context_get_params(stream_context_get_default());
     $context = stream_context_create(array_merge_recursive($_default_opts['options'], $opts));
     $user = json_decode(file_get_contents($url, false, $context));
     if (!is_array($user) or !isset($user[0]) or !($user = $user[0]) or array_key_exists("error_code", $user)) {
         throw new OAuth2_Exception((array) $user);
     }
     // Create a response from the request
     return array('via' => 'renren', 'uid' => $user->uid, 'screen_name' => $user->name, 'name' => '', 'location' => '', 'description' => '', 'image' => $user->tinyurl, 'access_token' => $token->access_token, 'expire_at' => $token->expires, 'refresh_token' => $token->refresh_token);
 }
开发者ID:PoppyLi,项目名称:PCMS,代码行数:14,代码来源:Renren.php


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