July 26, 2008, 8:13 pm
I ran into an instance recently where someone was trying to run Phergie in an environment where the exec function was disabled. This causes a warning in the Quit plugin, which uses exec to automatically detect the full path to the PHP CLI binary on non-Windows systems that it will later use that path to initiate a new PHP CLI process to “restart” the bot.
I realized when I started digging into this issue that I wasn’t aware of a way to check the PHP configuration to see whether or not a function was disabled, save for using the ini_get function to get the value of the disable_functions setting and parse it manually.
Thanks to Johannes Schlüter for cluing me into the fact that the SPL ReflectionFunction class has an isDisabled method, which is exactly what I was looking for. Unfortunately, there’s no equivalent method in the SPL ReflectionClass class for the disable_classes setting. Thankfully, though, I haven’t run into a use case for that yet.
Update: Apparently I inspired Johannes to write a patch to add ReflectionClass::isDisabled(). It most likely won’t make it in until 5.3.1, but at least the patch is there if you need the feature. Thanks Johannes!
July 12, 2008, 7:16 pm
When I first began working with Zend_View on a project at work, I noticed that the Url view helper was a bit of a pain to use. It was rare that I didn’t want to specify one or more of the action, controller, and module in my call along with the other Route assembly parameters. Having to label them with an array index made the calls to the helper ugly and more difficult to read. As well, I often wanted to refer to actions in the same controller or controllers in the same module with respect to the current action.
To get around this, I wrote a view helper that extended Zend_View_Helper_Url and had three optional parameters specifically for the action, controller, and module. Everything else was passed into the fourth parameter, an associative array of any other parameters I needed to include. If any component of the route is excluded or specified as null, I simply get its value from the current request.
My friend Andy Best took this a step further and added in support for specifying custom routes, which he’s using for a project of his own but I didn’t need myself because I only use the default routes provided by the standard rewrite router. The result is the code below.
<?php
require_once 'Zend/Controller/Front.php';
require_once 'Zend/View/Helper/Url.php';
class App_View_Helper_Route extends Zend_View_Helper_Url
{
public function route($action = null, $controller = null,
$module = null, $params = array(), $route = null)
{
$front = Zend_Controller_Front::getInstance();
$request = $front->getRequest();
$router = $front->getRouter();
if ($action === null) {
$action = $request->getActionName();
}
if ($controller === null) {
$controller = $request->getControllerName();
}
if ($module === null) {
$module = $request->getModuleName();
}
$urlOptions = array_merge($params, array(
'action' => $action,
'controller' => $controller,
'module' => $module
));
if ($router->hasRoute($controller) && $route === null) {
$route = $controller;
} else if ($route === null) {
$route = 'default';
}
return $this->url($urlOptions, $route, true);
}
}