Skip to content

Commit

Permalink
Merge pull request #17 from joomlatools/feature/15-disable
Browse files Browse the repository at this point in the history
#15 Add enabled state
  • Loading branch information
amazeika authored Mar 21, 2018
2 parents e07a761 + c9bdcb4 commit 885a878
Showing 1 changed file with 44 additions and 9 deletions.
53 changes: 44 additions & 9 deletions controller/behavior/loggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/
class ComActivitiesControllerBehaviorLoggable extends KControllerBehaviorAbstract
{
/**
* Behavior enabled state
*
* @var bool
*/
protected $_enabled;

/**
* Logger queue.
*
Expand All @@ -36,6 +43,8 @@ public function __construct(KObjectConfig $config)
// Create the logger queue
$this->__queue = $this->getObject('lib:object.queue');

$this->_enabled = $config->enabled;

// Attach the loggers
$loggers = KObjectConfig::unbox($config->loggers);

Expand All @@ -59,6 +68,7 @@ public function __construct(KObjectConfig $config)
protected function _initialize(KObjectConfig $config)
{
$config->append(array(
'enabled' => true,
'priority' => self::PRIORITY_LOWEST,
'loggers' => array(),
));
Expand All @@ -80,23 +90,48 @@ protected function _initialize(KObjectConfig $config)
*/
final public function execute(KCommandInterface $command, KCommandChainInterface $chain)
{
$action = $command->getName();

foreach($this->__queue as $logger)
if ($this->_enabled)
{
if (in_array($action, $logger->getActions()))
{
$object = $logger->getActivityObject($command);
$action = $command->getName();

if ($object instanceof KModelEntityInterface)
foreach($this->__queue as $logger)
{
if (in_array($action, $logger->getActions()))
{
$subject = $logger->getActivitySubject($command);
$logger->log($action, $object, $subject);
$object = $logger->getActivityObject($command);

if ($object instanceof KModelEntityInterface)
{
$subject = $logger->getActivitySubject($command);
$logger->log($action, $object, $subject);
}
}
}
}
}

/**
* Enables logging
*
* @return ComActivitiesControllerBehaviorLoggable
*/
public function enableLogging()
{
$this->_enabled = true;
return $this;
}

/**
* Disables logging
*
* @return ComActivitiesControllerBehaviorLoggable
*/
public function disableLogging()
{
$this->_enabled = false;
return $this;
}

/**
* Attach a logger.
*
Expand Down

0 comments on commit 885a878

Please sign in to comment.