Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.0RC1

Request #7442 avoid warning messages when driver is unloadable
Submitted: 2006-04-20 19:54 UTC
From: farell Assigned: scottmattocks
Status: Closed Package: PEAR_PackageUpdate (version 0.4.1)
PHP Version: 4.4.2 OS: Windows XP
Roadmaps: (Not assigned)    
Subscription  


 [2006-04-20 19:54 UTC] farell (Laurent Laville)
Description: ------------ Still working on PEAR_PackageUpdate_Web package proposal, i found few minor purposes that I think you could improve (in my own opinion). First: When driver is unloadable, or if you made a typo error like line below : $ppu = PEAR_PackageUpdate::factory('Gtk23', 'XML_RPC', 'pear'); You will get unecessary warning messages that will almost hide application control message. See test script below. I suggest to add a function like in PEAR_PackageFileManager2 to test if file is includeable before trying to include it: See PEAR_PackageUpdate2::factory method. Second: There are no reasons to use static version of call to determinePrefFile() into loadPreferences() and savePreferences() methods. Use $this->determinePrefFile() instead. Third and last: As loadPreferences() is called in class constructor, determinePrefFile() is always called too. So I think you could put require PEAR/Config outside class as a mandatory ressource and avoid to put require PEAR (already included by PEAR/Config). Laurent Test script: --------------- <?php require_once 'PEAR/PackageUpdate.php'; class PEAR_PackageUpdate2 extends PEAR_PackageUpdate { function &factory($driver, $packageName, $channel) { // Try to include the driver. $file = 'PEAR/PackageUpdate/' . $driver . '.php'; if (!PEAR_PackageUpdate2::isIncludeable($file)) { return false; } include_once $file; // See if the class exists now. $class = 'PEAR_PackageUpdate_' . $driver; if (!class_exists($class)) { return false; } // Try to instantiate the class. $instance =& new $class($packageName, $channel); return $instance; } function isIncludeable($file) { if (!defined('PATH_SEPARATOR')) { define('PATH_SEPARATOR', strtolower(substr(PHP_OS, 0, 3)) == 'win' ? ';' : ':'); } foreach (explode(PATH_SEPARATOR, ini_get('include_path')) as $path) { if (file_exists($path . DIRECTORY_SEPARATOR . $file) && is_readable($path . DIRECTORY_SEPARATOR . $file)) { return true; } } return false; } } $ppu = PEAR_PackageUpdate2::factory('Gtk23', 'XML_RPC', 'pear'); // Make sure the updater was created properly. if ($ppu === false) { echo "Could not create updater.\n"; echo "You might want to check for an install updates manually.\n"; die(); } print 'still alive'; ?> Expected result: ---------------- application warning message only : "Could not create updater. You might want to check for an install updates manually." Actual result: -------------- Warning: factory(PEAR/PackageUpdate/Gtk23.php): failed to open stream: No such file or directory in [...]pear\PEAR\PackageUpdate.php on line 229 Warning: factory(): Failed opening 'PEAR/PackageUpdate/Gtk23.php' for inclusion (include_path='[...]') in [...]pear\PEAR\PackageUpdate.php on line 229 Could not create updater. You might want to check for an install updates manually.

Comments

 [2006-04-20 20:46 UTC] scottmattocks (Scott Mattocks)
Thank you for your bug report. This issue has been fixed in the latest released version of the package, which you can download at http://pear.php.net/get/PEAR_PackageUpdate