Skip to content

Commit

Permalink
更新:优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Aug 5, 2023
1 parent 9df56fc commit d077f1e
Show file tree
Hide file tree
Showing 82 changed files with 255 additions and 206 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Expand Up @@ -4,8 +4,7 @@ ARG timezone

ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
APP_ENV=prod \
SCAN_CACHEABLE=(false)

SCAN_CACHEABLE=(true)

RUN set -ex \
# show php version and extensions
Expand Down
2 changes: 1 addition & 1 deletion app/CodeFec/Admin/LogServer.php
Expand Up @@ -10,7 +10,7 @@
*/
namespace App\CodeFec\Admin;

use Hyperf\Utils\Str;
use Hyperf\Stringable\Str;
use SleekDB\Exceptions\IdNotAllowedException;
use SleekDB\Exceptions\InvalidArgumentException;
use SleekDB\Exceptions\InvalidConfigurationException;
Expand Down
8 changes: 4 additions & 4 deletions app/CodeFec/DockerInstall.php
Expand Up @@ -17,7 +17,7 @@
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;
use Hyperf\DbConnection\Db;
use Hyperf\Utils\Str;
use Hyperf\Stringable\Str;
use PDOException;
use Swoole\Coroutine\System;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -121,7 +121,7 @@ public function migrate()
$input = new ArrayInput($params);
$output = new NullOutput();

$container = \Hyperf\Utils\ApplicationContext::getContainer();
$container = \Hyperf\Context\ApplicationContext::getContainer();

/** @var Application $application */
$application = $container->get(\Hyperf\Contract\ApplicationInterface::class);
Expand Down Expand Up @@ -150,7 +150,7 @@ public function migrate()
$input = new ArrayInput($params);
$output = new NullOutput();

$container = \Hyperf\Utils\ApplicationContext::getContainer();
$container = \Hyperf\Context\ApplicationContext::getContainer();

/** @var Application $application */
$application = $container->get(\Hyperf\Contract\ApplicationInterface::class);
Expand Down Expand Up @@ -215,7 +215,7 @@ public function update_v2()
$input = new ArrayInput($params);
$output = new NullOutput();

$container = \Hyperf\Utils\ApplicationContext::getContainer();
$container = \Hyperf\Context\ApplicationContext::getContainer();

