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


PHP JsonFile::read方法代码示例

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


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

示例5: init

 protected function init()
 {
     $this->data = $this->config->read();
     if (!empty($this->data['repositories'])) {
         foreach ($this->data['repositories'] as $repoData) {
             $repo = new Repository();
             $repo->setUrl($repoData['url']);
             $repo->setType($repoData['type']);
             $this->repositories[] = $repo;
         }
     }
     if (isset($this->data['config']['github-oauth']['github.com'])) {
         $this->oauth = $this->data['config']['github-oauth']['github.com'];
     }
 }
开发者ID:xamin123,项目名称:platform,代码行数:15,代码来源:Config.php

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

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

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

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

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

示例12: execute

 /**
  * @param InputInterface  $input  The input instance
  * @param OutputInterface $output The output instance
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $verbose = $input->getOption('verbose');
     $file = new JsonFile($input->getArgument('file'));
     if (!$file->exists()) {
         $output->writeln('<error>File not found: ' . $input->getArgument('file') . '</error>');
         return 1;
     }
     $config = $file->read();
     // disable packagist by default
     unset(Config::$defaultRepositories['packagist']);
     // fetch options
     $requireAll = isset($config['require-all']) && true === $config['require-all'];
     if (!$requireAll && !isset($config['require'])) {
         $output->writeln('No explicit requires defined, enabling require-all');
         $requireAll = true;
     }
     $composer = $this->getApplication()->getComposer(true, $config);
     $packages = $this->selectPackages($composer, $output, $verbose, $requireAll);
     if (!($outputDir = $input->getArgument('output-dir'))) {
         $outputDir = isset($config['output-dir']) ? $config['output-dir'] : null;
     }
     if ($htmlView = !$input->getOption('no-html-output')) {
         $htmlView = !isset($config['output-html']) || $config['output-html'];
     }
     $filename = $outputDir . '/packages.json';
     $this->dumpJson($packages, $output, $filename);
     if ($htmlView) {
         $rootPackage = $composer->getPackage();
         $this->dumpWeb($packages, $output, $rootPackage, $outputDir);
     }
 }
开发者ID:norbe,项目名称:satis,代码行数:36,代码来源:BuildCommand.php

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

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


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