How can I config `version` param for composer? - composer-php

I want to get https://github.com/mark-rolich/Event.js by composer.
I add this:
"repositories": [
{
"type":"package",
"package": {
"name": "mark-rolich/event.js",
"version": "*",
"source": {
"url": "https://github.com/mark-rolich/Event.js",
"type": "git",
"reference": "master"
}
}
}
],
When run composer require mark-rolich/event.js command.
give me this error:
[Composer\Repository\InvalidRepositoryException]
A repository of type "package" contains an invalid package definition: Invalid package information:
version : invalid value (*): Invalid version string "*"
Invalid package definition:
{"name":"mark-rolich\/event.js","version":"*","source":{"url":"https:\/\/github.com\/mark-rolich\/Event.js","type":"git","reference":"master"}}
require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...
How can I config version param for this package?

Download that file you are interested in, and add it to your own repository. That's way easier that trying to make Composer download something that it isn't meant to do in the first place:
Composer was built to manage PHP packages, which are not required to be placed in a particular directory.
Using packages will hugely benefit from composer.json files being present, and having the repository being registered on packagist.org
In order to install Javascript packages, which require being placed into a certain directory, you'd have to use some additional plugins.
Also there is an existing toolchain for Javascript to do just the same thing that Composer does for PHP: Bower or npm.
You want to use a package that consists of only one single code file that hasn't changed in the last 4 years. I'd consider it very unlikely it will change in the future - so there isn't even a benefit from using a package manager. Just be sure you stick to the license restrictions for this code when copying.

Related

Project Structure with composer

I'm trying to create a project with composer-file.
Reason is primarily a dependency which I never want to upload to git.
My intended structure is this:
project-root-folder
- project-sub-folder(s)
- vendor (with required dependencies)
- index.php
- composer.json
- README.md
But the installed structure using composer is this:
project-root-folder
- vendor
- vendor/composer
- vendor/smarty (dependency)
- vendor/my-project
- composer.json
I know that there are special installers for many different projects, I just don't understand that an installer is required to get the intended structure and also not how to do it without a special installer.
This is the content of one composer file I tried:
{
"name": "wdb/tutorial-oop",
"require": {
"smarty/smarty": "~3.1"
}
}
When I tried this composer-json content in a local file and just extecute composer install I get the same structure:
{
"require": {
"wdb/tutorial-oop": "dev-master"
}
}
So my question is, how a composer file has to look that the project structure is created like I described in the top of this question. The basic problem is that I don't want my project being installed as dependency in the vendor-directory but in the root of the project folder, and additionally that I don't want to use the composer autoloader.
Edit:
On request here my full composer file inside the project root:
{
"name": "wdb/tutorial-oop",
"type": "project",
"description": "Your package description goes here",
"keywords": ["oop","mvc","tutorial"],
"homepage": "https://barlians.com",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "David Bruchmann",
"email": "david.bruchmann#gmail.com",
"homepage": "https://barlians.com",
"role": "Author, Developer"
}
],
"support": {
"email": "david.bruchmann#gmail.com"
},
"require": {
"smarty/smarty": "~3.1"
}
}
You're installing your project in incorrect way. The composer require command is for installing dependencies, so they're installed to the vendor directory.
For installing a project you should use the create-project command:
composer create-project wdb/tutorial-oop

Composer only finds latest version (tag) of Gitlab hosted package

I have created a package with some annotated tags for versioning (1.0.0, 1.0.1, 1.1.0 and 2.0.0). This package lives on own hosting (so not via Packagist)
When trying to require the package, composer only finds the 2.0.0 version and fails on any other version requirement.
Composer.php file of project using package
{
"name": "projectname",
"description": "Description.",
"keywords": ["keys"],
"license": "Licence",
"type": "project",
"require": {
...
"space/package-name": "~1.0" // Also tried 1.0.0, 1.0.*, ~1.0#dev - only 2.0.0 works
}
"repositories": [
...
{
"type": "git",
"url": "git#gitlab.com:space/package-name.git" // Make sure package is found on specific hosting
}
],
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
On running composer show "space/package-name" I get versions: * 2.0.0. So upon update, composer produces the following error:
The requested package space/package-name ~1.0 exists as name/package-
name[2.0.0, dev-master] but these are rejected by your constraint.
It looks like composer is no able to find any other version than the latest, any way of fixing this?
Things already checked:
The package does not contain a version in the composer.json (that might conflict with the git tag)
Used tags are annotated tags and are pushed to the repo.
Updates:
Might be a Gitlab - Composer issue, see this comment.
Gitlab doesn't always provide tag info when Composer tries to read the repo.
Solution: also add version info in composer.json:
{
"name": "package/name",
"version": "1.0.0",
...
}
This will be readable by composer. Careful: Git tags must match versioning info in composer.json! (might cause errors otherwise)

Error after cloning a remote symfony3 repository

I have a remote repository that I tried to clone locally using
composer install
This worked fine for installing all the bundles and re-creating the parameters.yml, however I get an error right at the end which seems to be related to the change in directory structure from Symfony2->Symfony3:
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
Could not open input file: app/console
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception
Clearing the cache we can do manually but is this the only issue or would there be anything else being terminated that we should be aware of?
For me, this was caused by a change in composer.json.
In sf2 there was a config section specifying the binary directory.
In sf3 this all appears in the "extra" section, mine looks like this:
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
}
}
Once I had set symfony-bin-dir to "bin" everything started working.
the problem is the path app/console has moved to bin/console in the third version of Symfony

Composer autoload path not working

I have this script that use composer to setup the project but for some reasons does not work
<?php
include_once 'vendor/autoload.php';
use \LeagueWrap\Api;
$api = new Api($key = "somekey"); // Load up the API
$summoner = $api->summoner(); // Load up the summoner request object.
$bakasan = $summoner->info('bakasan'); // Get the information about this user.
$bakasan = $summoner->info(74602); // same thing as above, just to show that an id will wo$
echo $bakasan->summonerLevel; // 30
echo $bakasan->id; // 74602
echo $bakasan->name; // "bakasan"
echo $bakasan->profileIconId; // 24
echo $bakasan->revisionDate; // 1387391523000
echo $bakasan->revisionDateStr; // "12/18/2013 06:32 PM UTC"
?>
you can check here http://70.37.98.151/leaguewrap/tests/test2.php the error I get
Warning: include_once(vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/leaguewrap/tests/test2.php on line 3
my composer.json is
{
"name": "paquettg/leaguewrap",
"type": "library",
"description": "A wrapper for the League of Legends API.",
"version": "0.6.2",
"keywords": ["League", "legends", "wrap", "api", "facade", "proxy"],
"homepage": "https://github.com/paquettg/leaguewrap",
"license": "MIT",
"authors": [
{
"name": "Gilles Paquette",
"email": "paquettg#gmail.com",
"homepage": "http://gillespaquette.ca"
}
],
"require": {
"php": ">=5.4",
"guzzlehttp/guzzle": "4.0.*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"mockery/mockery": "0.8.*",
"satooshi/php-coveralls": "0.6.*"
},
"autoload": {
"psr-0": {
"LeagueWrap": "src/"
}
},
"minimum-stability": "dev"
}
and here folders tree
Your script cannot find the autoload file.
Including that file is like any other file: The path must be right, and which path is right depends on whether you are using an absolute path (unusual) or a relative path. Currently you are using a relative path.
Assuming your script is somewhere inside that src folder you showed, the path to the vendor/autoload.php must at least contain one ../ to go one directory level up - maybe more.
Seems like its the problem with your Composer Installation.
Follow these steps -
First make sure you have the Composer.json file created with all the dependencies.
Let's say you are creating a project, and you need a library that does logging. You decide to use monolog. In order to add it to your project, all you need to do is create a composer.json file which describes the project's dependencies.
{
"require": {
"monolog/monolog": "1.2.*"
}
}
Installation - Linux / Unix / OSX
Downloading the Composer Executable
There are in short, two ways to install Composer. Locally as part of your project, or globally as a system wide executable.
Locally
Installing Composer locally is a matter of just running the installer in your project directory:
curl -sS https://getcomposer.org/installer | php
Note: If the above fails for some reason, you can download the installer with php instead:
php -r "readfile('https://getcomposer.org/installer');" | php
The installer will just check a few PHP settings and then download composer.phar to your working directory. This file is the Composer binary. It is a PHAR (PHP archive), which is an archive format for PHP which can be run on the command line, amongst other things.
You can install Composer to a specific directory by using the --install-dir option and providing a target directory (it can be an absolute or relative path):
curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
Globally
You can place this file anywhere you wish. If you put it in your PATH, you can access it globally. On unixy systems you can even make it executable and invoke it without php.
You can run these commands to easily access composer from anywhere on your system:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Note: If the above fails due to permissions, run the mv line again with sudo.
Note: In OSX Yosemite the /usr directory does not exist by default. If you receive the error "/usr/local/bin/composer: No such file or directory" then you must create /usr/local/bin/ manually before proceeding.
Then, just run composer in order to run Composer instead of php composer.phar.
Installation - Windows
Using the Installer
This is the easiest way to get Composer set up on your machine.
Download and run Composer-Setup.exe, it will install the latest Composer version and set up your PATH so that you can just call composer from any directory in your command line.
Note: Close your current terminal. Test usage with a new terminal: That is
important since the PATH only gets loaded when the terminal starts.
Manual Installation#
Change to a directory on your PATH and run the install snippet to download composer.phar:
C:\Users\username>cd C:\bin
C:\bin>php -r "readfile('https://getcomposer.org/installer');" | php
Note: If the above fails due to readfile, use the http url or enable php_openssl.dll in php.ini
Create a new composer.bat file alongside composer.phar:
C:\bin>echo #php "%~dp0composer.phar" %*>composer.bat
Close your current terminal. Test usage with a new terminal:
C:\Users\username>composer -V
Composer version 27d8904
Using Composer
We will now use Composer to install the dependencies of the project.
To resolve and download dependencies, run the install command:
php composer.phar install
If you did a global install and do not have the phar in that directory run this instead:
composer install
Following the example above, this will download monolog into
the vendor/monolog/monolog directory.
Autoloading
Besides downloading the library, Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process:
require 'vendor/autoload.php';
You can also try with below require form -
defined('__ROOT__') or define('__ROOT__', dirname(dirname(__FILE__)));
require_once implode(
    DIRECTORY_SEPARATOR, array(__ROOT__, 'vendor', 'autoload.php')
);

Setting up alias for master branch in composer

I am trying to package a module for use with composer. I have a valid composer file and I am able to install it with composer, but only when I specify that it should use dev releases (via the "#dev" version directive or minimum stability dev). I am having trouble packaging my repo so that it is seen as a master release.
I found a composer document about aliases that seems to be made for my case, but I cant get it working. Heres the relevant portion of my composer.json:
"extra": {
"branch-alias": {
"dev-master": "1.0"
}
}
Also for reference heres the require from my main projects composer file:
"require": {
"misterglass/kohana-twig" : "1.*"
},
And the actual error from composer is:
Problem 1
- The requested package misterglass/kohana-twig 1.* could not be found.
According to some helpful people on the #composer IRC channel, aliases are just to associate different versions to each other, and not to assign stability.
In order to for composer to consider it stable, you need to add a tag, which you can do on the command line or by creating a release in github.

Resources