Skip to content
Snippets Groups Projects
Commit 20e39fdb authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Reformat SimpleSAML_Stats.

parent fed069a5
No related branches found
No related tags found
No related merge requests found
<?php <?php
/** /**
* Statistics handler class. * Statistics handler class.
* *
...@@ -7,87 +8,94 @@ ...@@ -7,87 +8,94 @@
* *
* @package SimpleSAMLphp * @package SimpleSAMLphp
*/ */
class SimpleSAML_Stats { class SimpleSAML_Stats
{
/**
* Whether this class is initialized. /**
* * Whether this class is initialized.
* @var boolean *
*/ * @var boolean
private static $initialized = FALSE; */
private static $initialized = false;
/**
* The statistics output callbacks. /**
* * The statistics output callbacks.
* @var array *
*/ * @var array
private static $outputs = NULL; */
private static $outputs = null;
/**
* Create an output from a configuration object. /**
* * Create an output from a configuration object.
* @param SimpleSAML_Configuration $config The configuration object. *
* @return mixed A new instance of the configured class. * @param SimpleSAML_Configuration $config The configuration object.
*/ *
private static function createOutput(SimpleSAML_Configuration $config) { * @return mixed A new instance of the configured class.
$cls = $config->getString('class'); */
$cls = SimpleSAML_Module::resolveClass($cls, 'Stats_Output', 'SimpleSAML_Stats_Output'); private static function createOutput(SimpleSAML_Configuration $config)
{
$output = new $cls($config); $cls = $config->getString('class');
return $output; $cls = SimpleSAML_Module::resolveClass($cls, 'Stats_Output', 'SimpleSAML_Stats_Output');
}
$output = new $cls($config);
return $output;
/** }
* Initialize the outputs.
*/
private static function initOutputs() { /**
* Initialize the outputs.
$config = SimpleSAML_Configuration::getInstance(); */
$outputCfgs = $config->getConfigList('statistics.out', array()); private static function initOutputs()
{
self::$outputs = array();
foreach ($outputCfgs as $cfg) { $config = SimpleSAML_Configuration::getInstance();
self::$outputs[] = self::createOutput($cfg); $outputCfgs = $config->getConfigList('statistics.out', array());
}
} self::$outputs = array();
foreach ($outputCfgs as $cfg) {
self::$outputs[] = self::createOutput($cfg);
/** }
* Notify about an event. }
*
* @param string $event The event.
* @param array $data Event data. Optional. /**
*/ * Notify about an event.
public static function log($event, array $data = array()) { *
assert('is_string($event)'); * @param string $event The event.
assert('!isset($data["op"])'); * @param array $data Event data. Optional.
assert('!isset($data["time"])'); *
assert('!isset($data["_id"])'); * @return void|boolean False if output is not enabled, void otherwise.
*/
if (!self::$initialized) { public static function log($event, array $data = array())
self::initOutputs(); {
self::$initialized = TRUE; assert('is_string($event)');
} assert('!isset($data["op"])');
assert('!isset($data["time"])');
if (empty(self::$outputs)) { assert('!isset($data["_id"])');
/* Not enabled. */
return; if (!self::$initialized) {
} self::initOutputs();
self::$initialized = true;
$data['op'] = $event; }
$data['time'] = microtime(TRUE);
if (empty(self::$outputs)) {
/* The ID generation is designed to cluster IDs related in time close together. */ // not enabled
$int_t = (int)$data['time']; return;
$hd = openssl_random_pseudo_bytes(16); }
$data['_id'] = sprintf('%016x%s', $int_t, bin2hex($hd));
$data['op'] = $event;
foreach (self::$outputs as $out) { $data['time'] = microtime(true);
$out->emit($data);
} // the ID generation is designed to cluster IDs related in time close together
} $int_t = (int) $data['time'];
$hd = openssl_random_pseudo_bytes(16);
$data['_id'] = sprintf('%016x%s', $int_t, bin2hex($hd));
foreach (self::$outputs as $out) {
$out->emit($data);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment