PluginProbe
Gantry 5 Framework / 5.519
Gantry 5 Framework v5.519
5.6.4 5.6.3 trunk 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.2.0 5.2.1 5.2.10 5.2.11 5.2.12 5.2.13 5.2.14 5.2.15 5.2.17 5.2.18 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 All 90 releases
gantry5 / src / RealLoader.php

RealLoader.php in Gantry 5 Framework 5.519, at src/RealLoader.php

134 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package Gantry5
5 * @author RocketTheme http://www.rockettheme.com
6 * @copyright Copyright (C) 2007 - 2022 RocketTheme, LLC
7 * @license Dual License: MIT or GNU/GPLv2 and later
8 *
9 * http://opensource.org/licenses/MIT
10 * http://www.gnu.org/licenses/gpl-2.0.html
11 *
12 * Gantry Framework code that extends GPL code is considered GNU/GPLv2 and later
13 */
14
15 namespace Gantry5;
16
17 use Composer\Autoload\ClassLoader;
18
19 /**
20 * Use \Gantry5\Loader::setup() or \Gantry5\Loader::get() instead.
21 *
22 * This class separates Loader logic from the \Gantry5\Loader class. By adding this extra class we are able to upgrade
23 * Gantry5 and initializing the new version during a single request -- as long as Gantry5 has not been initialized.
24 *
25 * @internal
26 */
27 abstract class RealLoader
28 {
29 /** @var string */
30 protected static $errorMessagePhpMin = 'You are running PHP %s, but Gantry 5 Framework needs at least PHP %s to run.';
31 /** @var string */
32 protected static $errorMessageGantryLoaded = 'Attempting to load Gantry 5 Framework multiple times.';
33
34 /**
35 * Initializes Gantry5 and returns Composer ClassLoader.
36 *
37 * @return \Composer\Autoload\ClassLoader
38 * @throws \RuntimeException
39 * @throws \LogicException
40 */
41 public static function getClassLoader()
42 {
43 // Fail safe version check for PHP <5.6.20.
44 if (version_compare($phpVersion = PHP_VERSION, '5.6.20', '<')) {
45 throw new \RuntimeException(sprintf(self::$errorMessagePhpMin, $phpVersion, '5.6.20'));
46 }
47
48 if (defined('GANTRY5_VERSION')) {
49 throw new \LogicException(self::$errorMessageGantryLoaded);
50 }
51
52 define('GANTRY5_VERSION', '5.5.19');
53 define('GANTRY5_VERSION_DATE', 'May 24, 2024');
54
55 if (!defined('DS')) {
56 define('DS', DIRECTORY_SEPARATOR);
57 }
58
59 define('GANTRY_DEBUGGER', class_exists('Gantry\\Debugger'));
60
61 return self::autoload();
62 }
63
64 /**
65 * @return \Composer\Autoload\ClassLoader
66 * @throws \LogicException
67 * @internal
68 */
69 protected static function autoload()
70 {
71 // Register platform specific overrides.
72 if (defined('JVERSION') && defined('JPATH_ROOT')) {
73 define('GANTRY5_PLATFORM', 'joomla');
74 define('GANTRY5_ROOT', JPATH_ROOT);
75 define('GANTRY5_LIBRARY', JPATH_ROOT . '/libraries/gantry5');
76 } elseif (defined('WP_DEBUG') && defined('ABSPATH') && defined('WP_CONTENT_DIR')) {
77 define('GANTRY5_PLATFORM', 'wordpress');
78 if (defined('CONTENT_DIR') && class_exists('Env')) {
79 // Bedrock support.
80 define('GANTRY5_ROOT', preg_replace('|' . preg_quote(CONTENT_DIR, '|'). '$|', '', WP_CONTENT_DIR));
81 } else {
82 // Plain WP support.
83 define('GANTRY5_ROOT', dirname(WP_CONTENT_DIR));
84 }
85 define('GANTRY5_LIBRARY', WP_CONTENT_DIR . '/plugins/gantry5');
86 } elseif (defined('GRAV_VERSION') && defined('ROOT_DIR')) {
87 /** @var \RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator $locator */
88 $locator = \Grav\Common\Grav::instance()['locator'];
89 define('GANTRY5_PLATFORM', 'grav');
90 define('GANTRY5_ROOT', rtrim(ROOT_DIR, '/'));
91 define('GANTRY5_LIBRARY', $locator('plugin://gantry5'));
92 } else {
93 throw new \RuntimeException('Gantry: CMS not detected!');
94 }
95
96 $lib = GANTRY5_LIBRARY;
97 $autoload = "{$lib}/vendor/autoload.php";
98
99 // Initialize auto-loading.
100 if (!file_exists($autoload)) {
101 throw new \LogicException('Please run composer in Gantry 5 Library!');
102 }
103
104 // In PHP >=7.2.5 we need to use newer version of ctype library.
105 $useNewLibraries = \PHP_VERSION_ID >= 70205 && GANTRY5_PLATFORM !== 'grav';
106 if ($useNewLibraries) {
107 /** @var ClassLoader $loader */
108 $loader = require "{$lib}/compat/vendor/autoload.php";
109 $loader->unregister();
110 }
111
112 /** @var ClassLoader $loader */
113 $loader = require $autoload;
114
115 // In PHP >=7.2.5 we need to use newer version of Pimple and Twig.
116 if ($useNewLibraries) {
117 $loader->setPsr4('Twig\\', "{$lib}/compat/vendor/twig/twig/src");
118 $loader->set('Twig_', "{$lib}/compat/vendor/twig/twig/lib");
119 $loader->set('Pimple', "{$lib}/compat/vendor/pimple/pimple/src");
120 }
121
122 // Skip registering SCSS compiler until it's needed.
123 $loader->setPsr4('ScssPhp\\ScssPhp\\', '');
124 $loader->setPsr4('Leafo\\ScssPhp\\', '');
125
126 // Support for development environments.
127 if (file_exists($lib . '/src/platforms')) {
128 $loader->addPsr4('Gantry\\', "{$lib}/src/platforms/" . GANTRY5_PLATFORM . '/classes/Gantry', true);
129 }
130
131 return $loader;
132 }
133 }
134