Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_Validate Class Reference
Inheritance diagram for PEAR_Validate:

Public Member Functions

 _addFailure ($field, $reason)
 _addWarning ($field, $reason)
 _validateFilelist ()
 _validPackageName ($name)
 getFailures ()
 setPackageFile (&$pf)
 validate ($state=null)
 validateChangelog ()
 validateDate ()
 validateDependencies ()
 validateDeps ()
 validateDescription ()
 validateFilelist ()
 validateLicense ()
 validateMainFilelist ()
 validateMaintainers ()
 validateNotes ()
 validatePackageName ()
 validateReleaseFilelist ()
 validateStability ()
 validateState ()
 validateSummary ()
 validateTime ()
 validateVersion ()
 validPackageName ($name, $validatepackagename=false)

Static Public Member Functions

static getValidStates ()
static validGroupName ($name)
static validState ($state)
static validVersion ($ver)

Data Fields

 $_failures = array('error' => array(), 'warning' => array())
 $_packagexml
 $_state = PEAR_VALIDATE_NORMAL
 $packageregex = _PEAR_COMMON_PACKAGE_NAME_PREG

Detailed Description

Definition at line 38 of file Validate.php.

Member Function Documentation

◆ _addFailure()

_addFailure ( $field,
$reason )

@access private

Definition at line 137 of file Validate.php.

138 {
139 $this->_failures['errors'][] = array('field' => $field, 'reason' => $reason);
140 }

Referenced by validateDate(), validatePackageName(), validateStability(), validateState(), validateTime(), validateVersion(), and PEAR_Validator_PECL\validateVersion().

Here is the caller graph for this function:

◆ _addWarning()

_addWarning ( $field,
$reason )

@access private

Definition at line 145 of file Validate.php.

146 {
147 $this->_failures['warnings'][] = array('field' => $field, 'reason' => $reason);
148 }

Referenced by validateDate(), validatePackageName(), PEAR_Validator_PECL\validatePackageName(), and validateVersion().

Here is the caller graph for this function:

◆ _validateFilelist()

_validateFilelist ( )

for package.xml 1.0 only @access private

Definition at line 579 of file Validate.php.

580 {
581 return true; // placeholder for now
582 }

◆ _validPackageName()

_validPackageName ( $name)

Override this method to handle validation of normal package names

Parameters
string
Returns
bool @access protected

Definition at line 62 of file Validate.php.

63 {
64 return (bool) preg_match('/^' . $this->packageregex . '\\z/', $name);
65 }

Referenced by validPackageName().

Here is the caller graph for this function:

◆ getFailures()

getFailures ( )

Definition at line 150 of file Validate.php.

151 {
152 $failures = $this->_failures;
153 $this->_failures = array('warnings' => array(), 'errors' => array());
154 return $failures;
155 }

References $_failures.

◆ getValidStates()

getValidStates ( )
static

Get a list of valid stability levels

Returns
array @final

Definition at line 109 of file Validate.php.

110 {
111 return array('snapshot', 'devel', 'alpha', 'beta', 'stable');
112 }

Referenced by validateStability(), and validateState().

Here is the caller graph for this function:

◆ setPackageFile()

setPackageFile ( & $pf)
Parameters
PEAR_PackageFile_v1|PEAR_PackageFile_v2

Definition at line 129 of file Validate.php.

130 {
131 $this->_packagexml = &$pf;
132 }

◆ validate()

validate ( $state = null)
Parameters
intone of the PEAR_VALIDATE_* constants

Definition at line 160 of file Validate.php.

