PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Configuration » Config » Bug #1865

How about a Config_Container::getDirective() method?

Details

Request #1865How about a Config_Container::getDirective() method?
Submitted2004-07-13 21:25 UTC
Fromphp dot devel at homelinkcs dot com
Assignedmansion
StatusClosed
PackageConfig
PHP VersionIrrelevant
OSALL
Roadmaps(Not assigned)

Comments

[2004-07-13 21:25 UTC] php dot devel at homelinkcs dot com

Description:
------------
Might I that suggest the following method be added to the
Config_Container class? Perhaps there is another way to do
what I want, but I haven't found one so far.

Reproduce code:
---------------
/**
* Return a child directive's content.
* This is an helper method calling getItem and getContent for you.
*
* @param string $name Name of the directive to look for
* @param int $index Index of the directive to set,
* in case there are more than one directive
* with the same name
* @return string directive's content
*/
function getDirective ($name, $index = -1) {
$item =& $this->getItem('directive', $name, null, null, $index);
return $item->getContent();
} // end func getDirective

Expected result:
----------------
The above patch allows me to write the following:

include($root->getDirective('myModuleName'));

Actual result:
--------------
Currently, I have only been able to do:

$dummyvar = $root->getItem('directive', 'myModuleName');
include($dummyvar->getContent());
unset($dummyvar); // Needed to prevent namespace cluttering
in large scripts

[2004-08-07 09:41 UTC] bmansion at mamasam dot com

This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.

In case this was a pear.php.net website problem, the change will show
up on the website in short time.

Thank you for the report, and for helping us make PEAR better.

The method implemented is called directiveContent() and works both with searchPath() and getITem(), allowing to find a directive content at deeper levels than just the item's direct children.