WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Самая быстрая Тема-конструктор для WordPress
класс не описан

Automattic\Jetpack\Autoloader

CustomAutoloaderPlugin{} WC 1.0

Class CustomAutoloaderPlugin.

Хуков нет.

Возвращает

Null. Ничего.

Использование

$CustomAutoloaderPlugin = new CustomAutoloaderPlugin();
// use class methods

Методы

  1. activate( Composer $composer, IOInterface $io )
  2. activate( Composer $composer, IOInterface $io )
  3. activate( Composer $composer, IOInterface $io )
  4. deactivate( Composer $composer, IOInterface $io )
  5. deactivate( Composer $composer, IOInterface $io )
  6. deactivate( Composer $composer, IOInterface $io )
  7. getSubscribedEvents()
  8. getSubscribedEvents()
  9. getSubscribedEvents()
  10. postAutoloadDump( Event $event )
  11. postAutoloadDump( Event $event )
  12. postAutoloadDump( Event $event )
  13. uninstall( Composer $composer, IOInterface $io )
  14. uninstall( Composer $composer, IOInterface $io )
  15. uninstall( Composer $composer, IOInterface $io )

Заметки

  • Пакет: automattic/jetpack-autoloader

Код CustomAutoloaderPlugin{} WC 4.6.1

<?php
class CustomAutoloaderPlugin implements PluginInterface, EventSubscriberInterface {

	/**
	 * IO object.
	 *
	 * @var IOInterface IO object.
	 */
	private $io;

	/**
	 * Composer object.
	 *
	 * @var Composer Composer object.
	 */
	private $composer;

	/**
	 * Do nothing.
	 *
	 * @param Composer    $composer Composer object.
	 * @param IOInterface $io IO object.
	 */
	public function activate( Composer $composer, IOInterface $io ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
		$this->composer = $composer;
		$this->io       = $io;
	}

	/**
	 * Do nothing.
	 * phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
	 *
	 * @param Composer    $composer Composer object.
	 * @param IOInterface $io IO object.
	 */
	public function deactivate( Composer $composer, IOInterface $io ) {
		/*
		 * Intentionally left empty. This is a PluginInterface method.
		 * phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
		 */
	}

	/**
	 * Do nothing.
	 * phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
	 *
	 * @param Composer    $composer Composer object.
	 * @param IOInterface $io IO object.
	 */
	public function uninstall( Composer $composer, IOInterface $io ) {
		/*
		 * Intentionally left empty. This is a PluginInterface method.
		 * phpcs:enable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
		 */
	}


	/**
	 * Tell composer to listen for events and do something with them.
	 *
	 * @return array List of subscribed events.
	 */
	public static function getSubscribedEvents() {
		return array(
			ScriptEvents::POST_AUTOLOAD_DUMP => 'postAutoloadDump',
		);
	}

	/**
	 * Generate the custom autolaoder.
	 *
	 * @param Event $event Script event object.
	 */
	public function postAutoloadDump( Event $event ) {

		$config = $this->composer->getConfig();

		if ( 'vendor' !== $config->raw()['config']['vendor-dir'] ) {
			$this->io->writeError( "\n<error>An error occurred while generating the autoloader files:", true );
			$this->io->writeError( 'The project\'s composer.json or composer environment set a non-default vendor directory.', true );
			$this->io->writeError( 'The default composer vendor directory must be used.</error>', true );
			exit();
		}

		$installationManager = $this->composer->getInstallationManager();
		$repoManager         = $this->composer->getRepositoryManager();
		$localRepo           = $repoManager->getLocalRepository();
		$package             = $this->composer->getPackage();
		$optimize            = true;
		$suffix              = $config->get( 'autoloader-suffix' )
			? $config->get( 'autoloader-suffix' )
			: md5( uniqid( '', true ) );

		$generator = new AutoloadGenerator( $this->io );

		$generator->dump( $config, $localRepo, $package, $installationManager, 'composer', $optimize, $suffix );
		$this->generated = true;
	}

}