autoload.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. $autoloadFile = './vendor/codeception/codeception/autoload.php';
  3. if (file_exists('./vendor/autoload.php') && file_exists($autoloadFile) && __FILE__ != realpath($autoloadFile)) {
  4. //for global installation or phar file
  5. fwrite(
  6. STDERR,
  7. "\n==== Redirecting to Composer-installed version in vendor/codeception ====\n"
  8. );
  9. require $autoloadFile;
  10. //require package/bin instead of codecept to avoid printing hashbang line
  11. require './vendor/codeception/codeception/package/bin';
  12. die;
  13. } elseif (file_exists(__DIR__ . '/vendor/autoload.php')) {
  14. // for phar
  15. require_once(__DIR__ . '/vendor/autoload.php');
  16. } elseif (file_exists(__DIR__ . '/../../autoload.php')) {
  17. //for composer
  18. require_once __DIR__ . '/../../autoload.php';
  19. }
  20. unset($autoloadFile);
  21. // @codingStandardsIgnoreStart
  22. include_once __DIR__ . DIRECTORY_SEPARATOR . 'shim.php';
  23. // compat
  24. if (PHP_MAJOR_VERSION < 7) {
  25. if (false === interface_exists('Throwable', false)) {
  26. interface Throwable {};
  27. }
  28. if (false === class_exists('ParseError', false)) {
  29. class ParseError extends \Exception {};
  30. }
  31. }
  32. // @codingStandardsIgnoreEnd
  33. if (!function_exists('json_last_error_msg')) {
  34. /**
  35. * Copied from http://php.net/manual/en/function.json-last-error-msg.php#117393
  36. * @return string
  37. */
  38. function json_last_error_msg()
  39. {
  40. static $errors = array(
  41. JSON_ERROR_NONE => 'No error',
  42. JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
  43. JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)',
  44. JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
  45. JSON_ERROR_SYNTAX => 'Syntax error',
  46. JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
  47. );
  48. $error = json_last_error();
  49. return isset($errors[$error]) ? $errors[$error] : 'Unknown error';
  50. }
  51. }
  52. // function not autoloaded in PHP, thus its a good place for them
  53. if (!function_exists('codecept_debug')) {
  54. function codecept_debug($data)
  55. {
  56. \Codeception\Util\Debug::debug($data);
  57. }
  58. }
  59. if (!function_exists('codecept_root_dir')) {
  60. function codecept_root_dir($appendPath = '')
  61. {
  62. return \Codeception\Configuration::projectDir() . $appendPath;
  63. }
  64. }
  65. if (!function_exists('codecept_output_dir')) {
  66. function codecept_output_dir($appendPath = '')
  67. {
  68. return \Codeception\Configuration::outputDir() . $appendPath;
  69. }
  70. }
  71. if (!function_exists('codecept_log_dir')) {
  72. function codecept_log_dir($appendPath = '')
  73. {
  74. return \Codeception\Configuration::outputDir() . $appendPath;
  75. }
  76. }
  77. if (!function_exists('codecept_data_dir')) {
  78. function codecept_data_dir($appendPath = '')
  79. {
  80. return \Codeception\Configuration::dataDir() . $appendPath;
  81. }
  82. }
  83. if (!function_exists('codecept_relative_path')) {
  84. function codecept_relative_path($path)
  85. {
  86. return \Codeception\Util\PathResolver::getRelativeDir(
  87. $path,
  88. \Codeception\Configuration::projectDir(),
  89. DIRECTORY_SEPARATOR
  90. );
  91. }
  92. }
  93. if (!function_exists('codecept_absolute_path')) {
  94. /**
  95. * If $path is absolute, it will be returned without changes.
  96. * If $path is relative, it will be passed to `codecept_root_dir()` function
  97. * to make it absolute.
  98. *
  99. * @param string $path
  100. * @return string the absolute path
  101. */
  102. function codecept_absolute_path($path)
  103. {
  104. return codecept_is_path_absolute($path) ? $path : codecept_root_dir($path);
  105. }
  106. }
  107. if (!function_exists('codecept_is_path_absolute')) {
  108. /**
  109. * Check whether the given $path is absolute.
  110. *
  111. * @param string $path
  112. * @return bool
  113. * @since 2.4.4
  114. */
  115. function codecept_is_path_absolute($path)
  116. {
  117. if (DIRECTORY_SEPARATOR === '/') {
  118. return mb_substr($path, 0, 1) === DIRECTORY_SEPARATOR;
  119. }
  120. return preg_match('#^[A-Z]:(?![^/\\])#i', $path) === 1;
  121. }
  122. }