cvs: pear-core /PEAR ChannelFile.php Registry.php Validate.php /PEAR/PackageFile/PHP4 v1.php v2.php /PEAR/PackageFile/v2 Validator.php
| From: | Greg Beaver | Date: | Wed, 03 Nov 2004 22:28:21 +0000 |
| Subject: | cvs: pear-core /PEAR ChannelFile.php Registry.php Validate.php /PEAR/PackageFile/PHP4 v1.php v2.php /PEAR/PackageFile/v2 Validator.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-1218@lists.php.net to get a copy of this message | ||
cellog Wed Nov 3 17:28:21 2004 EDT
Removed files:
/pear-core/PEAR/PackageFile/PHP4 v1.php v2.php
Modified files:
/pear-core/PEAR ChannelFile.php Registry.php Validate.php
/pear-core/PEAR/PackageFile/v2 Validator.php
Log:
remove defunct work on PHP4-only versions of PEAR_PackageFile_vX
allow . in channel validator packages. This will make it possible to guarantee
unique names as in:
package pear.chiaraquartet.net_Validate which is installed into directory:
pear.chiaraquartet.net/Validate.php
http://cvs.php.net/diff.php/pear-core/PEAR/ChannelFile.php?r1=1.28&r2=1.29&ty=u Index: pear-core/PEAR/ChannelFile.php diff -u pear-core/PEAR/ChannelFile.php:1.28 pear-core/PEAR/ChannelFile.php:1.29 --- pear-core/PEAR/ChannelFile.php:1.28 Wed Nov 3 16:53:33 2004 +++ pear-core/PEAR/ChannelFile.php Wed Nov 3 17:28:17 2004 @@ -16,7 +16,7 @@ // | Authors: Gregory Beaver <cellog@php.net> | // +----------------------------------------------------------------------+ // -// $Id: ChannelFile.php,v 1.28 2004/11/03 21:53:33 cellog Exp $ +// $Id: ChannelFile.php,v 1.29 2004/11/03 22:28:17 cellog Exp $ require_once 'PEAR/Common.php'; @@ -1617,17 +1617,18 @@ return $a; } if (isset($this->_channelInfo['validatepackage'])) { - if (!class_exists($this->_channelInfo['validatepackage']['name'])) { + if (!class_exists(str_replace('.', '_', + $this->_channelInfo['validatepackage']['name']))) { if ($this->isIncludeable(str_replace('_', '/', $this->_channelInfo['validatepackage']['name']) . '.php')) { include_once str_replace('_', '/', $this->_channelInfo['validatepackage']['name']) . '.php'; - $val = &new $this->_channelInfo['validatepackage']['name']; + $val = &new str_replace('.', '_', $this->_channelInfo['validatepackage']['name']); } else { return false; } } else { - $val = &new $this->_channelInfo['validatepackage']['name']; + $val = &new str_replace('.', '_', $this->_channelInfo['validatepackage']['name']); } } else { include_once 'PEAR/Validate.php'; http://cvs.php.net/diff.php/pear-core/PEAR/Registry.php?r1=1.79&r2=1.80&ty=u Index: pear-core/PEAR/Registry.php diff -u pear-core/PEAR/Registry.php:1.79 pear-core/PEAR/Registry.php:1.80 --- pear-core/PEAR/Registry.php:1.79 Wed Nov 3 16:49:40 2004 +++ pear-core/PEAR/Registry.php Wed Nov 3 17:28:17 2004 @@ -18,7 +18,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Registry.php,v 1.79 2004/11/03 21:49:40 cellog Exp $ +// $Id: Registry.php,v 1.80 2004/11/03 22:28:17 cellog Exp $ /* TODO: @@ -1598,8 +1598,9 @@ 'registry', null, null, $param); } $validate = $chan->getValidationObject(); + $vpackage = $chan->getValidationPackage(); // validate package name - if (!$validate->validPackageName($param['package'])) { + if (!$validate->validPackageName($param['package'], $vpackage['name'])) { return PEAR::raiseError('parsePackageName(): invalid package name "' . $param['package'] . '" in "' . $saveparam . '"', 'package', null, null, $param); http://cvs.php.net/diff.php/pear-core/PEAR/Validate.php?r1=1.19&r2=1.20&ty=u Index: pear-core/PEAR/Validate.php diff -u pear-core/PEAR/Validate.php:1.19 pear-core/PEAR/Validate.php:1.20 --- pear-core/PEAR/Validate.php:1.19 Wed Nov 3 16:51:11 2004 +++ pear-core/PEAR/Validate.php Wed Nov 3 17:28:17 2004 @@ -16,7 +16,7 @@ // | Authors: Gregory Beaver <cellog@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Validate.php,v 1.19 2004/11/03 21:51:11 cellog Exp $ +// $Id: Validate.php,v 1.20 2004/11/03 22:28:17 cellog Exp $ define('PEAR_VALIDATE_INSTALLING', 1); define('PEAR_VALIDATE_UNINSTALLING', 2); // this is not bit-mapped like the others define('PEAR_VALIDATE_NORMAL', 3); @@ -48,11 +48,27 @@ var $_failures = array('error' => array(), 'warning' => array()); /** + * Override this method to handle validation of normal package names * @param string + * @return bool + * @access protected */ - function validPackageName($name) + function _validPackageName($name) { - return (bool)preg_match('/^' . $this->packageregex . '$/', $name); + return (bool) preg_match('/^' . $this->packageregex . '$/', $name); + } + + /** + * @param string + */ + function validPackageName($name, $validatepackagename = false) + { + if ($validatepackagename) { + if (strtolower($name) == strtolower($validatepackagename)) { + return (bool) preg_match('/^[a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_]+)*$/', $name); + } + } + return $this->_validPackageName($name); } /** @@ -64,7 +80,7 @@ */ function validGroupName($name) { - return (bool)preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/', $name); + return (bool) preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/', $name); } function validState($state) http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v2/Validator.php?r1=1.3&r2=1.4&ty=u Index: pear-core/PEAR/PackageFile/v2/Validator.php diff -u pear-core/PEAR/PackageFile/v2/Validator.php:1.3 pear-core/PEAR/PackageFile/v2/Validator.php:1.4 --- pear-core/PEAR/PackageFile/v2/Validator.php:1.3 Mon Nov 1 23:52:55 2004 +++ pear-core/PEAR/PackageFile/v2/Validator.php Wed Nov 3 17:28:20 2004 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Validator.php,v 1.3 2004/11/02 04:52:55 cellog Exp $ +// $Id: Validator.php,v 1.4 2004/11/03 22:28:20 cellog Exp $ /** * Private validation class used by PEAR_PackageFile_v2 - do not use directly, its * sole purpose is to split up the PEAR/PackageFile/v2.php file to make it smaller @@ -145,17 +145,32 @@ if (!$chan) { $this->_unknownChannel($this->_pf->getChannel()); } else { + $valpack = $chan->getValidationPackage(); $validator = $chan->getValidationObject(); - $validator->setPackageFile($this->_pf); - $validator->validate($state); - $failures = $validator->getFailures(); - foreach ($failures['errors'] as $error) { - $this->_stack->push(__FUNCTION__, 'error', $error, - 'Channel validator error: field "%field%" - %reason%'); - } - foreach ($failures['warnings'] as $warning) { - $this->_stack->push(__FUNCTION__, 'warning', $warning, - 'Channel validator warning: field "%field%" - %reason%'); + if ($this->_pf->getPackage() != $valpack['name']) { + // only run these tests if we are not installing the validation package + if (!$validator) { + $this->_stack->push(__FUNCTION__, 'error', + array_merge( + array('channel' => $chan->getName(), + 'package' => $this->_pf->getPackage()), + $valpack + ), + 'package "%channel%/%package%" cannot be properly validated without ' . + 'validation package "%channel%/%name%-%version%"'); + return $this->_isValid = 0; + } + $validator->setPackageFile($this->_pf); + $validator->validate($state); + $failures = $validator->getFailures(); + foreach ($failures['errors'] as $error) { + $this->_stack->push(__FUNCTION__, 'error', $error, + 'Channel validator error: field "%field%" - %reason%'); + } + foreach ($failures['warnings'] as $warning) { + $this->_stack->push(__FUNCTION__, 'warning', $warning, + 'Channel validator warning: field "%field%" - %reason%'); + } } } }
http://cvs.php.net/diff.php/pear-core/PEAR/ChannelFile.php?r1=1.28&r2=1.29&ty=u Index: pear-core/PEAR/ChannelFile.php diff -u pear-core/PEAR/ChannelFile.php:1.28 pear-core/PEAR/ChannelFile.php:1.29 --- pear-core/PEAR/ChannelFile.php:1.28 Wed Nov 3 16:53:33 2004 +++ pear-core/PEAR/ChannelFile.php Wed Nov 3 17:28:17 2004 @@ -16,7 +16,7 @@ // | Authors: Gregory Beaver <cellog@php.net> | // +----------------------------------------------------------------------+ // -// $Id: ChannelFile.php,v 1.28 2004/11/03 21:53:33 cellog Exp $ +// $Id: ChannelFile.php,v 1.29 2004/11/03 22:28:17 cellog Exp $ require_once 'PEAR/Common.php'; @@ -1617,17 +1617,18 @@ return $a; } if (isset($this->_channelInfo['validatepackage'])) { - if (!class_exists($this->_channelInfo['validatepackage']['name'])) { + if (!class_exists(str_replace('.', '_', + $this->_channelInfo['validatepackage']['name']))) { if ($this->isIncludeable(str_replace('_', '/', $this->_channelInfo['validatepackage']['name']) . '.php')) { include_once str_replace('_', '/', $this->_channelInfo['validatepackage']['name']) . '.php'; - $val = &new $this->_channelInfo['validatepackage']['name']; + $val = &new str_replace('.', '_', $this->_channelInfo['validatepackage']['name']); } else { return false; } } else { - $val = &new $this->_channelInfo['validatepackage']['name']; + $val = &new str_replace('.', '_', $this->_channelInfo['validatepackage']['name']); } } else { include_once 'PEAR/Validate.php'; http://cvs.php.net/diff.php/pear-core/PEAR/Registry.php?r1=1.79&r2=1.80&ty=u Index: pear-core/PEAR/Registry.php diff -u pear-core/PEAR/Registry.php:1.79 pear-core/PEAR/Registry.php:1.80 --- pear-core/PEAR/Registry.php:1.79 Wed Nov 3 16:49:40 2004 +++ pear-core/PEAR/Registry.php Wed Nov 3 17:28:17 2004 @@ -18,7 +18,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Registry.php,v 1.79 2004/11/03 21:49:40 cellog Exp $ +// $Id: Registry.php,v 1.80 2004/11/03 22:28:17 cellog Exp $ /* TODO: @@ -1598,8 +1598,9 @@ 'registry', null, null, $param); } $validate = $chan->getValidationObject(); + $vpackage = $chan->getValidationPackage(); // validate package name - if (!$validate->validPackageName($param['package'])) { + if (!$validate->validPackageName($param['package'], $vpackage['name'])) { return PEAR::raiseError('parsePackageName(): invalid package name "' . $param['package'] . '" in "' . $saveparam . '"', 'package', null, null, $param); http://cvs.php.net/diff.php/pear-core/PEAR/Validate.php?r1=1.19&r2=1.20&ty=u Index: pear-core/PEAR/Validate.php diff -u pear-core/PEAR/Validate.php:1.19 pear-core/PEAR/Validate.php:1.20 --- pear-core/PEAR/Validate.php:1.19 Wed Nov 3 16:51:11 2004 +++ pear-core/PEAR/Validate.php Wed Nov 3 17:28:17 2004 @@ -16,7 +16,7 @@ // | Authors: Gregory Beaver <cellog@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Validate.php,v 1.19 2004/11/03 21:51:11 cellog Exp $ +// $Id: Validate.php,v 1.20 2004/11/03 22:28:17 cellog Exp $ define('PEAR_VALIDATE_INSTALLING', 1); define('PEAR_VALIDATE_UNINSTALLING', 2); // this is not bit-mapped like the others define('PEAR_VALIDATE_NORMAL', 3); @@ -48,11 +48,27 @@ var $_failures = array('error' => array(), 'warning' => array()); /** + * Override this method to handle validation of normal package names * @param string + * @return bool + * @access protected */ - function validPackageName($name) + function _validPackageName($name) { - return (bool)preg_match('/^' . $this->packageregex . '$/', $name); + return (bool) preg_match('/^' . $this->packageregex . '$/', $name); + } + + /** + * @param string + */ + function validPackageName($name, $validatepackagename = false) + { + if ($validatepackagename) { + if (strtolower($name) == strtolower($validatepackagename)) { + return (bool) preg_match('/^[a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_]+)*$/', $name); + } + } + return $this->_validPackageName($name); } /** @@ -64,7 +80,7 @@ */ function validGroupName($name) { - return (bool)preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/', $name); + return (bool) preg_match('/^' . _PEAR_COMMON_PACKAGE_NAME_PREG . '$/', $name); } function validState($state) http://cvs.php.net/diff.php/pear-core/PEAR/PackageFile/v2/Validator.php?r1=1.3&r2=1.4&ty=u Index: pear-core/PEAR/PackageFile/v2/Validator.php diff -u pear-core/PEAR/PackageFile/v2/Validator.php:1.3 pear-core/PEAR/PackageFile/v2/Validator.php:1.4 --- pear-core/PEAR/PackageFile/v2/Validator.php:1.3 Mon Nov 1 23:52:55 2004 +++ pear-core/PEAR/PackageFile/v2/Validator.php Wed Nov 3 17:28:20 2004 @@ -17,7 +17,7 @@ // | | // +----------------------------------------------------------------------+ // -// $Id: Validator.php,v 1.3 2004/11/02 04:52:55 cellog Exp $ +// $Id: Validator.php,v 1.4 2004/11/03 22:28:20 cellog Exp $ /** * Private validation class used by PEAR_PackageFile_v2 - do not use directly, its * sole purpose is to split up the PEAR/PackageFile/v2.php file to make it smaller @@ -145,17 +145,32 @@ if (!$chan) { $this->_unknownChannel($this->_pf->getChannel()); } else { + $valpack = $chan->getValidationPackage(); $validator = $chan->getValidationObject(); - $validator->setPackageFile($this->_pf); - $validator->validate($state); - $failures = $validator->getFailures(); - foreach ($failures['errors'] as $error) { - $this->_stack->push(__FUNCTION__, 'error', $error, - 'Channel validator error: field "%field%" - %reason%'); - } - foreach ($failures['warnings'] as $warning) { - $this->_stack->push(__FUNCTION__, 'warning', $warning, - 'Channel validator warning: field "%field%" - %reason%'); + if ($this->_pf->getPackage() != $valpack['name']) { + // only run these tests if we are not installing the validation package + if (!$validator) { + $this->_stack->push(__FUNCTION__, 'error', + array_merge( + array('channel' => $chan->getName(), + 'package' => $this->_pf->getPackage()), + $valpack + ), + 'package "%channel%/%package%" cannot be properly validated without ' . + 'validation package "%channel%/%name%-%version%"'); + return $this->_isValid = 0; + } + $validator->setPackageFile($this->_pf); + $validator->validate($state); + $failures = $validator->getFailures(); + foreach ($failures['errors'] as $error) { + $this->_stack->push(__FUNCTION__, 'error', $error, + 'Channel validator error: field "%field%" - %reason%'); + } + foreach ($failures['warnings'] as $warning) { + $this->_stack->push(__FUNCTION__, 'warning', $warning, + 'Channel validator warning: field "%field%" - %reason%'); + } } } }