Commit 1b5f7412 authored by wolfcode's avatar wolfcode

Webman-framework v1.4.9

parent ced1e593
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
}, },
"require": { "require": {
"php": ">=7.2", "php": ">=7.2",
"workerman/webman-framework": "1.4.3", "workerman/webman-framework": "^1.4",
"monolog/monolog": "^2.0", "monolog/monolog": "^2.0",
"webman/auto-route": "^1.0", "webman/auto-route": "^1.0",
"webman/think-orm": "1.0.2", "webman/think-orm": "1.0.2",
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
"aliyuncs/oss-sdk-php": "^2.4", "aliyuncs/oss-sdk-php": "^2.4",
"qcloud/cos-sdk-v5": "^2.5", "qcloud/cos-sdk-v5": "^2.5",
"jasongrimes/paginator": "^1.0", "jasongrimes/paginator": "^1.0",
"webman/console": "1.0.27" "webman/console": "^1.2"
}, },
"suggest": { "suggest": {
"ext-event": "For better performance. " "ext-event": "For better performance. "
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "1e7532d2b14481835ed4cafcfb0c520b", "content-hash": "42b09044b63aa27ff1c20f65be9f5f09",
"packages": [ "packages": [
{ {
"name": "aliyuncs/oss-sdk-php", "name": "aliyuncs/oss-sdk-php",
...@@ -3636,19 +3636,20 @@ ...@@ -3636,19 +3636,20 @@
}, },
{ {
"name": "webman/console", "name": "webman/console",
"version": "v1.0.27", "version": "v1.2.16",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/webman-php/console.git", "url": "https://github.com/webman-php/console.git",
"reference": "e450967eaabc43eb0c93cfcd6d8f420c16e22b67" "reference": "252868f948fe397e386577fa6ce0e7487ffc98ba"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/webman-php/console/zipball/e450967eaabc43eb0c93cfcd6d8f420c16e22b67", "url": "https://api.github.com/repos/webman-php/console/zipball/252868f948fe397e386577fa6ce0e7487ffc98ba",
"reference": "e450967eaabc43eb0c93cfcd6d8f420c16e22b67", "reference": "252868f948fe397e386577fa6ce0e7487ffc98ba",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"doctrine/inflector": "^2.0",
"symfony/console": ">=5.0" "symfony/console": ">=5.0"
}, },
"require-dev": { "require-dev": {
...@@ -3684,7 +3685,7 @@ ...@@ -3684,7 +3685,7 @@
"source": "https://github.com/webman-php/console", "source": "https://github.com/webman-php/console",
"wiki": "http://www.workerman.net/doc/webman" "wiki": "http://www.workerman.net/doc/webman"
}, },
"time": "2022-07-01T08:59:02+00:00" "time": "2022-10-08T13:46:48+00:00"
}, },
{ {
"name": "webman/think-cache", "name": "webman/think-cache",
...@@ -3823,16 +3824,16 @@ ...@@ -3823,16 +3824,16 @@
}, },
{ {
"name": "workerman/webman-framework", "name": "workerman/webman-framework",
"version": "v1.4.3", "version": "v1.4.9",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/walkor/webman-framework.git", "url": "https://github.com/walkor/webman-framework.git",
"reference": "0f4d5b6c58823656bdc9603f762d4be6e41ae380" "reference": "faf13663be7cad1608217a0ec2e3cb8913f866dc"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/walkor/webman-framework/zipball/0f4d5b6c58823656bdc9603f762d4be6e41ae380", "url": "https://api.github.com/repos/walkor/webman-framework/zipball/faf13663be7cad1608217a0ec2e3cb8913f866dc",
"reference": "0f4d5b6c58823656bdc9603f762d4be6e41ae380", "reference": "faf13663be7cad1608217a0ec2e3cb8913f866dc",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -3863,34 +3864,24 @@ ...@@ -3863,34 +3864,24 @@
{ {
"name": "walkor", "name": "walkor",
"email": "walkor@workerman.net", "email": "walkor@workerman.net",
"homepage": "http://www.workerman.net", "homepage": "https://www.workerman.net",
"role": "Developer" "role": "Developer"
} }
], ],
"description": "High performance HTTP Service Framework.", "description": "High performance HTTP Service Framework.",
"homepage": "http://www.workerman.net", "homepage": "https://www.workerman.net",
"keywords": [ "keywords": [
"High Performance", "High Performance",
"http service" "http service"
], ],
"support": { "support": {
"email": "walkor@workerman.net", "email": "walkor@workerman.net",
"forum": "http://wenda.workerman.net/", "forum": "https://wenda.workerman.net/",
"issues": "https://github.com/walkor/webman/issues", "issues": "https://github.com/walkor/webman/issues",
"source": "https://github.com/walkor/webman-framework", "source": "https://github.com/walkor/webman-framework",
"wiki": "http://doc.workerman.net/" "wiki": "https://doc.workerman.net/"
}, },
"funding": [ "time": "2022-10-20T06:42:33+00:00"
{
"url": "https://opencollective.com/walkor",
"type": "open_collective"
},
{
"url": "https://www.patreon.com/walkor",
"type": "patreon"
}
],
"time": "2022-08-15T12:35:14+00:00"
}, },
{ {
"name": "workerman/workerman", "name": "workerman/workerman",
......
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
Support\App::run(); support\App::run();
...@@ -22,10 +22,6 @@ use Webman\Util; ...@@ -22,10 +22,6 @@ use Webman\Util;
$worker = $worker ?? null; $worker = $worker ?? null;
if ($timezone = config('app.default_timezone')) {
date_default_timezone_set($timezone);
}
set_error_handler(function ($level, $message, $file = '', $line = 0) { set_error_handler(function ($level, $message, $file = '', $line = 0) {
if (error_reporting() & $level) { if (error_reporting() & $level) {
throw new ErrorException($message, 0, $level, $file, $line); throw new ErrorException($message, 0, $level, $file, $line);
...@@ -48,7 +44,11 @@ if (class_exists('Dotenv\Dotenv') && file_exists(base_path() . '/.env')) { ...@@ -48,7 +44,11 @@ if (class_exists('Dotenv\Dotenv') && file_exists(base_path() . '/.env')) {
} }
} }
Support\App::loadAllConfig(['route']); Config::clear();
support\App::loadAllConfig(['route']);
if ($timezone = config('app.default_timezone')) {
date_default_timezone_set($timezone);
}
foreach (config('autoload.files', []) as $file) { foreach (config('autoload.files', []) as $file) {
include_once $file; include_once $file;
......
<?php <?php
/** /**
* This file is part of webman. * This file is part of webman.
* *
...@@ -12,10 +13,10 @@ ...@@ -12,10 +13,10 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
use support\Container;
use support\Request; use support\Request;
use support\Response; use support\Response;
use support\Translation; use support\Translation;
use support\Container;
use support\view\Raw; use support\view\Raw;
use support\view\Blade; use support\view\Blade;
use support\view\ThinkPHP; use support\view\ThinkPHP;
...@@ -25,68 +26,95 @@ use Webman\App; ...@@ -25,68 +26,95 @@ use Webman\App;
use Webman\Config; use Webman\Config;
use Webman\Route; use Webman\Route;
// Phar support. // Webman version
if (\is_phar()) { define('WEBMAN_VERSION', '1.4');
\define('BASE_PATH', dirname(__DIR__));
} else { // Project base path
\define('BASE_PATH', realpath(__DIR__ . '/../')); define('BASE_PATH', dirname(__DIR__));
/**
* Generate paths based on given information
* @param string $front
* @param string $back
* @return string
*/
function path_combine(string $front, string $back)
{
return $front . ($back ? (DIRECTORY_SEPARATOR . ltrim($back, DIRECTORY_SEPARATOR)) : $back);
} }
\define('WEBMAN_VERSION', '1.4');
/** /**
* @param $return_phar * return the program execute directory
* @param string $path
* @return string
*/
function run_path(string $path = '')
{
static $run_path = '';
if (!$run_path) {
$run_path = \is_phar() ? \dirname(\Phar::running(false)) : BASE_PATH;
}
return \path_combine($run_path, $path);
}
/**
* if the param $path equal false,will return this program current execute directory
* @param string|false $path
* @return false|string * @return false|string
*/ */
function base_path(bool $return_phar = true) function base_path($path = '')
{ {
static $real_path = ''; if (false === $path) {
if (!$real_path) { return \run_path();
$real_path = \is_phar() ? \dirname(Phar::running(false)) : BASE_PATH;
} }
return $return_phar ? BASE_PATH : $real_path;
return \path_combine(BASE_PATH, $path);
} }
/** /**
* @param string $path
* @return string * @return string
*/ */
function app_path() function app_path(string $path = '')
{ {
return BASE_PATH . DIRECTORY_SEPARATOR . 'app'; return \path_combine(BASE_PATH . DIRECTORY_SEPARATOR . 'app', $path);
} }
/** /**
* @param string $path
* @return string * @return string
*/ */
function public_path() function public_path(string $path = '')
{ {
static $path = ''; static $public_path = '';
if (!$path) { if (!$public_path) {
$path = \config('app.public_path', BASE_PATH . DIRECTORY_SEPARATOR . 'public'); $public_path = \config('app.public_path') ? : \run_path('public');
} }
return $path; return \path_combine($public_path, $path);
} }
/** /**
* @param string $path
* @return string * @return string
*/ */
function config_path() function config_path(string $path = '')
{ {
return BASE_PATH . DIRECTORY_SEPARATOR . 'config'; return \path_combine(BASE_PATH . DIRECTORY_SEPARATOR . 'config', $path);
} }
/** /**
* Phar support. * Phar support.
* Compatible with the 'realpath' function in the phar file. * Compatible with the 'realpath' function in the phar file.
* * @param string $path
* @return string * @return string
*/ */
function runtime_path() function runtime_path(string $path = '')
{ {
static $path = ''; static $runtime_path = '';
if (!$path) { if (!$runtime_path) {
$path = \config('app.runtime_path', BASE_PATH . DIRECTORY_SEPARATOR . 'runtime'); $runtime_path = \config('app.runtime_path') ? : \run_path('runtime');
} }
return $path; return \path_combine($runtime_path, $path);
} }
/** /**
...@@ -210,7 +238,7 @@ function twig_view(string $template, array $vars = [], string $app = null) ...@@ -210,7 +238,7 @@ function twig_view(string $template, array $vars = [], string $app = null)
} }
/** /**
* @return Request * @return \Webman\Http\Request|Request|null
*/ */
function request() function request()
{ {
...@@ -379,7 +407,7 @@ function worker_bind($worker, $class) ...@@ -379,7 +407,7 @@ function worker_bind($worker, $class)
} }
} }
if (\method_exists($class, 'onWorkerStart')) { if (\method_exists($class, 'onWorkerStart')) {
[$class, 'onWorkerStart']($worker); \call_user_func([$class, 'onWorkerStart'], $worker);
} }
} }
...@@ -433,7 +461,6 @@ function worker_start($process_name, $config) ...@@ -433,7 +461,6 @@ function worker_start($process_name, $config)
$instance = Container::make($config['handler'], $config['constructor'] ?? []); $instance = Container::make($config['handler'], $config['constructor'] ?? []);
\worker_bind($worker, $instance); \worker_bind($worker, $instance);
} }
}; };
} }
......
...@@ -3792,26 +3792,27 @@ ...@@ -3792,26 +3792,27 @@
}, },
{ {
"name": "webman/console", "name": "webman/console",
"version": "v1.0.27", "version": "v1.2.16",
"version_normalized": "1.0.27.0", "version_normalized": "1.2.16.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/webman-php/console.git", "url": "https://github.com/webman-php/console.git",
"reference": "e450967eaabc43eb0c93cfcd6d8f420c16e22b67" "reference": "252868f948fe397e386577fa6ce0e7487ffc98ba"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/webman-php/console/zipball/e450967eaabc43eb0c93cfcd6d8f420c16e22b67", "url": "https://api.github.com/repos/webman-php/console/zipball/252868f948fe397e386577fa6ce0e7487ffc98ba",
"reference": "e450967eaabc43eb0c93cfcd6d8f420c16e22b67", "reference": "252868f948fe397e386577fa6ce0e7487ffc98ba",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"doctrine/inflector": "^2.0",
"symfony/console": ">=5.0" "symfony/console": ">=5.0"
}, },
"require-dev": { "require-dev": {
"workerman/webman": "^1.0" "workerman/webman": "^1.0"
}, },
"time": "2022-07-01T08:59:02+00:00", "time": "2022-10-08T13:46:48+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
...@@ -3991,17 +3992,17 @@ ...@@ -3991,17 +3992,17 @@
}, },
{ {
"name": "workerman/webman-framework", "name": "workerman/webman-framework",
"version": "v1.4.3", "version": "v1.4.9",
"version_normalized": "1.4.3.0", "version_normalized": "1.4.9.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/walkor/webman-framework.git", "url": "https://github.com/walkor/webman-framework.git",
"reference": "0f4d5b6c58823656bdc9603f762d4be6e41ae380" "reference": "faf13663be7cad1608217a0ec2e3cb8913f866dc"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/walkor/webman-framework/zipball/0f4d5b6c58823656bdc9603f762d4be6e41ae380", "url": "https://api.github.com/repos/walkor/webman-framework/zipball/faf13663be7cad1608217a0ec2e3cb8913f866dc",
"reference": "0f4d5b6c58823656bdc9603f762d4be6e41ae380", "reference": "faf13663be7cad1608217a0ec2e3cb8913f866dc",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -4013,7 +4014,7 @@ ...@@ -4013,7 +4014,7 @@
"suggest": { "suggest": {
"ext-event": "For better performance. " "ext-event": "For better performance. "
}, },
"time": "2022-08-15T12:35:14+00:00", "time": "2022-10-20T06:42:33+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
...@@ -4034,33 +4035,23 @@ ...@@ -4034,33 +4035,23 @@
{ {
"name": "walkor", "name": "walkor",
"email": "walkor@workerman.net", "email": "walkor@workerman.net",
"homepage": "http://www.workerman.net", "homepage": "https://www.workerman.net",
"role": "Developer" "role": "Developer"
} }
], ],
"description": "High performance HTTP Service Framework.", "description": "High performance HTTP Service Framework.",
"homepage": "http://www.workerman.net", "homepage": "https://www.workerman.net",
"keywords": [ "keywords": [
"High Performance", "High Performance",
"http service" "http service"
], ],
"support": { "support": {
"email": "walkor@workerman.net", "email": "walkor@workerman.net",
"forum": "http://wenda.workerman.net/", "forum": "https://wenda.workerman.net/",
"issues": "https://github.com/walkor/webman/issues", "issues": "https://github.com/walkor/webman/issues",
"source": "https://github.com/walkor/webman-framework", "source": "https://github.com/walkor/webman-framework",
"wiki": "http://doc.workerman.net/" "wiki": "https://doc.workerman.net/"
}, },
"funding": [
{
"url": "https://opencollective.com/walkor",
"type": "open_collective"
},
{
"url": "https://www.patreon.com/walkor",
"type": "patreon"
}
],
"install-path": "../workerman/webman-framework" "install-path": "../workerman/webman-framework"
}, },
{ {
......
<?php return array( <?php return array(
'root' => array( 'root' => array(
'name' => 'workerman/webman', 'name' => 'workerman/webman',
'pretty_version' => '1.0.0+no-version-set', 'pretty_version' => 'dev-main',
'version' => '1.0.0.0', 'version' => 'dev-main',
'reference' => NULL, 'reference' => 'ced1e593895e2164fa4d567e8d4685f231f65ae0',
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
...@@ -534,9 +534,9 @@ ...@@ -534,9 +534,9 @@
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'webman/console' => array( 'webman/console' => array(
'pretty_version' => 'v1.0.27', 'pretty_version' => 'v1.2.16',
'version' => '1.0.27.0', 'version' => '1.2.16.0',
'reference' => 'e450967eaabc43eb0c93cfcd6d8f420c16e22b67', 'reference' => '252868f948fe397e386577fa6ce0e7487ffc98ba',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../webman/console', 'install_path' => __DIR__ . '/../webman/console',
'aliases' => array(), 'aliases' => array(),
...@@ -570,18 +570,18 @@ ...@@ -570,18 +570,18 @@
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'workerman/webman' => array( 'workerman/webman' => array(
'pretty_version' => '1.0.0+no-version-set', 'pretty_version' => 'dev-main',
'version' => '1.0.0.0', 'version' => 'dev-main',
'reference' => NULL, 'reference' => 'ced1e593895e2164fa4d567e8d4685f231f65ae0',
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'workerman/webman-framework' => array( 'workerman/webman-framework' => array(
'pretty_version' => 'v1.4.3', 'pretty_version' => 'v1.4.9',
'version' => '1.4.3.0', 'version' => '1.4.9.0',
'reference' => '0f4d5b6c58823656bdc9603f762d4be6e41ae380', 'reference' => 'faf13663be7cad1608217a0ec2e3cb8913f866dc',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../workerman/webman-framework', 'install_path' => __DIR__ . '/../workerman/webman-framework',
'aliases' => array(), 'aliases' => array(),
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
"source": "https://github.com/webman-php/console" "source": "https://github.com/webman-php/console"
}, },
"require": { "require": {
"symfony/console": ">=5.0" "symfony/console": ">=5.0",
"doctrine/inflector": "^2.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
......
...@@ -17,11 +17,20 @@ class Command extends Application ...@@ -17,11 +17,20 @@ class Command extends Application
$dir_iterator = new \RecursiveDirectoryIterator($path); $dir_iterator = new \RecursiveDirectoryIterator($path);
$iterator = new \RecursiveIteratorIterator($dir_iterator); $iterator = new \RecursiveIteratorIterator($dir_iterator);
foreach ($iterator as $file) { foreach ($iterator as $file) {
if (is_dir($file)) { /** @var \SplFileInfo $file */
if (strpos($file->getFilename(), '.') === 0) {
continue; continue;
} }
$class_name = $namspace.'\\'.basename($file, '.php'); if ($file->getExtension() !== 'php') {
if (!is_a($class_name, Commands::class, true)) { continue;
}
// abc\def.php
$relativePath = str_replace(str_replace('/', '\\', $path . '\\'), '', str_replace('/', '\\', $file->getRealPath()));
// app\command\abc
$realNamespace = trim($namspace . '\\' . trim(dirname(str_replace('\\', DIRECTORY_SEPARATOR, $relativePath)), '.'), '\\');
// app\command\doc\def
$class_name = trim($realNamespace . '\\' . $file->getBasename('.php'), '\\');
if (!class_exists($class_name) || !is_a($class_name, Commands::class, true)) {
continue; continue;
} }
$this->add(new $class_name); $this->add(new $class_name);
......
This diff is collapsed.
...@@ -29,7 +29,7 @@ class MakeCommandCommand extends Command ...@@ -29,7 +29,7 @@ class MakeCommandCommand extends Command
*/ */
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$command = $name = $input->getArgument('name'); $command = $name = trim($input->getArgument('name'));
$output->writeln("Make command $name"); $output->writeln("Make command $name");
// make:command 不支持子目录 // make:command 不支持子目录
...@@ -37,12 +37,14 @@ class MakeCommandCommand extends Command ...@@ -37,12 +37,14 @@ class MakeCommandCommand extends Command
if (!$command_str = Util::guessPath(app_path(), 'command')) { if (!$command_str = Util::guessPath(app_path(), 'command')) {
$command_str = Util::guessPath(app_path(), 'controller') === 'Controller' ? 'Command' : 'command'; $command_str = Util::guessPath(app_path(), 'controller') === 'Controller' ? 'Command' : 'command';
} }
$upper = $command_str === 'Command'; $items= explode(':', $name);
$name = ucfirst($name); $name='';
foreach ($items as $item) {
$name.=ucfirst($item);
}
$file = app_path() . "/$command_str/$name.php"; $file = app_path() . "/$command_str/$name.php";
$upper = $command_str === 'Command';
$namespace = $upper ? 'App\Command' : 'app\command'; $namespace = $upper ? 'App\Command' : 'app\command';
$this->createCommand($name, $namespace, $file, $command); $this->createCommand($name, $namespace, $file, $command);
return self::SUCCESS; return self::SUCCESS;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Webman\Console\Commands; namespace Webman\Console\Commands;
use Doctrine\Inflector\InflectorFactory;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
...@@ -21,6 +22,7 @@ class MakeModelCommand extends Command ...@@ -21,6 +22,7 @@ class MakeModelCommand extends Command
protected function configure() protected function configure()
{ {
$this->addArgument('name', InputArgument::REQUIRED, 'Model name'); $this->addArgument('name', InputArgument::REQUIRED, 'Model name');
$this->addArgument('type', InputArgument::OPTIONAL, 'Type');
} }
/** /**
...@@ -32,6 +34,7 @@ class MakeModelCommand extends Command ...@@ -32,6 +34,7 @@ class MakeModelCommand extends Command
{ {
$name = $input->getArgument('name'); $name = $input->getArgument('name');
$name = Util::nameToClass($name); $name = Util::nameToClass($name);
$type = $input->getArgument('type');
$output->writeln("Make model $name"); $output->writeln("Make model $name");
if (!($pos = strrpos($name, '/'))) { if (!($pos = strrpos($name, '/'))) {
$name = ucfirst($name); $name = ucfirst($name);
...@@ -58,7 +61,18 @@ class MakeModelCommand extends Command ...@@ -58,7 +61,18 @@ class MakeModelCommand extends Command
$file = app_path() . "/$path/$name.php"; $file = app_path() . "/$path/$name.php";
$namespace = str_replace('/', '\\', ($upper ? 'App/' : 'app/') . $path); $namespace = str_replace('/', '\\', ($upper ? 'App/' : 'app/') . $path);
} }
if (!config('database') && config('thinkorm')) { if (!$type) {
$database = config('database');
if (isset($database['default']) && strpos($database['default'], 'plugin.') === 0) {
$database = false;
}
$thinkorm = config('thinkorm');
if (isset($thinkorm['default']) && strpos($thinkorm['default'], 'plugin.') === 0) {
$thinkorm = false;
}
$type = !$database && $thinkorm ? 'tp' : 'laravel';
}
if ($type == 'tp') {
$this->createTpModel($name, $namespace, $file); $this->createTpModel($name, $namespace, $file);
} else { } else {
$this->createModel($name, $namespace, $file); $this->createModel($name, $namespace, $file);
...@@ -86,8 +100,10 @@ class MakeModelCommand extends Command ...@@ -86,8 +100,10 @@ class MakeModelCommand extends Command
try { try {
$prefix = config('database.connections.mysql.prefix') ?? ''; $prefix = config('database.connections.mysql.prefix') ?? '';
$database = config('database.connections.mysql.database'); $database = config('database.connections.mysql.database');
if (\support\Db::select("show tables like '{$prefix}{$table}s'")) { $inflector = InflectorFactory::create()->build();
$table = "{$prefix}{$table}s"; $table_plura = $inflector->pluralize($inflector->tableize($class));
if (\support\Db::select("show tables like '{$prefix}{$table_plura}'")) {
$table = "{$prefix}{$table_plura}";
} else if (\support\Db::select("show tables like '{$prefix}{$table}'")) { } else if (\support\Db::select("show tables like '{$prefix}{$table}'")) {
$table_val = "'$table'"; $table_val = "'$table'";
$table = "{$prefix}{$table}"; $table = "{$prefix}{$table}";
......
...@@ -20,13 +20,13 @@ class RouteListCommand extends Command ...@@ -20,13 +20,13 @@ class RouteListCommand extends Command
*/ */
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$headers = ['uri', 'method', 'callback', 'middleware']; $headers = ['uri', 'method', 'callback', 'middleware', 'name'];
$rows = []; $rows = [];
foreach (Route::getRoutes() as $route) { foreach (Route::getRoutes() as $route) {
foreach ($route->getMethods() as $method) { foreach ($route->getMethods() as $method) {
$cb = $route->getCallback(); $cb = $route->getCallback();
$cb = $cb instanceof \Closure ? 'Closure' : (is_array($cb) ? json_encode($cb) : var_export($cb, 1)); $cb = $cb instanceof \Closure ? 'Closure' : (is_array($cb) ? json_encode($cb) : var_export($cb, 1));
$rows[] = [$route->getPath(), $method, $cb, json_encode($route->getMiddleware() ?: null)]; $rows[] = [$route->getPath(), $method, $cb, json_encode($route->getMiddleware() ?: null), $route->getName()];
} }
} }
......
<?php <?php
namespace Webman\Console; namespace Webman\Console;
use Doctrine\Inflector\InflectorFactory;
class Util class Util
{ {
public static function nameToNamespace($name) public static function nameToNamespace($name)
......
# These are supported funding model platforms
open_collective: walkor
patreon: walkor
...@@ -5,22 +5,22 @@ ...@@ -5,22 +5,22 @@
"high performance", "high performance",
"http service" "http service"
], ],
"homepage": "http://www.workerman.net", "homepage": "https://www.workerman.net",
"license": "MIT", "license": "MIT",
"description": "High performance HTTP Service Framework.", "description": "High performance HTTP Service Framework.",
"authors": [ "authors": [
{ {
"name": "walkor", "name": "walkor",
"email": "walkor@workerman.net", "email": "walkor@workerman.net",
"homepage": "http://www.workerman.net", "homepage": "https://www.workerman.net",
"role": "Developer" "role": "Developer"
} }
], ],
"support": { "support": {
"email": "walkor@workerman.net", "email": "walkor@workerman.net",
"issues": "https://github.com/walkor/webman/issues", "issues": "https://github.com/walkor/webman/issues",
"forum": "http://wenda.workerman.net/", "forum": "https://wenda.workerman.net/",
"wiki": "http://doc.workerman.net/", "wiki": "https://doc.workerman.net/",
"source": "https://github.com/walkor/webman-framework" "source": "https://github.com/walkor/webman-framework"
}, },
"require": { "require": {
......
...@@ -73,6 +73,14 @@ class Config ...@@ -73,6 +73,14 @@ class Config
static::load($config_path, $exclude_file); static::load($config_path, $exclude_file);
} }
/**
* @return void
*/
public static function clear()
{
static::$_config = [];
}
/** /**
* @return void * @return void
*/ */
...@@ -202,18 +210,18 @@ class Config ...@@ -202,18 +210,18 @@ class Config
} }
$key_array = \explode('.', $key); $key_array = \explode('.', $key);
$value = static::$_config; $value = static::$_config;
$finded = true; $found = true;
foreach ($key_array as $index) { foreach ($key_array as $index) {
if (!isset($value[$index])) { if (!isset($value[$index])) {
if (static::$_loaded) { if (static::$_loaded) {
return $default; return $default;
} }
$finded = false; $found = false;
break; break;
} }
$value = $value[$index]; $value = $value[$index];
} }
if ($finded) { if ($found) {
return $value; return $value;
} }
return static::read($key, $default); return static::read($key, $default);
......
...@@ -16,6 +16,10 @@ class Container implements ContainerInterface ...@@ -16,6 +16,10 @@ class Container implements ContainerInterface
* @var array * @var array
*/ */
protected $_instances = []; protected $_instances = [];
/**
* @var array
*/
protected $_definitions = [];
/** /**
* @param string $name * @param string $name
...@@ -25,10 +29,14 @@ class Container implements ContainerInterface ...@@ -25,10 +29,14 @@ class Container implements ContainerInterface
public function get(string $name) public function get(string $name)
{ {
if (!isset($this->_instances[$name])) { if (!isset($this->_instances[$name])) {
if (!\class_exists($name)) { if (isset($this->_definitions[$name])) {
throw new NotFoundException("Class '$name' not found"); $this->_instances[$name] = call_user_func($this->_definitions[$name], $this);
} else {
if (!\class_exists($name)) {
throw new NotFoundException("Class '$name' not found");
}
$this->_instances[$name] = new $name();
} }
$this->_instances[$name] = new $name();
} }
return $this->_instances[$name]; return $this->_instances[$name];
} }
...@@ -39,7 +47,8 @@ class Container implements ContainerInterface ...@@ -39,7 +47,8 @@ class Container implements ContainerInterface
*/ */
public function has(string $name): bool public function has(string $name): bool
{ {
return \array_key_exists($name, $this->_instances); return \array_key_exists($name, $this->_instances)
|| array_key_exists($name, $this->_definitions);
} }
/** /**
...@@ -56,4 +65,14 @@ class Container implements ContainerInterface ...@@ -56,4 +65,14 @@ class Container implements ContainerInterface
return new $name(... array_values($constructor)); return new $name(... array_values($constructor));
} }
/**
* @param array $definitions
* @return $this
*/
public function addDefinitions(array $definitions)
{
$this->_definitions = array_merge($this->_definitions, $definitions);
return $this;
}
} }
...@@ -21,7 +21,7 @@ use Webman\Http\Response; ...@@ -21,7 +21,7 @@ use Webman\Http\Response;
/** /**
* Class Handler * Class Handler
* @package Support\Exception * @package support\exception
*/ */
class ExceptionHandler implements ExceptionHandlerInterface class ExceptionHandler implements ExceptionHandlerInterface
{ {
......
...@@ -197,8 +197,8 @@ class Request extends \Workerman\Protocols\Http\Request ...@@ -197,8 +197,8 @@ class Request extends \Workerman\Protocols\Http\Request
if ($safe_mode && !static::isIntranetIp($remote_ip)) { if ($safe_mode && !static::isIntranetIp($remote_ip)) {
return $remote_ip; return $remote_ip;
} }
return $this->header('client-ip', $this->header('x-forwarded-for', return $this->header('x-real-ip', $this->header('x-forwarded-for',
$this->header('x-real-ip', $this->header('x-client-ip', $this->header('client-ip', $this->header('x-client-ip',
$this->header('via', $remote_ip))))); $this->header('via', $remote_ip)))));
} }
......
...@@ -64,7 +64,7 @@ class UploadFile extends File ...@@ -64,7 +64,7 @@ class UploadFile extends File
/** /**
* @return string * @return string
*/ */
public function getUploadMineType() public function getUploadMimeType()
{ {
return $this->_uploadMimeType; return $this->_uploadMimeType;
} }
...@@ -93,4 +93,12 @@ class UploadFile extends File ...@@ -93,4 +93,12 @@ class UploadFile extends File
return $this->_uploadErrorCode === UPLOAD_ERR_OK; return $this->_uploadErrorCode === UPLOAD_ERR_OK;
} }
} /**
\ No newline at end of file * @deprecated
* @return string
*/
public function getUploadMineType()
{
return $this->_uploadMimeType;
}
}
...@@ -47,8 +47,12 @@ class Install ...@@ -47,8 +47,12 @@ class Install
mkdir($parent_dir, 0777, true); mkdir($parent_dir, 0777, true);
} }
} }
copy_dir(__DIR__ . "/$source", base_path() . "/$dest", true); $source_file = __DIR__ . "/$source";
copy_dir($source_file, base_path() . "/$dest", true);
echo "Create $dest\r\n"; echo "Create $dest\r\n";
if (is_file($source_file)) {
@unlink($source_file);
}
} }
} }
......
...@@ -358,7 +358,7 @@ class Route ...@@ -358,7 +358,7 @@ class Route
require_once $route_config_file; require_once $route_config_file;
} }
if (!is_dir($plugin_config_path = $config_path . '/plugin')) { if (!is_dir($plugin_config_path = $config_path . '/plugin')) {
return; continue;
} }
$dir_iterator = new \RecursiveDirectoryIterator($plugin_config_path, \FilesystemIterator::FOLLOW_SYMLINKS); $dir_iterator = new \RecursiveDirectoryIterator($plugin_config_path, \FilesystemIterator::FOLLOW_SYMLINKS);
$iterator = new \RecursiveIteratorIterator($dir_iterator); $iterator = new \RecursiveIteratorIterator($dir_iterator);
......
...@@ -96,7 +96,7 @@ class Route ...@@ -96,7 +96,7 @@ class Route
if ($middleware === null) { if ($middleware === null) {
return $this->_middlewares; return $this->_middlewares;
} }
$this->_middlewares = \array_merge($this->_middlewares, (array)$middleware); $this->_middlewares = \array_merge($this->_middlewares, is_array($middleware) ? $middleware : [$middleware]);
return $this; return $this;
} }
......
#!/usr/bin/env php
<?php
require_once __DIR__ . '/vendor/autoload.php';
Support\App::run();
...@@ -19,11 +19,11 @@ class App ...@@ -19,11 +19,11 @@ class App
ini_set('display_errors', 'on'); ini_set('display_errors', 'on');
error_reporting(E_ALL); error_reporting(E_ALL);
if (class_exists(Dotenv::class) && file_exists(base_path() . '/.env')) { if (class_exists(Dotenv::class) && file_exists(run_path('.env'))) {
if (method_exists(Dotenv::class, 'createUnsafeImmutable')) { if (method_exists(Dotenv::class, 'createUnsafeImmutable')) {
Dotenv::createUnsafeImmutable(base_path())->load(); Dotenv::createUnsafeImmutable(run_path())->load();
} else { } else {
Dotenv::createMutable(base_path())->load(); Dotenv::createMutable(run_path())->load();
} }
} }
...@@ -97,7 +97,7 @@ class App ...@@ -97,7 +97,7 @@ class App
require_once \base_path() . '/support/bootstrap.php'; require_once \base_path() . '/support/bootstrap.php';
$app = new \Webman\App(config('app.request_class', Request::class), Log::channel('default'), app_path(), public_path()); $app = new \Webman\App(config('app.request_class', Request::class), Log::channel('default'), app_path(), public_path());
$worker->onMessage = [$app, 'onMessage']; $worker->onMessage = [$app, 'onMessage'];
[$app, 'onWorkerStart']($worker); \call_user_func([$app, 'onWorkerStart'], $worker);
}; };
} }
......
...@@ -7,7 +7,7 @@ use Symfony\Component\Cache\Psr16Cache; ...@@ -7,7 +7,7 @@ use Symfony\Component\Cache\Psr16Cache;
/** /**
* Class Cache * Class Cache
* @package Support\Bootstrap * @package support\bootstrap
* *
* Strings methods * Strings methods
* @method static mixed get($key, $default = null) * @method static mixed get($key, $default = null)
......
...@@ -19,7 +19,7 @@ use Webman\Config; ...@@ -19,7 +19,7 @@ use Webman\Config;
/** /**
* Class Container * Class Container
* @package Support * @package support
* @method static mixed get($name) * @method static mixed get($name)
* @method static mixed make($name, array $parameters) * @method static mixed make($name, array $parameters)
* @method static bool has($name) * @method static bool has($name)
......
...@@ -18,7 +18,7 @@ use Illuminate\Database\Capsule\Manager; ...@@ -18,7 +18,7 @@ use Illuminate\Database\Capsule\Manager;
/** /**
* Class Db * Class Db
* @package Support * @package support
* @method static array select(string $query, $bindings = [], $useReadPdo = true) * @method static array select(string $query, $bindings = [], $useReadPdo = true)
* @method static int insert(string $query, $bindings = []) * @method static int insert(string $query, $bindings = [])
* @method static int update(string $query, $bindings = []) * @method static int update(string $query, $bindings = [])
......
...@@ -21,7 +21,7 @@ use Monolog\Logger; ...@@ -21,7 +21,7 @@ use Monolog\Logger;
/** /**
* Class Log * Class Log
* @package Support * @package support
* *
* @method static void log($level, $message, array $context = []) * @method static void log($level, $message, array $context = [])
* @method static void debug($message, array $context = []) * @method static void debug($message, array $context = [])
......
...@@ -23,7 +23,7 @@ use Workerman\Worker; ...@@ -23,7 +23,7 @@ use Workerman\Worker;
/** /**
* Class Redis * Class Redis
* @package Support * @package support
* *
* Strings methods * Strings methods
* @method static int append($key, $value) * @method static int append($key, $value)
......
...@@ -16,7 +16,7 @@ namespace support; ...@@ -16,7 +16,7 @@ namespace support;
/** /**
* Class Request * Class Request
* @package Support * @package support
*/ */
class Request extends \Webman\Http\Request class Request extends \Webman\Http\Request
{ {
......
...@@ -16,7 +16,7 @@ namespace support; ...@@ -16,7 +16,7 @@ namespace support;
/** /**
* Class Response * Class Response
* @package Support * @package support
*/ */
class Response extends \Webman\Http\Response class Response extends \Webman\Http\Response
{ {
......
...@@ -19,7 +19,7 @@ use Webman\Exception\NotFoundException; ...@@ -19,7 +19,7 @@ use Webman\Exception\NotFoundException;
/** /**
* Class Translation * Class Translation
* @package Support * @package support
* @method static string trans(?string $id, array $parameters = [], string $domain = null, string $locale = null) * @method static string trans(?string $id, array $parameters = [], string $domain = null, string $locale = null)
* @method static void setLocale(string $locale) * @method static void setLocale(string $locale)
* @method static string getLocale() * @method static string getLocale()
......
<?php
/**
* This file is part of webman.
*
* Licensed under The MIT License
* For full copyright and license information, please see the MIT-LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @author walkor<walkor@workerman.net>
* @copyright walkor<walkor@workerman.net>
* @link http://www.workerman.net/
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Dotenv\Dotenv;
use support\Log;
use Webman\Bootstrap;
use Webman\Config;
use Webman\Route;
use Webman\Middleware;
use Webman\Util;
$worker = $worker ?? null;
if ($timezone = config('app.default_timezone')) {
date_default_timezone_set($timezone);
}
set_error_handler(function ($level, $message, $file = '', $line = 0) {
if (error_reporting() & $level) {
throw new ErrorException($message, 0, $level, $file, $line);
}
});
if ($worker) {
register_shutdown_function(function ($start_time) {
if (time() - $start_time <= 1) {
sleep(1);
}
}, time());
}
if (class_exists('Dotenv\Dotenv') && file_exists(base_path() . '/.env')) {
if (method_exists('Dotenv\Dotenv', 'createUnsafeImmutable')) {
Dotenv::createUnsafeImmutable(base_path())->load();
} else {
Dotenv::createMutable(base_path())->load();
}
}
Support\App::loadAllConfig(['route']);
foreach (config('autoload.files', []) as $file) {
include_once $file;
}
foreach (config('plugin', []) as $firm => $projects) {
foreach ($projects as $name => $project) {
if (!is_array($project)) {
continue;
}
foreach ($project['autoload']['files'] ?? [] as $file) {
include_once $file;
}
}
foreach ($projects['autoload']['files'] ?? [] as $file) {
include_once $file;
}
}
Middleware::load(config('middleware', []), '');
foreach (config('plugin', []) as $firm => $projects) {
foreach ($projects as $name => $project) {
if (!is_array($project) || $name === 'static') {
continue;
}
Middleware::load($project['middleware'] ?? [], '');
}
Middleware::load($projects['middleware'] ?? [], $firm);
if ($static_middlewares = config("plugin.$firm.static.middleware")) {
Middleware::load(['__static__' => $static_middlewares], $firm);
}
}
Middleware::load(['__static__' => config('static.middleware', [])], '');
foreach (config('bootstrap', []) as $class_name) {
if (!class_exists($class_name)) {
$log = "Warning: Class $class_name setting in config/bootstrap.php not found\r\n";
echo $log;
Log::error($log);
continue;
}
/** @var Bootstrap $class_name */
$class_name::start($worker);
}
foreach (config('plugin', []) as $firm => $projects) {
foreach ($projects as $name => $project) {
if (!is_array($project)) {
continue;
}
foreach ($project['bootstrap'] ?? [] as $class_name) {
if (!class_exists($class_name)) {
$log = "Warning: Class $class_name setting in config/plugin/$firm/$name/bootstrap.php not found\r\n";
echo $log;
Log::error($log);
continue;
}
/** @var Bootstrap $class_name */
$class_name::start($worker);
}
}
foreach ($projects['bootstrap'] ?? [] as $class_name) {
if (!class_exists($class_name)) {
$log = "Warning: Class $class_name setting in plugin/$firm/config/bootstrap.php not found\r\n";
echo $log;
Log::error($log);
continue;
}
/** @var Bootstrap $class_name */
$class_name::start($worker);
}
}
$directory = base_path() . '/plugin';
$paths = [config_path()];
foreach (Util::scanDir($directory) as $path) {
if (is_dir($path = "$path/config")) {
$paths[] = $path;
}
}
Route::load($paths);
...@@ -76,20 +76,13 @@ class LaravelDb implements Bootstrap ...@@ -76,20 +76,13 @@ class LaravelDb implements Bootstrap
// Heartbeat // Heartbeat
if ($worker) { if ($worker) {
Timer::add(55, function () use ($default, $connections) { Timer::add(55, function () use ($default, $connections, $capsule) {
if (!class_exists(Connection::class, false)) { foreach ($capsule->getDatabaseManager()->getConnections() as $connection) {
return; /* @var \Illuminate\Database\MySqlConnection $connection **/
} if ($connection->getConfig('driver') == 'mysql') {
foreach ($connections as $key => $item) {
if ($item['driver'] == 'mysql') {
try { try {
if ($key == $default) { $connection->select('select 1');
Db::select('select 1'); } catch (Throwable $e) {}
} else {
Db::connection($key)->select('select 1');
}
} catch (Throwable $e) {
}
} }
} }
}); });
...@@ -97,14 +90,22 @@ class LaravelDb implements Bootstrap ...@@ -97,14 +90,22 @@ class LaravelDb implements Bootstrap
// Paginator // Paginator
if (class_exists(Paginator::class)) { if (class_exists(Paginator::class)) {
Paginator::queryStringResolver(function () { if (method_exists(Paginator::class, 'queryStringResolver')) {
return request()->queryString(); Paginator::queryStringResolver(function () {
}); $request = request();
return $request ? $request->queryString() : null;
});
}
Paginator::currentPathResolver(function () { Paginator::currentPathResolver(function () {
return request()->path(); $request = request();
return $request ? $request->path(): '/';
}); });
Paginator::currentPageResolver(function ($page_name = 'page') { Paginator::currentPageResolver(function ($page_name = 'page') {
$page = (int)request()->input($page_name, 1); $request = request();
if (!$request) {
return 1;
}
$page = (int)($request->input($page_name, 1));
return $page > 0 ? $page : 1; return $page > 0 ? $page : 1;
}); });
} }
......
...@@ -21,7 +21,7 @@ use Workerman\Worker; ...@@ -21,7 +21,7 @@ use Workerman\Worker;
/** /**
* Class Session * Class Session
* @package Support * @package support
*/ */
class Session implements Bootstrap class Session implements Bootstrap
{ {
......
...@@ -15,12 +15,23 @@ ...@@ -15,12 +15,23 @@
namespace support\exception; namespace support\exception;
use Exception; use Exception;
use Webman\Http\Response;
use Webman\Http\Request;
/** /**
* Class BusinessException * Class BusinessException
* @package Support\Exception * @package support\exception
*/ */
class BusinessException extends Exception class BusinessException extends Exception
{ {
public function render(Request $request): ?Response
} {
\ No newline at end of file if ($request->expectsJson()) {
$code = $this->getCode();
$json = ['code' => $code ? $code : 500, 'msg' => $this->getMessage()];
return new Response(200, ['Content-Type' => 'application/json'],
\json_encode($json, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}
return new Response(200, [], $this->getMessage());
}
}
...@@ -21,7 +21,7 @@ use Webman\Http\Response; ...@@ -21,7 +21,7 @@ use Webman\Http\Response;
/** /**
* Class Handler * Class Handler
* @package Support\Exception * @package support\exception
*/ */
class Handler extends ExceptionHandler class Handler extends ExceptionHandler
{ {
...@@ -36,6 +36,11 @@ class Handler extends ExceptionHandler ...@@ -36,6 +36,11 @@ class Handler extends ExceptionHandler
public function render(Request $request, Throwable $exception): Response public function render(Request $request, Throwable $exception): Response
{ {
if(($exception instanceof BusinessException) && ($response = $exception->render($request)))
{
return $response;
}
return parent::render($request, $exception); return parent::render($request, $exception);
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
namespace support\View; namespace support\view;
use Jenssegers\Blade\Blade as BladeView; use Jenssegers\Blade\Blade as BladeView;
use Webman\View; use Webman\View;
...@@ -20,7 +20,7 @@ use Webman\View; ...@@ -20,7 +20,7 @@ use Webman\View;
/** /**
* Class Blade * Class Blade
* composer require jenssegers/blade * composer require jenssegers/blade
* @package Support\View * @package support\view
*/ */
class Blade implements View class Blade implements View
{ {
...@@ -50,13 +50,19 @@ class Blade implements View ...@@ -50,13 +50,19 @@ class Blade implements View
$request = \request(); $request = \request();
$plugin = $request->plugin ?? ''; $plugin = $request->plugin ?? '';
$app = $app === null ? $request->app : $app; $app = $app === null ? $request->app : $app;
$config_prefix = $plugin ? "plugin.$plugin." : '';
$base_view_path = $plugin ? \base_path() . "/plugin/$plugin/app" : \app_path(); $base_view_path = $plugin ? \base_path() . "/plugin/$plugin/app" : \app_path();
if (!isset($views[$app])) { $key = "{$plugin}-{$request->app}";
if (!isset($views[$key])) {
$view_path = $app === '' ? "$base_view_path/view" : "$base_view_path/$app/view"; $view_path = $app === '' ? "$base_view_path/view" : "$base_view_path/$app/view";
$views[$app] = new BladeView($view_path, \runtime_path() . '/views'); $views[$key] = new BladeView($view_path, \runtime_path() . '/views');
$extension = \config("{$config_prefix}view.extension");
if ($extension) {
$extension($views[$key]);
}
} }
$vars = \array_merge(static::$_vars, $vars); $vars = \array_merge(static::$_vars, $vars);
$content = $views[$app]->render($template, $vars); $content = $views[$key]->render($template, $vars);
static::$_vars = []; static::$_vars = [];
return $content; return $content;
} }
......
...@@ -12,14 +12,14 @@ ...@@ -12,14 +12,14 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
namespace support\View; namespace support\view;
use Webman\View; use Webman\View;
use Throwable; use Throwable;
/** /**
* Class Raw * Class Raw
* @package Support\View * @package support\view
*/ */
class Raw implements View class Raw implements View
{ {
...@@ -51,14 +51,14 @@ class Raw implements View ...@@ -51,14 +51,14 @@ class Raw implements View
$view_suffix = \config("{$config_prefix}view.options.view_suffix", 'html'); $view_suffix = \config("{$config_prefix}view.options.view_suffix", 'html');
$app = $app === null ? $request->app : $app; $app = $app === null ? $request->app : $app;
$base_view_path = $plugin ? \base_path() . "/plugin/$plugin/app" : \app_path(); $base_view_path = $plugin ? \base_path() . "/plugin/$plugin/app" : \app_path();
$view_path = $app === '' ? "$base_view_path/view/$template.$view_suffix" : "$base_view_path/$app/view/$template.$view_suffix"; $__template_path__ = $app === '' ? "$base_view_path/view/$template.$view_suffix" : "$base_view_path/$app/view/$template.$view_suffix";
\extract(static::$_vars, \EXTR_SKIP); \extract(static::$_vars);
\extract($vars, \EXTR_SKIP); \extract($vars);
\ob_start(); \ob_start();
// Try to include php file. // Try to include php file.
try { try {
include $view_path; include $__template_path__;
} catch (Throwable $e) { } catch (Throwable $e) {
static::$_vars = []; static::$_vars = [];
\ob_end_clean(); \ob_end_clean();
......
...@@ -12,14 +12,14 @@ ...@@ -12,14 +12,14 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
namespace support\View; namespace support\view;
use think\Template; use think\Template;
use Webman\View; use Webman\View;
/** /**
* Class Blade * Class Blade
* @package Support\View * @package support\view
*/ */
class ThinkPHP implements View class ThinkPHP implements View
{ {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License * @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
namespace support\View; namespace support\view;
use Twig\Environment; use Twig\Environment;
use Twig\Loader\FilesystemLoader; use Twig\Loader\FilesystemLoader;
...@@ -20,7 +20,7 @@ use Webman\View; ...@@ -20,7 +20,7 @@ use Webman\View;
/** /**
* Class Blade * Class Blade
* @package Support\View * @package support\view
*/ */
class Twig implements View class Twig implements View
{ {
...@@ -57,6 +57,10 @@ class Twig implements View ...@@ -57,6 +57,10 @@ class Twig implements View
$base_view_path = $plugin ? \base_path() . "/plugin/$plugin/app" : \app_path(); $base_view_path = $plugin ? \base_path() . "/plugin/$plugin/app" : \app_path();
$view_path = $app === '' ? "$base_view_path/view/" : "$base_view_path/$app/view/"; $view_path = $app === '' ? "$base_view_path/view/" : "$base_view_path/$app/view/";
$views[$key] = new Environment(new FilesystemLoader($view_path), \config("{$config_prefix}view.options", [])); $views[$key] = new Environment(new FilesystemLoader($view_path), \config("{$config_prefix}view.options", []));
$extension = \config("{$config_prefix}view.extension");
if ($extension) {
$extension($views[$key]);
}
} }
$vars = \array_merge(static::$_vars, $vars); $vars = \array_merge(static::$_vars, $vars);
$content = $views[$key]->render("$template.$view_suffix", $vars); $content = $views[$key]->render("$template.$view_suffix", $vars);
......
<?php
/**
* Start file for windows
*/
require_once __DIR__ . '/vendor/autoload.php';
use process\Monitor;
use support\App;
use Dotenv\Dotenv;
use Workerman\Worker;
ini_set('display_errors', 'on');
error_reporting(E_ALL);
if (class_exists('Dotenv\Dotenv') && file_exists(base_path() . '/.env')) {
if (method_exists('Dotenv\Dotenv', 'createUnsafeImmutable')) {
Dotenv::createUnsafeImmutable(base_path())->load();
} else {
Dotenv::createMutable(base_path())->load();
}
}
App::loadAllConfig(['route']);
$error_reporting = config('app.error_reporting');
if (isset($error_reporting)) {
error_reporting($error_reporting);
}
$runtime_process_path = runtime_path() . DIRECTORY_SEPARATOR . '/windows';
if (!is_dir($runtime_process_path)) {
mkdir($runtime_process_path);
}
$process_files = [
__DIR__ . DIRECTORY_SEPARATOR . 'start.php'
];
foreach (config('process', []) as $process_name => $config) {
$process_files[] = write_process_file($runtime_process_path, $process_name, '');
}
foreach (config('plugin', []) as $firm => $projects) {
foreach ($projects as $name => $project) {
if (!is_array($project)) {
continue;
}
foreach ($project['process'] ?? [] as $process_name => $config) {
$process_files[] = write_process_file($runtime_process_path, $process_name, "$firm.$name");
}
}
foreach ($projects['process'] ?? [] as $process_name => $config) {
$process_files[] = write_process_file($runtime_process_path, $process_name, $firm);
}
}
function write_process_file($runtime_process_path, $process_name, $firm)
{
$process_param = $firm ? "plugin.$firm.$process_name" : $process_name;
$config_param = $firm ? "config('plugin.$firm.process')['$process_name']" : "config('process')['$process_name']";
$file_content = <<<EOF
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
use Workerman\Worker;
use Webman\Config;
use support\App;
ini_set('display_errors', 'on');
error_reporting(E_ALL);
if (is_callable('opcache_reset')) {
opcache_reset();
}
App::loadAllConfig(['route']);
worker_start('$process_param', $config_param);
if (DIRECTORY_SEPARATOR != "/") {
Worker::\$logFile = config('server')['log_file'] ?? Worker::\$logFile;
}
Worker::runAll();
EOF;
$process_file = $runtime_process_path . DIRECTORY_SEPARATOR . "start_$process_param.php";
file_put_contents($process_file, $file_content);
return $process_file;
}
if ($monitor_config = config('process.monitor.constructor')) {
$monitor = new Monitor(...array_values($monitor_config));
}
function popen_processes($process_files)
{
$cmd = "php " . implode(' ', $process_files);
$descriptorspec = [STDIN, STDOUT, STDOUT];
$resource = proc_open($cmd, $descriptorspec, $pipes);
if (!$resource) {
exit("Can not execute $cmd\r\n");
}
return $resource;
}
$resource = popen_processes($process_files);
echo "\r\n";
while (1) {
sleep(1);
if (!empty($monitor) && $monitor->checkAllFilesChange()) {
$status = proc_get_status($resource);
$pid = $status['pid'];
shell_exec("taskkill /F /T /PID $pid");
proc_close($resource);
$resource = popen_processes($process_files);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment