Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🌴 Parse an array of arguments to call matching setter methods and/or merge with some defaults

License

Notifications You must be signed in to change notification settings

palmtreephp/argparser

Repository files navigation

Palmtree ArgParser

License

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

About

🌴 Parse an array of arguments to call matching setter methods and/or merge with some defaults

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /