• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Json\JsonFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Composer\Json\JsonFile的典型用法代码示例。如果您正苦于以下问题:PHP JsonFile类的具体用法?PHP JsonFile怎么用?PHP JsonFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了JsonFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     if ($input->post('FORM_SUBMIT') == 'tl_composer_migrate_undo') {
         /** @var RootPackage $rootPackage */
         $rootPackage = $this->composer->getPackage();
         $requires = $rootPackage->getRequires();
         foreach (array_keys($requires) as $package) {
             if ($package != 'contao-community-alliance/composer') {
                 unset($requires[$package]);
             }
         }
         $rootPackage->setRequires($requires);
         $lockPathname = preg_replace('#\\.json$#', '.lock', $this->configPathname);
         /** @var DownloadManager $downloadManager */
         $downloadManager = $this->composer->getDownloadManager();
         $downloadManager->setOutputProgress(false);
         $installer = Installer::create($this->io, $this->composer);
         if (file_exists(TL_ROOT . '/' . $lockPathname)) {
             $installer->setUpdate(true);
         }
         if ($installer->run()) {
             $_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
         } else {
             $_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
             $this->redirect('contao/main.php?do=composer&migrate=undo');
         }
         // load config
         $json = new JsonFile(TL_ROOT . '/' . $this->configPathname);
         $config = $json->read();
         // remove migration status
         unset($config['extra']['contao']['migrated']);
         // write config
         $json->write($config);
         // disable composer client and enable repository client
         $inactiveModules = deserialize($GLOBALS['TL_CONFIG']['inactiveModules']);
         $inactiveModules[] = '!composer';
         foreach (array('rep_base', 'rep_client', 'repository') as $module) {
             $pos = array_search($module, $inactiveModules);
             if ($pos !== false) {
                 unset($inactiveModules[$pos]);
             }
         }
         if (version_compare(VERSION, '3', '>=')) {
             $skipFile = new \File('system/modules/!composer/.skip');
             $skipFile->write('Remove this file to enable the module');
             $skipFile->close();
         }
         if (file_exists(TL_ROOT . '/system/modules/repository/.skip')) {
             $skipFile = new \File('system/modules/repository/.skip');
             $skipFile->delete();
         }
         $this->Config->update("\$GLOBALS['TL_CONFIG']['inactiveModules']", serialize($inactiveModules));
         $this->redirect('contao/main.php?do=repository_manager');
     }
     $template = new \BackendTemplate('be_composer_client_migrate_undo');
     $template->composer = $this->composer;
     $template->output = $_SESSION['COMPOSER_OUTPUT'];
     unset($_SESSION['COMPOSER_OUTPUT']);
     return $template->parse();
 }
开发者ID:designs2,项目名称:composer-client,代码行数:63,代码来源:UndoMigrationController.php


示例2: handle

 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 public function handle(\Input $input)
 {
     $packageName = $input->get('install');
     if ($packageName == 'contao/core') {
         $this->redirect('contao/main.php?do=composer');
     }
     if ($input->post('version')) {
         $version = base64_decode(rawurldecode($input->post('version')));
         // make a backup
         copy(TL_ROOT . '/' . $this->configPathname, TL_ROOT . '/' . $this->configPathname . '~');
         // update requires
         $json = new JsonFile(TL_ROOT . '/' . $this->configPathname);
         $config = $json->read();
         if (!array_key_exists('require', $config)) {
             $config['require'] = array();
         }
         $config['require'][$packageName] = $version;
         ksort($config['require']);
         $json->write($config);
         Messages::addInfo(sprintf($GLOBALS['TL_LANG']['composer_client']['added_candidate'], $packageName, $version));
         $_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
         $this->redirect('contao/main.php?do=composer');
     }
     $installationCandidates = $this->searchPackage($packageName);
     if (empty($installationCandidates)) {
         Messages::addError(sprintf($GLOBALS['TL_LANG']['composer_client']['noInstallationCandidates'], $packageName));
         $_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
         $this->redirect('contao/main.php?do=composer');
     }
     $template = new \BackendTemplate('be_composer_client_install');
     $template->composer = $this->composer;
     $template->packageName = $packageName;
     $template->candidates = $installationCandidates;
     return $template->parse();
 }
开发者ID:contao-community-alliance,项目名称:composer-client,代码行数:40,代码来源:DetailsController.php


示例3: handle

 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     $removeNames = $input->post('packages') ? explode(',', $input->post('packages')) : array($input->post('remove'));
     // filter undeletable packages
     $removeNames = array_filter($removeNames, function ($removeName) {
         return !in_array($removeName, InstalledController::$UNDELETABLE_PACKAGES);
     });
     // skip empty
     if (empty($removeNames)) {
         $this->redirect('contao/main.php?do=composer');
     }
     // make a backup
     copy(TL_ROOT . '/' . $this->configPathname, TL_ROOT . '/' . $this->configPathname . '~');
     // update requires
     $json = new JsonFile(TL_ROOT . '/' . $this->configPathname);
     $config = $json->read();
     if (!array_key_exists('require', $config)) {
         $config['require'] = array();
     }
     foreach ($removeNames as $removeName) {
         unset($config['require'][$removeName]);
     }
     $json->write($config);
     $_SESSION['TL_INFO'][] = sprintf($GLOBALS['TL_LANG']['composer_client']['removeCandidate'], implode(', ', $removeNames));
     $_SESSION['COMPOSER_OUTPUT'] .= $this->io->getOutput();
     $this->redirect('contao/main.php?do=composer');
 }
开发者ID:tim-bec,项目名称:composer-client,代码行数:30,代码来源:RemovePackageController.php


示例4: load

 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws \LogicException
  * @throws BadMethodCallException
  */
 public function load($resource, $type = null)
 {
     $path = $this->locator->locate($resource);
     $this->container->addResource(new FileResource($path));
     $file = new JsonFile($path);
     $content = $file->read();
     $extension = pathinfo($resource, PATHINFO_FILENAME);
     if (array_key_exists('parameters', $content)) {
         foreach ($content['parameters'] as $name => $parameter) {
             $this->container->setParameter($name, $parameter);
         }
         unset($content['parameters']);
     }
     if (array_key_exists('imports', $content)) {
         foreach ($content['imports'] as $import) {
             $importFilename = $import;
             if (!Path::isAbsolute($importFilename)) {
                 $importFilename = Path::join([dirname($path), $import]);
             }
             $this->import($importFilename, null, false, $file);
         }
         unset($content['imports']);
     }
     $this->container->loadFromExtension($extension, $content);
 }
开发者ID:nanbando,项目名称:core,代码行数:33,代码来源:JsonLoader.php


示例5: updateJson

 /**
  * Set up Composer JSON file.
  *
  * @return array|null
  */
 public function updateJson()
 {
     if (!is_file($this->getOption('composerjson'))) {
         $this->initJson($this->getOption('composerjson'));
     }
     $jsonFile = new JsonFile($this->getOption('composerjson'));
     if ($jsonFile->exists()) {
         $json = $jsonorig = $jsonFile->read();
         // Workaround Bolt 2.0 installs with "require": []
         if (isset($json['require']) && empty($json['require'])) {
             unset($json['require']);
         }
         $json = $this->setJsonDefaults($json);
     } else {
         // Error
         $this->messages[] = Trans::__("The Bolt extensions file '%composerjson%' isn't readable.", ['%composerjson%' => $this->getOption('composerjson')]);
         $this->app['extend.writeable'] = false;
         $this->app['extend.online'] = false;
         return null;
     }
     // Write out the file, but only if it's actually changed, and if it's writable.
     if ($json != $jsonorig) {
         try {
             umask(00);
             $jsonFile->write($json);
         } catch (\Exception $e) {
             $this->messages[] = Trans::__('The Bolt extensions Repo at %repository% is currently unavailable. Check your connection and try again shortly.', ['%repository%' => $this->app['extend.site']]);
         }
     }
     return $json;
 }
开发者ID:nectd,项目名称:nectd-web,代码行数:36,代码来源:BoltExtendJson.php


示例6: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $composer = $this->getComposer();
     $config = $composer->getConfig();
     $isInitDone = true;
     // Init packages.json
     $directory = $this->getRepositoryDirectory();
     $file = new JsonFile($directory . '/packages.json');
     if (!$file->exists()) {
         $output->writeln('<info>Initializing composer repository in</info> <comment>' . $directory . '</comment>');
         $file->write(array('packages' => (object) array()));
         $isInitDone = false;
     }
     // Init ~/composer/config.json
     $file = new JsonFile($this->getComposerHome() . '/config.json');
     $config = $file->exists() ? $file->read() : array();
     if (!isset($config['repositories'])) {
         $config['repositories'] = array();
     }
     $isRepoActived = false;
     foreach ($config['repositories'] as $repo) {
         if ($repo['type'] === 'composer' && $repo['url'] === 'file://' . $directory) {
             $isRepoActived = true;
         }
     }
     if (!$isRepoActived) {
         $output->writeln('<info>Writing stone repository in global configuration</info>');
         $config['repositories'][] = array('type' => 'composer', 'url' => 'file://' . $directory);
         $file->write($config);
         $isInitDone = false;
     }
     if ($isInitDone) {
         $output->writeln('<info>It seems stone is already configured</info>');
     }
 }
开发者ID:mattketmo,项目名称:stone,代码行数:38,代码来源:InitCommand.php


示例7: execute

 /**
  * @param InputInterface  $input  The input instance
  * @param OutputInterface $output The output instance
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $configFile = $input->getArgument('file');
     $repositoryUrl = $input->getArgument('url');
     if (preg_match('{^https?://}i', $configFile)) {
         $output->writeln('<error>Unable to write to remote file ' . $configFile . '</error>');
         return 2;
     }
     $file = new JsonFile($configFile);
     if (!$file->exists()) {
         $output->writeln('<error>File not found: ' . $configFile . '</error>');
         return 1;
     }
     if (!$this->isRepositoryValid($repositoryUrl)) {
         $output->writeln('<error>Invalid Repository URL: ' . $repositoryUrl . '</error>');
         return 3;
     }
     $config = $file->read();
     if (!isset($config['repositories']) || !is_array($config['repositories'])) {
         $config['repositories'] = [];
     }
     foreach ($config['repositories'] as $repository) {
         if (isset($repository['url']) && $repository['url'] == $repositoryUrl) {
             $output->writeln('<error>Repository already added to the file</error>');
             return 4;
         }
     }
     $config['repositories'][] = ['type' => 'vcs', 'url' => $repositoryUrl];
     $file->write($config);
     $output->writeln(['', $formatter->formatBlock('Your configuration file successfully updated! It\'s time to rebuild your repository', 'bg=blue;fg=white', true), '']);
     return 0;
 }
开发者ID:composer,项目名称:satis,代码行数:40,代码来源:AddCommand.php


示例8: initialize

 protected function initialize()
 {
     parent::initialize();
     $this->io->write('Initializing PEAR repository ' . $this->url);
     $this->initializeChannel();
     $this->io->write('Packages names will be prefixed with: pear-' . $this->channel . '/');
     // try to load as a composer repo
     try {
         $json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io));
         $packages = $json->read();
         if ($this->io->isVerbose()) {
             $this->io->write('Repository is Composer-compatible, loading via packages.json instead of PEAR protocol');
         }
         $loader = new ArrayLoader();
         foreach ($packages as $data) {
             foreach ($data['versions'] as $rev) {
                 if (strpos($rev['name'], 'pear-' . $this->channel) !== 0) {
                     $rev['name'] = 'pear-' . $this->channel . '/' . $rev['name'];
                 }
                 $this->addPackage($loader->load($rev));
                 if ($this->io->isVerbose()) {
                     $this->io->write('Loaded ' . $rev['name'] . ' ' . $rev['version']);
                 }
             }
         }
         return;
     } catch (\Exception $e) {
     }
     $this->fetchFromServer();
 }
开发者ID:nicodmf,项目名称:composer,代码行数:30,代码来源:PearRepository.php


示例9: has

 /**
  * Search for a given package version.
  *
  * Usage examples : Composition::has('php', '5.3.*') // PHP version
  *                  Composition::has('ext-memcache') // PHP extension
  *                  Composition::has('vendor/package', '>2.1') // Package version
  *
  * @param type $packageName  The package name
  * @param type $prettyString An optional version constraint
  *
  * @return boolean           Wether or not the package has been found.
  */
 public static function has($packageName, $prettyString = '*')
 {
     if (null === self::$pool) {
         if (null === self::$rootDir) {
             self::$rootDir = getcwd();
             if (!file_exists(self::$rootDir . '/composer.json')) {
                 throw new \RuntimeException('Unable to guess the project root dir, please specify it manually using the Composition::setRootDir method.');
             }
         }
         $minimumStability = 'dev';
         $config = new Config();
         $file = new JsonFile(self::$rootDir . '/composer.json');
         if ($file->exists()) {
             $projectConfig = $file->read();
             $config->merge($projectConfig);
             if (isset($projectConfig['minimum-stability'])) {
                 $minimumStability = $projectConfig['minimum-stability'];
             }
         }
         $vendorDir = self::$rootDir . '/' . $config->get('vendor-dir');
         $pool = new Pool($minimumStability);
         $pool->addRepository(new PlatformRepository());
         $pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed.json')));
         $pool->addRepository(new InstalledFilesystemRepository(new JsonFile($vendorDir . '/composer/installed_dev.json')));
         self::$pool = $pool;
     }
     $parser = new VersionParser();
     $constraint = $parser->parseConstraints($prettyString);
     $packages = self::$pool->whatProvides($packageName, $constraint);
     return empty($packages) ? false : true;
 }
开发者ID:bamarni,项目名称:composition,代码行数:43,代码来源:Composition.php


示例10: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filesystem = new Filesystem();
     $packageName = $this->getPackageFilename($name = $this->argument('name'));
     if (!($targetDir = $this->option('dir'))) {
         $targetDir = $this->container->path();
     }
     $sourcePath = $this->container->get('path.packages') . '/' . $name;
     $filesystem->ensureDirectoryExists($targetDir);
     $target = realpath($targetDir) . '/' . $packageName . '.zip';
     $filesystem->ensureDirectoryExists(dirname($target));
     $exludes = [];
     if (file_exists($composerJsonPath = $sourcePath . '/composer.json')) {
         $jsonFile = new JsonFile($composerJsonPath);
         $jsonData = $jsonFile->read();
         if (!empty($jsonData['archive']['exclude'])) {
             $exludes = $jsonData['archive']['exclude'];
         }
         if (!empty($jsonData['archive']['scripts'])) {
             system($jsonData['archive']['scripts'], $return);
             if ($return !== 0) {
                 throw new \RuntimeException('Can not executes scripts.');
             }
         }
     }
     $tempTarget = sys_get_temp_dir() . '/composer_archive' . uniqid() . '.zip';
     $filesystem->ensureDirectoryExists(dirname($tempTarget));
     $archiver = new PharArchiver();
     $archivePath = $archiver->archive($sourcePath, $tempTarget, 'zip', $exludes);
     rename($archivePath, $target);
     $filesystem->remove($tempTarget);
     return $target;
 }
开发者ID:4nxiety,项目名称:pagekit,代码行数:36,代码来源:ArchiveCommand.php


示例11: run

 /**
  * Runs the project configurator.
  *
  * @return void
  */
 public function run()
 {
     $namespace = $this->ask('Namespace', function ($namespace) {
         return $this->validateNamespace($namespace);
     }, 'App');
     $packageName = $this->ask('Package name', function ($packageName) {
         return $this->validatePackageName($packageName);
     }, $this->suggestPackageName($namespace));
     $license = $this->ask('License', function ($license) {
         return trim($license);
     }, 'proprietary');
     $description = $this->ask('Description', function ($description) {
         return trim($description);
     }, '');
     $file = new JsonFile('./composer.json');
     $config = $file->read();
     $config['name'] = $packageName;
     $config['license'] = $license;
     $config['description'] = $description;
     $config['autoload']['psr-4'] = [$namespace . '\\' => 'src/'];
     $config['autoload-dev']['psr-4'] = [$namespace . '\\Tests\\' => 'tests/'];
     unset($config['scripts']['post-root-package-install']);
     $config['extra']['branch-alias']['dev-master'] = '1.0-dev';
     $file->write($config);
     $this->composer->setPackage(Factory::create($this->io, null, true)->getPackage());
     // reload root package
     $filesystem = new Filesystem();
     $filesystem->removeDirectory('./app/Distribution');
 }
开发者ID:gerryvdm,项目名称:symfony-skeleton,代码行数:34,代码来源:ProjectConfigurator.php


示例12: dumpPackagesJson

 /**
  * Writes the packages.json of the repository.
  *
  * @param array $includes List of included JSON files.
  */
 private function dumpPackagesJson($includes)
 {
     $repo = array('packages' => array(), 'includes' => $includes);
     $this->output->writeln('<info>Writing packages.json</info>');
     $repoJson = new JsonFile($this->filename);
     $repoJson->write($repo);
 }
开发者ID:robertgit,项目名称:satis,代码行数:12,代码来源:PackagesBuilder.php


示例13: processComposer

 /**
  * @param OutputInterface $output
  * @param                 $dialog
  * @param                 $directory
  * @param                 $namespace
  * @param                 $phpunit
  */
 protected function processComposer(OutputInterface $output, $dialog, $directory, $namespace, $phpunit)
 {
     if ($dialog->ask($output, $dialog->getQuestion('Would you like to set up a composer file?', 'yes'), 'yes') == 'yes') {
         $this->getComposerApplication()->find('init')->run(new Input\ArrayInput(array('command' => 'init')), $output);
     }
     if (file_exists($directory . '/composer.json')) {
         $composerFile = new JsonFile($directory . '/composer.json');
         $composer = $composerFile->read();
         if (count($composer['require']) === 0) {
             unset($composer['require']);
         }
         if (isset($namespace) && $namespace) {
             $composer = array_merge($composer, array('autoload' => array('psr-0' => array($namespace => 'src/'))));
         }
         if (isset($phpunit) && $phpunit) {
             $phpunit = array('phpunit/phpunit' => '~3.7');
             if (isset($composer['require-dev'])) {
                 $composer['require-dev'] = array_merge($composer['require-dev'], $phpunit);
             } else {
                 $composer['require-dev'] = $phpunit;
             }
         }
         $composerFile->write($composer);
         if ($dialog->ask($output, $dialog->getQuestion('Would you like to run "composer install"?', 'yes'), 'yes') == 'yes') {
             if ($dialog->ask($output, $dialog->getQuestion('Would you like to install dev dependencies?', 'yes'), 'yes') == 'yes') {
                 $requireDev = true;
             } else {
                 $requireDev = false;
             }
             $output->writeln('Running composer install');
             $this->getComposerApplication()->run(new Input\ArrayInput(array('command' => 'install', '--dev' => $requireDev)));
         }
     }
 }
开发者ID:camspiers,项目名称:php-lib-create,代码行数:41,代码来源:CreateCommand.php


示例14: execute

 /**
  * Remove packages from the root install.
  *
  * @param  $packages array Indexed array of package names to remove
  *
  * @throws \Bolt\Exception\PackageManagerException
  *
  * @return int 0 on success or a positive error code on failure
  */
 public function execute(array $packages)
 {
     if (empty($packages)) {
         throw new PackageManagerException('No package specified for removal');
     }
     $io = $this->app['extend.manager']->getIO();
     $options = $this->app['extend.manager']->getOptions();
     $jsonFile = new JsonFile($options['composerjson']);
     $composerDefinition = $jsonFile->read();
     $composerBackup = file_get_contents($jsonFile->getPath());
     $json = new JsonConfigSource($jsonFile);
     $type = $options['dev'] ? 'require-dev' : 'require';
     // Remove packages from JSON
     foreach ($packages as $package) {
         if (isset($composerDefinition[$type][$package])) {
             $json->removeLink($type, $package);
         }
     }
     // Reload Composer config
     $composer = $this->app['extend.manager']->getFactory()->resetComposer();
     $install = Installer::create($io, $composer);
     try {
         $install->setVerbose($options['verbose'])->setDevMode(!$options['updatenodev'])->setUpdate(true)->setUpdateWhitelist($packages)->setWhitelistDependencies($options['updatewithdependencies'])->setIgnorePlatformRequirements($options['ignoreplatformreqs']);
         $status = $install->run();
         if ($status !== 0) {
             // Write out old JSON file
             file_put_contents($jsonFile->getPath(), $composerBackup);
         }
     } catch (\Exception $e) {
         $msg = __CLASS__ . '::' . __FUNCTION__ . ' recieved an error from Composer: ' . $e->getMessage() . ' in ' . $e->getFile() . '::' . $e->getLine();
         $this->app['logger.system']->critical($msg, array('event' => 'exception', 'exception' => $e));
         throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
     }
     return $status;
 }
