cvs: php4 /pear/PEAR Common.php

From: Date: Mon, 03 Feb 2003 02:54:41 +0000
Subject: cvs: php4 /pear/PEAR Common.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8701@lists.php.net to get a copy of this message
ssb Sun Feb 2 21:54:41 2003 EDT Modified files: /php4/pear/PEAR Common.php Log: * start using the source tokenizer Index: php4/pear/PEAR/Common.php diff -u php4/pear/PEAR/Common.php:1.85 php4/pear/PEAR/Common.php:1.86 --- php4/pear/PEAR/Common.php:1.85 Tue Dec 31 11:18:26 2002 +++ php4/pear/PEAR/Common.php Sun Feb 2 21:54:39 2003 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.85 2002/12/31 16:18:26 sebastian Exp $ +// $Id: Common.php,v 1.86 2003/02/03 02:54:39 ssb Exp $ require_once 'PEAR.php'; require_once 'Archive/Tar.php'; @@ -472,6 +472,13 @@ $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 @@ } $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 @@ 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 @@ $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 @@ $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--;

« previous php.pear.cvs (#8701) next »