drunomics/phapp-cli

为PHP应用程序提供标准化的控制台命令。

0.7.1 2023-04-05 10:55 UTC

README

为PHP应用程序提供标准化的控制台命令。

需求

  • Git版本 >= 2.0
  • Bash 4.*
  • PHP >5.6|>7.0

安装

安装需要composer。由于与最新drush版本存在一些依赖冲突,建议通过consolidation/cgr安装该工具。只需执行

# Download latest stable release.
php -r "
  ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0)');
  readfile(json_decode(file_get_contents('https://api.github.com/repos/drunomics/phapp-cli/releases/latest'))->assets[0]->browser_download_url);
" > phapp
chmod +x phapp

# Optional: Ensure ~/bin exists and configure it to be available in $PATH.
[ -d ~/bin ] || mkdir ~/bin
echo $PATH | grep -q ~/bin || (echo "export PATH=~/bin:\$PATH" >> ~/.bashrc && export PATH=~/bin:$PATH)

# Make phapp executable from everywhere by moving to a destination available in $PATH.
# If you skipped the optional step above, be sure to move it to a suiting destination.
mv phapp ~/bin/phapp

更新

运行

 phapp self:update

用法

运行 phapp list 显示支持命令列表,使用 phapp command --help 获取有关命令的更多信息。当前可用的命令列表如下

  build                 Builds the project with the current code checkout.
  clone                 Clones a Phapp project.
  create                Creates a new project base on a given template.
  help                  Displays help for a command
  init                  Initializes the app.
  install               Installs the application.
  list                  Lists commands
  setup                 Setups the phapp environment.
  status                Checks for a working and installed application.
  update                Updates the app.
 build
  build:branch          Builds a given branch.
  build:clean           Cleans all build related files.
 git
  git:pull              Updates local branches by pull from remote repositories.
  git:setup-remotes     Configures Git remote repositories.
 init
  init:manifest         Initializes a new phapp.yml for your project.
 self
  self:update           Updates the installed phar.

phapp.yml

应用在其 phapp.yml(phapp清单)中提供基本元数据和自定义命令。有关示例,请参阅 examples/phapp.yml

Phapp环境变量

phapp.yml中定义的命令可以使用Phapp环境变量。

dotenv支持

Phapp环境变量可以通过环境设置,即主机,或通过.env文件设置。

为了帮助根据一个或多个.env文件初始化环境,可以使用environment命令。此命令在其他命令之前执行(除了setup),以便它们可以依赖初始化的环境。

因此,.env文件可以写在setup命令中,作为environment命令的一部分。

可用变量

可用的环境变量必须是

可选的环境变量是

数据库连接。

PHAPP_ENV_MYSQL_DEFAULT_DATABASE=database
PHAPP_ENV_MYSQL_DEFAULT_USERNAME=user
PHAPP_ENV_MYSQL_DEFAULT_PASSWORD=pass
PHAPP_ENV_MYSQL_DEFAULT_HOST=localhost
PHAPP_ENV_MYSQL_DEFAULT_PORT="3306"

环境提供的一些其他变量。

PHAPP_ENV_DUMP_DIR="/data/mysql_dumps/sync"
PHAPP_ENV_DUMP_DB_FILENAME="${PHAPP_ENV_MYSQL_DEFAULT_DATABASE}-$(date -d "1 day ago" +%Y%m%d).sql.gz"

Phapp开发

构建新的phar

phar使用box构建,详细信息请参阅https://github.com/box-project/box2。要构建phar,只需运行

 composer install --dev
 composer build

创建新的发布版本

  • 标记新的版本并推送。
  • 构建新的phar(见上面)。
  • 在github发布页面上传新的phar。保持文件名不变。
  • 请注意,Packagist API不会立即更新。因此,新版本需要几分钟才能被self:update命令获取。