Hoa central
Assert.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Ruler\Bin;
38 
39 use Hoa\Console;
40 use Hoa\Ruler;
41 
51 {
57  protected $options = [
58  ['help', Console\GetOption::NO_ARGUMENT, 'h'],
59  ['help', Console\GetOption::NO_ARGUMENT, '?']
60  ];
61 
62 
63 
69  public function main()
70  {
71  $ruler = new Ruler();
72  $context = new Ruler\Context();
73 
74  while (false !== $c = $this->getOption($v)) {
75  switch ($c) {
76  case '__ambiguous':
77  $context[$v['option']] = $v['value'];
78 
79  break;
80 
81  case 'h':
82  case '?':
83  return $this->usage();
84  }
85  }
86 
87  $this->parser->listInputs($rule);
88 
89  if (empty($rule)) {
90  return $this->usage();
91  }
92 
93  return (int) (!$ruler->assert($rule, $context));
94  }
95 
101  public function usage()
102  {
103  echo
104  'Usage : ruler:assert <options> rule', "\n",
105  'Options :', "\n",
106  $this->makeUsageOptionsList([
107  'help' => 'This help.'
108  ]), "\n",
109  'Example : -x=2 -y=6 \'x in [1, 2, 4] and x < y\'.', "\n",
110  'See $? to see the result (0 for true, > 0 for false).', "\n";
111 
112  return;
113  }
114 }
115 
116 __halt_compiler();
117 Assert rules.
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
getOption(&$optionValue, $short=null)
Definition: Kit.php:104