开发者ID:aleksabp,项目名称:bolt,代码行数:44,代码来源:RemovePackage.php


示例15: updateSatisConfig

 protected function updateSatisConfig($package)
 {
     $satisConfig = $this->config->satisconfig;
     $satisUrl = $this->config->satisurl;
     if ($satisConfig) {
         $file = new JsonFile($satisConfig);
         $config = $file->read();
         if ($satisUrl) {
             if (!empty($this->vcs)) {
                 //$url = $package.'.git';
                 if (substr($package, -4) != '.git') {
                     $package .= '.git';
                 }
                 $repo = array('type' => 'vcs', 'url' => $this->vcs . ':' . $package);
             } else {
                 $url = $package . '.git';
                 $repo = array('type' => 'git', 'url' => $satisUrl . '/' . $url);
             }
         } else {
             $url = ltrim(realpath($this->config->repodir . '/' . $package . '.git'), '/');
             $repo = array('type' => 'git', 'url' => 'file:///' . $url);
         }
         $config['repositories'][] = $repo;
         $config['repositories'] = $this->deduplicate($config['repositories']);
         $file->write($config);
     }
 }
开发者ID:matsinet,项目名称:medusa,代码行数:27,代码来源:AddRepoCommand.php


示例16: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $factory = new Factory();
     $file = $factory->getComposerFile();
     if (!file_exists($file)) {
         $output->writeln('<error>' . $file . ' not found.</error>');
         return 1;
     }
     if (!is_readable($file)) {
         $output->writeln('<error>' . $file . ' is not readable.</error>');
         return 1;
     }
     $dialog = $this->getHelperSet()->get('dialog');
     $json = new JsonFile($file);
     $composer = $json->read();
     $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'));
     $requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
     $baseRequirements = array_key_exists($requireKey, $composer) ? $composer[$requireKey] : array();
     $requirements = $this->formatRequirements($requirements);
     if (!$this->updateFileCleanly($json, $baseRequirements, $requirements, $requireKey)) {
         foreach ($requirements as $package => $version) {
             $baseRequirements[$package] = $version;
         }
         $composer[$requireKey] = $baseRequirements;
         $json->write($composer);
     }
     $output->writeln('<info>' . $file . ' has been updated</info>');
     // Update packages
     $composer = $this->getComposer();
     $io = $this->getIO();
     $install = Installer::create($io, $composer);
     $install->setVerbose($input->getOption('verbose'))->setPreferSource($input->getOption('prefer-source'))->setDevMode($input->getOption('dev'))->setUpdate(true)->setUpdateWhitelist($requirements);
     return $install->run() ? 0 : 1;
 }
开发者ID:nicodmf,项目名称:composer,代码行数:34,代码来源:RequireCommand.php


示例17: getDefinition

 /**
  * @param string   $name
  * @param string   $vendor
  * @param string   $package
  * @param string   $packageName
  * @param JsonFile $json
  *
  * @return array
  */
 private static function getDefinition($packageName, JsonFile $json)
 {
     $composerDefinition = $json->read();
     unset($composerDefinition['scripts']['post-create-project-cmd']);
     $composerDefinition['name'] = $packageName;
     return $composerDefinition;
 }
开发者ID:larabros,项目名称:skeleton,代码行数:16,代码来源:Wizard.php


