dqroktbn005028
2014-04-17 04:08 阅读 246
已采纳

如何将第三方类库与Laravel集成,以便自动加载?

I am trying to integrate the Temboo SDK with the Laravel framework so that it autoloads like the rest of the vendors.

The SDK has the following structure:

temboo
    src
        library
            temboo._23andme.php
            temboo._37signals.php
            etc...
        temboo.php

Within the main Temboo file, they have multiple class declarations and each one uses naming such as class Temboo_Session and the classes in the library dir are of the form class _23andMe_Names extends Temboo_Choreography.

The temboo.php class file also includes an autoloader class Temboo_Loader and declaration spl_autoload_register(array('Temboo_Loader', 'autoload'));

This is my first time trying to integrate a non-PSR-0 library, so I am a little lost on this.

Any help would be appreciated.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongliao6777 dongliao6777 2014-04-17 14:51

    You can tell Composer to autoload any (non-PSR) class by adding the base folder to:

    "autoload": {
        "classmap": [
            "app/commands",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ],
        ....
    

    And you can also autoload autoloaders by adding them to the files section:

    "autoload": {
        "files": [
            "temboo/src/Temboo_Loader.php"
        ],
    ...
    

    After adding those entries, execute

    composer dumpautoload
    

    And check the file vendor/composer/autoload_classmap.php, the available classes must be all listed in it, if one file is not there it will not be autoloaded.

    点赞 评论 复制链接分享

相关推荐