Skip to content

Commit d8994a7

Browse files
author
qiang.sun
committed
数据库相关
1 parent 024354f commit d8994a7

File tree

12 files changed

+548
-5
lines changed

12 files changed

+548
-5
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: sunqiang
5+
* Date: 2018/11/21
6+
* Time: 3:01 PM
7+
*/
8+
9+
namespace App\Contracts;
10+
11+
12+
interface EventPusherInterface
13+
{
14+
public function push($message, array $data = array());
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: sunqiang
5+
* Date: 2018/11/20
6+
* Time: 5:16 PM
7+
*/
8+
9+
namespace App\Contracts;
10+
11+
use App\User;
12+
13+
interface OrderRepositoryInterface
14+
{
15+
public function getMostRecent(User $user);
16+
}

app/Contracts/PusherSdkInterface.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: sunqiang
5+
* Date: 2018/11/21
6+
* Time: 3:21 PM
7+
*/
8+
9+
namespace App\Contracts;
10+
11+
12+
interface PusherSdkInterface
13+
{
14+
15+
}

app/Providers/AppServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use App\Contracts\BillerInterface;
66
use App\Contracts\BillingNotifierInterface;
7+
use App\Contracts\OrderRepositoryInterface;
78
use App\Contracts\UserRepositoryInterface;
9+
use App\Repositories\DummyOrderRepository;
810
use App\Repositories\UserRepository;
911
use App\Services\EmailBillingNotifier;
1012
use App\Services\SmsBillingNotifier;
@@ -50,5 +52,9 @@ public function register()
5052

5153
$notifier = new SmsBillingNotifier;
5254
$this->app->instance(BillingNotifierInterface::class, $notifier);
55+
56+
$this->app->bind(OrderRepositoryInterface::class, function ($app) {
57+
return new DummyOrderRepository();
58+
});
5359
}
5460
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use App\Contracts\EventPusherInterface;
6+
use App\Contracts\PusherSdkInterface;
7+
use App\Services\PusherEventPusher;
8+
use Illuminate\Support\Facades\App;
9+
use Illuminate\Support\ServiceProvider;
10+
use Pusher\Pusher;
11+
12+
class EventPusherServiceProvider extends ServiceProvider
13+
{
14+
public function register()
15+
{
16+
$this->app->singleton(PusherSdkInterface::class, function ($app) {
17+
return new Pusher('app-key', 'secret-key', 'app-id');
18+
});
19+
20+
$this->app->singleton(EventPusherInterface::class, PusherEventPusher::class);
21+
}
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: sunqiang
5+
* Date: 2018/11/20
6+
* Time: 5:19 PM
7+
*/
8+
9+
namespace App\Repositories;
10+
11+
12+
use App\Contracts\OrderRepositoryInterface;
13+
use App\User;
14+
15+
class DummyOrderRepository implements OrderRepositoryInterface
16+
{
17+
public function getMostRecent(User $user)
18+
{
19+
return ['Order 1', 'Order 2', 'Order 3'];
20+
}
21+
}

app/Services/PusherEventPusher.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
namespace App\Services;
3+
4+
use App\Contracts\EventPusherInterface;
5+
use App\Contracts\PusherSdkInterface;
6+
7+
class PusherEventPusher implements EventPusherInterface
8+
{
9+
public function __construct(PusherSdkInterface $pusher)
10+
{
11+
$this->pusher = $pusher;
12+
}
13+
14+
public function push($message, array $data = array())
15+
{
16+
// 通过 Pusher SDK 推送消息
17+
}
18+
}

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"type": "project",
77
"require": {
88
"php": "^7.1.3",
9+
"doctrine/dbal": "^2.8",
910
"fideloper/proxy": "^4.0",
1011
"laravel/framework": "5.7.*",
11-
"laravel/tinker": "^1.0"
12+
"laravel/tinker": "^1.0",
13+
"pusher/pusher-php-server": "^3.2"
1214
},
1315
"require-dev": {
1416
"beyondcode/laravel-dump-server": "^1.0",

0 commit comments

Comments
 (0)