/** * Retrieve the package list. * * @param Request $request The request to process. * * @return JsonResponse * * @ApiDoc( * section="package", * statusCodes = { * 200 = "When everything worked out ok" * }, * authentication = true, * authenticationRoles = { * "ROLE_MANIPULATE_REQUIREMENTS" * }, * filters = { * { * "name"="all", * "description"="If present, all packages will get listed, only directly required ones otherwise." * } * } * ) * @ApiDescription( * response={ * "package name 1...n" = { * "actualType" = "object", * "subType" = "object", * "description" = "The content of the packages", * "children" = { * "name" = { * "dataType" = "string", * "description" = "The name of the package" * }, * "version" = { * "dataType" = "string", * "description" = "The version of the package" * }, * "constraint" = { * "dataType" = "string", * "description" = "The constraint of the package (when package is installed)" * }, * "type" = { * "dataType" = "string", * "description" = "The noted package type" * }, * "locked" = { * "dataType" = "string", * "description" = "Flag if the package has been locked for updates" * }, * "time" = { * "dataType" = "datetime", * "description" = "The release date" * }, * "upgrade_version" = { * "dataType" = "string", * "description" = "The version available for upgrade (optional, if any)" * }, * "description" = { * "dataType" = "string", * "description" = "The package description" * }, * "license" = { * "actualType" = "collection", * "subType" = "string", * "description" = "The licenses" * }, * "keywords" = { * "actualType" = "collection", * "subType" = "string", * "description" = "The keywords" * }, * "homepage" = { * "dataType" = "string", * "description" = "The support website (optional, if any)" * }, * "authors" = { * "actualType" = "collection", * "subType" = "object", * "description" = "The authors", * "children" = { * "name" = { * "dataType" = "string", * "description" = "Full name of the author (optional, if any)" * }, * "homepage" = { * "dataType" = "string", * "description" = "Email address of the author (optional, if any)" * }, * "email" = { * "dataType" = "string", * "description" = "Homepage URL for the author (optional, if any)" * }, * "role" = { * "dataType" = "string", * "description" = "Author's role in the project (optional, if any)" * } * } * }, * "support" = { * "actualType" = "collection", * "subType" = "object", * "description" = "The support options", * "children" = { * "email" = { * "dataType" = "string", * "description" = "Email address for support (optional, if any)" * }, * "issues" = { * "dataType" = "string", * "description" = "URL to the issue tracker (optional, if any)" * }, * "forum" = { * "dataType" = "string", * "description" = "URL to the forum (optional, if any)" * }, * "wiki" = { * "dataType" = "string", * "description" = "URL to the wiki (optional, if any)" * }, * "irc" = { * "dataType" = "string", * "description" = "IRC channel for support, as irc://server/channel (optional, if any)" * }, * "source" = { * "dataType" = "string", * "description" = "URL to browse or download the sources (optional, if any)" * }, * "docs" = { * "dataType" = "string", * "description" = "URL to the documentation (optional, if any)" * }, * } * }, * "extra" = { * "dataType" = "collection", * "description" = "The extra data from composer.json" * }, * "abandoned" = { * "dataType" = "boolean", * "description" = "Flag if this package is abandoned" * }, * "replacement" = { * "dataType" = "string", * "description" = "Replacement for this package (optional, if any)" * } * } * } * } * ) */ public function packageListAction(Request $request) { $composer = $this->getComposer(); $converter = new PackageConverter($composer->getPackage()); $upgrades = $this->getUpgradeRepository(); $packages = $converter->convertRepositoryToArray($composer->getRepositoryManager()->getLocalRepository(), !$request->query->has('all'), $upgrades)->getData(); ksort($packages); return new JsonResponse($packages, 200); }
/** * Test the conversion of a complete repository. * * @return void */ public function testConvertRepositoryToArrayOnlyRequired() { $repository = new ArrayRepository([$package1 = new CompletePackage('test/dependency1', '1.0.0.0', '1.0.0.0'), $package2 = new CompletePackage('test/non-dependency2', '2.0.0.0', '2.0.0.0')]); $package1->setType('project'); $package1->setLicense(['LGPL-3']); $package2->setType('project'); $package2->setLicense(['GPL-3']); $converter = new PackageConverter($rootPackage = new RootPackage('root/package', 'dev-master', 'dev-master')); $rootPackage->setRequires(['test/dependency1' => new Link('root/package', 'test/dependency1', new Constraint('<', '2.0'))]); $converted = $converter->convertRepositoryToArray($repository, true); $this->assertEquals(['test\\/dependency1'], $converted->getEntries('/')); $this->assertEquals(['test\\/dependency1/name', 'test\\/dependency1/version', 'test\\/dependency1/constraint', 'test\\/dependency1/type', 'test\\/dependency1/locked', 'test\\/dependency1/license', 'test\\/dependency1/abandoned'], $converted->getEntries('/test\\/dependency1')); $this->assertEquals($package1->getName(), $converted->get('test\\/dependency1/name')); $this->assertEquals($package1->getPrettyVersion(), $converted->get('test\\/dependency1/version')); $this->assertEquals($converted->get('test\\/dependency1/constraint'), '< 2.0'); $this->assertEquals($package1->getType(), $converted->get('test\\/dependency1/type')); $this->assertFalse($converted->get('test\\/dependency1/locked')); $this->assertEquals($package1->getLicense(), $converted->get('test\\/dependency1/license')); $this->assertFalse($converted->get('test\\/dependency1/abandoned')); }