/** @var Application $application */
$application = $container->get(\Hyperf\Contract\ApplicationInterface::class);
Expand Down
2 changes: 1 addition & 1 deletion app/CodeFec/Header/functions.php
Expand Up @@ -14,7 +14,7 @@ class functions
{
public static function header(): HeaderInterface
{
$container = \Hyperf\Utils\ApplicationContext::getContainer();
$container = \Hyperf\Context\ApplicationContext::getContainer();
return $container->get(HeaderInterface::class);
}

Expand Down
8 changes: 4 additions & 4 deletions app/CodeFec/Install.php
Expand Up @@ -17,7 +17,7 @@
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;
use Hyperf\DbConnection\Db;
use Hyperf\Utils\Str;
use Hyperf\Stringable\Str;
use PDOException;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -187,7 +187,7 @@ public function step_3()
$input = new ArrayInput($params);
$output = new NullOutput();

$container = \Hyperf\Utils\ApplicationContext::getContainer();
$container = \Hyperf\Context\ApplicationContext::getContainer();

/** @var Application $application */
$application = $container->get(\Hyperf\Contract\ApplicationInterface::class);
Expand Down Expand Up @@ -216,7 +216,7 @@ public function step_3()
$input = new ArrayInput($params);
$output = new NullOutput();

$container = \Hyperf\Utils\ApplicationContext::getContainer();
$container = \Hyperf\Context\ApplicationContext::getContainer();

/** @var Application $application */
$application = $container->get(\Hyperf\Contract\ApplicationInterface::class);
Expand Down Expand Up @@ -296,7 +296,7 @@ public function step_4()
$input = new ArrayInput($params);
$output = new NullOutput();

$container = \Hyperf\Utils\ApplicationContext::getContainer();
$container = \Hyperf\Context\ApplicationContext::getContainer();

/** @var Application $application */
$application = $container->get(\Hyperf\Contract\ApplicationInterface::class);
Expand Down
54 changes: 30 additions & 24 deletions app/CodeFec/Ui/Generate/PayGenerate.php
@@ -1,90 +1,96 @@
<?php

declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/SForum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/SForum/blob/master/LICENSE
*/
namespace App\CodeFec\Ui\Generate;

use Hyperf\Utils\Str;
use Hyperf\Stringable\Str;

class PayGenerate
{

/**
* 根据不同状态,选择不同文字样式
* @param string $status
* 根据不同状态,选择不同文字样式.
* @return string
*/
public function status_class_text(string $status){
public function status_class_text(string $status)
{
$style = ['text-blue'];
// 待支付
if (Str::is('*待支付*','*'.$status.'*') || Str::is('*未支付*','*'.$status.'*') || Str::is('*未付款*','*'.$status.'*')){
if (Str::is('*待支付*', '*' . $status . '*') || Str::is('*未支付*', '*' . $status . '*') || Str::is('*未付款*', '*' . $status . '*')) {
$style = ['text-lime'];
}

// 支付成功
if (Str::is('*成功*','*'.$status.'*')){
if (Str::is('*成功*', '*' . $status . '*')) {
$style = ['text-azure'];
}

// 退款
if (Str::is('*退款*','*'.$status.'*')){
if (Str::is('*退款*', '*' . $status . '*')) {
$style = ['text-orange'];
}

// 交易取消
if (Str::is('*取消*','*'.$status.'*')){
if (Str::is('*取消*', '*' . $status . '*')) {
$style = ['text-purple'];
}

// 交易关闭
if (Str::is('*关闭*','*'.$status.'*')){
if (Str::is('*关闭*', '*' . $status . '*')) {
$style = ['text-yellow'];
}

// 支付失败
if (Str::is('*失败*','*'.$status.'*')){
if (Str::is('*失败*', '*' . $status . '*')) {
$style = ['text-red'];
}

return implode(' ',$style);
return implode(' ', $style);
}

/**
* 根据不同状态,选择不同颜色名
* @param string $status
* 根据不同状态,选择不同颜色名.
* @return string
*/
public function status_color_name(string $status){
public function status_color_name(string $status)
{
$style = ['blue'];
// 待支付
if (Str::is('待支付','*'.$status.'*') || Str::is('*未支付*','*'.$status.'*') || Str::is('*未付款*','*'.$status.'*')){
if (Str::is('待支付', '*' . $status . '*') || Str::is('*未支付*', '*' . $status . '*') || Str::is('*未付款*', '*' . $status . '*')) {
$style = ['lime'];
}

// 支付成功
if (Str::is('*成功*','*'.$status.'*',)){
if (Str::is('*成功*', '*' . $status . '*', )) {
$style = ['azure'];
}

// 退款
if (Str::is('*退款*','*'.$status.'*',)){
if (Str::is('*退款*', '*' . $status . '*', )) {
$style = ['orange'];
}


// 交易关闭
if (Str::is('*关闭*','*'.$status.'*')){
if (Str::is('*关闭*', '*' . $status . '*')) {
$style = ['yellow'];
}

// 交易取消
if (Str::is('*取消*','*'.$status.'*')){
if (Str::is('*取消*', '*' . $status . '*')) {
$style = ['purple'];
}

// 支付失败
if (Str::is('*失败*','*'.$status.'*')){
if (Str::is('*失败*', '*' . $status . '*')) {
$style = ['red'];
}

return implode(' ',$style);
return implode(' ', $style);
}
}
}
2 changes: 1 addition & 1 deletion app/CodeFec/Ui/Ui.php
Expand Up @@ -26,7 +26,7 @@ public function add(int $id, string $type,string $value)
"type" => $type,
"value" => $value,
];
$this->list = Arr::add($this->list,$id,$arr);
$this->list = Arr::set($this->list,$id,$arr);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion app/CodeFec/Ui/functions.php
Expand Up @@ -6,7 +6,7 @@ class functions
{
public static function Ui()
{
return \Hyperf\Utils\ApplicationContext::getContainer()->get(UiInterface::class);
return \Hyperf\Context\ApplicationContext::getContainer()->get(UiInterface::class);
}

public static function get($type): array
Expand Down
2 changes: 1 addition & 1 deletion app/CodeFec/Upgrading.php
Expand Up @@ -174,7 +174,7 @@ private function AdminPluginMigrateAll(): void
$input = new ArrayInput($params);
$output = new NullOutput();

$container = \Hyperf\Utils\ApplicationContext::getContainer();
$container = \Hyperf\Context\ApplicationContext::getContainer();

/** @var Application $application */
$application = $container->get(\Hyperf\Contract\ApplicationInterface::class);
Expand Down
15 changes: 8 additions & 7 deletions app/CodeFec/View/HyperfViewEngine.php
Expand Up @@ -11,25 +11,26 @@
namespace App\CodeFec\View;

use App\CodeFec\Plugins;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Di\Annotation\Inject;
use Hyperf\View\Engine\EngineInterface;
use Hyperf\ViewEngine\Contract\FactoryInterface;

class HyperfViewEngine implements EngineInterface
{
#[Inject]
protected FactoryInterface $factory;

public function render($template, $data, $config): string
{
/** @var FactoryInterface $factory */
$factory = ApplicationContext::getContainer()->get(FactoryInterface::class);
// 插件
$plugin_list = (new Plugins())->getEnPlugins();
foreach ($plugin_list as $value) {
$factory->addNamespace($value, plugin_path($value . '/resources/views'));
$this->factory->addNamespace($value, plugin_path($value . '/resources/views'));
}
// 主题
$name = get_options('theme', 'CodeFec');
$factory->replaceNamespace('App', theme_path($name . '/resources/views'));
$factory->replaceNamespace('Core', theme_path($name . '/resources/views'));
return $factory->make($template, $data)->render();
$this->factory->replaceNamespace('App', theme_path($name . '/resources/views'));
$this->factory->replaceNamespace('Core', theme_path($name . '/resources/views'));
return $this->factory->make($template, $data)->render();
}
}
62 changes: 44 additions & 18 deletions app/Command/ServerDocker.php
@@ -1,6 +1,6 @@
<?php

declare (strict_types=1);
declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
Expand All @@ -13,11 +13,16 @@
use App\CodeFec\DockerInstall;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Watcher\Option;
use Hyperf\Watcher\Watcher;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Engine\Coroutine;
use Hyperf\Server\ServerFactory;
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Swoole\Coroutine\System;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[Command]
class ServerDocker extends HyperfCommand
Expand All @@ -26,7 +31,7 @@ class ServerDocker extends HyperfCommand
* @var ContainerInterface
*/
protected $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
Expand All @@ -36,30 +41,51 @@ public function __construct(ContainerInterface $container)
$this->addOption('dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, '', []);
$this->addOption('no-restart', 'N', InputOption::VALUE_NONE, 'Whether no need to restart server');
}

public function configure()
{
parent::configure();
$this->setDescription('start docker server');
}

public function handle()
{
if (!file_exists(BASE_PATH . '/app/CodeFec/storage/install.lock')) {
if (!is_dir(BASE_PATH . '/app/CodeFec/storage')) {
if (! file_exists(BASE_PATH . '/app/CodeFec/storage/install.lock')) {
if (! is_dir(BASE_PATH . '/app/CodeFec/storage')) {
System::exec('cd ' . BASE_PATH . '/app/CodeFec && mkdir storage');
}
$myfile = fopen(BASE_PATH . '/app/CodeFec/storage/install.step.lock', 'wb') or exit('Unable to open file!');
fwrite($myfile, "5");
fclose($myfile);
$install = make(DockerInstall::class, ['output' => $this->output, 'command' => $this]);
$install->run();
}
go(function () {
system_clear_cache();
});
$option = make(Option::class, ['dir' => $this->input->getOption('dir'), 'file' => $this->input->getOption('file'), 'restart' => !$this->input->getOption('no-restart')]);
$watcher = make(Watcher::class, ['option' => $option, 'output' => $this->output]);
$watcher->run();
}
}

protected function execute(InputInterface $input, OutputInterface $output)
{
shell_exec('composer du');
$this->checkEnvironment($output);
$serverFactory = $this->container->get(ServerFactory::class);
$serverFactory->setEventDispatcher($this->container->get(EventDispatcherInterface::class));
$serverFactory->setLogger($this->container->get(StdoutLoggerInterface::class));
$serverConfig = $this->container->get(ConfigInterface::class)->get('server', []);
if (! $serverConfig) {
throw new \InvalidArgumentException('At least one se$rver should be defined.');
}
$serverFactory->configure($serverConfig);
Coroutine::set(['hook_flags' => \Hyperf\Support\swoole_hook_flags()]);
$serverFactory->start();
return 0;
}

private function checkEnvironment(OutputInterface $output)
{
if (! extension_loaded('swoole')) {
return;
}
$useShortname = ini_get_all('swoole')['swoole.use_shortname']['local_value'];
$useShortname = strtolower(trim(str_replace('0', '', $useShortname)));
if (! in_array($useShortname, ['', 'off', 'false'], true)) {
$output->writeln("<error>ERROR</error> Swoole short function names must be disabled before the server starts, please set swoole.use_shortname='Off' in your php.ini.");
exit(SIGTERM);
}
}
}

0 comments on commit d077f1e

Please sign in to comment.