Provide some tools to use Pushover in a symfony 2 project.
Pushover is a simple notification provider for Android, iPhone, iPad, and Desktop.
- Create an account on Pushover.
- On the Pushover website, create an application to get a specific API key for the application
- Download the mobile app and synchronize it with your account
- Then add this bundle in your composer.json
$ composer require eheuje/pushover-bundle
- Enable the bundle in your appKernel.php
- Configure the following parameters in your config.yml with your own values (user_key, api_key and user_email are provided by Pushover once you've create your account and the specific application)
eheuje_pushover:
application:
user_key: <your_user_key>
api_key: <your_api_key>
user_email: <your_user_email>
To get the service from a controller that says "Hello World" :
$this->get('eheuje_pushover.pusher')
->setMessage("Hello World")
->push();
It's possible to add extra information in your notifications :
- the duration of a task
- the memomy used by the task
eheuje_pushover:
additional_information:
duration: ~ # true or false
memory: ~ # true or false
However, this feature is not automatic. It works with the StopWatch Component.
Further information about StopWatch
use Symfony\Component\Stopwatch\Stopwatch;
$stopwatch = new Stopwatch();
$stopwatch->start('eventName');
// ... some code goes here
$event = $stopwatch->stop('eventName');
$this->get('eheuje_pushover.pusher')
->setMessage("Hello World")
->setStopwatchEvent($event)
->push();
Further information about the Console Component
When you create huge commands, it takes a lot of time to execute them. If you don't want to wait behind your computer for the commands to terminate, you can create your command as an inheritance of PushoverCommand.
use Eheuje\PushoverBundle\Command\PushoverCommand;
use Symfony\Component\Console\Command\Command;
class GreetCommand extends PushoverCommand
{
// ... some code goes here
}
Then, call the command with the option --with-pushover.
$ php app/console foo:bar "Hello World" --with-pushover
When the command is terminated, you'll be notified if :
- the command is terminated with a with a awaiting exit code ;
- the command is terminated with an Exception.
- Do something with the pushover email function
- Do some tests
- Clean the bundle