cvs: pear-core /PEAR/PackageFile/v2 Validator.php
| From: | Helgi �ormar �orbj�rnsson | Date: | Fri, 27 Mar 2009 19:29:31 +0000 |
| Subject: | cvs: pear-core /PEAR/PackageFile/v2 Validator.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-8295@lists.php.net to get a copy of this message | ||
dufuz Fri Mar 27 19:29:31 2009 UTC
Modified files:
/pear-core/PEAR/PackageFile/v2 Validator.php
Log:
Make analyzeSourcecode in PackageFile_v2_Validator return pear errors when _stack is not set, this
allows us to make analyzeSourcecode in PEAR_Common to utilize that function instead of having
duplication
http://cvs.php.net/viewvc.cgi/pear-core/PEAR/PackageFile/v2/Validator.php?r1=1.109&r2=1.110&diff_format=u
Index: pear-core/PEAR/PackageFile/v2/Validator.php
diff -u pear-core/PEAR/PackageFile/v2/Validator.php:1.109
pear-core/PEAR/PackageFile/v2/Validator.php:1.110
--- pear-core/PEAR/PackageFile/v2/Validator.php:1.109 Tue Feb 24 23:46:03 2009
+++ pear-core/PEAR/PackageFile/v2/Validator.php Fri Mar 27 19:29:31 2009
@@ -9,7 +9,7 @@
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php
New BSD License
- * @version CVS: $Id: Validator.php,v 1.109 2009/02/24 23:46:03 dufuz Exp $
+ * @version CVS: $Id: Validator.php,v 1.110 2009/03/27 19:29:31 dufuz Exp $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a8
*/
@@ -1846,15 +1846,19 @@
'Parser error: token_get_all() function must exist to analyze source code, PHP
may have been compiled with --disable-tokenizer');
return false;
}
+
if (!defined('T_DOC_COMMENT')) {
define('T_DOC_COMMENT', T_COMMENT);
}
+
if (!defined('T_INTERFACE')) {
define('T_INTERFACE', -1);
}
+
if (!defined('T_IMPLEMENTS')) {
define('T_IMPLEMENTS', -1);
}
+
if ($string) {
$contents = $file;
} else {
@@ -1868,12 +1872,13 @@
// Silence this function so we can catch PHP Warnings and show our own custom message
$tokens = @token_get_all($contents);
if (isset($php_errormsg)) {
- $pn = $this->_pf->getPackage();
- $this->_stack->push(__FUNCTION__, 'warning',
- array('file' => $file, 'package' => $pn),
- 'in %file%: Could not process file for unkown reasons,' .
- ' possibly a PHP parse error in %file% from %package%');
-
+ if (isset($this->_stack)) {
+ $pn = $this->_pf->getPackage();
+ $this->_stack->push(__FUNCTION__, 'warning',
+ array('file' => $file, 'package' => $pn),
+ 'in %file%: Could not process file for unkown reasons,' .
+ ' possibly a PHP parse error in %file% from %package%');
+ }
}
/*
for ($i = 0; $i < sizeof($tokens); $i++) {
@@ -1914,6 +1919,7 @@
$token = $tokens[$i];
$data = '';
}
+
if ($inquote) {
if ($token != '"' && $token != T_END_HEREDOC) {
continue;
@@ -1922,6 +1928,7 @@
continue;
}
}
+
switch ($token) {
case T_WHITESPACE :
continue;
@@ -1957,8 +1964,14 @@
$interface = true;
case T_CLASS:
if (($current_class_level != -1) || ($current_function_level != -1)) {
- $this->_stack->push(__FUNCTION__, 'error',
array('file' => $file),
- 'Parser error: invalid PHP found in file "%file%"');
+ if (isset($this->_stack)) {
+ $this->_stack->push(__FUNCTION__, 'error',
array('file' => $file),
+ 'Parser error: invalid PHP found in file
"%file%"');
+ } else {
+ PEAR::raiseError("Parser error: invalid PHP found in file
\"$file\"",
+ PEAR_COMMON_ERROR_INVALIDPHP);
+ }
+
return false;
}
case T_FUNCTION:
@@ -1972,13 +1985,21 @@
if (in_array(strtolower($data),
array('public', 'private', 'protected',
'abstract',
'interface', 'implements', 'throw')
- )) {
- $this->_stack->push(__FUNCTION__, 'warning', array(
- 'file' => $file),
- 'Error, PHP5 token encountered in %file%,' .
- ' analysis should be in PHP5');
+ )
+ ) {
+ if (isset($this->_stack)) {
+ $this->_stack->push(__FUNCTION__, 'warning', array(
+ 'file' => $file),
+ 'Error, PHP5 token encountered in %file%,' .
+ ' analysis should be in PHP5');
+ } else {
+ PEAR::raiseError('Error: PHP5 token encountered in ' .
$file .
+ 'packaging should be done in PHP 5');
+ return false;
+ }
}
}
+
if ($look_for == T_CLASS) {
$current_class = $data;
$current_class_level = $brace_level;
@@ -2002,11 +2023,13 @@
$current_function = $data;
$declared_functions[] = $current_function;
}
+
$current_function_level = $brace_level;
$m = array();
} elseif ($look_for == T_NEW) {
$used_classes[$data] = true;
}
+
$look_for = 0;
continue 2;
case T_VARIABLE:
@@ -2023,17 +2046,26 @@
continue 2;
case T_DOUBLE_COLON:
if (!($tokens[$i - 1][0] == T_WHITESPACE || $tokens[$i - 1][0] == T_STRING)) {
- $this->_stack->push(__FUNCTION__, 'warning',
array('file' => $file),
- 'Parser error: invalid PHP found in file
"%file%"');
+ if (isset($this->_stack)) {
+ $this->_stack->push(__FUNCTION__, 'warning',
array('file' => $file),
+ 'Parser error: invalid PHP found in file
"%file%"');
+ } else {
+ PEAR::raiseError("Parser error: invalid PHP found in file
\"$file\"",
+ PEAR_COMMON_ERROR_INVALIDPHP);
+ }
+
return false;
}
+
$class = $tokens[$i - 1][1];
if (strtolower($class) != 'parent') {
$used_classes[$class] = true;
}
+
continue 2;
}
}
+
return array(
"source_file" => $file,
"declared_classes" => $declared_classes,
@@ -2043,7 +2075,7 @@
"used_classes" => array_diff(array_keys($used_classes), $nodeps),
"inheritance" => $extends,
"implements" => $implements,
- );
+ );
}
/**