1. Go to this page and download the library: Download namshi/notificator library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namshi / notificator example snippets
php
$handler = new MyHandler();
$handlers = array(
new AnotherHandler(), new AnotherOneHandler(),
);
$manager = new Manager();
// add multiple handlers
$manager->setHandlers($handlers);
// add a single handler
$manager->addHandler($handler);
// reset the handlers
$manager->setHandlers(array());
php
use Namshi\Notificator\Notification;
use Namshi\Notificator\NotificationInterface;
interface EchoedNotificationInterface extends NotificationInterface
{
public function getMessage();
}
interface EmailNotificationInterface extends NotificationInterface
{
public function getAddress();
public function getSubject();
public function getBody();
}
class DoubleNotification extends Notification implements EchoedNotificationInterface, EmailNotificationInterface
{
protected $address;
protected $body;
protected $subject;
public function __construct($address, $subject, $body, array $parameters = array())
{
parent::__construct($parameters);
$this->address = $address;
$this->body = $body;
$this->subject = $subject;
$this->message = $body;
}
public function getAddress()
{
return $this->address;
}
public function getSubject()
{
return $this->subject;
}
public function getBody()
{
return $this->body;
}
public function getMessage()
{
return $this->message;
}
}
php
use Namshi\Notificator\Notification\Handler\HandlerInterface;
use Namshi\Notificator\NotificationInterface;
class EchoedNotificationHandler implements HandlerInterface
{
public function shouldHandle(NotificationInterface $notification)
{
return $notification instanceOf EchoedNotificationInterface;
}
public function handle(NotificationInterface $notification)
{
echo $notification->getMessage();
}
}
php
use Namshi\Notificator\Notification\Handler\HandlerInterface;
use Namshi\Notificator\NotificationInterface;
class EmailNotificationHandler implements HandlerInterface
{
public function shouldHandle(NotificationInterface $notification)
{
return $notification instanceOf EmailNotificationInterface;
}
public function handle(NotificationInterface $notification)
{
mail($notification->getAddress(), $notification->getSubject(), $notification->getBody());
}
}
php
public function handle(NotificationInterface $notification)
{
// do whatever you want with the notification
// ...
return false;
}
$bundles = array(
...
new Namshi\Notificator\Symfony\NamshiNotificatorBundle()
);
php app/console rabbitmq:consumer -w notification
php
$publisher = $container->get('old_sound_rabbit_mq.notifications_producer');
$notification = new MyWhateverNotification("man, this comes from RabbitMQ and Symfony2!");
$publisher->publish(serialize($notification));
cli
php vendor/bin/phpspec run --format=dot
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.