digipolisgent/robo-digipolis-general

Robo Task Runner 的一般 Digipolis 任务

安装数: 86,769

依赖者: 3

建议者: 0

安全性: 0

星标: 0

关注者: 5

分支: 1

公开问题: 0

类型:robo-tasks

2.1.1 2023-10-10 12:45 UTC

This package is auto-updated.

Last update: 2024-09-10 14:48:26 UTC


README

Robo Task Runner 的一般 Digipolis 任务

Latest Stable Version Latest Unstable Version Total Downloads License

Build Status Maintainability Test Coverage PHP 7 ready

此包中的任务

DetermineProjectRoot

通过在给定文件夹中查找特定文件来确定项目的根目录。默认情况下,它查找 properties.ymlcomposer.json 文件。通常,这个任务在运行同一命令中的其他任务之前运行,以便可以将配置值传递给该任务。

// Recursively search for a project root folder in the current directory with a
// maximum depth of 2.
$result = $this->taskDetermineProjectRoot(getcwd(), 2)
    // Do not search in the tests and vendor folders.
    ->exclude(['tests', 'vendor'])
    // A folder containing a composer.json is considered a project root.
    ->searchFiles(['composer.json'])
    ->run();
// The project root is stored in the digipolis.root.project config.
$root = $this->getConfig()->get('digipolis.root.project');

DetermineWebRoot

通过在给定文件夹中查找特定文件来确定项目的 web 根目录。默认情况下,它查找 index.phpindex.htmlindex.htmhome.phphome.htmlhome.htm 文件。通常,这个任务在运行同一命令中的其他任务之前运行,以便可以将配置值传递给该任务。

// Recursively search for a web root folder in the current directory with a
// maximum depth of 2.
$result = $this->taskDetermineWebRoot(getcwd(), 2)
    // Do not search in the tests and vendor folders.
    ->exclude(['tests', 'vendor'])
    // A folder containing an index.php is considered a project root.
    ->searchFiles(['index.php'])
    ->run();
// The project root is stored in the digipolis.root.web config.
$root = $this->getConfig()->get('digipolis.root.web');

ReadProperties

从 yaml 文件(default.properties.ymlproperties.yml)中读取值并将它们存储在配置中。如果存在于 properties.yml 中,将覆盖 default.properties.yml 中的值。如果配置中设置了有效的 digipolis.root.web 路径,并且在该路径中存在 properties.yml 文件,则这些值将具有最高优先级。属性文件(即 default.properties.ymlproperties.yml)可以在 yaml 的根目录定义一个 _priority 键。优先级越高(数字越小)优先级越高,优先级越低(数字越大)优先级越低。

// Search for default.properties.yml and properties.yml files in the current
// directory.
$result = $this->taskReadProperties([getcwd()])
    ->run();
// Values are stored in config.
$root = $this->getConfig()->get('my.config.value');

在命令中使用这些任务

如果您想在命令中使用这些任务,可以使用 \DigipolisGent\Robo\Task\General\Common\DigipolisPropertiesAware 特性和实现 \DigipolisGent\Robo\Task\General\Common\DigipolisPropertiesAwareInterface 接口。这将公开一个 readProperties 方法,您可以将项目根目录、web 根目录和 vendor 目录的路径传递给它。如果使用特性调用的类中可用确定项目和 web 根目录的任务,并且没有将项目或 web 根目录作为参数传递给 readProperties 方法,则这些任务将用于确定路径。它们都默认为当前工作目录。vendor 目录默认为 web 根目录中的 vendor 目录。您的 RoboFile.php 可能看起来像这样:

class RoboFile extends \Robo\Tasks implements \DigipolisGent\Robo\Task\General\Common\DigipolisPropertiesAwareInterface
{
    use \DigipolisGent\Robo\Task\General\Common\DigipolisPropertiesAware;
    use \DigipolisGent\Robo\Task\General\loadTasks;

    public function myCommand(
        $arg1,
        $arg2,
        $opts = [
            'root|r' => null,
            'webroot|wr' => null,
            'vendor-folder|vf' => null,
        ]
    )
    {
        $this->readProperties(
            $opts['root'],
            $opts['webroot'],
            $opts['vendor-folder']
        );
        // All properties are stored in config now, so execute the command.
        $this->doCommand();
    }
}