@@ -472,6 +472,13 @@ function _element_start_1_0($xp, $name, $attribs)
472
472
$ this ->pkginfo ['configure_options ' ][] = $ attribs ;
473
473
}
474
474
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 ;
475
482
}
476
483
}
477
484
@@ -925,6 +932,12 @@ function _makeReleaseXml($pkginfo, $changelog = false)
925
932
}
926
933
$ ret .= "$ indent </configureoptions> \n" ;
927
934
}
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
+ }
928
941
if (isset ($ pkginfo ['filelist ' ])) {
929
942
$ ret .= "$ indent <filelist> \n" ;
930
943
foreach ($ pkginfo ['filelist ' ] as $ file => $ fa ) {
@@ -1087,17 +1100,101 @@ function validatePackageInfo($info, &$errors, &$warnings)
1087
1100
foreach ($ info ['filelist ' ] as $ file => $ fa ) {
1088
1101
if (empty ($ fa ['role ' ])) {
1089
1102
$ errors [] = "file $ file: missing role " ;
1103
+ continue ;
1090
1104
} elseif (!in_array ($ fa ['role ' ], $ _PEAR_Common_file_roles )) {
1091
1105
$ errors [] = "file $ file: invalid role, should be one of: " .implode (' ' , $ _PEAR_Common_file_roles );
1092
1106
}
1107
+ if ($ fa ['role ' ] == 'php ' ) {
1108
+ $ srcinfo = $ this ->analyzeSourceCode ($ file );
1109
+ $ this ->buildProvidesArray ($ srcinfo );
1110
+ }
1093
1111
// (ssb) Any checks we can do for baseinstalldir?
1094
1112
// (cox) Perhaps checks that either the target dir and
1095
1113
// baseInstall doesn't cointain "../../"
1096
1114
}
1097
1115
}
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
+ }
1098
1138
return true ;
1099
1139
}
1100
1140
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
+
1101
1198
// }}}
1102
1199
// {{{ analyzeSourceCode()
1103
1200
@@ -1120,7 +1217,7 @@ function analyzeSourceCode($file)
1120
1217
$ tokens = token_get_all ($ contents );
1121
1218
/*
1122
1219
for ($i = 0; $i < sizeof($tokens); $i++) {
1123
- list($token, $data) = $tokens[$i];
1220
+ @ list($token, $data) = $tokens[$i];
1124
1221
if (is_string($token)) {
1125
1222
var_dump($token);
1126
1223
} else {
@@ -1145,8 +1242,15 @@ function analyzeSourceCode($file)
1145
1242
$ used_functions = array ();
1146
1243
$ nodeps = array ();
1147
1244
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
+ }
1149
1251
switch ($ token ) {
1252
+ case T_CURLY_OPEN :
1253
+ case T_DOLLAR_OPEN_CURLY_BRACES :
1150
1254
case '{ ' : $ brace_level ++; continue 2 ;
1151
1255
case '} ' :
1152
1256
$ brace_level --;
0 commit comments