当前位置: 首页>>代码示例>>PHP>>正文


PHP JsonFile::write方法代码示例

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


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

示例1: 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

示例2: 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

示例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: initialize

 /**
  * {@inheritDoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     parent::initialize($input, $output);
     if ($input->getOption('global') && null !== $input->getOption('file')) {
         throw new \RuntimeException('--file and --global can not be combined');
     }
     $io = $this->getIO();
     $this->config = Factory::createConfig($io);
     // Get the local composer.json, global config.json, or if the user
     // passed in a file to use
     $configFile = $input->getOption('global') ? $this->config->get('home') . '/config.json' : ($input->getOption('file') ?: trim(getenv('COMPOSER')) ?: 'composer.json');
     // Create global composer.json if this was invoked using `composer global config`
     if ($configFile === 'composer.json' && !file_exists($configFile) && realpath(getcwd()) === realpath($this->config->get('home'))) {
         file_put_contents($configFile, "{\n}\n");
     }
     $this->configFile = new JsonFile($configFile, null, $io);
     $this->configSource = new JsonConfigSource($this->configFile);
     $authConfigFile = $input->getOption('global') ? $this->config->get('home') . '/auth.json' : dirname(realpath($configFile)) . '/auth.json';
     $this->authConfigFile = new JsonFile($authConfigFile, null, $io);
     $this->authConfigSource = new JsonConfigSource($this->authConfigFile, true);
     // Initialize the global file if it's not there, ignoring any warnings or notices
     if ($input->getOption('global') && !$this->configFile->exists()) {
         touch($this->configFile->getPath());
         $this->configFile->write(array('config' => new \ArrayObject()));
         Silencer::call('chmod', $this->configFile->getPath(), 0600);
     }
     if ($input->getOption('global') && !$this->authConfigFile->exists()) {
         touch($this->authConfigFile->getPath());
         $this->authConfigFile->write(array('http-basic' => new \ArrayObject(), 'github-oauth' => new \ArrayObject(), 'gitlab-oauth' => new \ArrayObject()));
         Silencer::call('chmod', $this->authConfigFile->getPath(), 0600);
     }
     if (!$this->configFile->exists()) {
         throw new \RuntimeException(sprintf('File "%s" cannot be found in the current directory', $configFile));
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:38,代码来源:ConfigCommand.php

示例5: manipulateJson

 protected function manipulateJson($method, $args, $fallback)
 {
     $args = func_get_args();
     // remove method & fallback
     array_shift($args);
     $fallback = array_pop($args);
     if ($this->file->exists()) {
         $contents = file_get_contents($this->file->getPath());
     } else {
         $contents = "{\n    \"config\": {\n    }\n}\n";
     }
     $manipulator = new JsonManipulator($contents);
     $newFile = !$this->file->exists();
     // try to update cleanly
     if (call_user_func_array(array($manipulator, $method), $args)) {
         file_put_contents($this->file->getPath(), $manipulator->getContents());
     } else {
         // on failed clean update, call the fallback and rewrite the whole file
         $config = $this->file->read();
         $this->array_unshift_ref($args, $config);
         call_user_func_array($fallback, $args);
         $this->file->write($config);
     }
     if ($newFile) {
         @chmod($this->file->getPath(), 0600);
     }
 }
开发者ID:symstriker,项目名称:composer,代码行数:27,代码来源:JsonConfigSource.php

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: initialize

 /**
  * {@inheritDoc}
  */
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('global') && 'composer.json' !== $input->getOption('file')) {
         throw new \RuntimeException('--file and --global can not be combined');
     }
     $this->config = Factory::createConfig($this->getIO());
     // Get the local composer.json, global config.json, or if the user
     // passed in a file to use
     $configFile = $input->getOption('global') ? $this->config->get('home') . '/config.json' : $input->getOption('file');
     $this->configFile = new JsonFile($configFile);
     $this->configSource = new JsonConfigSource($this->configFile);
     $authConfigFile = $input->getOption('global') ? $this->config->get('home') . '/auth.json' : dirname(realpath($input->getOption('file'))) . '/auth.json';
     $this->authConfigFile = new JsonFile($authConfigFile);
     $this->authConfigSource = new JsonConfigSource($this->authConfigFile, true);
     // initialize the global file if it's not there
     if ($input->getOption('global') && !$this->configFile->exists()) {
         touch($this->configFile->getPath());
         $this->configFile->write(array('config' => new \ArrayObject()));
         @chmod($this->configFile->getPath(), 0600);
     }
     if ($input->getOption('global') && !$this->authConfigFile->exists()) {
         touch($this->authConfigFile->getPath());
         $this->authConfigFile->write(array('http-basic' => new \ArrayObject(), 'github-oauth' => new \ArrayObject()));
         @chmod($this->authConfigFile->getPath(), 0600);
     }
     if (!$this->configFile->exists()) {
         throw new \RuntimeException('No composer.json found in the current directory');
     }
 }
开发者ID:aminembarki,项目名称:composer,代码行数:32,代码来源:ConfigCommand.php

示例12: 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

示例13: modifyComposerJson

 public function modifyComposerJson()
 {
     $configFile = new JsonFile('composer.json');
     $configJson = $configFile->read();
     $configJson = $this->addInitThemeScript($configJson);
     $configJson = $this->addChangeThemeVersionScript($configJson);
     $configJson = $this->addChangeThemeNameScript($configJson);
     $configFile->write($configJson);
 }
开发者ID:StoutLogic,项目名称:local-wordpress-theme-repository,代码行数:9,代码来源:Plugin.php

示例14: flush

 public function flush()
 {
     if (null === $this->oauth) {
         if (isset($this->data['config']['github-oauth'])) {
             unset($this->data['config']['github-oauth']['github.com']);
             // Fix json schema.
             if (empty($this->data['config']['github-oauth'])) {
                 $this->data['config']['github-oauth'] = new \stdClass();
             }
         }
     } else {
         $this->data['config']['github-oauth']['github.com'] = $this->oauth;
     }
     $repositories = [];
     foreach ($this->repositories as $repo) {
         $repositories[] = ['type' => $repo->getType(), 'url' => $repo->getUrl()];
     }
     $this->data['repositories'] = $repositories;
     $this->config->write($this->data);
 }
开发者ID:xamin123,项目名称:platform,代码行数:20,代码来源:Config.php

示例15: testUpdate

 /**
  * @depends testInstall
  */
 public function testUpdate($tempDir)
 {
     $composerJson = $tempDir . DIRECTORY_SEPARATOR . "composer.json";
     $file = new JsonFile($composerJson);
     $json = $file->read();
     $json['require']['nesbot/carbon'] = '1.0';
     $file->write($json);
     $app = new ComposerUI($tempDir);
     $this->assertTrue($app->update($tempDir));
     $this->assertTrue(is_dir($tempDir . DIRECTORY_SEPARATOR . 'vendor'));
     $this->assertTrue(is_dir($tempDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'seld' . DIRECTORY_SEPARATOR . 'jsonlint'));
     $this->assertTrue(is_dir($tempDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'monolog' . DIRECTORY_SEPARATOR . 'monolog'));
     $this->assertTrue(is_dir($tempDir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'nesbot' . DIRECTORY_SEPARATOR . 'carbon'));
 }
开发者ID:composer-ui,项目名称:core,代码行数:17,代码来源:CoreTest.php


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