public static function getNameFromClassName($cname) { //strip out namespace from class name $n = ''; $inname = false; for ($k = 0; $k < strlen($cname); $k++) { $c = substr($cname, $k, 1); if (!$inname && is_upper($c)) { $inname = true; } if ($inname) { $n .= $c; } } //strip out "Handler" at end if it exists $hlen = strlen('Handler'); if (strlen($n) > $hlen) { $estr = substr($n, strlen($n) - $hlen, $hlen); if ($estr == 'Handler') { $n = substr($n, 0, strlen($n) - $hlen); } } //convert upper to lower, put dashes in between lower and upper $tagName = ''; $firstUpper = true; $lastWasUpper = false; for ($k = 0; $k < strlen($n); $k++) { $c = substr($n, $k, 1); if (is_upper($c)) { if (!$firstUpper && !$lastWasUpper) { $tagName .= '-'; } else { $firstUpper = false; } $tagName .= strtolower($c); $lastWasUpper = true; } else { $lastWasUpper = false; $tagName .= $c; } } return $tagName; }
function is_lower($test, $offset = 0, $length = 0) { return !is_upper($test, $length, $offset); }
/** * atom ::= '(' expr ')' | '[' expr ']' | 'options' * | long | shorts | argument | command ; */ function parse_atom($tokens, \ArrayIterator $options) { $token = $tokens->current(); $result = array(); if ($token == '(' || $token == '[') { $tokens->move(); static $index; if (!$index) { $index = array('(' => array(')', __NAMESPACE__ . '\\Required'), '[' => array(']', __NAMESPACE__ . '\\Optional')); } list($matching, $pattern) = $index[$token]; $result = new $pattern(parse_expr($tokens, $options)); if ($tokens->move() != $matching) { $tokens->raiseException("Unmatched '{$token}'"); } return array($result); } elseif ($token == 'options') { $tokens->move(); return array(new AnyOptions()); } elseif (strpos($token, '--') === 0 && $token != '--') { return parse_long($tokens, $options); } elseif (strpos($token, '-') === 0 && $token != '-' && $token != '--') { return parse_shorts($tokens, $options); } elseif (strpos($token, '<') === 0 && ends_with($token, '>') || is_upper($token)) { return array(new Argument($tokens->move())); } else { return array(new Command($tokens->move())); } }