Re: addReplacement with Role_Web
| From: | Gregory Beaver | Date: | Thu, 15 Feb 2007 20:36:00 +0000 |
| Subject: | Re: addReplacement with Role_Web | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-45647@lists.php.net to get a copy of this message | ||
Tony Bibbs wrote:
> I've got a PHP file in a PEAR package with something like:
>
> require '/path/to/mysoftware/config.php';
>
> The PEAR package installs as a web application using pearified/Role_Web
> and what I'd like to do is during the install prevent users from having
> to touch the file that has that include above to use the right absolute
> path.
>
> I tried using the following in my packagefilemanager script:
>
> $pkg->addReplacement(
> 'public_html/file-to-edit.php',
> 'pear-config', '/path/to/mysoftware',
> 'web_dir'
> );
>
> Problem is that my web application installs into it's own directory
> under the web_dir so what I get after the above substitution is:
>
> require '/var/www/config.php';
>
> instead of:
>
> require '/var/www/packagename/config.php';
>
> I then tried to do a second substitution (that happens after the above
> substitution:
>
> define('CONFIGSTR','packagename/config.php');
> $pkg->addReplacement(
> 'public_html/file-to-edit.php',
> 'php-const',
> 'config.php',
> CONFIGSTR
> );
>
>
> ...but that gives me errors because addReplacement only allows actual
> PHP constants, not user defined constants.
>
> Is there an easy way around this?
$pkg->addReplacement('public_html/file-to-edit.php', 'pear-config',
'@WEB_DIR@', 'web_dir');
$pkg->addReplacement('public_html/file-to-edit.php', 'package-info',
'@PACKAGE@', 'name');
then,
if ('@WEB_DIR@' == '@'.'WEB_DIR@') {
// not installed through PEAR
require dirname(__FILE__) . '/config.php';
} else {
// installed through PEAR
require '@WEB_DIR@/@PACKAGE@/config.php';
}
Of course, you can also use:
require '@WEB_DIR@/packagename/config.php';
if you don't plan on changing the package name (which is likely :)
Greg