Skip to content

Commit e756a25

Browse files
committed
* start using the source tokenizer
1 parent 9561308 commit e756a25

File tree

1 file changed

+106
-2
lines changed

1 file changed

+106
-2
lines changed

pear/PEAR/Common.php

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,13 @@ function _element_start_1_0($xp, $name, $attribs)
472472
$this->pkginfo['configure_options'][] = $attribs;
473473
}
474474
break;
475+
case 'provides':
476+
if (empty($attribs['type']) || empty($attribs['name'])) {
477+
break;
478+
}
479+
$attribs['explicit'] = true;
480+
$this->pkginfo['provides']["$attribs[type];$attribs[name]"] = $attribs;
481+
break;
475482
}
476483
}
477484

@@ -925,6 +932,12 @@ function _makeReleaseXml($pkginfo, $changelog = false)
925932
}
926933
$ret .= "$indent </configureoptions>\n";
927934
}
935+
if (isset($pkginfo['provides'])) {
936+
foreach ($pkginfo['provides'] as $key => $what) {
937+
$ret .= "$indent <provides type=\"$what[type]\" ";
938+
$ret .= "name=\"$what[name]\" />\n";
939+
}
940+
}
928941
if (isset($pkginfo['filelist'])) {
929942
$ret .= "$indent <filelist>\n";
930943
foreach ($pkginfo['filelist'] as $file => $fa) {
@@ -1087,17 +1100,101 @@ function validatePackageInfo($info, &$errors, &$warnings)
10871100
foreach ($info['filelist'] as $file => $fa) {
10881101
if (empty($fa['role'])) {
10891102
$errors[] = "file $file: missing role";
1103+
continue;
10901104
} elseif (!in_array($fa['role'], $_PEAR_Common_file_roles)) {
10911105
$errors[] = "file $file: invalid role, should be one of: ".implode(' ', $_PEAR_Common_file_roles);
10921106
}
1107+
if ($fa['role'] == 'php') {
1108+
$srcinfo = $this->analyzeSourceCode($file);
1109+
$this->buildProvidesArray($srcinfo);
1110+
}
10931111
// (ssb) Any checks we can do for baseinstalldir?
10941112
// (cox) Perhaps checks that either the target dir and
10951113
// baseInstall doesn't cointain "../../"
10961114
}
10971115
}
1116+
$pn = $info['package'];
1117+
$pnl = strlen($pn);
1118+
foreach ($this->pkginfo['provides'] as $key => $what) {
1119+
if (isset($what['explicit'])) {
1120+
// skip conformance checks if the provides entry is
1121+
// specified in the package.xml file
1122+
continue;
1123+
}
1124+
extract($what);
1125+
if ($type == 'class') {
1126+
if (!strncasecmp($name, $pn, $pnl)) {
1127+
continue;
1128+
}
1129+
$warnings[] = "in $file: class \"$name\" not prefixed with package name \"$pn\"";
1130+
} elseif ($type == 'function') {
1131+
if (strstr($name, '::') || !strncasecmp($name, $pn, $pnl)) {
1132+
continue;
1133+
}
1134+
$warnings[] = "in $file: function \"$name\" not prefixed with package name \"$pn\"";
1135+
}
1136+
//print "$file: provides $what[type] $what[name]\n";
1137+
}
10981138
return true;
10991139
}
11001140

1141+
// }}}
1142+
// {{{ buildProvidesArray()
1143+
1144+
/**
1145+
* Build a "provides" array from data returned by
1146+
* analyzeSourceCode(). The format of the built array is like
1147+
* this:
1148+
*
1149+
* array(
1150+
* 'class;MyClass' => 'array('type' => 'class', 'name' => 'MyClass'),
1151+
* ...
1152+
* )
1153+
*
1154+
*
1155+
* @param array $srcinfo array with information about a source file
1156+
* as returned by the analyzeSourceCode() method.
1157+
*
1158+
* @return void
1159+
*
1160+
* @access public
1161+
*
1162+
*/
1163+
function buildProvidesArray($srcinfo)
1164+
{
1165+
foreach ($srcinfo['declared_classes'] as $class) {
1166+
$key = "class;$class";
1167+
if (isset($this->pkginfo['provides'][$key])) {
1168+
continue;
1169+
}
1170+
$this->pkginfo['provides'][$key] =
1171+
array('type' => 'class', 'name' => $class);
1172+
//var_dump($key, $this->pkginfo['provides'][$key]);
1173+
}
1174+
foreach ($srcinfo['declared_methods'] as $class => $methods) {
1175+
foreach ($methods as $method) {
1176+
$function = "$class::$method";
1177+
$key = "function;$function";
1178+
if ($method{0} == '_' || !strcasecmp($method, $class) ||
1179+
isset($this->pkginfo['provides'][$key])) {
1180+
continue;
1181+
}
1182+
$this->pkginfo['provides'][$key] =
1183+
array('type' => 'function', 'name' => $function);
1184+
//var_dump($key, $this->pkginfo['provides'][$key]);
1185+
}
1186+
}
1187+
foreach ($srcinfo['declared_functions'] as $function) {
1188+
$key = "function;$function";
1189+
if ($function{0} == '_' || isset($this->pkginfo['provides'][$key])) {
1190+
continue;
1191+
}
1192+
$this->pkginfo['provides'][$key] =
1193+
array('type' => 'function', 'name' => $function);
1194+
//var_dump($key, $this->pkginfo['provides'][$key]);
1195+
}
1196+
}
1197+
11011198
// }}}
11021199
// {{{ analyzeSourceCode()
11031200

@@ -1120,7 +1217,7 @@ function analyzeSourceCode($file)
11201217
$tokens = token_get_all($contents);
11211218
/*
11221219
for ($i = 0; $i < sizeof($tokens); $i++) {
1123-
list($token, $data) = $tokens[$i];
1220+
@list($token, $data) = $tokens[$i];
11241221
if (is_string($token)) {
11251222
var_dump($token);
11261223
} else {
@@ -1145,8 +1242,15 @@ function analyzeSourceCode($file)
11451242
$used_functions = array();
11461243
$nodeps = array();
11471244
for ($i = 0; $i < sizeof($tokens); $i++) {
1148-
list($token, $data) = $tokens[$i];
1245+
if (is_array($tokens[$i])) {
1246+
list($token, $data) = $tokens[$i];
1247+
} else {
1248+
$token = $tokens[$i];
1249+
$data = '';
1250+
}
11491251
switch ($token) {
1252+
case T_CURLY_OPEN:
1253+
case T_DOLLAR_OPEN_CURLY_BRACES:
11501254
case '{': $brace_level++; continue 2;
11511255
case '}':
11521256
$brace_level--;

0 commit comments

Comments
 (0)