[Solar-talk] Helper stack
Rodrigo Moraes
rodrigo.moraes at gmail.com
Sat Jul 22 08:35:02 PDT 2006
Hi,
A question about the helper stack. I'm wondering about the necessity
of Vendor_Helper and Vendor_View_Helper directories. Following
Solar_View_Helper, shouldn't Vendor_Helper be dropped for consistency
to avoid confusion? I'm confused because of the results I get.
Solar_Controller_Page says:
// add the helper classes to the view object.
// the order of searching will be:
// Vendor_App_Example_Helper_*, Vendor_App_Helper_*,
// Vendor_View_Helper_*, Solar_View_Helper_*
But my helper stack is:
'stack' =>
array (
0 => 'Tipos_App_Blog_Helper_',
1 => 'Tipos_Helper_',
2 => 'Tipos_View_Helper_',
3 => 'Solar_View_Helper_',
),
I think this would be more straightforward in
Controller_Page::_getLayout(), avoiding some strrpos() and substr():
// get directories list
$dirs = explode('_', $class);
// stack of helper classes
$helper = array();
// stack for directories
$stack = '';
// find all parent-level helpers
foreach($dirs as $dir) {
$stack .= $dir . '_';
$helper[] = $stack . 'Helper';
}
$helper = array_reverse($helper);
// add the helper class names to the view object
$layout->addHelperClass($helper);
It works as declared in the phpdoc, except because it doesn't include
Vendor_View_Helper, but if really needed just add a bit to the
foreach:
foreach($dirs as $key => $dir) {
$stack .= $dir . '_';
// find the vendor-level helpers (Vendor_View_Helper)
if($key == 0 && $dir != 'Solar') {
$directory = $stack . 'View_';
} else {
$directory = $stack;
}
$helper[] = $directory . 'Helper';
}
I wouldn't mind to not have Vendor_View_Helper, though.
The only problem I see is if someone uses a class
Vendor_App_Very_Long_Name_Oh_One_More, and although I can't think in a
reason for this, a foreach in eight or twenty values still wouldn't
hurt. Perhaps there are other problems I've missed.
regards,
rodrigo moraes / brazil
More information about the solar-talk
mailing list