LimeTrace.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of the Lime framework.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. * (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. abstract class LimeTrace
  12. {
  13. static public function findCaller($class)
  14. {
  15. $traces = debug_backtrace();
  16. $result = array($traces[0]['file'], $traces[0]['line']);
  17. $t = array_reverse($traces);
  18. foreach ($t as $trace)
  19. {
  20. if (isset($trace['object']) && isset($trace['file']) && isset($trace['line']))
  21. {
  22. $reflection = new ReflectionClass($trace['object']);
  23. if ($reflection->getName() == $class || $reflection->isSubclassOf($class))
  24. {
  25. $result = array($trace['file'], $trace['line']);
  26. break;
  27. }
  28. }
  29. }
  30. // remove .test suffix which is added in case of annotated tests
  31. if (substr($result[0], -5) == '.test')
  32. {
  33. $result[0] = substr($result[0], 0, -5);
  34. }
  35. return $result;
  36. }
  37. }