2014-04-17 172 views
4

我想使用作曲家將我的供應商文件夾添加一個bitbucket存儲庫。這是我在我的composer.json:autoload bitbucket存儲庫+ composer.json

{ 
    "require": { 
     "silex/silex": "~1.1", 
     "doctrine/dbal": "2.2.*", 
     "twig/twig" : "1.*", 
     "symfony/twig-bridge": "~2.3", 
     "twitter/bootstrap": "*", 
     "symfony/assetic-bundle": "2.1.*", 
     "leafo/lessphp": "*", 
     "silex/web-profiler": "~1.0", 
     "symfony/security": "~2.3", 
     "symfony/form": "~2.3", 
     "symfony/validator": "~2.3", 
     "symfony/config": "~2.3", 
     "symfony/translation": "~2.3", 
     "monolog/monolog": ">=1.0.0", 
     "symfony/yaml": "~2.3", 
     "jasongrimes": "dev-master" 
    }, 
    "autoload": { 
     "psr-0": { "": "src/" } 
    }, 
    "repositories": [ 
     { 
      "type": "package", 
      "package": { 
       "name": "jasongrimes", 
       "version": "dev-master", 
       "source": { 
        "url": "mybitbucketurl", 
        "type": "git", 
        "reference": "origin/master" 
       } 
      } 
     } 
    ] 
} 

我沒有在我的到位桶儲存庫composer.json,我想通過作曲家的補充。現在,當我跑我的應用程序出現以下錯誤:

Fatal error: Class 'SimpleUser\UserServiceProvider' not found in app/bootstrap.php on line 82 

我如何確保這也是在自動裝?

+0

不應該只是'reference'裏面的'master'嗎?除此之外,它與我用來將GitHub存儲庫克隆到我的供應商中幾乎完全相同。 –

+0

您的錯誤與composer或bitbucket無關,PHP無法加載類 –

+0

SimpleUser \ UserServiceProvider來自哪裏?你正在嘗試PSR-0自動加載它嗎? – Joseph

回答

17

當您指定一個軟件包存儲庫時,基本上提供了該軟件包的composer.json中的所有詳細信息(如果有)。爲了自動加載,必須指定軟件包的autoload屬性。作曲家手冊有details on the autoload property

如果您的bitbucket存儲庫符合PSR-0或PSR-4,您只需指定正確的標準以及要加載的類存儲在存儲庫中的位置。例如,PSR-4和您的類存放在src/目錄:

{ 
    "require": { 
     "jasongrimes": "dev-master" 
    }, 
    "repositories": [ 
     { 
      "type": "package", 
      "package": { 
       "name": "jasongrimes", 
       "version": "dev-master", 
       "source": { 
        "url": "mybitbucketurl", 
        "type": "git", 
        "reference": "origin/master" 
       }, 
       "autoload": { 
        "psr-4": { "": "src/" } 
       } 
      } 
     } 
    ] 
} 

否則,您可以使用classmap指定目錄或文件進行掃描.php.inc文件帶班。例如,如果您嘗試加載的課程位於您的資源庫中的文件SimpleUser/UserServiceProvider.php中:

{ 
    "require": { 
     "jasongrimes": "dev-master" 
    }, 
    "repositories": [ 
     { 
      "type": "package", 
      "package": { 
       "name": "jasongrimes", 
       "version": "dev-master", 
       "source": { 
        "url": "mybitbucketurl", 
        "type": "git", 
        "reference": "origin/master" 
       }, 
       "autoload": { 
        "classmap": [ "SimpleUser/UserServiceProvider.php" ] 
       } 
      } 
     } 
    ] 
} 
相關問題