douhu4692 2014-01-17 08:25 采纳率: 100%
浏览 36
已采纳

如何在symfony2.3中包含外部库

I want to implement yelp API in my new project.Downloaded their library and sample code.But this library is very old, uploaded 3 year back.I don't know how to include it in symfony2.3.Can anyone tell me that how to include this type of files in symfony2.3 projects.

  • 写回答

1条回答 默认 最新

  • dsfliu1129 2014-01-21 12:19
    关注

    I think you can define it as services like this:

    First of all include the Api inside your bundle, for example in:

    Acme/YourBundle/Yelp/
    

    But you will have to seperate the classes in individual files:

    Acme/YourBundle/Yelp/OAuthToken.php
    Acme/YourBundle/Yelp/OAuthConsumer.php
    Acme/YourBundle/Yelp/OAuthSignatureMethod_HMAC_SHA1.php
    Acme/YourBundle/Yelp/OAuthRequest.php
    

    And add a namespace to each:

    namespace Acme\YourBundle\Yelp;
    
    class OAuthToken {
        ...
    

    Then define the keys in your app/config/parameter.yml:

    parameters:
        yelp_token: "..."
        yelp_token_secret: "..."
        consumer_key: "..."
        consumer_secret: "..."
    

    Now the services in app/config/config.yml

    services:
        yelp_token:
            class: Acme\YourBundle\Yelp\OAuthToken
            arguments: [%yelp_token%, %yelp_token_secret%]
        yelp_consumer:
            class: Acme\YourBundle\Yelp\OAuthConsumer
            arguments: [%consumer_key%, %consumer_secret%]
        yelp_signature_method:
            class: Acme\YourBundle\Yelp\OAuthSignatureMethod_HMAC_SHA1
        yelp_oauthrequest:
            class: Acme\YourBundle\Yelp\OAuthRequest
    

    And in your controllers you can access the classes like this:

    $yelp_token = $this->container->get('yelp_token');
    

    I don't think this is a copy/paste solution but it might guide you in the right direction.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用