Source for file Validate.php
Documentation is available at Validate.php
* @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: Validate.php 313023 2011-07-06 19:17:11Z dufuz $
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
* Constants for install stage
define('PEAR_VALIDATE_INSTALLING', 1 );
define('PEAR_VALIDATE_UNINSTALLING', 2 ); // this is not bit-mapped like the others
define('PEAR_VALIDATE_NORMAL', 3 );
define('PEAR_VALIDATE_DOWNLOADING', 4 ); // this is not bit-mapped like the others
define('PEAR_VALIDATE_PACKAGING', 7 );
require_once 'PEAR/Common.php';
require_once 'PEAR/Validator/PECL.php';
* Validation class for package.xml - channel-level advanced validation
* @author Greg Beaver <cellog@php.net>
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license.php New BSD License
* @version Release: 1.9.4
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
* @var PEAR_PackageFile_v1|PEAR_PackageFile_v2
* @var int one of the PEAR_VALIDATE_* constants
var $_state = PEAR_VALIDATE_NORMAL;
* Format: ('error' => array('field' => name, 'reason' => reason), 'warning' => same)
var $_failures = array ('error' => array (), 'warning' => array ());
* Override this method to handle validation of normal package names
* @param string package name to validate
* @param string name of channel-specific validation package
if ($validatepackagename) {
return (bool) preg_match('/^[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*\\z/', $name);
* This validates a bundle name, and bundle names must conform
* to the PEAR naming convention, so the method is final and static.
* Determine whether $state represents a valid stability level
return in_array($state, array ('snapshot', 'devel', 'alpha', 'beta', 'stable'));
* Get a list of valid stability levels
return array ('snapshot', 'devel', 'alpha', 'beta', 'stable');
* Determine whether a version is a properly formatted version number that can be used
* @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
$this->_packagexml = &$pf;
function _addFailure ($field, $reason)
$this->_failures['errors'][] = array ('field' => $field, 'reason' => $reason);
function _addWarning ($field, $reason)
$this->_failures['warnings'][] = array ('field' => $field, 'reason' => $reason);
$failures = $this->_failures;
$this->_failures = array ('warnings' => array (), 'errors' => array ());
* @param int one of the PEAR_VALIDATE_* constants
if (!isset ($this->_packagexml)) {
$this->_failures = array ('warnings' => array (), 'errors' => array ());
if ($this->_packagexml->getPackagexmlVersion () == '1.0') {
} elseif ($this->_packagexml->getPackagexmlVersion () == '2.0' ||
$this->_packagexml->getPackagexmlVersion () == '2.1') {
//$this->validateGlobalTasks();
return !((bool) count($this->_failures['errors']));
if (($this->_packagexml->getPackagexmlVersion () == '2.0' ||
$this->_packagexml->getPackagexmlVersion () == '2.1') &&
$this->_packagexml->getExtends ()) {
$version = $this->_packagexml->getVersion () . '';
$name = $this->_packagexml->getPackage ();
$this->_addWarning ('package', " package $name extends package " .
$this->_packagexml->getExtends () . ' and so the name should ' .
'have a postfix equal to the major version like "' .
$this->_packagexml->getExtends () . $test . '"');
$this->_packagexml->getExtends ()) {
$this->_addWarning ('package', " package $name extends package " .
$this->_packagexml->getExtends () . ' and so the name must ' .
'be an extension like "' . $this->_packagexml->getExtends () .
$this->_addFailure ('name', 'package name "' .
$this->_packagexml->getPackage () . '" is invalid');
if (!$this->validVersion($this->_packagexml->getVersion ())) {
$this->_addFailure ('version',
'Invalid version number "' . $this->_packagexml->getVersion () . '"');
$version = $this->_packagexml->getVersion ();
$versioncomponents = explode('.', $version);
if (count($versioncomponents) != 3 ) {
$this->_addWarning ('version',
'A version number should have 3 decimals (x.y.z)');
$name = $this->_packagexml->getPackage ();
// version must be based upon state
switch ($this->_packagexml->getState ()) {
if ($versioncomponents[0 ] . 'a' == '0a') {
if ($versioncomponents[0 ] == 0 ) {
$versioncomponents[0 ] = '0';
$this->_addWarning ('version',
'version "' . $version . '" should be "' .
implode('.' ,$versioncomponents) . '"');
$this->_addWarning ('version',
'packages with devel stability must be < version 1.0.0');
// check for a package that extends a package,
if (substr($versioncomponents[2 ], 1 , 2 ) == 'rc') {
$this->_addFailure ('version', 'Release Candidate versions ' .
'must have capital RC, not lower-case rc');
if (!$this->_packagexml->getExtends ()) {
if ($versioncomponents[0 ] == '1') {
if ($versioncomponents[2 ]{0 } == '0') {
if ($versioncomponents[2 ] == '0') {
$this->_addWarning ('version',
'version 1.' . $versioncomponents[1 ] .
'.0 probably should not be alpha or beta');
} elseif (strlen($versioncomponents[2 ]) > 1 ) {
// version 1.*.0RC1 or 1.*.0beta24 etc.
$this->_addWarning ('version',
'version 1.' . $versioncomponents[1 ] .
'.0 probably should not be alpha or beta');
$this->_addWarning ('version',
'bugfix versions (1.3.x where x > 0) probably should ' .
} elseif ($versioncomponents[0 ] != '0') {
$this->_addWarning ('version',
'major versions greater than 1 are not allowed for packages ' .
'without an <extends> tag or an identical postfix (foo2 v2.0.0)');
if ($versioncomponents[0 ] . 'a' == '0a') {
if ($versioncomponents[0 ] == 0 ) {
$versioncomponents[0 ] = '0';
$this->_addWarning ('version',
'version "' . $version . '" should be "' .
implode('.' ,$versioncomponents) . '"');
$vlen = strlen($versioncomponents[0 ] . '');
if (($versioncomponents[0 ] != 0 ) && $majver != $versioncomponents[0 ]) {
$this->_addWarning ('version', 'first version number "' .
$versioncomponents[0 ] . '" must match the postfix of ' .
'package name "' . $name . '" (' .
if ($versioncomponents[0 ] == $majver) {
if ($versioncomponents[2 ]{0 } == '0') {
if ($versioncomponents[2 ] == '0') {
$this->_addWarning ('version',
" version $majver." . $versioncomponents[1 ] .
'.0 probably should not be alpha or beta');
} elseif (strlen($versioncomponents[2 ]) > 1 ) {
// version 2.*.0RC1 or 2.*.0beta24 etc.
$this->_addWarning ('version',
" version $majver." . $versioncomponents[1 ] .
'.0 cannot be alpha or beta');
$this->_addWarning ('version',
" bugfix versions ($majver.x.y where y > 0) should " .
} elseif ($versioncomponents[0 ] != '0') {
$this->_addWarning ('version',
" only versions 0.x.y and $majver.x.y are allowed for alpha/beta releases" );
if ($versioncomponents[0 ] . 'a' == '0a') {
if ($versioncomponents[0 ] == 0 ) {
$versioncomponents[0 ] = '0';
$this->_addWarning ('version',
'version "' . $version . '" should be "' .
implode('.' ,$versioncomponents) . '"');
if ($versioncomponents[0 ] == '0') {
$this->_addWarning ('version', 'versions less than 1.0.0 cannot ' .
$versioncomponents[2 ])) {
$this->_addWarning ('version', 'version "' . $version . '" or any ' .
'RC/beta/alpha version cannot be stable');
// check for a package that extends a package,
if ($this->_packagexml->getExtends ()) {
$vlen = strlen($versioncomponents[0 ] . '');
if (($versioncomponents[0 ] != 0 ) && $majver != $versioncomponents[0 ]) {
$this->_addWarning ('version', 'first version number "' .
$versioncomponents[0 ] . '" must match the postfix of ' .
'package name "' . $name . '" (' .
} elseif ($versioncomponents[0 ] > 1 ) {
$this->_addWarning ('version', 'major version x in x.y.z may not be greater than ' .
'1 for any package that does not have an <extends> tag');
// maintainers can only be truly validated server-side for most channels
// but allow this customization for those who wish it
$this->_packagexml->getDate (), $res) ||
$this->_addFailure ('date', 'invalid release date "' .
$this->_packagexml->getDate () . '"');
$this->_packagexml->getDate () != date('Y-m-d')) {
$this->_addWarning ('date', 'Release Date "' .
$this->_packagexml->getDate () . '" is not today');
if (!$this->_packagexml->getTime ()) {
// default of no time value set
// packager automatically sets time, so only validate if pear validate is called
$this->_packagexml->getTime ())) {
$this->_addFailure ('time', 'invalid release time "' .
$this->_packagexml->getTime () . '"');
$result = preg_match('|\d{2}\:\d{2}\:\d{2}|', $this->_packagexml->getTime (), $matches);
if ($result === false || empty ($matches)) {
$this->_addFailure ('time', 'invalid release time "' .
$this->_packagexml->getTime () . '"');
// this is the closest to "final" php4 can get
if (strtolower($this->_packagexml->getState () == 'rc')) {
$this->_addFailure ('state', 'RC is not a state, it is a version ' .
'postfix, use ' . $this->_packagexml->getVersion () . 'RC1, state beta');
$this->_addFailure ('state', 'invalid release state "' .
$this->_packagexml->getState () . '", must be one of: ' .
$packagestability = $this->_packagexml->getState ();
$apistability = $this->_packagexml->getState ('api');
$this->_addFailure ('state', 'invalid release stability "' .
$this->_packagexml->getState () . '", must be one of: ' .
if (!in_array($apistability, $apistates)) {
$this->_addFailure ('state', 'invalid API stability "' .
$this->_packagexml->getState ('api') . '", must be one of: ' .
* for package.xml 2.0 only - channels can't use package.xml 1.0
* for package.xml 1.0 only
function _validateFilelist ()
return true; // placeholder for now
* for package.xml 2.0 only
return true; // placeholder for now
* for package.xml 2.0 only
return true; // placeholder for now
Documentation generated on Wed, 06 Jul 2011 23:31:39 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.
|