1010use Monolog \Logger ;
1111use Psr \Log \LoggerInterface ;
1212use Psr \Log \LogLevel ;
13- use Tripod \Exceptions \Exception ;
14- use Tripod \IEventHook ;
1513use Tripod \ITripodStat ;
1614use Tripod \Mongo \Composites \Views ;
1715use Tripod \StatsD ;
2018
2119abstract class DriverBase
2220{
23- /**
24- * constants for the supported hook functions that can be applied.
25- */
26- public const HOOK_FN_PRE = 'pre ' ;
27-
28- public const HOOK_FN_SUCCESS = 'success ' ;
29-
30- public const HOOK_FN_FAILURE = 'failure ' ;
31-
3221 public static ?LoggerInterface $ logger = null ;
3322
3423 protected string $ storeName ;
@@ -157,11 +146,6 @@ protected function getStatFromStatFactory(): ITripodStat
157146 return TripodStatFactory::create ($ this ->statsConfig );
158147 }
159148
160- protected function getExpirySecFromNow (int $ secs ): int
161- {
162- return time () + $ secs ;
163- }
164-
165149 protected function getContextAlias (?string $ context = null ): string
166150 {
167151 $ contextAlias = $ this ->labeller ->uri_to_alias ((empty ($ context )) ? $ this ->defaultContext : $ context );
@@ -337,33 +321,6 @@ protected function getCollection(): Collection
337321 return $ this ->collection ;
338322 }
339323
340- /**
341- * @param IEventHook[] $hooks
342- *
343- * @throws Exception If an invalid hook function is requested
344- */
345- protected function applyHooks (string $ fn , array $ hooks , array $ args = []): void
346- {
347- switch ($ fn ) {
348- case $ this ::HOOK_FN_PRE :
349- case $ this ::HOOK_FN_SUCCESS :
350- case $ this ::HOOK_FN_FAILURE :
351- break ;
352-
353- default :
354- throw new Exception (sprintf ('Invalid hook function %s requested ' , $ fn ));
355- }
356-
357- foreach ($ hooks as $ hook ) {
358- try {
359- call_user_func ([$ hook , $ fn ], $ args );
360- } catch (\Exception $ e ) {
361- // don't let rabid hooks stop tripod
362- static ::getLogger ()->error ('Hook ' . get_class ($ hook ) . sprintf (' threw exception %s, continuing ' , $ e ->getMessage ()));
363- }
364- }
365- }
366-
367324 /**
368325 * @codeCoverageIgnore
369326 */
@@ -372,46 +329,3 @@ private function log(string $level, string $message, ?array $params): void
372329 self ::getLogger ()->log ($ level , $ message , $ params ?: []);
373330 }
374331}
375-
376- final class NoStat implements ITripodStat
377- {
378- /**
379- * @var self
380- */
381- public static $ instance ;
382-
383- public function increment (string $ operation , int $ inc = 1 ): void
384- {
385- // do nothing
386- }
387-
388- /**
389- * @param float|int $duration
390- */
391- public function timer (string $ operation , $ duration ): void
392- {
393- // do nothing
394- }
395-
396- public function getConfig (): array
397- {
398- return [];
399- }
400-
401- public static function getInstance (): self
402- {
403- if (self ::$ instance == null ) {
404- self ::$ instance = new NoStat ();
405- }
406-
407- return self ::$ instance ;
408- }
409-
410- /**
411- * @return self
412- */
413- public static function createFromConfig (array $ config = [])
414- {
415- return self ::getInstance ();
416- }
417- }
0 commit comments