Giter Site home page Giter Site logo

district09 / robo-digipolis-general Goto Github PK

View Code? Open in Web Editor NEW
0.0 5.0 1.0 59 KB

General Digipolis tasks for Robo Task Runner: read properties files, determine project and web root.

License: MIT License

PHP 100.00%
robo robo-digipolis-general robo-tasks web d09check22

robo-digipolis-general's Introduction

Robo Digipolis General

General Digipolis tasks for Robo Task Runner

Latest Stable Version Latest Unstable Version Total Downloads License

Build Status Maintainability Test Coverage PHP 7 ready

Tasks in this package

DetermineProjectRoot

Determines the root folder of the project by looking for certain files in the given folder. By default it looks for a properties.yml or a composer.json file. Usually this task is ran before running an other task in the same command so the config value can be passed to that task.

// 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

Determines the web root folder of the project by looking for certain files in the given folder. By default it looks for a index.php, index.html, index.htm, home.php, home.html or a home.htm file. Usually this task is ran before running an other task in the same command so the config value can be passed to that task.

// 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

Reads values from yaml files (default.properties.yml and properties.yml) and stores them in config. Values from default.properties.yml will be overridden if they exist in a properties.yml. If a valid path is set for digipolis.root.web in config, and a properties.yml file exists in that path, those values will have top priority. Property files (both default.properties.yml and properties.yml) can define a _priority key at the root of the yaml. Higher priorities (lower number) take precedence over lower priorities (higher number).

// 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');

Using these tasks in a command

If you want to use these tasks in a command, you can use the \DigipolisGent\Robo\Task\General\Common\DigipolisPropertiesAware trait and implement the \DigipolisGent\Robo\Task\General\Common\DigipolisPropertiesAwareInterface interface. This will expose a readProperties method to which you can pass the paths to the project root, the web root and the vendor folder. If the tasks to determine the project and web root are available on the class using the trait, and no project or web root are given as a parameter to the readProperties method, these tasks will be used to determine the paths. They both default to the current working directory. The vendor folder defaults to the vendor folder in the web root. Your RoboFile.php might look something like this:

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();
    }
}

robo-digipolis-general's People

Contributors

daften avatar jelle-s avatar michaelvdwalle avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

davehenton

robo-digipolis-general's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.