diff options
author | Stig Bakken <ssb@php.net> | 2003-02-03 02:54:39 +0000 |
---|---|---|
committer | Stig Bakken <ssb@php.net> | 2003-02-03 02:54:39 +0000 |
commit | e756a253d964d8ef25a14b705d1f2290ccd15fb6 (patch) | |
tree | f1242b9d53b03f8f2a3b57a185d623647a88b4a7 | |
parent | 95613086e17f4f19af71354d749b0511565a8685 (diff) | |
download | php-git-e756a253d964d8ef25a14b705d1f2290ccd15fb6.tar.gz |
* start using the source tokenizer
-rw-r--r-- | pear/PEAR/Common.php | 108 |
1 files changed, 106 insertions, 2 deletions
diff --git a/pear/PEAR/Common.php b/pear/PEAR/Common.php index 560dff893f..83c8d20f39 100644 --- a/pear/PEAR/Common.php +++ b/pear/PEAR/Common.php @@ -472,6 +472,13 @@ class PEAR_Common extends PEAR $this->pkginfo['configure_options'][] = $attribs; } break; + case 'provides': + if (empty($attribs['type']) || empty($attribs['name'])) { + break; + } + $attribs['explicit'] = true; + $this->pkginfo['provides']["$attribs[type];$attribs[name]"] = $attribs; + break; } } @@ -925,6 +932,12 @@ class PEAR_Common extends PEAR } $ret .= "$indent </configureoptions>\n"; } + if (isset($pkginfo['provides'])) { + foreach ($pkginfo['provides'] as $key => $what) { + $ret .= "$indent <provides type=\"$what[type]\" "; + $ret .= "name=\"$what[name]\" />\n"; + } + } if (isset($pkginfo['filelist'])) { $ret .= "$indent <filelist>\n"; foreach ($pkginfo['filelist'] as $file => $fa) { @@ -1087,18 +1100,102 @@ class PEAR_Common extends PEAR foreach ($info['filelist'] as $file => $fa) { if (empty($fa['role'])) { $errors[] = "file $file: missing role"; + continue; } elseif (!in_array($fa['role'], $_PEAR_Common_file_roles)) { $errors[] = "file $file: invalid role, should be one of: ".implode(' ', $_PEAR_Common_file_roles); } + if ($fa['role'] == 'php') { + $srcinfo = $this->analyzeSourceCode($file); + $this->buildProvidesArray($srcinfo); + } // (ssb) Any checks we can do for baseinstalldir? // (cox) Perhaps checks that either the target dir and // baseInstall doesn't cointain "../../" } } + $pn = $info['package']; + $pnl = strlen($pn); + foreach ($this->pkginfo['provides'] as $key => $what) { + if (isset($what['explicit'])) { + // skip conformance checks if the provides entry is + // specified in the package.xml file + continue; + } + extract($what); + if ($type == 'class') { + if (!strncasecmp($name, $pn, $pnl)) { + continue; + } + $warnings[] = "in $file: class \"$name\" not prefixed with package name \"$pn\""; + } elseif ($type == 'function') { + if (strstr($name, '::') || !strncasecmp($name, $pn, $pnl)) { + continue; + } + $warnings[] = "in $file: function \"$name\" not prefixed with package name \"$pn\""; + } + //print "$file: provides $what[type] $what[name]\n"; + } return true; } // }}} + // {{{ buildProvidesArray() + + /** + * Build a "provides" array from data returned by + * analyzeSourceCode(). The format of the built array is like + * this: + * + * array( + * 'class;MyClass' => 'array('type' => 'class', 'name' => 'MyClass'), + * ... + * ) + * + * + * @param array $srcinfo array with information about a source file + * as returned by the analyzeSourceCode() method. + * + * @return void + * + * @access public + * + */ + function buildProvidesArray($srcinfo) + { + foreach ($srcinfo['declared_classes'] as $class) { + $key = "class;$class"; + if (isset($this->pkginfo['provides'][$key])) { + continue; + } + $this->pkginfo['provides'][$key] = + array('type' => 'class', 'name' => $class); + //var_dump($key, $this->pkginfo['provides'][$key]); + } + foreach ($srcinfo['declared_methods'] as $class => $methods) { + foreach ($methods as $method) { + $function = "$class::$method"; + $key = "function;$function"; + if ($method{0} == '_' || !strcasecmp($method, $class) || + isset($this->pkginfo['provides'][$key])) { + continue; + } + $this->pkginfo['provides'][$key] = + array('type' => 'function', 'name' => $function); + //var_dump($key, $this->pkginfo['provides'][$key]); + } + } + foreach ($srcinfo['declared_functions'] as $function) { + $key = "function;$function"; + if ($function{0} == '_' || isset($this->pkginfo['provides'][$key])) { + continue; + } + $this->pkginfo['provides'][$key] = + array('type' => 'function', 'name' => $function); + //var_dump($key, $this->pkginfo['provides'][$key]); + } + } + + // }}} // {{{ analyzeSourceCode() /** @@ -1120,7 +1217,7 @@ class PEAR_Common extends PEAR $tokens = token_get_all($contents); /* for ($i = 0; $i < sizeof($tokens); $i++) { - list($token, $data) = $tokens[$i]; + @list($token, $data) = $tokens[$i]; if (is_string($token)) { var_dump($token); } else { @@ -1145,8 +1242,15 @@ class PEAR_Common extends PEAR $used_functions = array(); $nodeps = array(); for ($i = 0; $i < sizeof($tokens); $i++) { - list($token, $data) = $tokens[$i]; + if (is_array($tokens[$i])) { + list($token, $data) = $tokens[$i]; + } else { + $token = $tokens[$i]; + $data = ''; + } switch ($token) { + case T_CURLY_OPEN: + case T_DOLLAR_OPEN_CURLY_BRACES: case '{': $brace_level++; continue 2; case '}': $brace_level--; |