Tools.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace KarmaFW\App;
  3. class Tools
  4. {
  5. public static function loadHelpers($dir)
  6. {
  7. $helpers = glob($dir . '/helpers_*.php');
  8. foreach ($helpers as $helper) {
  9. require $helper;
  10. }
  11. }
  12. public static function isCli()
  13. {
  14. return (php_sapi_name() == 'cli');
  15. }
  16. public static function getCaller($excludeFiles = [], $formatted = true, $traceOffset = 2)
  17. {
  18. $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
  19. $backtrace = array_slice($backtrace, $traceOffset);
  20. $excludeFiles[] = VENDOR_DIR . '/karmasolutions/karmafw/src/Database/Sql/SqlTable.php';
  21. $excludeFiles[] = VENDOR_DIR . '/karmasolutions/karmafw/src/Database/Sql/SqlTableModel.php';
  22. //$excludeFiles[] = VENDOR_DIR . '/karmasolutions/karmafw/src/Database/Sql/SqlQuery.php';
  23. //$excludeFiles[] = VENDOR_DIR . '/karmasolutions/karmafw/src/App/Middlewares/DebugBar.php';
  24. //$excludeFiles[] = VENDOR_DIR . '/karmasolutions/karmafw/src/Routing/Router.php';
  25. //$excludeFiles[] = VENDOR_DIR . '/karmasolutions/karmafw/src/App/Pipe.php';
  26. foreach ($backtrace as $index => $context) {
  27. if (isset($context['file']) && ! in_array($context['file'], $excludeFiles)) {
  28. break;
  29. }
  30. }
  31. if (!isset($context)) {
  32. return null;
  33. }
  34. if ($formatted) {
  35. return isset($context) && array_key_exists('file', $context) ? $context['file'] . ':' . $context['line'] : null;
  36. }
  37. return $context;
  38. }
  39. }