161 {
162 if (!isset($this->_packagexml)) {
163 return false;
164 }
165 if ($state !== null) {
166 $this->_state = $state;
167 }
168 $this->_failures = array('warnings' => array(), 'errors' => array());
169 $this->validatePackageName();
170 $this->validateVersion();
171 $this->validateMaintainers();
172 $this->validateDate();
173 $this->validateSummary();
174 $this->validateDescription();
175 $this->validateLicense();
176 $this->validateNotes();
177 if ($this->_packagexml->getPackagexmlVersion() == '1.0') {
178 $this->validateState();
179 $this->validateFilelist();
180 } elseif ($this->_packagexml->getPackagexmlVersion() == '2.0' ||
181 $this->_packagexml->getPackagexmlVersion() == '2.1') {
182 $this->validateTime();
183 $this->validateStability();
184 $this->validateDeps();
185 $this->validateMainFilelist();
187 //$this->validateGlobalTasks();
188 $this->validateChangelog();
189 }
190 return !((bool) count($this->_failures['errors']));
191 }
validateReleaseFilelist()
Definition Validate.php:597

References validateChangelog(), validateDate(), validateDeps(), validateDescription(), validateFilelist(), validateLicense(), validateMainFilelist(), validateMaintainers(), validateNotes(), validatePackageName(), validateReleaseFilelist(), validateStability(), validateState(), validateSummary(), validateTime(), and validateVersion().

Here is the call graph for this function:

◆ validateChangelog()

validateChangelog ( )

@access protected

Definition at line 605 of file Validate.php.

606 {
607 return true;
608 }

Referenced by validate().

Here is the caller graph for this function:

◆ validateDate()

validateDate ( )

@access protected

Definition at line 436 of file Validate.php.

437 {
438 if ($this->_state == PEAR_VALIDATE_NORMAL ||
439 $this->_state == PEAR_VALIDATE_PACKAGING) {
440
441 if (!preg_match('/(\d\d\d\d)\-(\d\d)\-(\d\d)/',
442 $this->_packagexml->getDate(), $res) ||
443 count($res) < 4
444 || !checkdate($res[2], $res[3], $res[1])
445 ) {
446 $this->_addFailure('date', 'invalid release date "' .
447 $this->_packagexml->getDate() . '"');
448 return false;
449 }
450
451 if ($this->_state == PEAR_VALIDATE_PACKAGING &&
452 $this->_packagexml->getDate() != date('Y-m-d')) {
453 $this->_addWarning('date', 'Release Date "' .
454 $this->_packagexml->getDate() . '" is not today');
455 }
456 }
457 return true;
458 }
const PEAR_VALIDATE_PACKAGING
Definition Validate.php:22
const PEAR_VALIDATE_NORMAL
Definition Validate.php:20
_addFailure($field, $reason)
Definition Validate.php:137
_addWarning($field, $reason)
Definition Validate.php:145

References _addFailure(), _addWarning(), PEAR_VALIDATE_NORMAL, and PEAR_VALIDATE_PACKAGING.

Referenced by validate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateDependencies()

validateDependencies ( )

for package.xml 2.0 only - channels can't use package.xml 1.0 @access protected

Definition at line 570 of file Validate.php.

571 {
572 return true;
573 }

◆ validateDeps()

validateDeps ( )

@access protected

Definition at line 621 of file Validate.php.

622 {
623 return true;
624 }

Referenced by validate().

Here is the caller graph for this function:

◆ validateDescription()

validateDescription ( )

@access protected

Definition at line 545 of file Validate.php.

546 {
547 return true;
548 }

Referenced by validate().

Here is the caller graph for this function:

◆ validateFilelist()

validateFilelist ( )

@access protected

Definition at line 613 of file Validate.php.

614 {
615 return true;
616 }

Referenced by validate().

Here is the caller graph for this function:

◆ validateLicense()

validateLicense ( )

@access protected

Definition at line 553 of file Validate.php.

554 {
555 return true;
556 }

Referenced by validate().

Here is the caller graph for this function:

◆ validateMainFilelist()

validateMainFilelist ( )

for package.xml 2.0 only @access protected

Definition at line 588 of file Validate.php.

589 {
590 return true; // placeholder for now
591 }

