Skip to content

Commit

Permalink
update: migrate syntax to php 8.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 7, 2021
1 parent 0296a11 commit 590fe4a
Show file tree
Hide file tree
Showing 26 changed files with 311 additions and 333 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
}
],
"require": {
"php": ">7.2.0",
"php": ">8.0.0",
"psr/http-client": "^1.0",
"toolkit/stdlib": "^1.0"
"toolkit/stdlib": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
29 changes: 29 additions & 0 deletions example/refer-file_get_contents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);

require dirname(__DIR__) . '/test/bootstrap.php';

/**
* # example 1 获取一个页面并发送 POST 数据
*
* @link https://secure.php.net/manual/zh/context.http.php#refsect1-context.http-examples
*/

$postdata = http_build_query(
[
'var1' => 'some content',
'var2' => 'doh'
]
);

$opts = [
'http' =>
[
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
]
];

$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/submit.php', false, $context);

18 changes: 18 additions & 0 deletions example/refer-file_get_contents1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

require dirname(__DIR__) . '/test/bootstrap.php';

/**
* @see https://secure.php.net/manual/zh/context.http.php#114867
*/

// php 5.4 : array syntax and header option with array value
$data = file_get_contents('http://www.example.com/', false, stream_context_create([
'http' => [
'protocol_version' => 1.1,
'header' => [
'Connection: close',
],
],
]));

22 changes: 22 additions & 0 deletions example/refer-fopen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types=1);

require dirname(__DIR__) . '/test/bootstrap.php';

/**
* @link https://secure.php.net/manual/zh/context.http.php#110449
*/

$stream = stream_context_create([
'http' => [
'method' => 'GET',
'timeout' => 20,
'header' => 'User-agent: Myagent',
'proxy' => 'tcp://my-proxy.localnet:3128',
'request_fulluri' => true /* without this option we get an HTTP error! */
]
]);

if ($fp = fopen('http://example.com', 'rb', false, $stream)) {
print 'well done';
}

32 changes: 32 additions & 0 deletions example/refer-fopen2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

require dirname(__DIR__) . '/test/bootstrap.php';

/**
* # example 2 忽略重定向并获取 header 和内容
*
* @link https://secure.php.net/manual/zh/context.http.php#refsect1-context.http-examples
*/

$url = 'http://www.example.org/header.php';

$opts = [
'http' =>
[
'method' => 'GET',
'max_redirects' => '0',
'ignore_errors' => '1'
]
];

$context = stream_context_create($opts);
$stream = fopen($url, 'rb', false, $context);

// header information as well as meta data
// about the stream
vdump(stream_get_meta_data($stream));

// actual data at $url
vdump(stream_get_contents($stream));
fclose($stream);

93 changes: 0 additions & 93 deletions example/refer.php

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 590fe4a

Please sign in to comment.