PHP code example of d2g / reactor

1. Go to this page and download the library: Download d2g/reactor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

d2g / reactor example snippets


class Mycommand extends \D2G\Reactor\Command

function __construct($args, $opts, $flags)
{
    parent::construct($args, $opts, $flags);
    $this->commands = array(
        '<pre>__DEFAULT__</pre>'=>'__help',
        // the name of your method
        'my_method'=>array(
            // defining expected inputs 
            'expecting'=>array(
                // defining expected arguments
                'args'=>array(
                    array(
                        // used in error message
                        'name'=>'my-argument',
                        // internal function will try to cast the argument to this type
                        'type'=>'type of argument',
                        // command will fail if an expected argument is not present
                        '                 // flags
                        'a',
                        'longflag'
                    )
                ),
            ),
        )
    );
}