Referenced by validate().

Here is the caller graph for this function:

◆ validateMaintainers()

validateMaintainers ( )

@access protected

Definition at line 426 of file Validate.php.

427 {
428 // maintainers can only be truly validated server-side for most channels
429 // but allow this customization for those who wish it
430 return true;
431 }

Referenced by validate().

Here is the caller graph for this function:

◆ validateNotes()

validateNotes ( )

@access protected

Definition at line 561 of file Validate.php.

562 {
563 return true;
564 }

Referenced by validate().

Here is the caller graph for this function:

◆ validatePackageName()

validatePackageName ( )

@access protected

Reimplemented in PEAR_Validator_PECL.

Definition at line 196 of file Validate.php.

197 {
198 if ($this->_state == PEAR_VALIDATE_PACKAGING ||
199 $this->_state == PEAR_VALIDATE_NORMAL) {
200 if (($this->_packagexml->getPackagexmlVersion() == '2.0' ||
201 $this->_packagexml->getPackagexmlVersion() == '2.1') &&
202 $this->_packagexml->getExtends()) {
203 $version = $this->_packagexml->getVersion() . '';
204 $name = $this->_packagexml->getPackage();
205 $a = explode('.', $version);
206 $test = array_shift($a);
207 if ($test == '0') {
208 return true;
209 }
210 $vlen = strlen($test);
211 $majver = substr($name, strlen($name) - $vlen);
212 while ($majver && !is_numeric($majver[0])) {
213 $majver = substr($majver, 1);
214 }
215 if ($majver != $test) {
216 $this->_addWarning('package', "package $name extends package " .
217 $this->_packagexml->getExtends() . ' and so the name should ' .
218 'have a postfix equal to the major version like "' .
219 $this->_packagexml->getExtends() . $test . '"');
220 return true;
221 } elseif (substr($name, 0, strlen($name) - $vlen) !=
222 $this->_packagexml->getExtends()) {
223 $this->_addWarning('package', "package $name extends package " .
224 $this->_packagexml->getExtends() . ' and so the name must ' .
225 'be an extension like "' . $this->_packagexml->getExtends() .
226 $test . '"');
227 return true;
228 }
229 }
230 }
231 if (!$this->validPackageName($this->_packagexml->getPackage())) {
232 $this->_addFailure('name', 'package name "' .
233 $this->_packagexml->getPackage() . '" is invalid');
234 return false;
235 }
236 }
validPackageName($name, $validatepackagename=false)
Definition Validate.php:72

References _addFailure(), _addWarning(), PEAR_VALIDATE_NORMAL, PEAR_VALIDATE_PACKAGING, and validPackageName().

Referenced by validate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateReleaseFilelist()

validateReleaseFilelist ( )

for package.xml 2.0 only @access protected

Definition at line 597 of file Validate.php.

598 {
599 return true; // placeholder for now
600 }

Referenced by validate().

Here is the caller graph for this function:

◆ validateStability()

validateStability ( )

@access protected

Definition at line 512 of file Validate.php.

513 {
514 $ret = true;
515 $packagestability = $this->_packagexml->getState();
516 $apistability = $this->_packagexml->getState('api');
517 if (!PEAR_Validate::validState($packagestability)) {
518 $this->_addFailure('state', 'invalid release stability "' .
519 $this->_packagexml->getState() . '", must be one of: ' .
520 implode(', ', PEAR_Validate::getValidStates()));
521 $ret = false;
522 }
523 $apistates = PEAR_Validate::getValidStates();
524 array_shift($apistates); // snapshot is not allowed
525 if (!in_array($apistability, $apistates)) {
526 $this->_addFailure('state', 'invalid API stability "' .
527 $this->_packagexml->getState('api') . '", must be one of: ' .
528 implode(', ', $apistates));
529 $ret = false;
530 }
531 return $ret;
532 }
static validState($state)
Definition Validate.php:99
static getValidStates()
Definition Validate.php:109

