cvs: pear-core /PEAR Validate.php

From: Date: Fri, 10 Sep 2004 20:06:20 +0000
Subject: cvs: pear-core /PEAR Validate.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-23802@lists.php.net to get a copy of this message
cellog Fri Sep 10 16:06:20 2004 EDT Modified files: /pear-core/PEAR Validate.php Log: use "i" switch (Martin) add validation for state and v2.0 stability http://cvs.php.net/diff.php/pear-core/PEAR/Validate.php?r1=1.8&r2=1.9&ty=u Index: pear-core/PEAR/Validate.php diff -u pear-core/PEAR/Validate.php:1.8 pear-core/PEAR/Validate.php:1.9 --- pear-core/PEAR/Validate.php:1.8 Fri Sep 10 15:52:23 2004 +++ pear-core/PEAR/Validate.php Fri Sep 10 16:06:16 2004 @@ -16,7 +16,7 @@ // | Authors: Gregory Beaver <cellog@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Validate.php,v 1.8 2004/09/10 19:52:23 cellog Exp $ +// $Id: Validate.php,v 1.9 2004/09/10 20:06:16 cellog Exp $ define('PEAR_VALIDATE_INSTALLING', 1); define('PEAR_VALIDATE_NORMAL', 3); define('PEAR_VALIDATE_PACKAGING', 7); @@ -31,7 +31,12 @@ * @var int one of the PEAR_VALIDATE_* constants */ var $_state = PEAR_VALIDATE_NORMAL; - + /** + * Valid release states + * @var array + * @access private + */ + var $_validStates = array('alpha','beta','stable','snapshot','devel'); /** * Format: ('error' => array('field' => name, 'reason' => reason), 'warning' => same) * @var array @@ -82,6 +87,11 @@ } $this->validatePackageName(); $this->validateVersion(); + if ($this->_packagexml->getPackagexmlVersion() == '1.0') { + $this->validateState($this->_packagexml->getState()); + } elseif ($this->_packagexml->getPackagexmlVersion() == '2.0') { + $this->validateStability($this->_packagexml->getStability()); + } } function validatePackageName() @@ -184,7 +194,7 @@ return false; } if (!is_numeric($versioncomponents[2])) { - if (preg_match('/\n+(RC|rc|a|alpha|A|ALPHA|b|beta|B|BETA)\n*/', + if (preg_match('/\n+(rc|a|alpha||b|beta|)\n*/i', $versioncomponents[2])) { $this->_addFailure('version', 'RC/beta/alpha cannot be stable'); return false; @@ -196,6 +206,37 @@ return false; break; } + } + + function validateState() + { + if (!in_array($this->_packagexml->getState(), $this->_validStates)) { + $this->_addFailure('state', 'release state "' . + $this->_packagexml->getState() . '" is not valid, must be one of: ' . + implode(', ', $this->_validStates)); + return false; + } + return true; + } + + function validateStability() + { + $ret = true; + $packagestability = $this->_packagexml->getState(); + $apistability = $this->_packagexml->getState('api'); + if (!in_array($packagestability, $this->_validStates)) { + $this->_addFailure('state', 'package stability "' . + $this->_packagexml->getState() . '" is not valid, must be one of: ' . + implode(', ', $this->_validStates)); + $ret = false; + } + if (!in_array($apistability, $this->_validStates)) { + $this->_addFailure('state', 'API stability "' . + $this->_packagexml->getState() . '" is not valid, must be one of: ' . + implode(', ', $this->_validStates)); + $ret = false; + } + return $ret; } } ?>

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