Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Added support for collection and array
Browse files Browse the repository at this point in the history
- Regardless of `phpushbullet` implementation
  • Loading branch information
Max13 committed Nov 18, 2015
1 parent 0eddb41 commit 275cf5f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ To push to multiple devices:
PushBullet::device('Chrome')->device('Galaxy S4')->note('Remember', 'Buy some eggs.');
// or
PushBullet::device('Chrome', 'Galaxy S4')->note('Remember', 'Buy some eggs.');
// or using an array
PushBullet::device(['Chrome', 'Galaxy S4'])->note('Remember', 'Buy some eggs.');
// or using a collection
PushBullet::device(Device::all()->pluck('name'))->note('Remember', 'Buy some eggs.');
```

If you want to push to all devices
Expand All @@ -114,6 +118,10 @@ PushBullet::type('android')->note('Remember', 'Buy some eggs.');
PushBullet::type('android')->type('chrome')->note('Remember', 'Buy some eggs.');
// or
PushBullet::type('android', 'chrome')->note('Remember', 'Buy some eggs.');
// or using an array
PushBullet::type(['android', 'chrome'])->note('Remember', 'Buy some eggs.');
// or using a collection
PushBullet::type(Type::all()->pluck('name'))->note('Remember', 'Buy some eggs.');
```


Expand All @@ -134,6 +142,10 @@ To push to multiple users:
PushBullet::user('joe@example.com')->user('anne@example.com')->note('Remember', 'Buy some eggs.');
// or
PushBullet::user('joe@example.com', 'anne@example.com')->note('Remember', 'Buy some eggs.');
// or using an array
PushBullet::user(['joe@example.com', 'anne@example.com'])->note('Remember', 'Buy some eggs.');
// or using a collection
PushBullet::user(User::findMany([1, 2, 3])->pluck('email'))->note('Remember', 'Buy some eggs.');
```
## Types

Expand Down
35 changes: 34 additions & 1 deletion src/LaravelPushbullet.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Lahaxearnaud\LaravelPushbullet;

use Illuminate\Database\Eloquent\Collection;
use PHPushbullet\PHPushbullet;

class LaravelPushbullet extends PHPushbullet {
Expand All @@ -24,9 +25,28 @@ public function all()
return $this;
}

public function device()
{
if (func_get_arg(0) instanceof Collection) {
$args = func_get_arg(0)->toArray();
} elseif (is_array(func_get_arg(0))) {
$args = func_get_arg(0);
} else {
$args = func_get_args();
}

return call_user_func_array(['parent', 'device'], $args);
}

public function type()
{
foreach (func_get_args() as $type) {
if (func_get_arg(0) instanceof Collection || is_array(func_get_arg(0))) {
$args = func_get_arg(0);
} else {
$args = func_get_args();
}

foreach ($args as $type) {
$devices = $this->devices();
foreach ($devices as $device) {
if(strcasecmp($device->type, $type) === 0 && $device->active) {
Expand All @@ -41,4 +61,17 @@ public function type()

return $this;
}

public function user()
{
if (func_get_arg(0) instanceof Collection) {
$args = func_get_arg(0)->toArray();
} elseif (is_array(func_get_arg(0))) {
$args = func_get_arg(0);
} else {
$args = func_get_args();
}

return call_user_func_array(['parent', 'user'], $args);
}
}

0 comments on commit 275cf5f

Please sign in to comment.