@@ -8,33 +8,33 @@ |
||
8 | 8 | |
9 | 9 | class Registrar implements RegistrarContract |
10 | 10 | { |
11 | - /** |
|
12 | - * Get a validator for an incoming registration request. |
|
13 | - * |
|
14 | - * @param array $data |
|
15 | - * |
|
16 | - * @return \Illuminate\Contracts\Validation\Validator |
|
17 | - */ |
|
18 | - public function validator(array $data) |
|
19 | - { |
|
20 | - return Validator::make($data, [ |
|
21 | - 'email' => 'required|email|max:255|unique:users', |
|
22 | - 'password' => 'required|confirmed|min:6', |
|
23 | - ]); |
|
24 | - } |
|
11 | + /** |
|
12 | + * Get a validator for an incoming registration request. |
|
13 | + * |
|
14 | + * @param array $data |
|
15 | + * |
|
16 | + * @return \Illuminate\Contracts\Validation\Validator |
|
17 | + */ |
|
18 | + public function validator(array $data) |
|
19 | + { |
|
20 | + return Validator::make($data, [ |
|
21 | + 'email' => 'required|email|max:255|unique:users', |
|
22 | + 'password' => 'required|confirmed|min:6', |
|
23 | + ]); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Create a new user instance after a valid registration. |
|
28 | - * |
|
29 | - * @param array $data |
|
30 | - * |
|
31 | - * @return User |
|
32 | - */ |
|
33 | - public function create(array $data) |
|
34 | - { |
|
35 | - return User::create([ |
|
36 | - 'email' => $data['email'], |
|
37 | - 'password' => bcrypt($data['password']), |
|
38 | - ]); |
|
39 | - } |
|
26 | + /** |
|
27 | + * Create a new user instance after a valid registration. |
|
28 | + * |
|
29 | + * @param array $data |
|
30 | + * |
|
31 | + * @return User |
|
32 | + */ |
|
33 | + public function create(array $data) |
|
34 | + { |
|
35 | + return User::create([ |
|
36 | + 'email' => $data['email'], |
|
37 | + 'password' => bcrypt($data['password']), |
|
38 | + ]); |
|
39 | + } |
|
40 | 40 | } |
@@ -4,17 +4,17 @@ |
||
4 | 4 | |
5 | 5 | abstract class Transformer |
6 | 6 | { |
7 | - /** |
|
8 | - * Transform a collection of items. |
|
9 | - * |
|
10 | - * @param array $items |
|
11 | - * |
|
12 | - * @return array |
|
13 | - */ |
|
14 | - public function transformCollection(array $items) |
|
15 | - { |
|
16 | - return array_map([$this, 'transform'], $items); |
|
17 | - } |
|
7 | + /** |
|
8 | + * Transform a collection of items. |
|
9 | + * |
|
10 | + * @param array $items |
|
11 | + * |
|
12 | + * @return array |
|
13 | + */ |
|
14 | + public function transformCollection(array $items) |
|
15 | + { |
|
16 | + return array_map([$this, 'transform'], $items); |
|
17 | + } |
|
18 | 18 | |
19 | - abstract public function transform($item); |
|
19 | + abstract public function transform($item); |
|
20 | 20 | } |
@@ -10,26 +10,26 @@ |
||
10 | 10 | |
11 | 11 | class User extends Model implements AuthenticatableContract, CanResetPasswordContract |
12 | 12 | { |
13 | - use Authenticatable, CanResetPassword; |
|
13 | + use Authenticatable, CanResetPassword; |
|
14 | 14 | |
15 | - /** |
|
16 | - * The database table used by the model. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $table = 'users'; |
|
15 | + /** |
|
16 | + * The database table used by the model. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $table = 'users'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * The attributes that are mass assignable. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $fillable = ['email', 'password']; |
|
22 | + /** |
|
23 | + * The attributes that are mass assignable. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $fillable = ['email', 'password']; |
|
28 | 28 | |
29 | - /** |
|
30 | - * The attributes excluded from the model's JSON form. |
|
31 | - * |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $hidden = ['password', 'remember_token']; |
|
29 | + /** |
|
30 | + * The attributes excluded from the model's JSON form. |
|
31 | + * |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $hidden = ['password', 'remember_token']; |
|
35 | 35 | } |
@@ -4,5 +4,5 @@ |
||
4 | 4 | |
5 | 5 | abstract class Event |
6 | 6 | { |
7 | - // |
|
7 | + // |
|
8 | 8 | } |
@@ -4,16 +4,16 @@ |
||
4 | 4 | |
5 | 5 | class DeviceTransformer extends Transformer |
6 | 6 | { |
7 | - public function transform($device) |
|
8 | - { |
|
9 | - return [ |
|
10 | - 'id' => $device['id'], |
|
11 | - 'ip' => $device['ip'], |
|
12 | - 'name' => $device['name'], |
|
13 | - 'group' => $device['group'], |
|
14 | - 'on_home_page' => $device['public'], |
|
15 | - 'device_added' => $device['created_at']->toIso8601String(), |
|
16 | - 'last_contact' => $device['updated_at']->toIso8601String(), |
|
17 | - ]; |
|
18 | - } |
|
7 | + public function transform($device) |
|
8 | + { |
|
9 | + return [ |
|
10 | + 'id' => $device['id'], |
|
11 | + 'ip' => $device['ip'], |
|
12 | + 'name' => $device['name'], |
|
13 | + 'group' => $device['group'], |
|
14 | + 'on_home_page' => $device['public'], |
|
15 | + 'device_added' => $device['created_at']->toIso8601String(), |
|
16 | + 'last_contact' => $device['updated_at']->toIso8601String(), |
|
17 | + ]; |
|
18 | + } |
|
19 | 19 | } |
@@ -10,138 +10,138 @@ |
||
10 | 10 | |
11 | 11 | class DeviceController extends ApiController |
12 | 12 | { |
13 | - /** |
|
14 | - * @var DeviceTransformer |
|
15 | - */ |
|
16 | - private $transformer; |
|
17 | - |
|
18 | - public function __construct(DeviceTransformer $transformer) |
|
19 | - { |
|
20 | - $this->middleware('auth.basic', ['except' => ['index', 'poke', 'show']]); |
|
21 | - |
|
22 | - $this->transformer = $transformer; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Display a listing of the resource. |
|
27 | - * |
|
28 | - * @param null $group |
|
29 | - * |
|
30 | - * @return Response |
|
31 | - */ |
|
32 | - public function index($group = null) |
|
33 | - { |
|
34 | - $devices = $group ? Device::where('group', $group)->get() : Device::onHomePage()->get(); |
|
35 | - |
|
36 | - return $this->respond([ |
|
37 | - 'data' => $this->transformer->transformCollection($devices->all()), |
|
38 | - 'server_time' => Carbon::now()->toIso8601String(), |
|
39 | - ]); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Store a newly created resource in storage. |
|
44 | - * |
|
45 | - * @param StoreComputerRequest $request |
|
46 | - * |
|
47 | - * @return Response |
|
48 | - */ |
|
49 | - public function store(StoreComputerRequest $request) |
|
50 | - { |
|
51 | - $device = Device::create($request->all()); |
|
52 | - |
|
53 | - $device->public = $request->get('public', 'auto'); |
|
54 | - |
|
55 | - return $this->respondCreated($this->transformer->transform($device), $device->id); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Display the specified resource. |
|
60 | - * |
|
61 | - * @param int $id |
|
62 | - * |
|
63 | - * @return Response |
|
64 | - */ |
|
65 | - public function show($id) |
|
66 | - { |
|
67 | - $device = Device::find($id); |
|
68 | - |
|
69 | - if (!$device) { |
|
70 | - return $this->respondNotFound('Did not find the device you are looking for!'); |
|
71 | - } |
|
72 | - |
|
73 | - return $this->respond([ |
|
74 | - 'data' => $this->transformer->transform($device), |
|
75 | - ]); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Update the specified resource in storage. |
|
80 | - * |
|
81 | - * @param StoreComputerRequest $request |
|
82 | - * @param int $id |
|
83 | - * |
|
84 | - * @return Response |
|
85 | - */ |
|
86 | - public function update(StoreComputerRequest $request, $id) |
|
87 | - { |
|
88 | - $device = Device::find($id); |
|
89 | - |
|
90 | - if (!$device) { |
|
91 | - return $this->respondNotFound('Did not find the device you are looking for!'); |
|
92 | - } |
|
93 | - |
|
94 | - $device = $device->fill($request->all()); |
|
95 | - |
|
96 | - $device->save(); |
|
97 | - |
|
98 | - return $this->respond([ |
|
99 | - 'data' => $this->transformer->transform($device), |
|
100 | - ]); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Remove the specified resource from storage. |
|
105 | - * |
|
106 | - * @param int $id |
|
107 | - * |
|
108 | - * @return Response |
|
109 | - */ |
|
110 | - public function destroy($id) |
|
111 | - { |
|
112 | - $device = Device::find($id); |
|
113 | - |
|
114 | - if (!$device) { |
|
115 | - return $this->respondNotFound('Did not find the device you are looking for!'); |
|
116 | - } |
|
117 | - |
|
118 | - $device->delete(); |
|
119 | - |
|
120 | - return $this->respondNoContent(); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Handle device pokes. |
|
125 | - * |
|
126 | - * @param StoreComputerRequest $request |
|
127 | - * |
|
128 | - * @throws \Exception |
|
129 | - * |
|
130 | - * @return Response |
|
131 | - */ |
|
132 | - public function poke(StoreComputerRequest $request) |
|
133 | - { |
|
134 | - $device = Device::firstOrNew(['mac' => $request->mac]); |
|
135 | - |
|
136 | - $device->fill($request->all()); |
|
137 | - |
|
138 | - $device->group = $request->get('group', null); |
|
139 | - $device->public = $request->get('public', 'auto'); |
|
140 | - |
|
141 | - $device->touch(); |
|
142 | - |
|
143 | - event(new ServerWasPoked(array_add($device, 'server_time', Carbon::now()->toDateTimeString()))); |
|
144 | - |
|
145 | - return $this->respondPoked($this->transformer->transform($device), $device->id); |
|
146 | - } |
|
13 | + /** |
|
14 | + * @var DeviceTransformer |
|
15 | + */ |
|
16 | + private $transformer; |
|
17 | + |
|
18 | + public function __construct(DeviceTransformer $transformer) |
|
19 | + { |
|
20 | + $this->middleware('auth.basic', ['except' => ['index', 'poke', 'show']]); |
|
21 | + |
|
22 | + $this->transformer = $transformer; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Display a listing of the resource. |
|
27 | + * |
|
28 | + * @param null $group |
|
29 | + * |
|
30 | + * @return Response |
|
31 | + */ |
|
32 | + public function index($group = null) |
|
33 | + { |
|
34 | + $devices = $group ? Device::where('group', $group)->get() : Device::onHomePage()->get(); |
|
35 | + |
|
36 | + return $this->respond([ |
|
37 | + 'data' => $this->transformer->transformCollection($devices->all()), |
|
38 | + 'server_time' => Carbon::now()->toIso8601String(), |
|
39 | + ]); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Store a newly created resource in storage. |
|
44 | + * |
|
45 | + * @param StoreComputerRequest $request |
|
46 | + * |
|
47 | + * @return Response |
|
48 | + */ |
|
49 | + public function store(StoreComputerRequest $request) |
|
50 | + { |
|
51 | + $device = Device::create($request->all()); |
|
52 | + |
|
53 | + $device->public = $request->get('public', 'auto'); |
|
54 | + |
|
55 | + return $this->respondCreated($this->transformer->transform($device), $device->id); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Display the specified resource. |
|
60 | + * |
|
61 | + * @param int $id |
|
62 | + * |
|
63 | + * @return Response |
|
64 | + */ |
|
65 | + public function show($id) |
|
66 | + { |
|
67 | + $device = Device::find($id); |
|
68 | + |
|
69 | + if (!$device) { |
|
70 | + return $this->respondNotFound('Did not find the device you are looking for!'); |
|
71 | + } |
|
72 | + |
|
73 | + return $this->respond([ |
|
74 | + 'data' => $this->transformer->transform($device), |
|
75 | + ]); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Update the specified resource in storage. |
|
80 | + * |
|
81 | + * @param StoreComputerRequest $request |
|
82 | + * @param int $id |
|
83 | + * |
|
84 | + * @return Response |
|
85 | + */ |
|
86 | + public function update(StoreComputerRequest $request, $id) |
|
87 | + { |
|
88 | + $device = Device::find($id); |
|
89 | + |
|
90 | + if (!$device) { |
|
91 | + return $this->respondNotFound('Did not find the device you are looking for!'); |
|
92 | + } |
|
93 | + |
|
94 | + $device = $device->fill($request->all()); |
|
95 | + |
|
96 | + $device->save(); |
|
97 | + |
|
98 | + return $this->respond([ |
|
99 | + 'data' => $this->transformer->transform($device), |
|
100 | + ]); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Remove the specified resource from storage. |
|
105 | + * |
|
106 | + * @param int $id |
|
107 | + * |
|
108 | + * @return Response |
|
109 | + */ |
|
110 | + public function destroy($id) |
|
111 | + { |
|
112 | + $device = Device::find($id); |
|
113 | + |
|
114 | + if (!$device) { |
|
115 | + return $this->respondNotFound('Did not find the device you are looking for!'); |
|
116 | + } |
|
117 | + |
|
118 | + $device->delete(); |
|
119 | + |
|
120 | + return $this->respondNoContent(); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Handle device pokes. |
|
125 | + * |
|
126 | + * @param StoreComputerRequest $request |
|
127 | + * |
|
128 | + * @throws \Exception |
|
129 | + * |
|
130 | + * @return Response |
|
131 | + */ |
|
132 | + public function poke(StoreComputerRequest $request) |
|
133 | + { |
|
134 | + $device = Device::firstOrNew(['mac' => $request->mac]); |
|
135 | + |
|
136 | + $device->fill($request->all()); |
|
137 | + |
|
138 | + $device->group = $request->get('group', null); |
|
139 | + $device->public = $request->get('public', 'auto'); |
|
140 | + |
|
141 | + $device->touch(); |
|
142 | + |
|
143 | + event(new ServerWasPoked(array_add($device, 'server_time', Carbon::now()->toDateTimeString()))); |
|
144 | + |
|
145 | + return $this->respondPoked($this->transformer->transform($device), $device->id); |
|
146 | + } |
|
147 | 147 | } |
@@ -7,32 +7,32 @@ |
||
7 | 7 | |
8 | 8 | class DeviceObserver |
9 | 9 | { |
10 | - /** |
|
11 | - * @var PusherManager |
|
12 | - */ |
|
13 | - protected $pusher; |
|
10 | + /** |
|
11 | + * @var PusherManager |
|
12 | + */ |
|
13 | + protected $pusher; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var DeviceTransformer |
|
17 | - */ |
|
18 | - private $transformer; |
|
15 | + /** |
|
16 | + * @var DeviceTransformer |
|
17 | + */ |
|
18 | + private $transformer; |
|
19 | 19 | |
20 | - /** |
|
21 | - * DeviceObserver constructor. |
|
22 | - * |
|
23 | - * @param PusherManager $pusher |
|
24 | - * @param DeviceTransformer $transformer |
|
25 | - */ |
|
26 | - public function __construct(PusherManager $pusher, DeviceTransformer $transformer) |
|
27 | - { |
|
28 | - $this->pusher = $pusher; |
|
29 | - $this->transformer = $transformer; |
|
30 | - } |
|
20 | + /** |
|
21 | + * DeviceObserver constructor. |
|
22 | + * |
|
23 | + * @param PusherManager $pusher |
|
24 | + * @param DeviceTransformer $transformer |
|
25 | + */ |
|
26 | + public function __construct(PusherManager $pusher, DeviceTransformer $transformer) |
|
27 | + { |
|
28 | + $this->pusher = $pusher; |
|
29 | + $this->transformer = $transformer; |
|
30 | + } |
|
31 | 31 | |
32 | - public function deleted($device) |
|
33 | - { |
|
34 | - $this->pusher->trigger(env('PUSHER_CHANNEL', 'pi-finder'), 'DeviceWasDeleted', [ |
|
35 | - 'device' => $this->transformer->transform($device), |
|
36 | - ]); |
|
37 | - } |
|
32 | + public function deleted($device) |
|
33 | + { |
|
34 | + $this->pusher->trigger(env('PUSHER_CHANNEL', 'pi-finder'), 'DeviceWasDeleted', [ |
|
35 | + 'device' => $this->transformer->transform($device), |
|
36 | + ]); |
|
37 | + } |
|
38 | 38 | } |