本文整理汇总了PHP中Composer\Json\JsonFile类的典型用法代码示例。如果您正苦于以下问题:PHP JsonFile类的具体用法?PHP JsonFile怎么用?PHP JsonFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JsonFile类的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();
}
示例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();
}
示例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');
}
示例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);
}
示例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;
}
示例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>');
}
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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');
}
示例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);
}
示例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)));
}
}
}
示例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;
}
示例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);
}
}