将自定义包添加到composer.json文件

时间:2015-11-03 09:32:01

标签: composer-php laravel-5.1 service-provider

我有一个未在githubpackagist上传的自定义程序包,我需要将其添加到Laravel 5.1项目中。

这是我的包文件夹结构:

Packages
   \_ christian
     \_ smsservice
       \_src
         \_ Facades
           \_ MySMS.php
         \_ SMSServiceServiceProvider.php
       \_ vendor
         \_ composer
         \_ autoload.php

我编辑了我的root composer.json来添加包:

"psr-4": {
    "App\\": "app/",
    "Christian\\SMSService\\": "app/Packages/christian/smsservice/src/"
},

然后我将ervice providerfacade添加到app.php文件中,但当我尝试使用该包时,我得到了:

FatalErrorException in ProviderRepository.php line 146:
Class 'Christian\SMSService\SMSServiceServiceProvider' not found

但ServiceProvider存在且名称空间正确:

namespace Christian\SMSService;


use Illuminate\Support\ServiceProvider;
use Illuminate\Routing\Router;

class SMSServiceServiceProvider extends ServiceProvider {
  //Code
}

1 个答案:

答案 0 :(得分:0)

我也需要这个功能。我将以下代码用于我当地的一个Laravel项目:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "repositories": [
        {
            "type": "path",
            "url": "../../GitHub/laravel-page-visits-counter"
        }
    ],
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0",
        "cyrildewit/laravel-page-visits-counter": "dev-master"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    }
}