Skip to content

Commit

Permalink
updates for Swoole 4.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
deminy committed Feb 9, 2021
1 parent b5a45a0 commit 3292fef
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 19 deletions.
6 changes: 3 additions & 3 deletions output/swoole/constants.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

define('SWOOLE_VERSION', '4.6.2');
define('SWOOLE_VERSION_ID', 40602);
define('SWOOLE_VERSION', '4.6.3');
define('SWOOLE_VERSION_ID', 40603);
define('SWOOLE_MAJOR_VERSION', 4);
define('SWOOLE_MINOR_VERSION', 6);
define('SWOOLE_RELEASE_VERSION', 2);
define('SWOOLE_RELEASE_VERSION', 3);
define('SWOOLE_EXTRA_VERSION', '');
define('SWOOLE_DEBUG', '');
define('SWOOLE_HAVE_COMPRESSION', '1');
Expand Down
29 changes: 13 additions & 16 deletions output/swoole_library/src/alias_ns.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@

declare(strict_types=1);

namespace Swoole\Coroutine {
use Swoole\Coroutine;
namespace Co;

use Swoole\Coroutine;

if (SWOOLE_USE_SHORTNAME) {
function run(callable $fn, ...$args)
{
$s = new Scheduler();
$options = Coroutine::getOptions();
if (!isset($options['hook_flags'])) {
$s->set(['hook_flags' => SWOOLE_HOOK_ALL]);
}
$s->add($fn, ...$args);
return $s->start();
return \Swoole\Coroutine\run($fn, ...$args);
}

function go(callable $fn, ...$args)
{
return Coroutine::create($fn, ...$args);
}
}

namespace Co {
if (SWOOLE_USE_SHORTNAME) {
function run(callable $fn, ...$args)
{
return \Swoole\Coroutine\run($fn, ...$args);
}
function defer(callable $fn)
{
Coroutine::defer($fn);
}
}
2 changes: 2 additions & 0 deletions output/swoole_library/src/core/Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class Constant

public const OPTION_HTTP_GZIP_LEVEL = 'http_gzip_level';

public const OPTION_COMPRESSION_MIN_LENGTH = 'compression_min_length';

public const OPTION_UPLOAD_TMP_DIR = 'upload_tmp_dir';

public const OPTION_HOST = 'host';
Expand Down
21 changes: 21 additions & 0 deletions output/swoole_library/src/core/Coroutine/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@

use Swoole\Coroutine;

function run(callable $fn, ...$args)
{
$s = new Scheduler();
$options = Coroutine::getOptions();
if (!isset($options['hook_flags'])) {
$s->set(['hook_flags' => SWOOLE_HOOK_ALL]);
}
$s->add($fn, ...$args);
return $s->start();
}

function go(callable $fn, ...$args)
{
Coroutine::create($fn, ...$args);
}

function defer(callable $fn)
{
Coroutine::defer($fn);
}

function batch(array $tasks, float $timeout = -1): array
{
$wg = new WaitGroup(count($tasks));
Expand Down
1 change: 1 addition & 0 deletions output/swoole_library/src/core/Server/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Helper
'http_parse_files' => true,
'http_compression' => true,
'http_compression_level' => true,
'compression_min_length' => true,
'http_gzip_level' => true,
'websocket_compression' => true,
'upload_tmp_dir' => true,
Expand Down
120 changes: 120 additions & 0 deletions output/swoole_library/src/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php
/**
* This file is part of Swoole.
*
* @link https://www.swoole.com
* @contact [email protected]
* @license https://github.com/swoole/library/blob/master/LICENSE
*/

declare(strict_types=1);

if (PHP_VERSION_ID < 70200) {
throw new RuntimeException('require PHP version 7.2 or later');
}

if (SWOOLE_USE_SHORTNAME) {
function _string(string $string = ''): Swoole\StringObject
{
return new Swoole\StringObject($string);
}

function _mbstring(string $string = ''): Swoole\MultibyteStringObject
{
return new Swoole\MultibyteStringObject($string);
}

function _array(array $array = []): Swoole\ArrayObject
{
return new Swoole\ArrayObject($array);
}
}

function swoole_string(string $string = ''): Swoole\StringObject
{
return new Swoole\StringObject($string);
}

function swoole_mbstring(string $string = ''): Swoole\MultibyteStringObject
{
return new Swoole\MultibyteStringObject($string);
}

function swoole_array(array $array = []): Swoole\ArrayObject
{
return new Swoole\ArrayObject($array);
}

function swoole_table(int $size, string $fields): Swoole\Table
{
$_fields = swoole_string($fields)->trim()->split(',');

$table = new Swoole\Table($size, 0.25);

foreach ($_fields as $f) {
$_f = swoole_string($f)->trim()->split(':');
$name = $_f->get(0)->trim()->toString();
$type = $_f->get(1)->trim();

switch ($type) {
case 'i':
case 'int':
$table->column($name, Swoole\Table::TYPE_INT);
break;
case 'f':
case 'float':
$table->column($name, Swoole\Table::TYPE_FLOAT);
break;
case 's':
case 'string':
if ($_f->count() < 3) {
throw new RuntimeException('need to give string length');
}
$length = intval($_f->get(2)->trim()->toString());
if ($length <= 0) {
throw new RuntimeException("invalid string length[{$length}]");
}
$table->column($name, Swoole\Table::TYPE_STRING, $length);
break;
default:
throw new RuntimeException("unknown field type[{$type}]");
break;
}
}

if (!$table->create()) {
throw new RuntimeException('failed to create table');
}

return $table;
}

function swoole_array_list(...$arrray): Swoole\ArrayObject
{
return new Swoole\ArrayObject($arrray);
}

function swoole_array_default_value(array $array, $key, $default_value = null)
{
return array_key_exists($key, $array) ? $array[$key] : $default_value;
}

if (!function_exists('array_key_last')) {
function array_key_last(array $array)
{
if (!empty($array)) {
return key(array_slice($array, -1, 1, true));
}
return null;
}
}

if (!function_exists('array_key_first')) {
function array_key_first(array $array)
{
foreach ($array as $key => $unused) {
return $key;
}
return null;
}
}

0 comments on commit 3292fef

Please sign in to comment.