for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @copyright Anton Tuyakhov <[email protected]>
*/
namespace tuyakhov\notifications;
use yii\helpers\Inflector;
trait NotifiableTrait
{
* Determines if notifiable entity should receive the notification by checking in notification settings.
* @param NotificationInterface $notification
* @return bool
public function shouldReceiveNotification(NotificationInterface $notification)
$notificationAlias = Inflector::camel2id(get_class($notification));
if (isset($this->notificationSettings[$notificationAlias])) {
return (bool) $this->notificationSettings[$notificationAlias];
notificationSettings
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
return true;
* Send notifications via email by default
* @return array
public function viaChannels()
return ['mail'];
* Return the notification routing information for the given channel.
* ```php
* public function routeNotificationForMail() {
* return $this->email;
* }
* ```
* @param $channel string
* @return mixed
public function routeNotificationFor($channel)
if (method_exists($this, $method = 'routeNotificationFor'.Inflector::id2camel($channel))) {
return $this->{$method}();
switch ($channel) {
case 'mail':
return $this->email;
email
case 'nexmo':
return $this->phone_number;
phone_number
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: