g3yuri / volt-php

一个轻量级的PHP框架

1.0.0 2023-05-01 08:02 UTC

This package is auto-updated.

Last update: 2024-09-30 01:31:02 UTC


README

数据库

使用Php unit进行测试

PHPUnit与composer一起使用,应在terminus中添加gieuiten

    { 
        "keys": ["super+t"],
        "command": "terminus_open",
        
        "args": {
            "shell_cmd": "ssh ene -t 'cd /www/wwwroot/slim.alpayana.gd.pe; ./vendor/bin/phpunit tests'",
            "working_dir": "$folder",
            "title": "Linea de Comandos",
            "auto_close": false,
        }
    },

更多terminus配置信息请参考:https://packagecontrol.io/packages/Terminus

步骤 1:服务器 - aapanel

为了在服务器上启动

  • 在github.com上生成一个个人令牌
  • 通过git克隆项目
  • 移动到根目录
  • 除了vendor和storage外,属性必须在ubuntu:www中
  • 需要安装php的fileinfo扩展
cd /www/wwwroot/slim.gmi.gd.pe
sudo git clone https://github.com/g3yuri/slim.gmi.git
sudo mv slim.gmi/* .
sudo chown ubuntu:www -R .

步骤 2:执行composer install

php.ini文件必须在:/www/server/php/74/etc/php.ini,此文件被复制并在disable_functions =中查找,必须为空,这限制了函数

使用composer安装包

php -c ~/php.ini /usr/bin/composer install

如果不起作用,请使用/www/server/php/74/bin/php -c ~/php.ini /usr/bin/composer install,文件夹74可能根据aapanel中安装的php版本而变化

必须确保用户是vendor文件夹的所有者

步骤 3:配置Nginx以读取index.php路径

在服务器配置中必须包含以下内容

    index index.php;
    root /www/wwwroot/slim.gmi.gd.pe/public;
    location / {
          try_files $uri $uri/ /index.php?$args;
    }

必须注释一些项

    #location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    #{
    #    expires      30d;
    #    error_log /dev/null;
    #    access_log off;
    #}

    #location ~ .*\.(js|css)?$
    #{
    #    expires      12h;
    #    error_log /dev/null;
    #    access_log off; 
    #}

步骤 4:扩展 ext-info - 时区 - /public目录中的网站

  • ext-info:需要phpoffice/phpspreadsheet,league/flysystem

  • MySQL:从系统获取,需要通过命令设置

    1. 使用timedatectl获取时间和日期信息
    2. 列出时区timedatectl list-timezones
    3. 设置时区sudo timedatectl set-timezone America/Toronto
  • PHP:需要修改apanel中的配置

  • public目录必须作为网站开始

为了刷新autoload类映射

  • 执行composer dump-autoload

安装pear扩展

  • 步骤 1:安装必要的软件sudo apt install php-pear php-dev,php-pear用于使用pecl命令,php-dev用于使用php-config
  • 步骤 2:将生成的扩展复制到php的扩展目录,可以是如/usr/lib/php/20190902的目录,并复制到如/www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902的目录,执行sudo cp /usr/lib/php/20190902/dbase.so /www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902,路径可能不同

存储

参考:https://flysystem.thephpleague.com/docs/

函数参数中的路径URL是相对的

测试

参考:https://docs.phpunit.de/en/9.6/

假设测试文件位于tests目录中

./vendor/bin/phpunit tests

在代码编辑器中添加快捷方式

  • 在Visual Studio Code中:安装扩展multi-command,然后在keybondongs.json文件中添加以下代码
{
    "key": "alt+cmd+b",
    "command": "extension.multiCommand.execute",
    "args": { 
        "sequence": [
            "workbench.action.createTerminalEditor",
            {
                "command": "workbench.action.terminal.sendSequence",
                "args": {
                    "text": "ssh ene -t 'cd /www/wwwroot/slim.gmi.gd.pe;./vendor/bin/phpunit tests'\u000D"
                }
            }
        ]
    }
}
  • 在Sublime text中:安装扩展terminus,然后在Sublime Text > 设置 > 键绑定中添加以下代码
{ 
    "keys": ["super+g"],
    "command": "terminus_open",
    
    "args": {
        "shell_cmd": "ssh ene -t 'cd /www/wwwroot/slim.gmi.gd.pe; sudo su -c \"./vendor/bin/phpunit tests\"'",
        "working_dir": "$folder",
        "title": "Linea de Comandos",
        "auto_close": false,
    }
}

任务 / CronJobs

参考:https://github.com/crunzphp/crunz

待办

此待办从单个变量拉取以下数据

  • 数据库连接配置在 config.php 和 db.php 文件中
  • 网站域名在 test 文件夹和其他文件,如 session.php 中
  • 为了能够从 config.php 读取 storage 的根路径,修改 storage.php 中的以下行 return self::path_join("https://slim.presto.gd.pe/storage/",$path);
  • 添加到 storage
    public static function lastModified($path)  {
        return self::driver()->lastModified($path);
    }
  • 添加到 app.php 以获取 origin
        if (array_key_exists('HTTP_ORIGIN', $_SERVER)) {
            $origin = $_SERVER['HTTP_ORIGIN'];
        } else if (array_key_exists('HTTP_REFERER', $_SERVER)) {
            $origin = $_SERVER['HTTP_REFERER'];
        } else {
            $origin = $_SERVER['REMOTE_ADDR'];
        }
  • 添加到 storage.php
    public static function write($path, $content) {
        $fs = self::driver();
        $fs->write($path, $content);
    }
  • 为了将 PHP 升级到 8.2,现在:路由器 Klein 正在抛出 deprecates 消息,因此正在添加 error_reporting(E_ALL ^ E_DEPRECATED); 以避免这些消息。需要:使用其他路由器如 FastRouter (https://github.com/nikic/FastRoute) 进行更改

  • 任务 必须添加 composer require lavary/crunz 更多关于 Crunz 的信息请见 [Crunz] [https://github.com/lavary/crunz] 创建配置文件

/project/vendor/bin/crunz publish:config

以下是如何添加一个常规 cronjobs 的方式

* * * * * cd /project && vendor/bin/crunz schedule:run /path/to/tasks/directory