dubpub/robo-reset

There is no license information available for the latest version (dev-master) of this package.

A trait to reset RoboFile.

dev-master 2015-10-05 12:11 UTC

This package is not auto-updated.

Last update: 2024-04-27 16:47:29 UTC


README

#Dubpub: RoboReset

Build Status Code Climate Coverage Status

dubpub/robo-reset is an extension for codegyro/robo package. It allows you to restart your robo process.

####Contents

##Installing

You can install dubpub/robo-reset using composer:

    "require": {
        "dubpub/robo-reset": "dev-master"
    }

or from shell

composer require dubpub/robo-reset

##Usage

You can use dubpub/robo-reset either from trait, provided by package Dubpub\RoboReset\RoboResetTrait:

<?php // file - ./RoboFile.php

include_once 'vendor/autoload.php'

class RoboFile extends \Robo\Tasks
{
    use Dubpub\RoboReset\RoboResetTrait;
}

Or you can use dubpub/robo-reset by extending \Dubpub\RoboReset\RoboRestartable, that extends \Robo\Tasks:

<?php // file - ./RoboFile.php

include_once 'vendor/autoload.php'

class RoboFile extends \Dubpub\RoboReset\RoboRestartable
{

}

##Examples

The most simple example of usage is monitoring your composer.json changes - if your composer.json file was changed, you need to dump autoloader and restart your RoboFile with new autoloader:

<?php // file - ./RoboFile.php

include_once 'vendor/autoload.php'

class RoboFile extends \Robo\Tasks
{
    use Dubpub\RoboReset\RoboResetTrait;
    
    public function watchComposer() 
    {
        $this->taskWatch('composer.json', function () {
            if ($this->taskComposerDumpAutoload()->run()->wasSuccessful()) {
                /**
                * Reset robo and output reason-message(optional)
                **/
                $this->resetRobo('Dumped autoloader');
            }
        })->run();
    }
}

Or you could restart your RoboFile each time it gets modified as well:

<?php // file - ./RoboFile.php

include_once 'vendor/autoload.php';

class RoboFile extends \Robo\Tasks
{
    use Dubpub\RoboReset\RoboResetTrait;

    public function watch()
    {
        /**
         * This method binds a listener on RoboFile.
         * If RoboFile was modified and it's code passes
         * standart php lint checks the robo process will be
         * restarted.
         *
         * Method returns an instance of \Robo\Task\Base\Watch
         *
         * @var \Robo\Task\Base\Watch $taskWatch
         */
        $taskWatch = $this->restartOnRoboChange();

        $taskWatch->monitor(['composer.json'], function () {
            if ($this->taskComposerDumpAutoload()->run()->wasSuccessful()) {
                /**
                 * Reset robo and output reason-message(optional)
                 **/
                $this->resetRobo('Dumped autoloader');
            }
        });

        $taskWatch->run();
    }
}