References _addFailure(), getValidStates(), and validState().

Referenced by validate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateState()

validateState ( )

@access protected

Definition at line 493 of file Validate.php.

494 {
495 // this is the closest to "final" php4 can get
496 if (!PEAR_Validate::validState($this->_packagexml->getState())) {
497 if (strtolower($this->_packagexml->getState() == 'rc')) {
498 $this->_addFailure('state', 'RC is not a state, it is a version ' .
499 'postfix, use ' . $this->_packagexml->getVersion() . 'RC1, state beta');
500 }
501 $this->_addFailure('state', 'invalid release state "' .
502 $this->_packagexml->getState() . '", must be one of: ' .
503 implode(', ', PEAR_Validate::getValidStates()));
504 return false;
505 }
506 return true;
507 }

References _addFailure(), getValidStates(), and validState().

Referenced by validate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateSummary()

validateSummary ( )

@access protected

Definition at line 537 of file Validate.php.

538 {
539 return true;
540 }

Referenced by validate().

Here is the caller graph for this function:

◆ validateTime()

validateTime ( )

@access protected

Definition at line 463 of file Validate.php.

464 {
465 if (!$this->_packagexml->getTime()) {
466 // default of no time value set
467 return true;
468 }
469
470 // packager automatically sets time, so only validate if pear validate is called
471 if ($this->_state = PEAR_VALIDATE_NORMAL) {
472 if (!preg_match('/\d\d:\d\d:\d\d/',
473 $this->_packagexml->getTime())) {
474 $this->_addFailure('time', 'invalid release time "' .
475 $this->_packagexml->getTime() . '"');
476 return false;
477 }
478
479 $result = preg_match('|\d{2}\:\d{2}\:\d{2}|', $this->_packagexml->getTime(), $matches);
480 if ($result === false || empty($matches)) {
481 $this->_addFailure('time', 'invalid release time "' .
482 $this->_packagexml->getTime() . '"');
483 return false;
484 }
485 }
486
487 return true;
488 }
$result

References $result, _addFailure(), and PEAR_VALIDATE_NORMAL.

Referenced by validate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateVersion()

validateVersion ( )

@access protected

Reimplemented in PEAR_Validator_PECL.

Definition at line 241 of file Validate.php.

