简体   繁体   中英

symfony working with Web Service

I am working in symfony. I am retrivind data from a web service.

Currently I am using "Listener" to get data using web service. Is it wring way to do through listeners?

Is there any concept of Models in symfony to get data using web service? rather than calling web service from listener!

Actually a listener isn't something that would fit your case. You need a regular service, because listeners are supposed to react to Symfony domain events.

On creating services, you should read the official documentation (though if you've created an EventListener then most parts of the manual would be familiar to you).

If you're wrapping a foreign API then you should definitely do some research on whether the API is already wrapped (packagist.org is a good start: here's a wrapper for Twitter's API for example). If it's not, then it's up to you to pick an HTTP client to communicate with the service, and wrap its API into a PHP class that you would then expose in your service.

To understand how exactly you want to do this, try searching Packagist for Symfony bundles that wrap some APIs. Here's a Foursquare API bundle that uses an abstracted client library for example. Note that it depends on Guzzle HTTP client , and also take a look at the Guzzle Client class .

Also, here's Google's official API client for PHP . You could grab some ideas from there, too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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