1 | <?php |
||
2 | |||
3 | namespace App\Services; |
||
4 | |||
5 | use App\Entities\Judger; |
||
6 | use App\Exceptions\Judger\JudgerNameExist; |
||
7 | use App\Repositories\JudgerRepository; |
||
8 | |||
9 | class JudgerService |
||
10 | { |
||
11 | /** |
||
12 | * @param string $name |
||
13 | * @param null $bind_ip |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
14 | * |
||
15 | * @throws \App\Exceptions\Judger\JudgerNameExist |
||
16 | * |
||
17 | * @return \App\Entities\Judger |
||
18 | */ |
||
19 | public function newJudger($name, $bind_ip = null) |
||
20 | { |
||
21 | if ($this->exist($name)) { |
||
22 | throw new JudgerNameExist(); |
||
23 | } |
||
24 | $judger = new Judger(); |
||
25 | $judger->name = $name; |
||
26 | $judger->code = new_judge_code(); |
||
27 | $judger->status = Judger::ST_ACTIVITY; |
||
28 | if ($bind_ip) { |
||
0 ignored issues
–
show
|
|||
29 | $judger->bind_ip = $bind_ip; |
||
30 | } |
||
31 | $judger->save(); |
||
32 | |||
33 | return $judger; |
||
34 | } |
||
35 | |||
36 | private function exist($name) |
||
37 | { |
||
38 | return app(JudgerRepository::class)->findBy('name', $name); |
||
39 | } |
||
40 | |||
41 | public function find($id) |
||
42 | { |
||
43 | return app(JudgerRepository::class)->findOrFail($id); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param $code |
||
48 | * |
||
49 | * @return Judger |
||
50 | */ |
||
51 | public function getJudger($code) |
||
52 | { |
||
53 | if ($code) { |
||
54 | return app(JudgerRepository::class)->findBy('code', $code); |
||
55 | } |
||
56 | |||
57 | return null; |
||
58 | } |
||
59 | } |
||
60 |