242 {
243 if ($this->_state != PEAR_VALIDATE_PACKAGING) {
244 if (!$this->validVersion($this->_packagexml->getVersion())) {
245 $this->_addFailure('version',
246 'Invalid version number "' . $this->_packagexml->getVersion() . '"');
247 }
248 return false;
249 }
250 $version = $this->_packagexml->getVersion();
251 $versioncomponents = explode('.', $version);
252 if (count($versioncomponents) != 3) {
253 $this->_addWarning('version',
254 'A version number should have 3 decimals (x.y.z)');
255 return true;
256 }
257 $name = $this->_packagexml->getPackage();
258 // version must be based upon state
259 switch ($this->_packagexml->getState()) {
260 case 'snapshot' :
261 return true;
262 case 'devel' :
263 if ($versioncomponents[0] . 'a' == '0a') {
264 return true;
265 }
266 if ($versioncomponents[0] == 0) {
267 $versioncomponents[0] = '0';
268 $this->_addWarning('version',
269 'version "' . $version . '" should be "' .
270 implode('.' ,$versioncomponents) . '"');
271 } else {
272 $this->_addWarning('version',
273 'packages with devel stability must be < version 1.0.0');
274 }
275 return true;
276 break;
277 case 'alpha' :
278 case 'beta' :
279 // check for a package that extends a package,
280 // like Foo and Foo2
281 if ($this->_state == PEAR_VALIDATE_PACKAGING) {
282 if (substr($versioncomponents[2], 1, 2) == 'rc') {
283 $this->_addFailure('version', 'Release Candidate versions ' .
284 'must have capital RC, not lower-case rc');
285 return false;
286 }
287 }
288 if (!$this->_packagexml->getExtends()) {
289 if ($versioncomponents[0] == '1') {
290 if ($versioncomponents[2][0] == '0') {
291 if ($versioncomponents[2] == '0') {
292 // version 1.*.0000
293 $this->_addWarning('version',
294 'version 1.' . $versioncomponents[1] .
295 '.0 probably should not be alpha or beta');
296 return true;
297 } elseif (strlen($versioncomponents[2]) > 1) {
298 // version 1.*.0RC1 or 1.*.0beta24 etc.
299 return true;
300 } else {
301 // version 1.*.0
302 $this->_addWarning('version',
303 'version 1.' . $versioncomponents[1] .
304 '.0 probably should not be alpha or beta');
305 return true;
306 }
307 } else {
308 $this->_addWarning('version',
309 'bugfix versions (1.3.x where x > 0) probably should ' .
310 'not be alpha or beta');
311 return true;
312 }
313 } elseif ($versioncomponents[0] != '0') {
314 $this->_addWarning('version',
315 'major versions greater than 1 are not allowed for packages ' .
316 'without an <extends> tag or an identical postfix (foo2 v2.0.0)');
317 return true;
318 }
319 if ($versioncomponents[0] . 'a' == '0a') {
320 return true;
321 }
322 if ($versioncomponents[0] == 0) {
323 $versioncomponents[0] = '0';
324 $this->_addWarning('version',
325 'version "' . $version . '" should be "' .
326 implode('.' ,$versioncomponents) . '"');
327 }
328 } else {
329 $vlen = strlen($versioncomponents[0] . '');
330 $majver = substr($name, strlen($name) - $vlen);
331 while ($majver && !is_numeric($majver[0])) {
332 $majver = substr($majver, 1);
333 }
334 if (($versioncomponents[0] != 0) && $majver != $versioncomponents[0]) {
335 $this->_addWarning('version', 'first version number "' .
336 $versioncomponents[0] . '" must match the postfix of ' .
337 'package name "' . $name . '" (' .
338 $majver . ')');
339 return true;
340 }
341 if ($versioncomponents[0] == $majver) {
342 if ($versioncomponents[2][0] == '0') {
343 if ($versioncomponents[2] == '0') {
344 // version 2.*.0000
345 $this->_addWarning('version',
346 "version $majver." . $versioncomponents[1] .
347 '.0 probably should not be alpha or beta');
348 return false;
349 } elseif (strlen($versioncomponents[2]) > 1) {
350 // version 2.*.0RC1 or 2.*.0beta24 etc.
351 return true;
352 } else {
353 // version 2.*.0
354 $this->_addWarning('version',
355 "version $majver." . $versioncomponents[1] .
356 '.0 cannot be alpha or beta');
357 return true;
358 }
359 } else {
360 $this->_addWarning('version',
361 "bugfix versions ($majver.x.y where y > 0) should " .
362 'not be alpha or beta');
363 return true;
364 }
365 } elseif ($versioncomponents[0] != '0') {
366 $this->_addWarning('version',
367 "only versions 0.x.y and $majver.x.y are allowed for alpha/beta releases");
368 return true;
369 }
370 if ($versioncomponents[0] . 'a' == '0a') {
371 return true;
372 }
373 if ($versioncomponents[0] == 0) {
374 $versioncomponents[0] = '0';
375 $this->_addWarning('version',
376 'version "' . $version . '" should be "' .
377 implode('.' ,$versioncomponents) . '"');
378 }
379 }
380 return true;
381 break;
382 case 'stable' :
383 if ($versioncomponents[0] == '0') {
384 $this->_addWarning('version', 'versions less than 1.0.0 cannot ' .
385 'be stable');
386 return true;
387 }
388 if (!is_numeric($versioncomponents[2])) {
389 if (preg_match('/\d+(rc|a|alpha|b|beta)\d*/i',
390 $versioncomponents[2])) {
391 $this->_addWarning('version', 'version "' . $version . '" or any ' .
392 'RC/beta/alpha version cannot be stable');
393 return true;
394 }
395 }
396 // check for a package that extends a package,
397 // like Foo and Foo2
398 if ($this->_packagexml->getExtends()) {
399 $vlen = strlen($versioncomponents[0] . '');
400 $majver = substr($name, strlen($name) - $vlen);
401 while ($majver && !is_numeric($majver[0])) {
402 $majver = substr($majver, 1);
403 }
404 if (($versioncomponents[0] != 0) && $majver != $versioncomponents[0]) {
405 $this->_addWarning('version', 'first version number "' .
406 $versioncomponents[0] . '" must match the postfix of ' .
407 'package name "' . $name . '" (' .
408 $majver . ')');
409 return true;
410 }
411 } elseif ($versioncomponents[0] > 1) {
412 $this->_addWarning('version', 'major version x in x.y.z may not be greater than ' .
413 '1 for any package that does not have an <extends> tag');
414 }
415 return true;
416 break;
417 default :
418 return false;
419 break;
420 }
421 }
static validVersion($ver)
Definition Validate.php:121

