Skip to content

Commit

Permalink
add some configs
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Mar 3, 2022
1 parent 0891aba commit 97f5171
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
return [
'debug' => true,
'default_timezone' => 'Asia/Shanghai',
'public_path' => base_path() . DIRECTORY_SEPARATOR . 'public',
'runtime_path' => base_path(false) . DIRECTORY_SEPARATOR . 'runtime',
];
40 changes: 21 additions & 19 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,29 @@
Worker::$statusFile = $config['status_file'] ?? '';
}

$worker = new Worker($config['listen'], $config['context']);
$property_map = [
'name',
'count',
'user',
'group',
'reusePort',
'transport',
];
foreach ($property_map as $property) {
if (isset($config[$property])) {
$worker->$property = $config[$property];
if ($config['listen']) {
$worker = new Worker($config['listen'], $config['context']);
$property_map = [
'name',
'count',
'user',
'group',
'reusePort',
'transport',
];
foreach ($property_map as $property) {
if (isset($config[$property])) {
$worker->$property = $config[$property];
}
}
}

$worker->onWorkerStart = function ($worker) {
require_once base_path() . '/support/bootstrap.php';
$app = new App($worker, Container::instance(), Log::channel('default'), app_path(), public_path());
Http::requestClass(config('server.request_class') ?? Request::class);
$worker->onMessage = [$app, 'onMessage'];
};
$worker->onWorkerStart = function ($worker) {
require_once base_path() . '/support/bootstrap.php';
$app = new App($worker, Container::instance(), Log::channel('default'), app_path(), public_path());
Http::requestClass(config('server.request_class') ?? Request::class);
$worker->onMessage = [$app, 'onMessage'];
};
}

// Windows does not support custom processes.
if (\DIRECTORY_SEPARATOR === '/') {
Expand Down
29 changes: 20 additions & 9 deletions support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@


/**
* @return string
* @param $return_phar
* @return false|string
*/
function base_path()
function base_path($return_phar = true)
{
return BASE_PATH;
static $real_path = '';
if (!$real_path) {
$real_path = is_phar() ? dirname(Phar::running(false)) : BASE_PATH;
}
return $return_phar ? BASE_PATH : $real_path;
}

/**
Expand All @@ -55,7 +60,11 @@ function app_path()
*/
function public_path()
{
return BASE_PATH . DIRECTORY_SEPARATOR . 'public';
static $path = '';
if (!$path) {
$path = get_realpath(config('app.public_path', BASE_PATH . DIRECTORY_SEPARATOR . 'public'));
}
return $path;
}

/**
Expand All @@ -74,12 +83,11 @@ function config_path()
*/
function runtime_path()
{
static $runtime_path;
if (!$runtime_path) {
$runtime_path = is_phar() ? dirname(Phar::running(false)) . DIRECTORY_SEPARATOR . 'runtime'
: $runtime_path = BASE_PATH . DIRECTORY_SEPARATOR . 'runtime';
static $path = '';
if (!$path) {
$path = get_realpath(config('app.runtime_path', BASE_PATH . DIRECTORY_SEPARATOR . 'runtime'));
}
return $runtime_path;
return $path;
}

/**
Expand Down Expand Up @@ -308,6 +316,9 @@ function copy_dir($source, $dest, $overwrite = false)
*/
function remove_dir($dir)
{
if (is_link($dir) || is_file($dir)) {
return unlink($dir);
}
$files = array_diff(scandir($dir), array('.', '..'));
foreach ($files as $file) {
(is_dir("$dir/$file") && !is_link($dir)) ? remove_dir("$dir/$file") : unlink("$dir/$file");
Expand Down

0 comments on commit 97f5171

Please sign in to comment.