本文整理匯總了PHP中Composer\Script\Event::getName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Event::getName方法的具體用法?PHP Event::getName怎麽用?PHP Event::getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Composer\Script\Event
的用法示例。
在下文中一共展示了Event::getName方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: install
/**
* Install the "status" database into the project
*
* This should be added to the composer.json of the project requiring this
* package.
*
* {
* "require": {
* "zfcampus/zf-apigility-rest-example": "dev-master"
* },
* "scripts": {
* "post-package-install": "ZF\\ApiFirstRestExample\\Installer::install",
* "post-create-project-cmd": "ZF\\ApiFirstRestExample\\Installer::install"
* }
* }
*
*
* @param Event $event
* @return void
*/
public static function install(Event $event)
{
$composer = $event->getComposer();
$eventName = $event->getName();
if ($event instanceof PackageEvent) {
$package = $event->getOperation()->getPackage();
if ($package != 'zfcampus/zf-apigility-example') {
return;
}
} else {
$package = $composer->getRepositoryManager()->findPackage('zfcampus/zf-apigility-example');
if (null === $package) {
return;
}
}
$dataDir = getcwd() . '/data/db';
$dbTarget = $dataDir . '/status.db';
if (file_exists($dbTarget)) {
// If it's already present, do nothing
return;
}
if (!is_dir($dataDir)) {
mkdir($dataDir);
}
$installManager = $composer->getInstallationManager();
$packageDir = $installManager->getInstallPath($package);
copy($packageDir . '/data/status.db', $dbTarget);
chmod($dataDir . '/status.db', 0777);
}
示例2: listen
/**
* Listens to Composer events.
*
* This method is very minimalist on purpose. We want to load the actual
* implementation only after updating the Composer packages so that we get
* the updated version (if available).
*
* @param Event $event The Composer event.
*/
public function listen(Event $event)
{
if (!empty($this->handledEvents[$event->getName()])) {
return;
}
$this->handledEvents[$event->getName()] = true;
// Plugin has been uninstalled
if (!file_exists(__FILE__) || !file_exists(__DIR__ . '/PluginImplementation.php')) {
return;
}
// Load the implementation only after updating Composer so that we get
// the new version of the plugin when a new one was installed
if (null === $this->pluginImplementation) {
$this->pluginImplementation = new PluginImplementation($event);
}
switch ($event->getName()) {
case ScriptEvents::PRE_AUTOLOAD_DUMP:
$this->pluginImplementation->preAutoloadDump();
break;
case ScriptEvents::POST_AUTOLOAD_DUMP:
$this->pluginImplementation->postAutoloadDump();
break;
}
}
示例3: listen
/**
* Listens to Composer events.
*
* This method is very minimalist on purpose. We want to load the actual
* implementation only after updating the Composer packages so that we get
* the updated version (if available).
*
* @param Event $event The Composer event.
*/
public function listen(Event $event)
{
// Plugin has been uninstalled
if (!file_exists(__FILE__) || !file_exists(__DIR__ . '/PuliPluginImpl.php')) {
return;
}
// Load the implementation only after updating Composer so that we get
// the new version of the plugin when a new one was installed
if (null === $this->impl) {
$this->impl = new PuliPluginImpl($event);
}
switch ($event->getName()) {
case ScriptEvents::POST_AUTOLOAD_DUMP:
$this->impl->postAutoloadDump();
break;
case ScriptEvents::POST_INSTALL_CMD:
case ScriptEvents::POST_UPDATE_CMD:
$this->impl->postInstall();
break;
}
}
示例4: hook
public static function hook(Event $event)
{
switch ($event->getName()) {
case ScriptEvents::POST_INSTALL_CMD:
$command = 'install';
break;
case ScriptEvents::POST_UPDATE_CMD:
$command = 'update';
break;
default:
return;
}
$executableFinder = new ExecutableFinder();
$npmPath = $executableFinder->find('npm');
if ($npmPath === null) {
throw new \RuntimeException('Unable to locate npm executable.');
}
exec('cd ' . escapeshellarg(__DIR__ . '/js') . ' && "' . $npmPath . '" ' . escapeshellarg($command), $out, $code);
$io = $event->getIO();
if ($code != 0) {
throw new \RuntimeException('Error executing npm: ' . $out);
}
$io->write($out);
}
示例5: onInstallUpdateOrDump
/**
* Handle an event callback for an install, update or dump command by
* checking for "merge-plugin" in the "extra" data and merging package
* contents if found.
*
* @param Event $event
*/
public function onInstallUpdateOrDump(Event $event)
{
$this->state->loadSettings();
$this->state->setDevMode($event->isDevMode());
$this->mergeFiles($this->state->getIncludes(), false);
$this->mergeFiles($this->state->getRequires(), true);
if ($event->getName() === ScriptEvents::PRE_AUTOLOAD_DUMP) {
$this->state->setDumpAutoloader(true);
$flags = $event->getFlags();
if (isset($flags['optimize'])) {
$this->state->setOptimizeAutoloader($flags['optimize']);
}
}
}
示例6: createUser
public static function createUser(Event $event)
{
self::call(new Event($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), ['-route=honeybee.system_account.user.create']));
}
示例7: getListeners
/**
* @param Event $event Event object
* @return array Listeners
*/
protected function getListeners(Event $event)
{
$package = $this->composer->getPackage();
$scripts = $package->getScripts();
if (empty($scripts[$event->getName()])) {
return array();
}
if ($this->loader) {
$this->loader->unregister();
}
$generator = $this->composer->getAutoloadGenerator();
$packages = $this->composer->getRepositoryManager()->getLocalRepository()->getPackages();
$packageMap = $generator->buildPackageMap($this->composer->getInstallationManager(), $package, $packages);
$map = $generator->parseAutoloads($packageMap, $package);
$this->loader = $generator->createLoader($map);
$this->loader->register();
return $scripts[$event->getName()];
}
示例8: onInstallUpdateOrDump
/**
* Handle an event callback for an install, update or dump command by
* checking for "merge-patterns" in the "extra" data and merging package
* contents if found.
*
* @param Event $event
*/
public function onInstallUpdateOrDump(Event $event)
{
$config = $this->readConfig($this->getRootPackage());
if (isset($config['recurse'])) {
$this->recurse = (bool) $config['recurse'];
}
if ($config['include']) {
$this->loader = new ArrayLoader();
$this->duplicateLinks = array('require' => array(), 'require-dev' => array());
$this->devMode = $event->isDevMode();
$this->mergePackages($config);
}
if ($event->getName() === ScriptEvents::PRE_AUTOLOAD_DUMP) {
$this->dumpAutoloader = true;
$flags = $event->getFlags();
if (isset($flags['optimize'])) {
$this->optimizeAutoloader = $flags['optimize'];
}
}
}
示例9: install
/**
* Install phpBB
*
* Run ``composer run-script post-install-cmd`` to test the script.
*
* @param Event $event
*/
public static function install(Event $event)
{
$eventName = $event->getName();
$io = $event->getIO();
$composer = $event->getComposer();
$packages = $composer->getRepositoryManager()->getLocalRepository()->getPackages();
$installationManager = $composer->getInstallationManager();
// Get project dir
$projectDir = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
// Get phpbb installation dir
$topExtra = $composer->getPackage()->getExtra();
$installationDir = 'phpbb';
if (!empty($topExtra['phpbb-install-dir'])) {
$installationDir = $topExtra['phpbb-install-dir'];
}
$dest = $projectDir . DIRECTORY_SEPARATOR . $installationDir;
$phpbbPackage = false;
/* @var $package \Composer\Package\PackageInterface */
foreach ($packages as $package) {
if ($package->getName() == 'phpbb/phpbb' && version_compare($package->getVersion(), '3.0') >= 0) {
$io->write(sprintf('<info>Detected phpBB %s</info>', $package->getVersion()));
$phpbbPackage = $package;
}
}
if (!$phpbbPackage) {
$io->write('<error>phpBB is not installed!</error>');
return;
}
if (!is_dir($dest)) {
if (!mkdir($dest, 0644, true)) {
$io->write(sprintf('<error>Failed to create destination: </error>', $dest));
return;
}
$io->write(sprintf('<info>Created destination: </info>', $dest));
}
// Get phpBB vendor dir
$src = $installationManager->getInstallPath($phpbbPackage);
// Copy resources
$io->write('<info>Copying resources</info>', false);
foreach (self::$resources as $resource => $destination) {
self::xcopy($src . $resource, $dest . $destination, 0644);
$io->write('.', false);
}
$io->write(' <info>Done!</info>');
// Set permissions
$io->write('<info>Setting permissions</info>', false);
foreach (self::$permissions as $resource => $permission) {
if (!file_exists($dest . $resource)) {
$io->write('<comment>.</comment>', false);
} elseif (chmod($dest . $resource, $permission)) {
$io->write('.', false);
} else {
$io->write('<error>F</error>', false);
}
}
$io->write(' <info>Done!</info>');
// Setup .htaccess
$autoloader = $projectDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
$content = <<<EOF
SetEnv PHPBB_NO_COMPOSER_AUTOLOAD true
SetEnv PHPBB_AUTOLOAD {$autoloader}
EOF;
$io->write('<info>Patching .htaccess</info>', false);
$content .= file_get_contents($src . DIRECTORY_SEPARATOR . '.htaccess');
if (false !== file_put_contents($dest . DIRECTORY_SEPARATOR . '.htaccess', $content)) {
$io->write('.', false);
} else {
$io->write('<error>F</error>', false);
}
$io->write(' <info>Done!</info>');
// Ready
$io->write(sprintf('<comment>Please open %s and delete %s afterwards.</comment>', 'http://your-site.com/install/database_update.php', $dest . DIRECTORY_SEPARATOR . 'install'));
}
示例10: __construct
/**
* Instantiate an AbstractTask object.
*
* @since 0.1.0
*
* @param ConfigInterface $config Configuration settings.
* @param Event $event The Composer Event that is being handled.
*
* @throws FailedToProcessConfigException If the configuration could not be processed.
*/
public function __construct(ConfigInterface $config, Event $event)
{
$this->processConfig($config);
$this->event = $event;
$this->name = $event->getName();
$this->arguments = $event->getArguments();
$this->flags = $event->getFlags();
$this->composer = $event->getComposer();
$this->io = $event->getIO();
}