martin-georgiev / social-post-bundle

Symfony bundle to publish status updates on Facebook, LinkedIn and Twitter.
https://packagist.org/packages/martin-georgiev/social-post-bundle
MIT License
39 stars 17 forks source link

Update documentation to show using DI #26

Open tacman opened 5 years ago

tacman commented 5 years ago

Can you add an example in the documentation showing how to call the service via Dependency Injection, that than through the container?

That's Symfony's best practice recommendations now.

Thanks.

phtmgt commented 4 years ago

yay, + one. We need this for symfony 4.3+.

phtmgt commented 4 years ago

Let me help here, feel free to add this to the documentation:

services.yaml:

MartinGeorgiev\SocialPost\Publisher: '@social_post'

In your Controller:

use MartinGeorgiev\SocialPost\Publisher as SocialPublisher;
use MartinGeorgiev\SocialPost\Message as SocialMessage;

...
public function myFunction (SocialPublisher $publisher) {
...

$post = new SocialMessage('post content here');
$publisher->publish($post);

...
}

Is you want to use it in a service, just pass SocialPublisher to the __construct method. Hope this helps.