php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch check-valid-options for Doc Build problem Bug #54217

Patch version 2011-03-17 03:39 UTC

Return to Bug #54217 | Download this patch
Patch Revisions:

Developer: moacir@php.net

Index: phpdotnet/phd/Options/Parser.php
===================================================================
--- phpdotnet/phd/Options/Parser.php	(revisão 308948)
+++ phpdotnet/phd/Options/Parser.php	(cópia de trabalho)
@@ -63,9 +63,34 @@
         return implode('', array_values($this->defaultHandler->optionList()));
     }
 
+    private function checkOptions() {
+        $argv = $_SERVER['argv'];
+        $argc = $_SERVER['argc'];
+
+        $short = str_split(str_replace(':', '', $this->getShortOptions()));
+        $long = array();
+        foreach ($this->getLongOptions() as $opt) {
+            $long[] = str_replace(':', '', $opt);
+        }
+
+        for ($i=1; $i < $argc; $i++) {
+            if (substr($argv[$i], 0, 2) == '--') {
+                if (!in_array(substr($argv[$i], 2), $long)) {
+                    trigger_error('Invalid long option ' . $argv[$i], E_USER_ERROR);
+                }
+            } elseif (substr($argv[$i], 0, 1) == '-') {
+                if (!in_array(substr($argv[$i], 1), $short)) {
+                    trigger_error('Invalid short option ' . $argv[$i], E_USER_ERROR);
+                }
+            }
+        }
+    }
+
     public static function getopt() {
         $self = self::instance();
 
+        $self->checkOptions();
+
         $args = getopt($self->getShortOptions(), $self->getLongOptions());
         if ($args === false) {
             trigger_error("Something happend with getopt(), please report a bug", E_USER_ERROR);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 07:01:29 2024 UTC