Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Controller_Action_Helper_Audit Class Reference

Logs first action dispatch with details of the active site, the user that invoked the action and request params. More...

List of all members.

Public Member Functions

 addLoggedParam ($param)
 Adds a parameter to the whitelist of parameters to write to the log message.
 addLoggedParams ($params)
 Adds a list of parameters to the whitelist of parameters to write to the log message.
 getLoggedParams ()
 Returns the current whitelist of parameters that will be written to the log message.
 init ()
 Record the module, controller, and action at the time of the first dispatch, as they may be changed later.
 postDispatch ()
 Log the action, the site, the user, the method, and requested params.
 setLoggedParams ($params)
 Sets the whitelist of paramters that will be written to the log message.

Protected Attributes

 $_auditLogLevel = P4Cms_Log::INFO
 $_initialDispatch = array()
 $_loggedDispatch = false
 $_loggedParams = array('format', 'id')

Detailed Description

Logs first action dispatch with details of the active site, the user that invoked the action and request params.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

P4Cms_Controller_Action_Helper_Audit::addLoggedParam ( param)

Adds a parameter to the whitelist of parameters to write to the log message.

Parameters:
string$paramA single parameter to add.
    {
        if (!in_array($param, $this->_loggedParams)) {
            $this->_loggedParams[] = $param;
        }
    }
P4Cms_Controller_Action_Helper_Audit::addLoggedParams ( params)

Adds a list of parameters to the whitelist of parameters to write to the log message.

Parameters:
array$paramsA list of parameters to add.
    {
        foreach ($params as $param) {
            $this->addLoggedParam($param);
        }
    }
P4Cms_Controller_Action_Helper_Audit::getLoggedParams ( )

Returns the current whitelist of parameters that will be written to the log message.

Returns:
array The current whitelist of parameters.
    {
        return $this->_loggedParams;
    }
P4Cms_Controller_Action_Helper_Audit::init ( )

Record the module, controller, and action at the time of the first dispatch, as they may be changed later.

Returns:
void return early if we have already logged the intial dispatch.
    {
        // only log the first dispatch.
        if (empty($this->_initialDispatch)) {
            $this->_initialDispatch = array(
                'module'        => $this->getRequest()->getModuleName(),
                'controller'    => $this->getRequest()->getControllerName(),
                'action'        => $this->getRequest()->getActionName()
            );
        }
    }
P4Cms_Controller_Action_Helper_Audit::postDispatch ( )

Log the action, the site, the user, the method, and requested params.

Returns:
void Return early if we have already logged for this dispatch.
    {
        
        // only log the first dispatch.
        if ($this->_loggedDispatch) {
            return;
        }
        
        // log the action being dispatched.
        $message = "Dispatch: "
                 . $this->_initialDispatch['module']
                 . '/' . $this->_initialDispatch['controller']
                 . '/' . $this->_initialDispatch['action'];
        
        // incorporate active site id
        $site     = P4Cms_Site::hasActive()
            ? P4Cms_Site::fetchActive()->getId()
            : '<none>';
        $message .= ", Site: " . $site; 
        
        // incorporate active user id
        $user     = P4Cms_User::hasActive() && !P4Cms_User::fetchActive()->isAnonymous()
            ? P4Cms_User::fetchActive()->getId()
            : '<anonymous>';
        $message .= ", User: " . $user;
        
        // incorporate request method and parameters.
        $requestParams    = $this->getRequest()->getParams();
        $params           = array();

        foreach ($this->getLoggedParams() as $param) {
            if (array_key_exists($param, $requestParams)) {
                $params[] = $param . '=' . $requestParams[$param];
            }
        }
        
        $message .= ", Method: " . $this->getRequest()->getMethod();
        $message .= ", Params: " . implode(', ', $params);        
        
        P4Cms_Log::log($message, $this->_auditLogLevel);
        
        $this->_loggedDispatch = true;
    }
P4Cms_Controller_Action_Helper_Audit::setLoggedParams ( params)

Sets the whitelist of paramters that will be written to the log message.

Parameters:
array$paramsThe list of parameters to set.
    {
        $this->_loggedParams = array();
        $this->addLoggedParams($params);
    }

Member Data Documentation

P4Cms_Controller_Action_Helper_Audit::$_auditLogLevel = P4Cms_Log::INFO [protected]
P4Cms_Controller_Action_Helper_Audit::$_initialDispatch = array() [protected]
P4Cms_Controller_Action_Helper_Audit::$_loggedDispatch = false [protected]
P4Cms_Controller_Action_Helper_Audit::$_loggedParams = array('format', 'id') [protected]

The documentation for this class was generated from the following file: