简体   繁体   English

如何将第3方类库与Laravel集成在一起以使其自动加载?

[英]How to integrate a 3rd party class library with Laravel so it autoloads?

I am trying to integrate the Temboo SDK with the Laravel framework so that it autoloads like the rest of the vendors. 我正在尝试将Temboo SDK与Laravel框架集成在一起,以便像其他供应商一样自动加载。

The SDK has the following structure: SDK具有以下结构:

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 . 在主Temboo文件中,它们具有多个类声明,并且每个类都使用诸如class Temboo_Session之类的命名,并且library dir中的class _23andMe_Names extends Temboo_Choreography的形式为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')); temboo.php类文件还包括一个自动加载器类Temboo_Loader和声明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. 这是我第一次尝试集成非PSR-0库,因此对此我有些迷失。

Any help would be appreciated. 任何帮助,将不胜感激。

You can tell Composer to autoload any (non-PSR) class by adding the base folder to: 您可以通过将基本文件夹添加到以下内容来告诉Composer自动加载任何(非PSR)类:

"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. 并检查文件vendor/composer/autoload_classmap.php ,可用类必须全部列出在其中,如果没有一个文件,则不会自动加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM