Skip to content

Commit 0deb022

Browse files
committed
Update last of existing services to use repositories, includes unit tests
Also update PHPDocs on all the repository interfaces and classes to be correct.
1 parent 50588a1 commit 0deb022

21 files changed

+807
-206
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository;
26+
27+
interface ApiKeyRepositoryInterface extends RepositoryInterface
28+
{
29+
//
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Contracts\Repository;
26+
27+
interface ApiPermissionRepositoryInterface extends RepositoryInterface
28+
{
29+
//
30+
}

app/Contracts/Repository/Attributes/SearchableInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,11 @@
2626

2727
interface SearchableInterface
2828
{
29+
/**
30+
* Filter results by search term.
31+
*
32+
* @param string $term
33+
* @return $this
34+
*/
2935
public function search($term);
3036
}

app/Contracts/Repository/DatabaseHostInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,14 @@
2626

2727
interface DatabaseHostInterface extends RepositoryInterface
2828
{
29+
/**
30+
* Delete a database host from the DB if there are no databases using it.
31+
*
32+
* @param int $id
33+
* @return bool|null
34+
*
35+
* @throws \Pterodactyl\Exceptions\DisplayException
36+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
37+
*/
2938
public function deleteIfNoDatabases($id);
3039
}

app/Contracts/Repository/LocationRepositoryInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,14 @@
2828

2929
interface LocationRepositoryInterface extends RepositoryInterface, SearchableInterface
3030
{
31+
/**
32+
* Delete a location only if there are no nodes attached to it.
33+
*
34+
* @param $id
35+
* @return bool|mixed|null
36+
*
37+
* @throws \Pterodactyl\Exceptions\DisplayException
38+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
39+
*/
3140
public function deleteIfNoNodes($id);
3241
}

app/Contracts/Repository/RepositoryInterface.php

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,108 @@
2626

2727
interface RepositoryInterface
2828
{
29+
/**
30+
* Return an identifier or Model object to be used by the repository.
31+
*
32+
* @return string|\Closure|object
33+
*/
2934
public function model();
3035

36+
/**
37+
* Return the model being used for this repository instance.
38+
*
39+
* @return mixed
40+
*/
3141
public function getModel();
3242

43+
/**
44+
* Returns an instance of a query builder.
45+
*
46+
* @return mixed
47+
*/
3348
public function getBuilder();
3449

50+
/**
51+
* Returns the colummns to be selected or returned by the query.
52+
*
53+
* @return mixed
54+
*/
3555
public function getColumns();
3656

57+
/**
58+
* An array of columns to filter the response by.
59+
*
60+
* @param array $columns
61+
* @return $this
62+
*/
3763
public function withColumns($columns = ['*']);
3864

39-
public function create($fields);
65+
/**
66+
* Disable returning a fresh model when data is inserted or updated.
67+
*
68+
* @return $this
69+
*/
70+
public function withoutFresh();
4071

72+
/**
73+
* Create a new model instance and persist it to the database.
74+
*
75+
* @param array $fields
76+
* @param bool $validate
77+
* @return mixed
78+
*
79+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
80+
*/
81+
public function create(array $fields, $validate = true);
82+
83+
/**
84+
* Delete a given record from the database.
85+
*
86+
* @param int $id
87+
* @return bool|null
88+
*/
4189
public function delete($id);
4290

91+
/**
92+
* Find a model that has the specific ID passed.
93+
*
94+
* @param int $id
95+
* @return mixed
96+
*
97+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
98+
*/
4399
public function find($id);
44100

45-
public function findWhere($fields);
101+
/**
102+
* Find a model matching an array of where clauses.
103+
*
104+
* @param array $fields
105+
* @return mixed
106+
*
107+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
108+
*/
109+
public function findWhere(array $fields);
46110

47-
public function update($id, $fields);
111+
/**
112+
* Update a given ID with the passed array of fields.
113+
*
114+
* @param int $id
115+
* @param array $fields
116+
* @param bool $validate
117+
* @param bool $force
118+
* @return mixed
119+
*
120+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
121+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
122+
*/
123+
public function update($id, array $fields, $validate = true, $force = false);
48124

49-
public function massUpdate($fields);
125+
/**
126+
* Update multiple records matching the passed clauses.
127+
*
128+
* @param array $where
129+
* @param array $fields
130+
* @return mixed
131+
*/
132+
public function massUpdate(array $where, array $fields);
50133
}

app/Contracts/Repository/UserRepositoryInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,20 @@
2828

2929
interface UserRepositoryInterface extends RepositoryInterface, SearchableInterface
3030
{
31+
/**
32+
* Return all users with counts of servers and subusers of servers.
33+
*
34+
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
35+
*/
3136
public function getAllUsersWithCounts();
3237

38+
/**
39+
* Delete a user if they have no servers attached to their account.
40+
*
41+
* @param int $id
42+
* @return bool
43+
*
44+
* @throws \Pterodactyl\Exceptions\DisplayException
45+
*/
3346
public function deleteIfNoServers($id);
3447
}

app/Models/APIPermission.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class APIPermission extends Model implements ValidableContract
3636
/**
3737
* List of permissions available for the API.
3838
*/
39-
const PERMISSIONS = [
39+
const CONST_PERMISSIONS = [
4040
// Items within this block are available to non-adminitrative users.
4141
'_user' => [
4242
'server' => [

app/Providers/RepositoryServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
namespace Pterodactyl\Providers;
2626

2727
use Illuminate\Support\ServiceProvider;
28+
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
29+
use Pterodactyl\Contracts\Repository\ApiPermissionRepositoryInterface;
2830
use Pterodactyl\Contracts\Repository\DatabaseHostInterface;
2931
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
32+
use Pterodactyl\Repositories\Eloquent\ApiKeyRepository;
33+
use Pterodactyl\Repositories\Eloquent\ApiPermissionRepository;
3034
use Pterodactyl\Repositories\Eloquent\DatabaseHostRepository;
3135
use Pterodactyl\Repositories\Eloquent\LocationRepository;
3236
use Pterodactyl\Repositories\Eloquent\UserRepository;
@@ -39,6 +43,8 @@ class RepositoryServiceProvider extends ServiceProvider
3943
*/
4044
public function register()
4145
{
46+
$this->app->bind(ApiKeyRepositoryInterface::class, ApiKeyRepository::class);
47+
$this->app->bind(ApiPermissionRepositoryInterface::class, ApiPermissionRepository::class);
4248
$this->app->bind(DatabaseHostInterface::class, DatabaseHostRepository::class);
4349
$this->app->bind(LocationRepositoryInterface::class, LocationRepository::class);
4450
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/*
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Repositories\Eloquent;
26+
27+
use Pterodactyl\Models\APIKey;
28+
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
29+
30+
class ApiKeyRepository extends EloquentRepository implements ApiKeyRepositoryInterface
31+
{
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function model()
36+
{
37+
return APIKey::class;
38+
}
39+
}

0 commit comments

Comments
 (0)