palmtree / argparser
ArgParser component for Palmtree PHP
Installs: 4 778
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=7.1
- palmtree/nameconverter: ~2.0
Requires (Dev)
README
Parse an array of arguments and call matching setters and/or merge with default arguments.
Requirements
- PHP >= 7.1
Installation
Use composer to add the package to your dependencies:
composer require palmtree/argparser
Usage
<?php 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; } }
<?php // Calls $obj->setName('Andy') and sets the force arg to true $obj = new SomeClass([ 'name' => 'Andy', 'force' => true, ]);
License
Released under the MIT license