plugins-bootstrap.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. use Grav\Common\Grav;
  3. use Grav\Common\Plugin;
  4. use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
  5. \define('GRAV_CLI', true);
  6. \define('GRAV_REQUEST_TIME', microtime(true));
  7. \define('GRAV_USER_INSTANCE', 'FLEX');
  8. $autoload = require __DIR__ . '/../../vendor/autoload.php';
  9. if (version_compare($ver = PHP_VERSION, $req = GRAV_PHP_MIN, '<')) {
  10. exit(sprintf("You are running PHP %s, but Grav needs at least PHP %s to run.\n", $ver, $req));
  11. }
  12. if (!ini_get('date.timezone')) {
  13. date_default_timezone_set('UTC');
  14. }
  15. if (!file_exists(GRAV_ROOT . '/index.php')) {
  16. exit('FATAL: Must be run from ROOT directory of Grav!');
  17. }
  18. $grav = Grav::instance(['loader' => $autoload]);
  19. $grav->setup('tests');
  20. $grav['config']->init();
  21. // Find all plugins in Grav installation and autoload their classes.
  22. /** @var UniformResourceLocator $locator */
  23. $locator = Grav::instance()['locator'];
  24. $iterator = $locator->getIterator('plugins://');
  25. /** @var DirectoryIterator $directory */
  26. foreach ($iterator as $directory) {
  27. if (!$directory->isDir()) {
  28. continue;
  29. }
  30. $plugin = $directory->getBasename();
  31. $file = $directory->getPathname() . '/' . $plugin . '.php';
  32. $classloader = null;
  33. if (file_exists($file)) {
  34. require_once $file;
  35. $pluginClass = "\\Grav\\Plugin\\{$plugin}Plugin";
  36. if (is_subclass_of($pluginClass, Plugin::class, true)) {
  37. $class = new $pluginClass($plugin, $grav);
  38. if (is_callable([$class, 'autoload'])) {
  39. $classloader = $class->autoload();
  40. }
  41. }
  42. }
  43. if (null === $classloader) {
  44. $autoloader = $directory->getPathname() . '/vendor/autoload.php';
  45. if (file_exists($autoloader)) {
  46. require $autoloader;
  47. }
  48. }
  49. }
  50. define('GANTRY_DEBUGGER', true);
  51. define('GANTRY5_DEBUG', true);
  52. define('GANTRY5_PLATFORM', 'grav');
  53. define('GANTRY5_ROOT', rtrim(ROOT_DIR, '/'));
  54. define('GANTRY5_VERSION', '@version@');
  55. define('GANTRY5_VERSION_DATE', '@versiondate@');
  56. define('GANTRYADMIN_PATH', '');