harish
harish

Reputation: 628

How to integrate own php package GitHub project with composer to use as well as develop it simultaneously

I want to develope laravel package I have created sample project on github with a class. I use the package name from my github php package composer.json in my project composer.json in require{} array.

When I do composer update I get error. I need illustrative steps to develope and integrate PHP/Laravel package from using Github and composer.

Composer.json for project i am adding my package to, is :

    {
       "name": "laravel/laravel",
       "description": "The Laravel Framework.",
       "keywords": ["framework", "laravel"],
       "license": "MIT",
       "type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.2.*",
    "jeroen-g/laravel-packager": "^1.3",
    "igaster/laravel-theme": "^1.1",
    "laura/cms": "*.*"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "symfony/css-selector": "2.8.*|3.0.*",
    "symfony/dom-crawler": "2.8.*|3.0.*"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ]
},
"config": {
    "preferred-install": "dist"
},
"repositories": [{
    "type": "vcs",
    "url": "https://github.com/harish-php/lauracms"
}]

}

Upvotes: 3

Views: 656

Answers (1)

David Maes
David Maes

Reputation: 573

EDIT

Added some more explanation on how to create the custom package

Custom package composer.json

{
  
    "name": “packageName”,
  
    "autoload": {
    
        "psr-4": {
      
                “MySourcesNamespace\\”: "srcDir”
    
        }
  
    }

}

Composer.son of application

"require": {
   
    "packageName": "1.0.*"

},
"repositories": [
  {
      
    "type": "vcs",
     
    "url":  "https://github.com/…"  
}
]

The version here should be tagged. If you do not have a Tag you can depend on the master branch:

"require": {
   
    "MySourcesNamespace\\": "dev-master"

},

When doing composer update your classes should be inside the vendor directory.

Upvotes: 2

Related Questions