{"id":17189456,"url":"https://github.com/nadar/php-composer-reader","last_synced_at":"2026-03-07T05:32:33.031Z","repository":{"id":57023203,"uuid":"116104710","full_name":"nadar/php-composer-reader","owner":"nadar","description":"A PHP library to read and manipulate the composer.json file.","archived":false,"fork":false,"pushed_at":"2025-01-02T08:29:05.000Z","size":127,"stargazers_count":23,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-07T13:21:48.110Z","etag":null,"topics":["composer","composer-library","hacktoberfest","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nadar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-03T07:12:36.000Z","updated_at":"2025-01-02T08:27:54.000Z","dependencies_parsed_at":"2022-08-23T14:20:51.532Z","dependency_job_id":"511d5889-c63c-4142-8dda-29871499efbd","html_url":"https://github.com/nadar/php-composer-reader","commit_stats":{"total_commits":58,"total_committers":3,"mean_commits":"19.333333333333332","dds":0.06896551724137934,"last_synced_commit":"9d7a029690bdc7621774cb9da1c3adf95d11e743"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/nadar/php-composer-reader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadar%2Fphp-composer-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadar%2Fphp-composer-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadar%2Fphp-composer-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadar%2Fphp-composer-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nadar","download_url":"https://codeload.github.com/nadar/php-composer-reader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nadar%2Fphp-composer-reader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30208731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T05:23:27.321Z","status":"ssl_error","status_checked_at":"2026-03-07T05:00:17.256Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","composer-library","hacktoberfest","php"],"created_at":"2024-10-15T01:11:40.996Z","updated_at":"2026-03-07T05:32:32.999Z","avatar_url":"https://github.com/nadar.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Composer JSON Reader and Manipulator\n\n![Tests](https://github.com/nadar/php-composer-reader/workflows/Tests/badge.svg)\n[![Latest Stable Version](https://poser.pugx.org/nadar/php-composer-reader/v/stable)](https://packagist.org/packages/nadar/php-composer-reader)\n[![Total Downloads](https://poser.pugx.org/nadar/php-composer-reader/downloads)](https://packagist.org/packages/nadar/php-composer-reader)\n[![License](https://poser.pugx.org/nadar/php-composer-reader/license)](https://packagist.org/packages/nadar/php-composer-reader)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/3d695b2ba5d4298e28fe/test_coverage)](https://codeclimate.com/github/nadar/php-composer-reader/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/3d695b2ba5d4298e28fe/maintainability)](https://codeclimate.com/github/nadar/php-composer-reader/maintainability)\n\nA small PHP library for manipulating and reading the **composer.json** file. It allows you to add new sections, check if it's writable/readable, or retrieve information from the composer schema such as description, title, and more.\n\n## Installation\n\nInstall via Composer:\n\n```sh\ncomposer require nadar/php-composer-reader\n```\n\n## Usage\n\nTo load the composer.json file into ComposerReader:\n\n```php\nrequire 'vendor/autoload.php';\n\n$reader = new ComposerReader('path/to/composer.json');\n\nif (!$reader-\u003ecanRead()) {\n   throw new Exception(\"Unable to read the JSON file.\");\n}\n\nif (!$reader-\u003ecanWrite()) {\n   throw new Exception(\"Unable to write to the JSON file.\");\n}\n\n// Dump the full content\nvar_dump($reader-\u003egetContent());\n```\n\n### Reading Section Data\n\nRetrieve an array of objects for each package in the `require` section of the composer.json file:\n\n```php\n$reader = new ComposerReader('path/to/composer.json');\n$section = new RequireSection($reader);\n\nforeach ($section as $package) {\n    echo $package-\u003ename . ' with ' . $package-\u003econstraint;\n\n    // Check if the package version is greater than a given version constraint.\n    if ($package-\u003egreaterThan('^6.5')) {\n        echo \"Numerous releases available!\";\n    }\n}\n```\n\nRetrieve an array of objects for each PSR definition in the `autoload` section of the composer.json file:\n\n```php\n$reader = new ComposerReader('path/to/composer.json');\n$section = new AutoloadSection($reader, AutoloadSection::TYPE_PSR4);\n\nforeach ($section as $autoload) {\n    echo $autoload-\u003enamespace . ' with ' . $autoload-\u003esource;\n}\n```\n\nThe following section readers are available for the composer schema ([Composer Schema Documentation](https://getcomposer.org/doc/04-schema.md)):\n\n| Section        | Class              |\n|----------------|--------------------|\n| `require`      | RequireSection     |\n| `require-dev`  | RequireDevSection  |\n| `autoload`     | AutoloadSection    |\n| `autoload-dev` | AutoloadDevSection |\n\nAdditional schema information can be retrieved from the ComposerReader object with: `$reader-\u003econtentSection('extra', null);`\n\n### Changing Section Data\n\nAdd a new PSR autoload definition to an existing composer.json file and save it:\n\n```php\n$reader = new ComposerReader('path/to/composer.json');\n\n// Generate a new autoload section object\n$new = new Autoload($reader, 'Foo\\\\Bar\\\\', 'src/foo/bar', AutoloadSection::TYPE_PSR4);\n\n// Store the new autoload object in the autoload section and save\n$section = new AutoloadSection($reader);\n$section-\u003eadd($new)-\u003esave();\n```\n\n## Running Commands\n\nTo perform composer operations, use the `runCommand()` method:\n\n```php\n$reader = new ComposerReader('path/to/composer.json');\n$reader-\u003erunCommand('dump-autoload'); // This is equivalent to running `composer dump-autoload`\n```\n\nThis attempts to execute the dump-autoload command for the specified composer.json file. **This requires a globally installed Composer command** on your system ([Install Composer globally](https://getcomposer.org/doc/00-intro.md#globally)).\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnadar%2Fphp-composer-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnadar%2Fphp-composer-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnadar%2Fphp-composer-reader/lists"}