summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaime Perez Crespo <jaime.perez@uninett.no>2015-08-05 14:37:16 +0200
committerJaime Perez Crespo <jaime.perez@uninett.no>2015-08-05 14:37:16 +0200
commit20e39fdbbcca02ebf3354be3a4427db587ba883c (patch)
treee6ffe7721a114532d61e7d60477a633c5e455beb
parentfed069a5d8089b7016bf14109ab1bf9fb86f5668 (diff)
downloadsimplesamlphp-20e39fdbbcca02ebf3354be3a4427db587ba883c.zip
simplesamlphp-20e39fdbbcca02ebf3354be3a4427db587ba883c.tar.gz
simplesamlphp-20e39fdbbcca02ebf3354be3a4427db587ba883c.tar.bz2
Reformat SimpleSAML_Stats.
-rw-r--r--lib/SimpleSAML/Stats.php172
1 files changed, 90 insertions, 82 deletions
diff --git a/lib/SimpleSAML/Stats.php b/lib/SimpleSAML/Stats.php
index e0f844c..42bd72c 100644
--- a/lib/SimpleSAML/Stats.php
+++ b/lib/SimpleSAML/Stats.php
@@ -1,5 +1,6 @@
<?php
+
/**
* Statistics handler class.
*
@@ -7,87 +8,94 @@
*
* @package SimpleSAMLphp
*/
-class SimpleSAML_Stats {
-
- /**
- * Whether this class is initialized.
- *
- * @var boolean
- */
- private static $initialized = FALSE;
-
-
- /**
- * The statistics output callbacks.
- *
- * @var array
- */
- private static $outputs = NULL;
-
-
- /**
- * Create an output from a configuration object.
- *
- * @param SimpleSAML_Configuration $config The configuration object.
- * @return mixed A new instance of the configured class.
- */
- private static function createOutput(SimpleSAML_Configuration $config) {
- $cls = $config->getString('class');
- $cls = SimpleSAML_Module::resolveClass($cls, 'Stats_Output', 'SimpleSAML_Stats_Output');
-
- $output = new $cls($config);
- return $output;
- }
-
-
- /**
- * Initialize the outputs.
- */
- private static function initOutputs() {
-
- $config = SimpleSAML_Configuration::getInstance();
- $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.
- */
- public static function log($event, array $data = array()) {
- assert('is_string($event)');
- assert('!isset($data["op"])');
- assert('!isset($data["time"])');
- assert('!isset($data["_id"])');
-
- if (!self::$initialized) {
- self::initOutputs();
- self::$initialized = TRUE;
- }
-
- if (empty(self::$outputs)) {
- /* Not enabled. */
- return;
- }
-
- $data['op'] = $event;
- $data['time'] = microtime(TRUE);
-
- /* 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);
- }
- }
+class SimpleSAML_Stats
+{
+
+ /**
+ * Whether this class is initialized.
+ *
+ * @var boolean
+ */
+ private static $initialized = false;
+
+
+ /**
+ * The statistics output callbacks.
+ *
+ * @var array
+ */
+ private static $outputs = null;
+
+
+ /**
+ * Create an output from a configuration object.
+ *
+ * @param SimpleSAML_Configuration $config The configuration object.
+ *
+ * @return mixed A new instance of the configured class.
+ */
+ private static function createOutput(SimpleSAML_Configuration $config)
+ {
+ $cls = $config->getString('class');
+ $cls = SimpleSAML_Module::resolveClass($cls, 'Stats_Output', 'SimpleSAML_Stats_Output');
+
+ $output = new $cls($config);
+ return $output;
+ }
+
+
+ /**
+ * Initialize the outputs.
+ */
+ private static function initOutputs()
+ {
+
+ $config = SimpleSAML_Configuration::getInstance();
+ $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.
+ *
+ * @return void|boolean False if output is not enabled, void otherwise.
+ */
+ public static function log($event, array $data = array())
+ {
+ assert('is_string($event)');
+ assert('!isset($data["op"])');
+ assert('!isset($data["time"])');
+ assert('!isset($data["_id"])');
+
+ if (!self::$initialized) {
+ self::initOutputs();
+ self::$initialized = true;
+ }
+
+ if (empty(self::$outputs)) {
+ // not enabled
+ return;
+ }
+
+ $data['op'] = $event;
+ $data['time'] = microtime(true);
+
+ // 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);
+ }
+ }
}