PHP code example of palmtree / argparser

1. Go to this page and download the library: Download palmtree/argparser 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/ */

    

palmtree / argparser example snippets




use Palmtree\ArgParser\ArgParser;

class SomeClass {
    public static $defaultArgs = [
        'force' => false,
    ];

    private $name;
    private $args = [];

    public function __construct($args = []) {
        $parser = new ArgParser($args);

        $parser->parseSetters($this);
        $this->args = $parser->resolveOptions(static::$defaultArgs);
    }

    public function setName($name) {
        $this->name = $name;
    }
}


// Calls $obj->setName('Andy') and sets the force arg to true
$obj = new SomeClass([
    'name' => 'Andy',
    'force' => true,
]);