2015-11-03 85 views
3

我有一個自定義軟件包未上傳到githubpackagist,我需要將其添加到Laravel 5.1項目中。將自定義軟件包添加到composer.json文件

這是我的包的文件夾結構:

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

我已經編輯我的根composer.json添加軟件包:

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

然後我已經加入的S ervice providerfacadeapp.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

您是否在添加「psr-4」後刷新了作曲家自動載入?試試如果沒有,請嘗試'composer dump-autoload'並刷新。 –

+0

是的,我試過但沒有結果 –

+0

這個路徑 - 「Christian \\ SMSService \\」:**「app/Packages/christian/smsservice/src」** - 應該是相對於你的'composer.json'。它通常和'/ vendor'在同一個目錄下,但你的'/ vendor'位於'app/Packages/christian/smsservice'。 你能告訴我們你的'composer.json'和確切的位置? –

回答

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 
    } 
} 
相關問題