本文整理汇总了PHP中stream_context_get_options函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_context_get_options函数的具体用法?PHP stream_context_get_options怎么用?PHP stream_context_get_options使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_context_get_options函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_raw_chain
function get_raw_chain($host, $port = 443)
{
global $timeout;
$data = [];
$stream = stream_context_create(array("ssl" => array("capture_peer_cert" => true, "capture_peer_cert_chain" => true, "verify_peer" => false, "peer_name" => $host, "verify_peer_name" => false, "allow_self_signed" => true, "capture_session_meta" => true, "sni_enabled" => true)));
$read_stream = stream_socket_client("ssl://{$host}:{$port}", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $stream);
if ($read_stream === false) {
return false;
} else {
$context = stream_context_get_params($read_stream);
$context_meta = stream_context_get_options($read_stream)['ssl']['session_meta'];
$cert_data = openssl_x509_parse($context["options"]["ssl"]["peer_certificate"]);
$chain_data = $context["options"]["ssl"]["peer_certificate_chain"];
$chain_length = count($chain_data);
if (isset($chain_data) && $chain_length < 10) {
foreach ($chain_data as $key => $value) {
$data["chain"][$key] = $value;
}
} else {
$data["error"] = ["Chain too long."];
return $data;
}
}
return $data;
}
示例2: getOptions
function getOptions()
{
if (empty($this->_options)) {
$this->_options->merge(stream_context_get_options($this->_resource));
}
return $this->_options;
}
示例3: getIncomingStream
/**
* {@inheritDoc}
*/
public function getIncomingStream()
{
$options = stream_context_get_options($this->context);
$method = 'GET';
if (isset($options['http']['method'])) {
$method = $options['http']['method'];
}
$headers = [];
if (isset($options['http']['header'])) {
$headerLines = explode("\r\n", $options['http']['header']);
foreach ($headerLines as $headerLine) {
list($header, $value) = explode(': ', $headerLine, 2);
$headers[$header][] = $value;
}
}
$body = null;
if (isset($options['http']['content'])) {
$body = $options['http']['content'];
}
$protocolVersion = 1.1;
if (isset($options['http']['protocol_version'])) {
$protocolVersion = $options['http']['protocol_version'];
}
$request = new Request($method, $this->path, $headers, $body, $protocolVersion);
return \GuzzleHttp\Psr7\stream_for(\GuzzleHttp\Psr7\str($request));
}
示例4: stream_open
public function stream_open($path, $mode, $options, &$opened_path)
{
$context = stream_context_get_options($this->context);
$this->state = $context['nativesmb']['state'];
$this->handle = $context['nativesmb']['handle'];
return true;
}
示例5: __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__);
}
示例6: 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);
}
示例7: checkoutExistingSocket
private function checkoutExistingSocket($uri, $options)
{
if (empty($this->sockets[$uri])) {
return null;
}
$needsRebind = false;
foreach ($this->sockets[$uri] as $socketId => $poolStruct) {
if (!$poolStruct->isAvailable) {
continue;
} elseif ($this->isSocketDead($poolStruct->resource)) {
unset($this->sockets[$uri][$socketId]);
} elseif (($bindToIp = @stream_context_get_options($poolStruct->resource)['socket']['bindto']) && $bindToIp == $options[self::OP_BINDTO]) {
$poolStruct->isAvailable = false;
$this->reactor->disable($poolStruct->idleWatcher);
return $poolStruct->resource;
} elseif ($bindToIp) {
$needsRebind = true;
} else {
$poolStruct->isAvailable = false;
$this->reactor->disable($poolStruct->idleWatcher);
return $poolStruct->resource;
}
}
$this->needsRebind = $needsRebind;
return null;
}
示例8: stream_open
function stream_open($path, $mode, $options, &$opened_path)
{
if ($this->context) {
print_r(stream_context_get_options($this->context));
}
return false;
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->rfs = new RemoteFilesystem($this->getIO());
$output->write('Checking platform settings: ');
$this->outputResult($output, $this->checkPlatform());
$output->write('Checking http connectivity: ');
$this->outputResult($output, $this->checkHttp());
$opts = stream_context_get_options(StreamContextFactory::getContext());
if (!empty($opts['http']['proxy'])) {
$output->write('Checking HTTP proxy: ');
$this->outputResult($output, $this->checkHttpProxy());
$output->write('Checking HTTPS proxy support for request_fulluri: ');
$this->outputResult($output, $this->checkHttpsProxyFullUriRequestParam());
}
$composer = $this->getComposer(false);
if ($composer) {
$output->write('Checking composer.json: ');
$this->outputResult($output, $this->checkComposerSchema());
}
if ($composer) {
$config = $composer->getConfig();
} else {
$config = Factory::createConfig();
}
if ($oauth = $config->get('github-oauth')) {
foreach ($oauth as $domain => $token) {
$output->write('Checking ' . $domain . ' oauth access: ');
$this->outputResult($output, $this->checkGithubOauth($domain, $token));
}
}
$output->write('Checking composer version: ');
$this->outputResult($output, $this->checkVersion());
return $this->failures;
}
示例10: create
/**
* Creates a stream context based on the provided configuration.
*
* @param ConfigInterface $config The configuration.
*
* @return resource A stream context based on the provided configuration.
*/
public function create(ConfigInterface $config)
{
$options = array();
$headers = array();
$proxy = $config->get('proxy');
if (is_array($proxy)) {
$options = array('http' => array('proxy' => $proxy['proxy_host'] . ':' . $proxy['proxy_port']));
if (isset($proxy['proxy_login']) && isset($proxy['proxy_password'])) {
// Support for proxy authentication is untested. The current implementation is based on
// http://php.net/manual/en/function.stream-context-create.php#74431.
$headers[] = 'Proxy-Authorization: Basic ' . base64_encode($proxy['proxy_login'] . ':' . $proxy['proxy_password']);
}
}
$soapOptions = $config->get('soapClientOptions');
if ((!isset($soapOptions['authentication']) || $soapOptions['authentication'] === SOAP_AUTHENTICATION_BASIC) && isset($soapOptions['login']) && isset($soapOptions['password'])) {
$headers[] = 'Authorization: Basic ' . base64_encode($soapOptions['login'] . ':' . $soapOptions['password']);
}
if (count($headers) > 0) {
$options['http']['header'] = $headers;
}
// If we already created a stream context, make sure we use the same options.
if (isset($soapOptions['stream_context'])) {
$options = array_merge($options, stream_context_get_options($soapOptions['stream_context']));
}
return stream_context_create($options);
}
示例11: testStreamContext
public function testStreamContext()
{
$context = stream_context_get_options($this->context)['swiftfs'];
$this->assertNotEmpty($context['token']);
$this->assertNotEmpty($context['swift_endpoint']);
$this->assertEquals(self::FTYPE, $context['content_type']);
}
示例12: php_compat_file_get_contents
/**
* Replace file_get_contents()
*
* @category PHP
* @package PHP_Compat
* @license LGPL - http://www.gnu.org/licenses/lgpl.html
* @copyright 2004-2007 Aidan Lister <aidan@php.net>, Arpad Ray <arpad@php.net>
* @link http://php.net/function.file_get_contents
* @author Aidan Lister <aidan@php.net>
* @author Arpad Ray <arpad@php.net>
* @version $Revision: 280045 $
* @internal resource_context is only supported for PHP 4.3.0+ (stream_context_get_options)
* @since PHP 4.3.0
* @require PHP 4.0.0 (user_error)
*/
function php_compat_file_get_contents($filename, $incpath = false, $resource_context = null, $offset = -1, $maxlen = -1)
{
if (is_resource($resource_context) && function_exists('stream_context_get_options')) {
$opts = stream_context_get_options($resource_context);
}
$colon_pos = strpos($filename, '://');
$wrapper = $colon_pos === false ? 'file' : substr($filename, 0, $colon_pos);
$opts = empty($opts) || empty($opts[$wrapper]) ? array() : $opts[$wrapper];
$data = false;
switch ($wrapper) {
case 'http':
$max_redirects = isset($opts[$wrapper]['max_redirects']) ? $opts[$proto]['max_redirects'] : PHP_COMPAT_FILE_GET_CONTENTS_MAX_REDIRECTS;
for ($i = 0; $i < $max_redirects; $i++) {
$data = php_compat_http_get_contents_helper($filename, $opts);
if (is_array($contents)) {
// redirected
$filename = rtrim($contents[1]);
$data = '';
continue;
}
break 2;
}
user_error('redirect limit exceeded', E_USER_WARNING);
return;
case 'ftp':
case 'https':
case 'ftps':
case 'socket':
// tbc
}
if (false === $data) {
if (is_resource($resource_context) && version_compare(PHP_VERSION, '4.3.0', 'ge')) {
$fh = fopen($filename, 'rb', $incpath, $resource_context);
} else {
$fh = fopen($filename, 'rb', $incpath);
}
if (false === $fh) {
user_error('failed to open stream: No such file or directory', E_USER_WARNING);
return false;
}
clearstatcache();
if ($fsize = @filesize($filename)) {
$data = fread($fh, $fsize);
} else {
$data = '';
while (!feof($fh)) {
$data .= fread($fh, 8192);
}
}
fclose($fh);
}
if ($offset != -1) {
$data = substr($data, $offset);
}
if ($maxlen != -1) {
$data = substr($data, 0, $maxlen);
}
return $data;
}
示例13: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer(false);
if ($composer) {
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'diagnose', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$this->getIO()->write('Checking composer.json: ', false);
$this->outputResult($this->checkComposerSchema());
}
if ($composer) {
$config = $composer->getConfig();
} else {
$config = Factory::createConfig();
}
$this->rfs = new RemoteFilesystem($this->getIO(), $config);
$this->process = new ProcessExecutor($this->getIO());
$this->getIO()->write('Checking platform settings: ', false);
$this->outputResult($this->checkPlatform());
$this->getIO()->write('Checking git settings: ', false);
$this->outputResult($this->checkGit());
$this->getIO()->write('Checking http connectivity: ', false);
$this->outputResult($this->checkHttp());
$opts = stream_context_get_options(StreamContextFactory::getContext('http://example.org'));
if (!empty($opts['http']['proxy'])) {
$this->getIO()->write('Checking HTTP proxy: ', false);
$this->outputResult($this->checkHttpProxy());
$this->getIO()->write('Checking HTTP proxy support for request_fulluri: ', false);
$this->outputResult($this->checkHttpProxyFullUriRequestParam());
$this->getIO()->write('Checking HTTPS proxy support for request_fulluri: ', false);
$this->outputResult($this->checkHttpsProxyFullUriRequestParam());
}
if ($oauth = $config->get('github-oauth')) {
foreach ($oauth as $domain => $token) {
$this->getIO()->write('Checking ' . $domain . ' oauth access: ', false);
$this->outputResult($this->checkGithubOauth($domain, $token));
}
} else {
$this->getIO()->write('Checking github.com rate limit: ', false);
try {
$rate = $this->getGithubRateLimit('github.com');
$this->outputResult(true);
if (10 > $rate['remaining']) {
$this->getIO()->write('<warning>WARNING</warning>');
$this->getIO()->write(sprintf('<comment>Github has a rate limit on their API. ' . 'You currently have <options=bold>%u</options=bold> ' . 'out of <options=bold>%u</options=bold> requests left.' . PHP_EOL . 'See https://developer.github.com/v3/#rate-limiting and also' . PHP_EOL . ' https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens</comment>', $rate['remaining'], $rate['limit']));
}
} catch (\Exception $e) {
if ($e instanceof TransportException && $e->getCode() === 401) {
$this->outputResult('<comment>The oauth token for github.com seems invalid, run "composer config --global --unset github-oauth.github.com" to remove it</comment>');
} else {
$this->outputResult($e);
}
}
}
$this->getIO()->write('Checking disk free space: ', false);
$this->outputResult($this->checkDiskSpace($config));
$this->getIO()->write('Checking composer version: ', false);
$this->outputResult($this->checkVersion());
return $this->failures;
}
示例14: getHttpOptionsFromContext
/**
* Returns HTTP options from current stream context.
*
* @see http://php.net/manual/en/context.http.php
* @return array HTTP options.
*/
protected static function getHttpOptionsFromContext($context)
{
if (!$context) {
return array();
}
$options = stream_context_get_options($context);
return !empty($options['http']) ? $options['http'] : array();
}
示例15: file_get_contents
public static function file_get_contents($url, $flags = null, $context = null, $offset = null, $maxlen = null)
{
// Not a URL? Do not handle.
if (strpos($url, '://') === false) {
return file_get_contents($url, $flags, $context, $offset, $maxlen);
}
if ($url != static::$url) {
self::$httpstatus = 404;
}
global $http_response_header_test;
if (self::$setHeaders && self::$httpstatus != 404) {
$http_response_header_test = array('HTTP/1.1 ' . self::$httpstatus);
} else {
$http_response_header_test = null;
}
if (self::$httpstatus != 200) {
return '';
}
// Get the from/to from the context
$from = 0;
$to = 0;
if (is_resource($context)) {
$contextOptions = stream_context_get_options($context);
if (isset($contextOptions['http']) && isset($contextOptions['http']['header'])) {
$headers = $contextOptions['http']['header'];
$headers = explode("\r\n", $headers);
foreach ($headers as $line) {
if (substr($line, 0, 13) != 'Range: bytes=') {
continue;
}
$line = substr($line, 13);
$line = trim($line, "\r\n=");
list($from, $to) = explode('-', $line);
}
}
}
if (empty($from) && empty($to)) {
return self::returnBytes(self::$returnSize);
}
$buffer = '';
if (empty($from)) {
$from = 0;
}
if ($from > self::$returnSize - 1) {
return '';
}
if ($from < 0) {
$from = 0;
}
if (empty($to)) {
$to = self::$returnSize - 1;
}
if ($to > self::$returnSize - 1) {
$to = self::$returnSize - 1;
}
$bytes = 1 + $to - $from;
return self::returnBytes($bytes);
}