bootstrap.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * This file is part of PHPOffice Common
  4. *
  5. * PHPOffice Common is free software distributed under the terms of the GNU Lesser
  6. * General Public License version 3 as published by the Free Software Foundation.
  7. *
  8. * For the full copyright and license information, please read the LICENSE
  9. * file that was distributed with this source code. For the full list of
  10. * contributors, visit https://github.com/PHPOffice/Common/contributors.
  11. *
  12. * @copyright 2010-2016 PHPOffice Common contributors
  13. * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
  14. * @link https://github.com/PHPOffice/Common
  15. */
  16. date_default_timezone_set('UTC');
  17. // defining base dir for tests
  18. if (!defined('PHPOFFICE_COMMON_TESTS_BASE_DIR')) {
  19. define('PHPOFFICE_COMMON_TESTS_BASE_DIR', realpath(__DIR__));
  20. }
  21. $vendor = realpath(__DIR__ . '/../vendor');
  22. if (file_exists($vendor . "/autoload.php")) {
  23. require $vendor . "/autoload.php";
  24. } else {
  25. $vendor = realpath(__DIR__ . '/../../../');
  26. if (file_exists($vendor . "/autoload.php")) {
  27. require $vendor . "/autoload.php";
  28. } else {
  29. throw new Exception("Unable to load dependencies");
  30. }
  31. }
  32. spl_autoload_register(function ($class) {
  33. $class = ltrim($class, '\\');
  34. $prefix = 'PhpOffice\\Common\\Tests';
  35. if (strpos($class, $prefix) === 0) {
  36. $class = str_replace('\\', DIRECTORY_SEPARATOR, $class);
  37. $class = join(DIRECTORY_SEPARATOR, array('Common', 'Tests', '_includes')) .
  38. substr($class, strlen($prefix));
  39. $file = __DIR__ . DIRECTORY_SEPARATOR . $class . '.php';
  40. if (file_exists($file)) {
  41. require_once $file;
  42. }
  43. }
  44. });
  45. require_once __DIR__ . "/../src/Common/Autoloader.php";
  46. \PhpOffice\Common\Autoloader::register();