Help with PEAR_Command_Install and PEAR_Command
| From: | Chris Mattmann | Date: | Sun, 06 Apr 2008 23:33:39 +0000 |
| Subject: | Help with PEAR_Command_Install and PEAR_Command | ||
| Groups: | php.pear.core | ||
| Request: | Send a blank email to pear-core+get-7448@lists.php.net to get a copy of this message | ||
Hi there,
I really think that PEAR is awesome, and so far I've been able to figure it
out more or less, even with a very beginner's knowledge of PHP 5 (I used to
program some PHP 4 back in the day but it's literally been about 5 years).
Here is the trouble I have been running into:
I am trying to wrap the "pear install" command, and call it programmatically
through PHP. I have the PEAR Manifesto book, and have read through Chapter
6, where it talks about using PEAR_Command_* to programmatically interface
with the PEAR Installer command line interface. I've managed to write a
small wrapper function that makes a call to a particular PEAR Command:
function runPEARCommand($commandName, $opts, $params, $workDirPath = null) {
if ($workDirPath != null) {
$pwd = getcwd();
chdir($workDirPath);
}
$config = &PEAR_Config :: singleton();
$cmd = PEAR_Command :: factory($commandName, $config);
$ok = $cmd->run($commandName, $opts, $params);
if ($workDirPath != null) {
chdir($pwd);
}
return $ok;
}
This wrapper function has worked great, e.g., for "pear package", e.g.,
using the following code:
echo "INFO: packaging using package.xml file: [" . $pkgFileFullPath . "]\n";
$opts = array ();
$params = array ($pkgFileFullPath);
$commandName = "package";
$ok = $this->runPEARCommand($commandName, $opts, $params, $dirPath);
The problem I am running into is when I try to use my code to wrap "pear
install". The code that I'm using is similar to that of above:
$opts = array ('force'=>true);
$params = array ($filePath); /* $filePath is a path to a .tgz PEAR pkg,
something that I want to install to the default channel */
echo "INFO: Using PEAR to install installer dependency: [" . $filePath .
"]\n";
$ok = $this->runPEARCommand($commandName, $opts, $params);
I'm noticing 2 different behaviors:
1. I've got a pear package that overrides some core PEAR framework code
(e.g., I have one that overrides the default PackageFile/v2/Validator.php
class so that I can have postgres and apache dependency check tags, similar
to pearinstaller). In this case, when I run the above code, I get:
...
INFO: Using PEAR to install installer dependency:
[/Users/mattmann/src/211/211linq_installer/211custom_packagefile/pear_dists/
PEAR_PackageFile_v2_211LinQPackageFile-1.0.0.tgz]
PHP Fatal error: Call to a member function outputData() on a non-object in
/usr/local/php5/lib/php/PEAR/Command/Install.php on line 673
...
2. I've got a traditional pear package that doesn't override core PEAR
framework code, but only adds to it. In this case, when I run the above
code, I get:
...
INFO: Using PEAR to install installer dependency:
[/Users/mattmann/src/211/211linq_installer/211linq_roles/web_role/pear_dists
/PEAR_Installer_Role_Web211linq-1.0.0.tgz]
PHP Fatal error: Call to a member function outputData() on a non-object in
/usr/local/php5/lib/php/PEAR/Command/Install.php on line 750
...
Do anyone have any clue as to why this is happening? I'm also noticing
errors on lines 570: ( PHP Fatal error: Call to a member function
outputData() on a non-object in
/usr/local/php5/lib/php/PEAR/Command/Install.php on line 570), and on lines
1533: ( PHP Fatal error: Cannot use object of type PEAR_Error as array in
/usr/local/php5/lib/php/PEAR/Installer.php on line 1533) if I try to
continue to uninstall using similar code.
I would appreciate any advice you have. Thanks!
Cheers,
Chris