This Java library turns your binary ASTO storage into a PHP Composer repository.
Similar solutions:
Some valuable references:
Getting started
This is the dependency you need:
<dependency>
<groupId>com.artipie</groupId>
<artifactId>composer-adapter</artifactId>
<version>[...]</version>
</dependency>
Save PHP Composer package JSON file like composer.json
(particular name does not matter) to ASTO storage.
import com.artipie.asto.*;
Storage storage = new FileStorage(Path.of("/path/to/storage"));
storage.save(
new Key.From("composer.json"),
Files.readAllBytes(Path.of("/my/files/composer.json"))
);
Then, make an instance of Repository
class with storage as an argument. Finally, instruct Repository
to add the package to repository:
import com.artipie.composer.*;
Repository repo = new Repository(storage);
repo.add(new Key.From("composer.json"));
After that package metadata could be accessed by it's name:
Packages packages = repo.packages(new Name("vendor/package"));
Read the Javadoc for more technical details.
Project status
- Adding package to repository #1
- HTTP support for adding package as
composer.json
#22 - HTTP support for getting package metadata #24
- HTTP support for adding package as ZIP archive #23
Composer repository structure
Composer has the following repository structure:
(repository root)
| -packages.json
| +-vendor
| -composer.json
| -composer.lock
| +-some_vendor
| | +-package_name
| | | -files_for_package_name
| -autoload.php
| +-composer
| | -files_for_composer
composer.lock
file is generated automatically. It is necessary for installing packages of specified versions. If it does not exist, it will be generated after calling the command composer install
automatically according to composer.json
file.
By calling the command composer update
composer.lock
will be automatically updated according to existing composer.json
.
Content of composer.json
There are required packages in this file with specified version. For example, this file. Also, in this file the type of repository could be defined. There are several types of repositories, but it is necessary to pay attention to composer and artifact repositores. Example of composer.json
file for composer
repository:
{
"repositories": [
{
"type": "composer",
"url": "http://central.artipie.com/"
},
{
"packagist.org": false
}
],
"require": {
"psr/log": "1.1.3"
}
}
Example of composer.json
file for artifact
repository:
{
"repositories": [
{
"type": "artifact",
"url": "path/to/directory/with/zips/"
},
{
"packagist.org": false
}
],
"require": {
"psr/log": "1.1.3"
}
}
Packages index file
The only required field is package
. An example of JSON file:
{
"packages": {
"vendor/package-name": {
"0.0.1": {
"name (required)": "vendor/package-name",
"version (required)": "0.0.1",
"dist (required)": {
"url": "https://host:port/path/vendor/package-name-0.0.1.zip",
"type": "zip"
}
},
"1.0.0": { "similar structure": "" }
}
}
}
So, information about a specific version of package is obtained from remote source by specifying url.
How to contribute
Fork repository, make changes, send us a pull request. We will review your changes and apply them to the master
branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build:
$ mvn clean install -Pqulice
To avoid build errors use Maven 3.2+.