Skip to main content

Hidden Gems of Composer

·322 words·2 mins
Hari KT
Author
Hari KT
Freelancer | Founder of Tripti and Tanvish | Maintainer of Aura for PHP, created by Paul M Jones

I hope everyone in the PHP world is aware of composer the dependency management tool that gives an end to Pear.

We can look into some of the hidden gems of composer. Some of them are already documented in the composer docs.

Bug Fixing :
#

Documented over Loading a package from a VCS repository

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/igorw/monolog"
        }
    ],
    "require": {
        "monolog/monolog": "dev-bugfix"
    }
}

The above example assume you have pushed your code to github. But you can also make use of the local directory.

Assume you are organizing your code something like

1
2
3
4
5
6
home
└── github.com
    └── harikt
        ├── Aura.Router
        ├── Aura.Web
        └── monolog

Now on your project you could make use of the patches you are working on the local directory without pushing it to github.

Note : You should commit the changes though.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
    "minimum-stability":"dev",
    "repositories": [
        {
            "type": "vcs",
            "url": "/home/github.com/harikt/monolog"            
        }
    ],
    "require": {
        "monolog/monolog": "dev-bugfix"
    }
}

And you can also disable packagist for fast look up.

Experimenting your own packages
#

I did add packages in packagist for testing. This is really a wrong way to do, you are adding more packages that makes other people’s life hard to find a useful package.

What I learned is, you can do in a different way. See docs under Package

So your composer.json will look something like this.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
    "minimum-stability":"dev",
    "repositories": [        
        {
            "type": "package",
            "package": {
                "name": "harikt/experiments",
                "version": "3.1.7",               
                "source": {
                    "type": "git",
                    "url": "/home/github.com/harikt/experiments",
                    "reference": "master"
                },
                "autoload": {
                    "classmap": ["libs/"]
                }
            }
        }
    ],
    "require": {        
        "harikt/experiments": "3.1.*"
    }
}

That’s for now.

Happy PhPing!

Related

Installing an Aura Framework Project via Composer

·56 words·1 min
In this tutorial I am showing how to install aura framework project v2 via composer. composer create-project -s beta aura/framework-project path-to-project Aura.Framework_Project helps you to build web and cli applications. If you need only web based application then Aura.Web_Project is what you need. {% showterm b971330ea7fd28d22e2f3 %} If you need only cli, then Aura.Cli_Project helps you.

Composer Support for ProcessWire, Part 2

·155 words·1 min
In my earlier post I mentioned about adding a composer.json in the root of the github repo. Sometimes you may see a non composer.json repo or some times people reject it, you still can do like the below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <?php { "minimum-stability": "dev", "repositories": [ { "type": "package", "package": { "name": "ryancramerdesign/process-export-profile", "version": "1.0.0", "source": { "url": "https://github.com/ryancramerdesign/ProcessExportProfile", "type": "git", "reference": "master" }, "type": "pw-module", "require": { "hari/pw-module": "~1.0" } } } ], "require": { "ryancramerdesign/process-export-profile": "1.0.0" } } And run

Composer Support for ProcessWire Modules

·272 words·2 mins
I am a huge fan of composer. PW ( ProcessWire) is missing one of the good parts of composer. So here is a new installer to install the 3rd party modules of PW via composer. If you have created a module for PW, what you need to do is add a composer.json file in your github repo and add it to packagist. An example composer.json is 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 { "name": "vendor/package-name", "type": "pw-module", "description": "Your module what it does", "keywords": [ "keywords", "comma", "seprated"], "homepage": "https://github.com/harikt/Assets", "license": "BSD-2-Clause", "authors": [ { "name": "Assets Contributors", "homepage": "https://github.com/harikt/Assets/contributors" } ], "require": { "php": ">=5.3.0", "hari/pw-module": "~1.0" } } Note the minimum requirement is PHP 5.3 for composer is 5.3 .