本文整理匯總了PHP中Composer\Script\Event::getComposer方法的典型用法代碼示例。如果您正苦於以下問題:PHP Event::getComposer方法的具體用法?PHP Event::getComposer怎麽用?PHP Event::getComposer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Composer\Script\Event
的用法示例。
在下文中一共展示了Event::getComposer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generate
public static function generate(Event $event)
{
$io = $event->getIO();
$packages = $event->getComposer()->getRepositoryManager()->getLocalRepository()->getPackages();
$requires = $event->getComposer()->getPackage()->getRequires();
// the packages and the required dependencies does not have all information
// so we have to use both arrays to extract needed details
foreach ($requires as $i => $require) {
/** @var $require \Composer\Package\Link **/
$search = array_filter($packages, function ($e) use($require) {
return $e->getName() == $require->getTarget();
});
if (!empty($search)) {
$package = current($search);
/** @var $package \Composer\Package\Package **/
$io->write('<info>name</info> : ' . '<comment>' . $package->getPrettyName() . '</comment>', true);
$io->write('<info>descrip.</info> : ' . $package->getDescription(), true);
$io->write('<info>license</info> : ' . implode(', ', $package->getLicense()), true);
$io->write('<info>version</info> : ' . $package->getPrettyVersion(), true);
$io->write('<info>constraint</info> : ' . $require->getPrettyConstraint(), true);
$io->write('<info>source</info> : ' . $package->getSourceUrl(), true);
$io->write('<info>homepage</info> : ' . ($package->getHomepage() ? $package->getHomepage() : str_replace(".git", "", $package->getSourceUrl())), true);
$subRequires = implode(', ', array_map(function ($package) {
return $package->getTarget();
}, $package->getRequires()));
$io->write('<info>requires</info> : ' . ($subRequires ? $subRequires : 'none'), true);
$io->write('', true);
}
}
}
示例2: addPhpCsToPreCommitHook
public static function addPhpCsToPreCommitHook(Event $event)
{
$extra = $event->getComposer()->getPackage()->getExtra();
$dependencyToResolve = self::arrayResolvePath("codesniffer:standard:dependency", $extra);
if (is_null($dependencyToResolve)) {
$event->getIO()->writeError("Cannot install pre-commit hooks. No CodeSniffer standard configured at extra->codesniffer->standard.");
return;
}
if (is_array($dependencyToResolve)) {
$event->getIO()->writeError("Cannot install pre-commit hooks. Configuration of extra->codesniffer->standard->dependency is invalid.");
return;
}
$originFile = getcwd() . '/.git/hooks/pre-commit';
if (!is_dir(dirname($originFile))) {
mkdir(dirname($originFile), 0777, true);
}
$templateContent = file_get_contents(__DIR__ . '/templates/git/hooks/pre-commit-phpcs');
$originContent = '';
if (file_exists($originFile)) {
$originContent = file_get_contents($originFile);
}
if (strpos($originContent, '# BEGIN:metasyntactical/composer-codesniffer-hooks') !== false) {
return;
}
$newContent = $originContent;
if (mb_strlen($originContent)) {
$newContent .= "\n";
}
$newContent .= str_replace(array("{STANDARDPATH}"), array($event->getComposer()->getConfig()->get("vendor-dir", Config::RELATIVE_PATHS) . "/{$dependencyToResolve}/ruleset.xml"), $templateContent);
file_put_contents($originFile, $newContent);
$perms = fileperms($originFile);
chmod($originFile, $perms | 0x40 | 0x8 | 0x1);
clearstatcache(null, $originFile);
}
示例3: getOptions
/**
* Private method that manages the options of commands.
*
* @param Event $event The command event
*
* @return array
*/
private static function getOptions(Event $event)
{
$extras = $event->getComposer()->getPackage()->getExtra();
$options = isset($extras['kreta-distribution']) ? $extras['kreta-distribution'] : [];
$options = array_merge(['npm-bin-links' => true, 'process-timeout' => $event->getComposer()->getConfig()->get('process-timeout')], $options);
return $options;
}
示例4: install
/**
* @return int
*/
public function install()
{
$io = $this->event->getIO();
$composer = $this->event->getComposer();
$repository = new PhantomJSVersionRepository($io, $composer);
$versions = $repository->getVersions();
if (!count($versions)) {
$io->write('<error>Could not found any version.</error>');
return 1;
}
$binDir = $composer->getConfig()->get('bin-dir');
is_dir($binDir) ?: mkdir($binDir, 0755, true);
$binDir = realpath($binDir);
$vendorDir = $composer->getConfig()->get('vendor-dir') . '/sgc-fireball/phantomjs';
is_dir($vendorDir) ?: mkdir($vendorDir, 0755, true);
$vendorDir = realpath($vendorDir);
$downloader = new PhantomJSDownloader($io, $composer);
foreach ($versions as $version) {
try {
$package = $downloader->createComposerPackage($version, $vendorDir);
if ($downloader->download($package)) {
copy($vendorDir . '/bin/phantomjs', $binDir . '/phantomjs');
chmod($binDir . '/phantomjs', 0755);
return 0;
}
} catch (\Exception $e) {
}
}
$io->write(sprintf('<error>Could not download %s.</error>', $package->getDistUrl()));
return 2;
}
示例5: install
/**
* Installs the shop files.
*
* @param \Composer\Script\Event $event Event instance
* @throws \RuntimeException If an error occured
*/
public static function install(\Composer\Script\Event $event)
{
$repository = $event->getComposer()->getRepositoryManager();
$t3package = $repository->findPackage('aimeos/aimeos-typo3', '*');
if ($t3package !== null) {
$installer = $event->getComposer()->getInstallationManager();
$t3path = $installer->getInstallPath($t3package);
if (($package = $repository->findPackage('aimeos/ai-client-html', '*')) !== null) {
$event->getIO()->write('Installing Aimeos public files from HTML client');
$path = $installer->getInstallPath($package);
self::copyRecursive($path . '/client/html/themes', $t3path . '/Resources/Public/Themes');
}
if (($package = $repository->findPackage('aimeos/ai-admin-extadm', '*')) !== null) {
$event->getIO()->write('Installing Aimeos public files from ExtJS admin');
$path = $installer->getInstallPath($package);
self::copyRecursive($path . '/admin/extjs/resources', $t3path . '/Resources/Public/Admin/extjs/resources');
self::copyRecursive($path . '/admin/extjs/lib/ext.ux/Portal/resources', $t3path . '/Resources/Public/Admin/extjs/lib/ext.ux/Portal');
self::copyRecursive($path . '/admin/extjs/lib/ext.ux/AdvancedSearch/resources', $t3path . '/Resources/Public/Admin/extjs/lib/ext.ux/AdvancedSearch');
}
if (file_exists($t3path . '/Resources/Private/Extensions') === false && ($package = $repository->findPackage('aimeos/ai-typo3', '*')) !== null) {
$event->getIO()->write('Creating symlink to Aimeos extension directory');
$path = dirname($installer->getInstallPath($package));
symlink(getcwd() . '/' . $path, $t3path . '/Resources/Private/Extensions');
}
}
}
示例6: preAutoloadDumpEvent
public function preAutoloadDumpEvent(Script\Event $event)
{
if ($event->isPropagationStopped()) {
return;
}
$references = array();
// find current package reference
$localPackageReference = $this->determineLocalPackageReference();
if ($localPackageReference !== null) {
$references[$event->getComposer()->getPackage()->getName()] = $localPackageReference;
}
// enumerate local repository packages
foreach ($event->getComposer()->getRepositoryManager()->getLocalRepository()->getCanonicalPackages() as $package) {
if ($package->getSourceReference() !== null) {
$references[$package->getName()] = $package->getSourceReference();
} else {
if ($package->getDistReference() !== null) {
$references[$package->getName()] = $package->getDistReference();
}
}
}
$destination = $event->getComposer()->getConfig()->get('vendor-dir') . DIRECTORY_SEPARATOR . 'mcuelenaere' . DIRECTORY_SEPARATOR . 'composer-revision-plugin' . DIRECTORY_SEPARATOR . 'gen' . DIRECTORY_SEPARATOR . 'revisions.php';
$classGenerator = new ReferenceClassGenerator($event->getComposer()->getConfig());
$classGenerator->generate($destination, $references);
}
示例7: build
/**
* @param Event $event
*
* @throws \InvalidArgumentException when extra configuration is not defined properly
*/
public static function build(Event $event)
{
$io = $event->getIO();
// everything needed for this installer
// is stored in the "extra" config section
$extra = $event->getComposer()->getPackage()->getExtra();
if (!array_key_exists(self::PROPERTY_PUPPET_MODULES_DIR, $extra) || !array_key_exists(self::PROPERTY_PUPPET_MODULES, $extra)) {
throw new \InvalidArgumentException('"extra" configuration needs properties "modules-dir" and "modules"');
}
// find out where we are and where we should install the puppet modules
$modulesDir = $extra[self::PROPERTY_PUPPET_MODULES_DIR];
$vendorDir = realpath($event->getComposer()->getConfig()->get('vendor-dir'));
$projectDir = realpath($vendorDir . '/..');
// copy original puppet module dir from vendors to the puppet modules dir
foreach ($extra[self::PROPERTY_PUPPET_MODULES] as $name => $target) {
if (empty($name) || empty($target)) {
$io->write(sprintf('Skip Puppet module installation from "%s" to "%s"', $name, $target));
continue;
}
$modulePath = $modulesDir . '/' . $target;
$io->write(sprintf('Installing Puppet module "%s" to "%s"', $name, $modulePath));
$from = $vendorDir . '/' . $name;
$to = $projectDir . '/' . $modulePath;
// @TODO is there a better way without installing any other vendor lib?
shell_exec("rsync -rv --delete {$from}/ {$to}/");
}
}
示例8: overload
/**
* @param Event $event
*/
public static function overload(Event $event)
{
$extra = $event->getComposer()->getPackage()->getExtra();
if ($event->isDevMode()) {
$envs = [static::EXTRA_OVERLOAD_CLASS, static::EXTRA_OVERLOAD_CLASS_DEV];
$cacheDir = static::EXTRA_OVERLOAD_CACHE_DIR_DEV;
if (array_key_exists($cacheDir, $extra) === false) {
$cacheDir = static::EXTRA_OVERLOAD_CACHE_DIR;
}
} else {
$envs = [static::EXTRA_OVERLOAD_CLASS];
$cacheDir = static::EXTRA_OVERLOAD_CACHE_DIR;
}
foreach ($envs as $extraKey) {
if (array_key_exists($extraKey, $extra)) {
$autoload = $event->getComposer()->getPackage()->getAutoload();
if (array_key_exists('classmap', $autoload) === false) {
$autoload['classmap'] = array();
}
foreach ($extra[$extraKey] as $className => $infos) {
static::generateProxy($extra[$cacheDir], $className, $infos['original-file']);
$autoload['classmap'][$className] = $infos['overload-file'];
}
$event->getComposer()->getPackage()->setAutoload($autoload);
}
}
}
示例9: onPostAutoloadDump
/**
* Plugin callback for this script event, which calls the previously implemented static method
*
* @param \Composer\Script\Event $event
* @return bool
*/
public function onPostAutoloadDump(\Composer\Script\Event $event)
{
$flags = $event->getFlags();
$config = $event->getComposer()->getConfig();
$optimizeAutoloadFiles = !empty($flags['optimize']) || $config->get('optimize-autoloader') || $config->get('classmap-authoritative');
$aliasMapGenerator = new ClassAliasMapGenerator($event->getComposer(), $event->getIO(), $optimizeAutoloadFiles);
return $aliasMapGenerator->generateAliasMap();
}
示例10: checker
/**
* @param Event $event
*/
public static function checker(Event $event)
{
$extras = $event->getComposer()->getConfig()->getExtra();
var_dump($event->getComposer()->getPackage()->getRepositories());
die('d');
$event->getIO()->write("<info>[CheckerPlugin]</info> plugin activate");
var_dump($extras);
}
示例11: copyAssets
/**
* Copy assets into you assets directory
*
* @param Event $event
*/
public static function copyAssets(Event $event)
{
$extra = $event->getComposer()->getPackage()->getExtra();
if (!isset($extra[self::EXTRA_ASSET_DIR])) {
return;
}
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
$fs = new Filesystem();
$fs->mirror($vendorDir . '/itkg/profiler/src/Itkg/Profiler/Resources/public', $extra[self::EXTRA_ASSET_DIR] . '/vendor/itkg/profiler/assets');
}
示例12: postInstall
/**
* @param Event $event
*/
public static function postInstall(Event $event)
{
static::$installationManager = $event->getComposer()->getInstallationManager();
static::$localRepository = $event->getComposer()->getRepositoryManager()->getLocalRepository();
$rootDirectory = __DIR__ . '/../../../../';
static::copyFile('twbs/bootstrap', 'dist/css/bootstrap.min.css', $rootDirectory . 'public/css/bootstrap.min.css');
static::mirrorDirectory('twbs/bootstrap', 'dist/fonts', $rootDirectory . 'public/fonts');
if (!file_exists($rootDirectory . 'app/settings.yml')) {
static::getFileSystem()->copy($rootDirectory . 'app/settings.example.yml', $rootDirectory . 'app/settings.yml', true);
}
}
示例13: getRecorder
/**
* @param Event $event
*
* @return Recorder
*/
private static function getRecorder(Event $event)
{
if (!isset(static::$recorder)) {
$vendorDir = realpath(rtrim($event->getComposer()->getConfig()->get('vendor-dir'), '/'));
$configDir = realpath($vendorDir . '/../app/config');
$logger = new ConsoleIoLogger($event->getIO());
$manager = $event->getComposer()->getRepositoryManager();
$rootPackage = $event->getComposer()->getPackage();
static::$recorder = new Recorder($manager->getLocalRepository(), new Detector($vendorDir), new BundleHandler($configDir, $logger), $rootPackage->getAliases(), $vendorDir);
}
return static::$recorder;
}
示例14: postInstallCmd
/**
* On post install cmd.
*
* @param Event $e
* @return void
*/
public static function postInstallCmd(Event $e)
{
$vendorDir = $e->getComposer()->getConfig()->get('vendor-dir');
foreach ($e->getComposer()->getPackage()->getExtra() as $pattern => $folder) {
foreach (glob($vendorDir . DIRECTORY_SEPARATOR . $pattern) as $file) {
if (file_exists($folder) === false) {
mkdir($folder);
}
copy($file, $folder . DIRECTORY_SEPARATOR . basename($file));
}
}
}
示例15: onPostUpdateInstall
/**
* Script callback; Acted on after install or update.
*/
public function onPostUpdateInstall(Event $event)
{
$settings = array('targetDir' => 'vendor/nodejs/nodejs', 'forceLocal' => false, 'includeBinInPath' => false);
$extra = $event->getComposer()->getPackage()->getExtra();
if (isset($extra['mouf']['nodejs'])) {
$rootSettings = $extra['mouf']['nodejs'];
$settings = array_merge($settings, $rootSettings);
$settings['targetDir'] = trim($settings['targetDir'], '/\\');
}
$binDir = $event->getComposer()->getConfig()->get('bin-dir');
if (!class_exists(__NAMESPACE__ . '\\NodeJsVersionMatcher')) {
//The package is being uninstalled
$this->onUninstall($binDir, $settings['targetDir']);
return;
}
$nodeJsVersionMatcher = new NodeJsVersionMatcher();
$versionConstraint = $this->getMergedVersionConstraint();
$this->verboseLog("<info>NodeJS installer:</info>");
$this->verboseLog(" - Requested version: " . $versionConstraint);
$nodeJsInstaller = new NodeJsInstaller($this->io);
$isLocal = false;
if ($settings['forceLocal']) {
$this->verboseLog(" - Forcing local NodeJS install.");
$this->installLocalVersion($nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$isLocal = true;
} else {
$globalVersion = $nodeJsInstaller->getNodeJsGlobalInstallVersion();
if ($globalVersion !== null) {
$this->verboseLog(" - Global NodeJS install found: v" . $globalVersion);
$npmPath = $nodeJsInstaller->getGlobalInstallPath('npm');
if (!$npmPath) {
$this->verboseLog(" - No NPM install found");
$this->installLocalVersion($nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$isLocal = true;
} elseif (!$nodeJsVersionMatcher->isVersionMatching($globalVersion, $versionConstraint)) {
$this->installLocalVersion($nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$isLocal = true;
} else {
$this->verboseLog(" - Global NodeJS install matches constraint " . $versionConstraint);
}
} else {
$this->verboseLog(" - No global NodeJS install found");
$this->installLocalVersion($nodeJsInstaller, $versionConstraint, $settings['targetDir']);
$isLocal = true;
}
}
// Now, let's create the bin scripts that start node and NPM
$nodeJsInstaller->createBinScripts($binDir, $settings['targetDir'], $isLocal);
// Finally, let's register vendor/bin in the PATH.
if ($settings['includeBinInPath']) {
$nodeJsInstaller->registerPath($binDir);
}
}