PHP code example of symplify / composer-json-manipulator
1. Go to this page and download the library: Download symplify/composer-json-manipulator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
symplify / composer-json-manipulator example snippets
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\ComposerJsonManipulator\ValueObject\ComposerJsonManipulatorConfig;
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(ComposerJsonManipulatorConfig::FILE_PATH);
};
namespace App;
use Symplify\ComposerJsonManipulator\ComposerJsonFactory;
class SomeClass
{
/**
* @var ComposerJsonFactory
*/
private $composerJsonFactory;
public function __construct(ComposerJsonFactory $composerJsonFactory)
{
$this->composerJsonFactory = $composerJsonFactory;
}
public function run(): void
{
// ↓ instance of \Symplify\ComposerJsonManipulator\ValueObject\ComposerJson
$composerJson = $this->composerJsonFactory->createFromFilePath(getcwd() . '/composer.json');
// Add a PRS-4 namespace
$autoLoad = $composerJson->getAutoload();
$autoLoad['psr-4']['Cool\\Stuff\\'] = './lib/';
$composerJson->setAutoload($autoLoad);
$this->jsonFileManager->printComposerJsonToFilePath($composerJson, $composerJson->getFileInfo()->getRealPath());
}
}