示例18: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelperSet()->get('dialog');
     $whitelist = array('name', 'description', 'author', 'require');
     $options = array_filter(array_intersect_key($input->getOptions(), array_flip($whitelist)));
     if (isset($options['author'])) {
         $options['authors'] = $this->formatAuthors($options['author']);
         unset($options['author']);
     }
     $options['require'] = isset($options['require']) ? $this->formatRequirements($options['require']) : new \stdClass();
     $file = new JsonFile('composer.json');
     $json = $file->encode($options);
     if ($input->isInteractive()) {
         $output->writeln(array('', $json, ''));
         if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     $file->write($options);
     if ($input->isInteractive()) {
         $ignoreFile = realpath('.gitignore');
         if (false === $ignoreFile) {
             $ignoreFile = realpath('.') . '/.gitignore';
         }
         if (!$this->hasVendorIgnore($ignoreFile)) {
             $question = 'Would you like the <info>vendor</info> directory added to your <info>.gitignore</info> [<comment>yes</comment>]?';
             if ($dialog->askConfirmation($output, $question, true)) {
                 $this->addVendorIgnore($ignoreFile);
             }
         }
     }
 }
开发者ID:natxet,项目名称:composer,代码行数:33,代码来源:InitCommand.php


示例19: __construct

 /**
  * Command constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $this->file = new JsonFile($this->container->basePath() . DIRECTORY_SEPARATOR . 'composer.json');
     $this->files = $this->container->make('files');
     $this->backup = $this->file->read();
     $this->json = new JsonConfigSource($this->file);
 }
开发者ID:notadd,项目名称:framework,代码行数:11,代码来源:Command.php


示例20: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = Factory::getComposerFile();
     if (!file_exists($file) && !file_put_contents($file, "{\n}\n")) {
         $output->writeln('<error>' . $file . ' could not be created.</error>');
         return 1;
     }
     if (!is_readable($file)) {
         $output->writeln('<error>' . $file . ' is not readable.</error>');
         return 1;
     }
     if (!is_writable($file)) {
         $output->writeln('<error>' . $file . ' is not writable.</error>');
         return 1;
     }
     $json = new JsonFile($file);
     $composer = $json->read();
     $composerBackup = file_get_contents($json->getPath());
     $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'));
     $requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
     $removeKey = $input->getOption('dev') ? 'require' : 'require-dev';
     $baseRequirements = array_key_exists($requireKey, $composer) ? $composer[$requireKey] : array();
     $requirements = $this->formatRequirements($requirements);
     // validate requirements format
     $versionParser = new VersionParser();
     foreach ($requirements as $constraint) {
         $versionParser->parseConstraints($constraint);
     }
     if (!$this->updateFileCleanly($json, $baseRequirements, $requirements, $requireKey, $removeKey)) {
         foreach ($requirements as $package => $version) {
             $baseRequirements[$package] = $version;
             if (isset($composer[$removeKey][$package])) {
                 unset($composer[$removeKey][$package]);
             }
         }
         $composer[$requireKey] = $baseRequirements;
         $json->write($composer);
     }
     $output->writeln('<info>' . $file . ' has been updated</info>');
     if ($input->getOption('no-update')) {
         return 0;
     }
     $updateDevMode = !$input->getOption('update-no-dev');
     // Update packages
     $composer = $this->getComposer();
     $composer->getDownloadManager()->setOutputProgress(!$input->getOption('no-progress'));
     $io = $this->getIO();
     $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'require', $input, $output);
     $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
     $install = Installer::create($io, $composer);
     $install->setVerbose($input->getOption('verbose'))->setPreferSource($input->getOption('prefer-source'))->setPreferDist($input->getOption('prefer-dist'))->setDevMode($updateDevMode)->setUpdate(true)->setUpdateWhitelist(array_keys($requirements))->setWhitelistDependencies($input->getOption('update-with-dependencies'));
     $status = $install->run();
     if ($status !== 0) {
         $output->writeln("\n" . '<error>Installation failed, reverting ' . $file . ' to its original content.</error>');
         file_put_contents($json->getPath(), $composerBackup);
     }
     return $status;
 }
开发者ID:aminembarki,项目名称:composer,代码行数:58,代码来源:RequireCommand.php



注:本文中的Composer\Json\JsonFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Package\Package类代码示例发布时间:2022-05-23
下一篇:
PHP IO\IOInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap