How to create my own composite package in github?

7

I never distribute a library using a repository with composer, I have no experience with this, what I tried to do is was to create a folder structure like this:

./
 |-- composer.json
 |-- src/
     |-- Test/
           |-- Foo.php

In the% repository% file of the repository I have added the following content:

{
    "name": "[vendor]/[nome do repositorio]",
    "autoload": {
        "psr-0": {
            "Test": "src/"
        }
    }
}

I edit in my project (on my machine composer.json ):

{
    "name": "foo/bar",
    "description": "Framwork foo",
    "type": "project",
    "authors": [
        {
            "name": "Foo bar",
            "email": "[email protected]"
        }
    ],
    "require": {
        "php": ">=5.3.0",
        "[vendor]/[nome do repositorio]": "*"
    }
 }

After this I execute the following command (linux):

$ cd /home/project1
$ php composer.phar update

Windows:

cd c:\wamp\www\project1
composer update

But it returns the following failure:

  

Problem 1      - The requested package brcontainer / composer-test could not be found in any version, there may be a typo in the package name.

I tried to change composer.json to minimum-stability , but there was the same problem, did I add something in the repository?

    
asked by anonymous 24.11.2015 / 20:57

2 answers

6

This error occurs due to 3 possible factors:

  • Typing error
  • Package is not available
  • You are trying to use a dev package%
  • The first error is easy to understand, the problem is the second one, it is not very clear what "package" is or where we should leave it available, at first I thought that the composer consults github and / or bitbucket, but in fact this is not how it works, you can use any repository other than github, but you will have to make the .git available as a package and this.

    On the link site, there is a link called Browse Packages this is where magic happens:

    Whenaccessingwearetakentothe link , then you just have to sign in with your account by clicking use github (if it is another repository like bitbucket will have create an account manually, click Create One Now for this):

    Afterthishewillaskforthenecessarypermissions,justaccept,readandthenaccept.

    Theninthetopmenuclick Submit , in the "Repository URL (Git / Svn / Hg)" field, you must paste the githube%% (supports other formats), to get the .git go to your repository and at the top you will have the link, for example:

    Thenjustpasteitintothe Submit field and then click Check:

    Iftheerroroccurs:

      

    TheCSRFtokenisinvalid.Pleasetrytoresubmittheform.

    It'sbecausethepagehasexpired,justclickthe Submit link at the top and try again. You may see other repositories (of others) with similar names, it is the opportunity to think of a more creative name for yours, but it is totally optional, just click the Submit button to confirm.

    It should look something like this:

    YouneedtocreateaReleaseingithub(ifyouareusinggithub),gotoReleasesinyourrepository:

    ThenclicktheCreateanewreleasebutton,fillouttheformandclickthePublishrelease

    HoweversomerepositoriesdonothaveReleases(thisisthethirdproblemImentionedatthebeginning)eventhoughitisinPackgist,thisisbecausetheprojectisstillunderdevelopment,soitisnecessarytomodifyyour.gitofyourprojectandaddthis:

    "minimum-stability": "dev",
    "prefer-stable": true,
    

    It should look like this:

    {
        "name": "foo/bar",
        "description": "Framwork foo",
        "type": "project",
        "authors": [
            {
                "name": "Foo bar",
                "email": "[email protected]"
            }
        ],
        "require": {
            "php": ">=5.3.0",
            "[vendor]/[nome do repositorio]": "*"
        },
        "minimum-stability": "dev",
        "prefer-stable": true
     }
    

    After this, just test your repository in your project that is in your machine:

    cd c:\wamp\projeto1
    composer update
    

    The result must be something like this:

    Loading composer repositories with package information
    Updating dependencies (including require-dev)
      - Installing brcontainer/composer-test-2 (v1.0.0)
        Downloading: 100%
    

    Installing by command line to your project

    After preparing everything, note that it is possible to download the package without adding to your project composer.json, like this:

     composer require [vendor]/[nome do repositorio]
    

    Or:

     php composer.phar require [vendor]/[nome do repositorio]
    

    However if the project does not have a Release it is necessary to execute the command like this:

     composer require [vendor]/[nome do repositorio]:dev-master
    

    Or:

     php composer.phar require [vendor]/[nome do repositorio]:dev-master
    
        
    08.12.2015 / 23:26
    1

    When you place your package as a project dependency, you need to specify whether you want any version constraint . If you have not yet versioned this dependency, you need to configure it to use a branch of it as a dependency.

    Using a version constraint:

    "require": {
        "php": ">=5.3.0",
        "[vendor]/[nome do repositorio]": "^1.0"
    }
    

    Using a branch:

    "require": {
        "php": ">=5.3.0",
        "[vendor]/[nome do repositorio]": "dev-master"
    }
    
        
    08.12.2015 / 20:27