Skip to content

Commit

Permalink
Merge pull request #254 from fenos/develop
Browse files Browse the repository at this point in the history
v4.0.3
  • Loading branch information
Gummibeer committed Jan 16, 2017
2 parents 0bba585 + fb48038 commit 460685d
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ after_script:

## Send Build Notifications to Slack
notifications:
slack: notifynder:CnF7P2xaZuJTJ4VzNOy6ksDH
slack: astrotomic:CnF7P2xaZuJTJ4VzNOy6ksDH
7 changes: 1 addition & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@
"satooshi/php-coveralls": "^1.0"
},
"autoload": {
"classmap": [

],
"psr-4": {
"Fenos\\Notifynder\\": "src/Notifynder"
},
"files": [

"src/Notifynder/Helpers/helpers.php"
]
},
Expand All @@ -47,6 +43,5 @@
"psr-4": {
"Fenos\\Tests\\": "tests/models"
}
},
"minimum-stability": "stable"
}
}
15 changes: 14 additions & 1 deletion src/Notifynder/Contracts/SenderManagerContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function hasSender($name);

/**
* @param string $name
* @return Closure
* @return Closure|null
*/
public function getSender($name);

Expand All @@ -34,6 +34,19 @@ public function getSender($name);
*/
public function extend($name, Closure $sender);

/**
* @param string $class
* @param callable $callback
* @return bool
*/
public function setCallback($class, callable $callback);

/**
* @param string $class
* @return callable|null
*/
public function getCallback($class);

/**
* @param string $name
* @param array $notifications
Expand Down
30 changes: 30 additions & 0 deletions src/Notifynder/Managers/SenderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class SenderManager implements SenderManagerContract
*/
protected $senders = [];

/**
* @var array
*/
protected $callbacks = [];

/**
* @param array $notifications
* @return bool
Expand Down Expand Up @@ -67,6 +72,31 @@ public function extend($name, Closure $sender)
return false;
}

/**
* @param string $class
* @param callable $callback
* @return bool
*/
public function setCallback($class, callable $callback)
{
if (class_exists($class)) {
$this->callbacks[$class] = $callback;

return true;
}

return false;
}

/**
* @param string $class
* @return callable|null
*/
public function getCallback($class)
{
return Arr::get($this->callbacks, $class);
}

/**
* @param string $name
* @param array $notifications
Expand Down
13 changes: 12 additions & 1 deletion src/Notifynder/Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

/**
* Class Notification.
*
* @property int $to_id
* @property string $to_type
* @property int $from_id
* @property string $from_type
* @property int $category_id
* @property bool $read
* @property string $url
* @property array $extra
* @property string $expires_at
* @property int $stack_id
*/
class Notification extends Model
{
Expand Down Expand Up @@ -45,7 +56,7 @@ class Notification extends Model
/**
* Notification constructor.
*
* @param array $attributes
* @param array|\Fenos\Notifynder\Builder\Notification $attributes
*/
public function __construct($attributes = [])
{
Expand Down
6 changes: 5 additions & 1 deletion src/Notifynder/Models/NotificationCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

/**
* Class NotificationCategory.
*
* @property string $name
* @property string $text
* @method Builder byName($name)
*/
class NotificationCategory extends Model
{
Expand Down Expand Up @@ -66,7 +70,7 @@ public function setNameAttribute($value)
}

/**
* @return string
* @return \Symfony\Component\Translation\TranslatorInterface|string
*/
public function getTemplateBodyAttribute()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Notifynder/NotifynderServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function bindContracts()
*/
protected function bindConfig()
{
$this->app->singleton('notifynder.config', function ($app) {
$this->app->singleton('notifynder.config', function () {
return new Config();
});
}
Expand All @@ -89,7 +89,7 @@ protected function bindConfig()
*/
protected function bindSender()
{
$this->app->singleton('notifynder.sender', function ($app) {
$this->app->singleton('notifynder.sender', function () {
return new SenderManager();
});
}
Expand Down Expand Up @@ -181,8 +181,8 @@ protected function getMigrationFilepath($filename)
{
if (function_exists('database_path')) {
return database_path('/migrations/'.$filename);
} else {
return base_path('/database/migrations/'.$filename); // @codeCoverageIgnore
}

return base_path('/database/migrations/'.$filename); // @codeCoverageIgnore
}
}
17 changes: 12 additions & 5 deletions src/Notifynder/Parsers/NotificationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,22 @@ protected function mixedGet($object, $key, $default = null)
foreach (explode('.', $key) as $segment) {
if (is_object($object) && isset($object->{$segment})) {
$object = $object->{$segment};
} elseif (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) {
continue;
}
if (is_object($object) && method_exists($object, '__get') && ! is_null($object->__get($segment))) {
$object = $object->__get($segment);
} elseif (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) {
continue;
}
if (is_object($object) && method_exists($object, 'getAttribute') && ! is_null($object->getAttribute($segment))) {
$object = $object->getAttribute($segment);
} elseif (is_array($object) && array_key_exists($segment, $object)) {
continue;
}
if (is_array($object) && array_key_exists($segment, $object)) {
$object = array_get($object, $segment, $default);
} else {
return value($default);
continue;
}

return value($default);
}

return $object;
Expand Down
4 changes: 2 additions & 2 deletions src/Notifynder/Senders/OnceSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public function send(SenderManagerContract $sender)
$query = $this->getQuery($notification);
if (! $query->exists()) {
$success = $sender->send([$notification]) ? $success : false;
} else {
$query->firstOrFail()->resend();
continue;
}
$success = $query->firstOrFail()->resend() ? $success : false;
}

return $success;
Expand Down
6 changes: 1 addition & 5 deletions src/Notifynder/Traits/NotifableBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ protected function updateSingleReadStatus($notification, $value)
}

if ($this->getNotificationRelation()->where($notification->getKeyName(), $notification->getKey())->exists()) {
if ($value) {
return $notification->read();
} else {
return $notification->unread();
}
return $value ? $notification->read() : $notification->unread();
}

return false;
Expand Down
19 changes: 19 additions & 0 deletions src/Notifynder/Traits/SenderCallback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Fenos\Notifynder\Traits;

trait SenderCallback
{
/**
* @return callable
*/
public function getCallback()
{
$callback = app('notifynder.sender')->getCallback(get_called_class());
if (! is_callable($callback)) {
throw new \UnexpectedValueException("The callback isn't callable.");
}

return $callback;
}
}

0 comments on commit 460685d

Please sign in to comment.