Skip to content

Commit 60eb600

Browse files
committed
Update repository base code to be cleaner and make use of PHP 7 features
1 parent 0ec5a4e commit 60eb600

File tree

96 files changed

+1043
-1780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1043
-1780
lines changed

app/Console/Commands/User/DeleteUserCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function handle()
6161
$search = $this->option('user') ?? $this->ask(trans('command/messages.user.search_users'));
6262
Assert::notEmpty($search, 'Search term must be a non-null value, received %s.');
6363

64-
$results = $this->repository->search($search)->all();
64+
$results = $this->repository->setSearchTerm($search)->all();
6565
if (count($results) < 1) {
6666
$this->error(trans('command/messages.user.no_users_found'));
6767
if ($this->input->isInteractive()) {

app/Console/Commands/User/DisableTwoFactorCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function handle()
5454
}
5555

5656
$email = $this->option('email') ?? $this->ask(trans('command/messages.user.ask_email'));
57-
$user = $this->repository->withColumns(['id', 'email'])->findFirstWhere([['email', '=', $email]]);
57+
$user = $this->repository->setColumns(['id', 'email'])->findFirstWhere([['email', '=', $email]]);
5858

5959
$this->repository->withoutFresh()->update($user->id, [
6060
'use_totp' => false,
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository;
114

5+
use Illuminate\Support\Collection;
6+
127
interface AllocationRepositoryInterface extends RepositoryInterface
138
{
149
/**
@@ -18,13 +13,13 @@ interface AllocationRepositoryInterface extends RepositoryInterface
1813
* @param array $ids
1914
* @return int
2015
*/
21-
public function assignAllocationsToServer($server, array $ids);
16+
public function assignAllocationsToServer(int $server = null, array $ids): int;
2217

2318
/**
2419
* Return all of the allocations for a specific node.
2520
*
2621
* @param int $node
27-
* @return \Illuminate\Database\Eloquent\Collection
22+
* @return \Illuminate\Support\Collection
2823
*/
29-
public function getAllocationsForNode($node);
24+
public function getAllocationsForNode(int $node): Collection;
3025
}
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository\Attributes;
114

125
interface SearchableInterface
136
{
147
/**
15-
* Filter results by search term.
8+
* Set the search term.
169
*
17-
* @param string $term
10+
* @param string|null $term
1811
* @return $this
12+
* @deprecated
1913
*/
2014
public function search($term);
15+
16+
/**
17+
* Set the search term to use when requesting all records from
18+
* the model.
19+
*
20+
* @param string|null $term
21+
* @return $this
22+
*/
23+
public function setSearchTerm(string $term = null);
24+
25+
/**
26+
* Determine if a valid search term is set on this repository.
27+
*
28+
* @return bool
29+
*/
30+
public function hasSearchTerm(): bool;
31+
32+
/**
33+
* Return the search term.
34+
*
35+
* @return string|null
36+
*/
37+
public function getSearchTerm();
2138
}

app/Contracts/Repository/DaemonKeyRepositoryInterface.php

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
11
<?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-
*/
242

253
namespace Pterodactyl\Contracts\Repository;
264

@@ -44,14 +22,6 @@ interface DaemonKeyRepositoryInterface extends RepositoryInterface
4422
*/
4523
public function loadServerAndUserRelations(DaemonKey $key, bool $refresh = false): DaemonKey;
4624

47-
/**
48-
* Gets the daemon keys associated with a specific server.
49-
*
50-
* @param int $server
51-
* @return \Illuminate\Support\Collection
52-
*/
53-
public function getServerKeys($server);
54-
5525
/**
5626
* Return a daemon key with the associated server relation attached.
5727
*
@@ -60,7 +30,7 @@ public function getServerKeys($server);
6030
*
6131
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
6232
*/
63-
public function getKeyWithServer($key);
33+
public function getKeyWithServer(string $key): DaemonKey;
6434

6535
/**
6636
* Get all of the keys for a specific user including the information needed
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository;
114

5+
use Illuminate\Support\Collection;
6+
use Pterodactyl\Models\DatabaseHost;
7+
128
interface DatabaseHostRepositoryInterface extends RepositoryInterface
139
{
1410
/**
15-
* Return database hosts with a count of databases and the node information for which it is attached.
11+
* Return database hosts with a count of databases and the node
12+
* information for which it is attached.
1613
*
1714
* @return \Illuminate\Support\Collection
1815
*/
19-
public function getWithViewDetails();
16+
public function getWithViewDetails(): Collection;
2017

2118
/**
22-
* Return a database host with the databases and associated servers that are attached to said databases.
19+
* Return a database host with the databases and associated servers
20+
* that are attached to said databases.
2321
*
2422
* @param int $id
25-
* @return mixed
23+
* @return \Pterodactyl\Models\DatabaseHost
2624
*
2725
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
2826
*/
29-
public function getWithServers($id);
27+
public function getWithServers(int $id): DatabaseHost;
3028
}

app/Contracts/Repository/DatabaseRepositoryInterface.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Pterodactyl\Contracts\Repository;
1111

12+
use Pterodactyl\Models\Database;
1213
use Illuminate\Support\Collection;
1314

1415
interface DatabaseRepositoryInterface extends RepositoryInterface
@@ -43,20 +44,20 @@ public function getDatabasesForServer(int $server): Collection;
4344
* the provided details.
4445
*
4546
* @param array $data
46-
* @return mixed
47+
* @return \Pterodactyl\Models\Database
4748
*
48-
* @throws \Pterodactyl\Exceptions\DisplayException
4949
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
50+
* @throws \Pterodactyl\Exceptions\Repository\DuplicateDatabaseNameException
5051
*/
51-
public function createIfNotExists(array $data);
52+
public function createIfNotExists(array $data): Database;
5253

5354
/**
5455
* Create a new database on a given connection.
5556
*
5657
* @param string $database
5758
* @return bool
5859
*/
59-
public function createDatabase($database);
60+
public function createDatabase(string $database): bool;
6061

6162
/**
6263
* Create a new database user on a given connection.
@@ -66,7 +67,7 @@ public function createDatabase($database);
6667
* @param string $password
6768
* @return bool
6869
*/
69-
public function createUser($username, $remote, $password);
70+
public function createUser(string $username, string $remote, string $password): bool;
7071

7172
/**
7273
* Give a specific user access to a given database.
@@ -76,22 +77,22 @@ public function createUser($username, $remote, $password);
7677
* @param string $remote
7778
* @return bool
7879
*/
79-
public function assignUserToDatabase($database, $username, $remote);
80+
public function assignUserToDatabase(string $database, string $username, string $remote): bool;
8081

8182
/**
8283
* Flush the privileges for a given connection.
8384
*
84-
* @return mixed
85+
* @return bool
8586
*/
86-
public function flush();
87+
public function flush(): bool;
8788

8889
/**
8990
* Drop a given database on a specific connection.
9091
*
9192
* @param string $database
9293
* @return bool
9394
*/
94-
public function dropDatabase($database);
95+
public function dropDatabase(string $database): bool;
9596

9697
/**
9798
* Drop a given user on a specific connection.
@@ -100,5 +101,5 @@ public function dropDatabase($database);
100101
* @param string $remote
101102
* @return mixed
102103
*/
103-
public function dropUser($username, $remote);
104+
public function dropUser(string $username, string $remote): bool;
104105
}
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Contracts\Repository;
114

5+
use Pterodactyl\Models\Location;
6+
use Illuminate\Support\Collection;
127
use Pterodactyl\Contracts\Repository\Attributes\SearchableInterface;
138

149
interface LocationRepositoryInterface extends RepositoryInterface, SearchableInterface
1510
{
1611
/**
1712
* Return locations with a count of nodes and servers attached to it.
1813
*
19-
* @return mixed
14+
* @return \Illuminate\Support\Collection
2015
*/
21-
public function getAllWithDetails();
16+
public function getAllWithDetails(): Collection;
2217

2318
/**
2419
* Return all of the available locations with the nodes as a relationship.
2520
*
2621
* @return \Illuminate\Support\Collection
2722
*/
28-
public function getAllWithNodes();
23+
public function getAllWithNodes(): Collection;
2924

3025
/**
3126
* Return all of the nodes and their respective count of servers for a location.
@@ -35,7 +30,7 @@ public function getAllWithNodes();
3530
*
3631
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
3732
*/
38-
public function getWithNodes($id);
33+
public function getWithNodes(int $id): Location;
3934

4035
/**
4136
* Return a location and the count of nodes in that location.
@@ -45,5 +40,5 @@ public function getWithNodes($id);
4540
*
4641
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
4742
*/
48-
public function getWithNodeCount($id);
43+
public function getWithNodeCount(int $id): Location;
4944
}

0 commit comments

Comments
 (0)