References _addFailure(), _addWarning(), PEAR_VALIDATE_PACKAGING, and validVersion().

Referenced by validate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validGroupName()

validGroupName ( $name)
static

This validates a bundle name, and bundle names must conform to the PEAR naming convention, so the method is final and static.

Parameters
string@final

Definition at line 88 of file Validate.php.

89 {
90 return (bool) preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '\\z/', $name);
91 }
const _PEAR_COMMON_PACKAGE_NAME_PREG
Definition Common.php:28

References _PEAR_COMMON_PACKAGE_NAME_PREG.

Referenced by PEAR_PackageFile_v2_Validator\_validateDependencies(), and PEAR_Registry\parsePackageName().

Here is the caller graph for this function:

◆ validPackageName()

validPackageName ( $name,
$validatepackagename = false )
Parameters
stringpackage name to validate
stringname of channel-specific validation package @final

Definition at line 72 of file Validate.php.

73 {
74 if ($validatepackagename) {
75 if (strtolower($name) == strtolower($validatepackagename)) {
76 return (bool) preg_match('/^[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*\\z/', $name);
77 }
78 }
79 return $this->_validPackageName($name);
80 }
_validPackageName($name)
Definition Validate.php:62

References _validPackageName().

Referenced by validatePackageName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validState()

validState ( $state)
static

Determine whether $state represents a valid stability level

Parameters
string
Returns
bool @final

Definition at line 99 of file Validate.php.

100 {
101 return in_array($state, array('snapshot', 'devel', 'alpha', 'beta', 'stable'));
102 }

Referenced by validateStability(), and validateState().

Here is the caller graph for this function:

◆ validVersion()

validVersion ( $ver)
static

Determine whether a version is a properly formatted version number that can be used by version_compare

Parameters
string
Returns
bool @final

Definition at line 121 of file Validate.php.

122 {
123 return (bool) preg_match(PEAR_COMMON_PACKAGE_VERSION_PREG, $ver);
124 }
const PEAR_COMMON_PACKAGE_VERSION_PREG
Definition Common.php:33

References PEAR_COMMON_PACKAGE_VERSION_PREG.

Referenced by validateVersion().

Here is the caller graph for this function:

Field Documentation

◆ $_failures

$_failures = array('error' => array(), 'warning' => array())

Definition at line 54 of file Validate.php.

Referenced by getFailures().

◆ $_packagexml

$_packagexml

Definition at line 44 of file Validate.php.

◆ $_state

Definition at line 48 of file Validate.php.

◆ $packageregex

Definition at line 40 of file Validate.php.


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/PEAR/Validate.php