[英]How to include external libraries in symfony2.3
我想在我的新项目中实现yelp API,下载了他们的库和示例代码,但是这个库很旧,三年前上传了,我不知道如何在symfony2.3中包含它,有人可以告诉我如何在symfony2.3项目中包含此类文件。
I think you can define it as services like this: 我认为您可以将其定义为这样的服务:
First of all include the Api inside your bundle, for example in: 首先,将Api包含在捆绑软件中,例如:
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
: 然后在您的app/config/parameter.yml
定义键:
parameters:
yelp_token: "..."
yelp_token_secret: "..."
consumer_key: "..."
consumer_secret: "..."
Now the services in app/config/config.yml
现在,服务在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. 我认为这不是复制/粘贴解决方案,但它可能会指导您朝着正确的方向发展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.