PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.7.0
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.7.0
1.7.2 1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / vendor / automattic / jetpack-autoloader / src / CustomAutoloaderPlugin.php
hostinger-reach / vendor / automattic / jetpack-autoloader / src Last commit date
AutoloadFileWriter.php 7 months ago AutoloadGenerator.php 1 month ago AutoloadProcessor.php 1 year ago CustomAutoloaderPlugin.php 1 month ago ManifestGenerator.php 1 year ago autoload.php 1 year ago class-autoloader-handler.php 1 year ago class-autoloader-locator.php 1 year ago class-autoloader.php 1 year ago class-container.php 1 year ago class-hook-manager.php 1 year ago class-latest-autoloader-guard.php 1 year ago class-manifest-reader.php 1 year ago class-path-processor.php 1 year ago class-php-autoloader.php 1 year ago class-plugin-locator.php 1 year ago class-plugins-handler.php 1 year ago class-shutdown-handler.php 1 year ago class-version-loader.php 1 year ago class-version-selector.php 1 year ago
CustomAutoloaderPlugin.php
189 lines
1 <?php
2 /**
3 * Custom Autoloader Composer Plugin, hooks into composer events to generate the custom autoloader.
4 *
5 * @package automattic/jetpack-autoloader
6 */
7
8 namespace Automattic\Jetpack\Autoloader;
9
10 use Composer\Composer;
11 use Composer\EventDispatcher\EventSubscriberInterface;
12 use Composer\IO\IOInterface;
13 use Composer\Plugin\PluginInterface;
14 use Composer\Script\Event;
15 use Composer\Script\ScriptEvents;
16
17 /**
18 * Class CustomAutoloaderPlugin.
19 *
20 * @package automattic/jetpack-autoloader
21 */
22 class CustomAutoloaderPlugin implements PluginInterface, EventSubscriberInterface {
23
24 /**
25 * IO object.
26 *
27 * @var IOInterface IO object.
28 */
29 private $io;
30
31 /**
32 * Composer object.
33 *
34 * @var Composer Composer object.
35 */
36 private $composer;
37
38 /**
39 * Do nothing.
40 *
41 * @param Composer $composer Composer object.
42 * @param IOInterface $io IO object.
43 */
44 public function activate( Composer $composer, IOInterface $io ) {
45 $this->composer = $composer;
46 $this->io = $io;
47 }
48
49 /**
50 * Do nothing.
51 * phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
52 *
53 * @param Composer $composer Composer object.
54 * @param IOInterface $io IO object.
55 */
56 public function deactivate( Composer $composer, IOInterface $io ) {
57 /*
58 * Intentionally left empty. This is a PluginInterface method.
59 * phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
60 */
61 }
62
63 /**
64 * Do nothing.
65 * phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
66 *
67 * @param Composer $composer Composer object.
68 * @param IOInterface $io IO object.
69 */
70 public function uninstall( Composer $composer, IOInterface $io ) {
71 /*
72 * Intentionally left empty. This is a PluginInterface method.
73 * phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
74 */
75 }
76
77 /**
78 * Tell composer to listen for events and do something with them.
79 *
80 * @return array List of subscribed events.
81 */
82 public static function getSubscribedEvents() {
83 return array(
84 ScriptEvents::POST_AUTOLOAD_DUMP => 'postAutoloadDump',
85 );
86 }
87
88 /**
89 * Generate the custom autolaoder.
90 *
91 * @param Event $event Script event object.
92 */
93 public function postAutoloadDump( Event $event ) {
94 // When the autoloader is not required by the root package we don't want to execute it.
95 // This prevents unwanted transitive execution that generates unused autoloaders or
96 // at worst throws fatal executions.
97 if ( ! $this->isRequiredByRoot() ) {
98 return;
99 }
100
101 $config = $this->composer->getConfig();
102
103 if ( 'vendor' !== $config->raw()['config']['vendor-dir'] ) {
104 $this->io->writeError( "\n<error>An error occurred while generating the autoloader files:", true );
105 $this->io->writeError( 'The project\'s composer.json or composer environment set a non-default vendor directory.', true );
106 $this->io->writeError( 'The default composer vendor directory must be used.</error>', true );
107 exit( 0 );
108 }
109
110 $installationManager = $this->composer->getInstallationManager();
111 $repoManager = $this->composer->getRepositoryManager();
112 $localRepo = $repoManager->getLocalRepository();
113 $package = $this->composer->getPackage();
114 $optimize = $event->getFlags()['optimize'];
115 $suffix = $this->determineSuffix();
116
117 $generator = new AutoloadGenerator( $this->io );
118 $generator->dump( $this->composer, $config, $localRepo, $package, $installationManager, 'composer', $optimize, $suffix );
119 }
120
121 /**
122 * Determine the suffix for the autoloader class.
123 *
124 * Reuses an existing suffix from vendor/autoload_packages.php or vendor/autoload.php if possible.
125 *
126 * @return string Suffix.
127 */
128 private function determineSuffix() {
129 $config = $this->composer->getConfig();
130 $vendorPath = $config->get( 'vendor-dir' );
131
132 // Command line.
133 $suffix = $config->get( 'autoloader-suffix' );
134 if ( $suffix ) {
135 return $suffix;
136 }
137
138 // Reuse our own suffix, if any.
139 if ( is_readable( $vendorPath . '/autoload_packages.php' ) ) {
140 $content = file_get_contents( $vendorPath . '/autoload_packages.php' );
141 if ( preg_match( '/^namespace Automattic\\\\Jetpack\\\\Autoloader\\\\jp([^;\s]+?)(?:\\\\al[^;\s]+)?;/m', $content, $match ) ) {
142 return $match[1];
143 }
144 }
145
146 // Reuse Composer's suffix, if any.
147 if ( is_readable( $vendorPath . '/autoload.php' ) ) {
148 $content = file_get_contents( $vendorPath . '/autoload.php' );
149 if ( preg_match( '{ComposerAutoloaderInit([^:\s]+)::}', $content, $match ) ) {
150 return $match[1];
151 }
152 }
153
154 // Generate a random suffix.
155 return md5( uniqid( '', true ) );
156 }
157
158 /**
159 * Checks to see whether or not the root package is the one that required the autoloader.
160 *
161 * @return bool
162 */
163 private function isRequiredByRoot() {
164 $package = $this->composer->getPackage();
165 $requires = $package->getRequires();
166 if ( ! is_array( $requires ) ) { // @phan-suppress-current-line PhanRedundantCondition -- Earlier Composer versions may not have guaranteed this.
167 $requires = array();
168 }
169 $devRequires = $package->getDevRequires();
170 if ( ! is_array( $devRequires ) ) { // @phan-suppress-current-line PhanRedundantCondition -- Earlier Composer versions may not have guaranteed this.
171 $devRequires = array();
172 }
173 $requires = array_merge( $requires, $devRequires );
174
175 if ( empty( $requires ) ) {
176 $this->io->writeError( "\n<error>The package is not required and this should never happen?</error>", true );
177 exit( 0 );
178 }
179
180 foreach ( $requires as $require ) {
181 if ( 'automattic/jetpack-autoloader' === $require->getTarget() ) {
182 return true;
183 }
184 }
185
186 return false;
187 }
188 }
189