Skip to content

Commit b31d6ac

Browse files
authored
Merge pull request #937 from userfrosting/develop-4.3-jordan
PHP 7.1 Optimisations
2 parents fc00e07 + f431f56 commit b31d6ac

19 files changed

Lines changed: 69 additions & 73 deletions

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ services:
99
- redis-server
1010

1111
php:
12-
- 5.6
13-
- 7
1412
- 7.1
1513
- 7.2
1614
- 7.3

app/sprinkles/account/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
],
1414
"require": {
1515
"birke/rememberme" : "^2.0",
16-
"nikic/php-parser" : "^1",
17-
"php": ">=5.6"
16+
"nikic/php-parser" : "^1"
1817
},
1918
"autoload": {
2019
"psr-4": {

app/sprinkles/account/src/Account/Registration.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function register()
9191
$this->validate();
9292

9393
// Set default group
94-
$defaultGroup = $this->ci->classMapper->staticMethod('group', 'where', 'slug', $this->defaultGroup)->first();
94+
$defaultGroup = $this->ci->classMapper->getClassMapping('group')::where('slug', $this->defaultGroup)->first();
9595

9696
if (!$defaultGroup) {
9797
$e = new HttpException("Account registration is not working because the default group '{$this->defaultGroup}' does not exist.");
@@ -127,7 +127,7 @@ public function register()
127127
]);
128128

129129
// Load default roles
130-
$defaultRoles = $this->ci->classMapper->staticMethod('role', 'whereIn', 'slug', $this->defaultRoles)->get();
130+
$defaultRoles = $this->ci->classMapper->getClassMapping('role')::whereIn('slug', $this->defaultRoles)->get();
131131
$defaultRoleIds = $defaultRoles->pluck('id')->all();
132132

133133
// Attach default roles
@@ -195,7 +195,7 @@ public function validate()
195195
*/
196196
public function usernameIsUnique($username)
197197
{
198-
return !($this->ci->classMapper->staticMethod('user', 'findUnique', $username, 'user_name'));
198+
return !($this->ci->classMapper->getClassMapping('user')::findUnique($username, 'user_name'));
199199
}
200200

201201
/**
@@ -208,7 +208,7 @@ public function usernameIsUnique($username)
208208
*/
209209
public function emailIsUnique($email)
210210
{
211-
return !($this->ci->classMapper->staticMethod('user', 'findUnique', $email, 'email'));
211+
return !($this->ci->classMapper->getClassMapping('user')::findUnique($email, 'email'));
212212
}
213213

214214
/**
@@ -227,7 +227,7 @@ protected function setDefaults()
227227
$this->verified = $this->ci->config['site.registration.require_email_verification'];
228228
$this->requireEmailVerification = $this->ci->config['site.registration.require_email_verification'];
229229
$this->defaultGroup = $this->ci->config['site.registration.user_defaults.group'];
230-
$this->defaultRoles = $this->ci->classMapper->staticMethod('role', 'getDefaultSlugs');
230+
$this->defaultRoles = $this->ci->classMapper->getClassMapping('role')::getDefaultSlugs();
231231
}
232232

233233
/**

app/sprinkles/account/src/Authenticate/Authenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function __construct(ClassMapper $classMapper, Session $session, Config $
145145
public function attempt($identityColumn, $identityValue, $password, $rememberMe = false)
146146
{
147147
// Try to load the user, using the specified conditions
148-
$user = $this->classMapper->staticMethod('user', 'where', $identityColumn, $identityValue)->first();
148+
$user = $this->classMapper->getClassMapping('user')::where($identityColumn, $identityValue)->first();
149149

150150
if (!$user) {
151151
throw new InvalidCredentialsException();
@@ -257,7 +257,7 @@ public function logout($complete = false)
257257

258258
// User logout actions
259259
if ($currentUserId) {
260-
$currentUser = $this->classMapper->staticMethod('user', 'find', $currentUserId);
260+
$currentUser = $this->classMapper->getClassMapping('user')::find($currentUserId);
261261
if ($currentUser) {
262262
$currentUser->onLogout();
263263
}
@@ -425,7 +425,7 @@ protected function validateUserAccount($userId)
425425
// Load user from db, cache the result
426426
$key = $this->config['cache.user.key'] . $userId;
427427
$user = $this->cache->remember($key, $this->config['cache.user.delay'], function () use ($userId) {
428-
return $this->classMapper->staticMethod('user', 'find', (int) $userId);
428+
return $this->classMapper->getClassMapping('user')::find((int) $userId);
429429
});
430430

431431
// If the user doesn't exist any more, throw an exception.

app/sprinkles/account/src/Controller/AccountController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function checkUsername(Request $request, Response $response, $args)
103103
// Log throttleable event
104104
$throttler->logEvent('check_username_request');
105105

106-
if ($classMapper->staticMethod('user', 'findUnique', $data['user_name'], 'user_name')) {
106+
if ($classMapper->getClassMapping('user')::findUnique($data['user_name'], 'user_name')) {
107107
$message = $translator->translate('USERNAME.NOT_AVAILABLE', $data);
108108

109109
return $response->write($message)->withStatus(200);
@@ -245,7 +245,7 @@ public function forgotPassword(Request $request, Response $response, $args)
245245
$throttler->logEvent('password_reset_request', $throttleData);
246246

247247
// Load the user, by email address
248-
$user = $classMapper->staticMethod('user', 'where', 'email', $data['email'])->first();
248+
$user = $classMapper->getClassMapping('user')::where('email', $data['email'])->first();
249249

250250
// Check that the email exists.
251251
// If there is no user with that email address, we should still pretend like we succeeded, to prevent account enumeration
@@ -894,7 +894,7 @@ public function register(Request $request, Response $response, $args)
894894
}
895895

896896
// Security measure: do not allow registering new users until the master account has been created.
897-
if (!$classMapper->staticMethod('user', 'find', $config['reserved_user_ids.master'])) {
897+
if (!$classMapper->getClassMapping('user')::find($config['reserved_user_ids.master'])) {
898898
$ms->addMessageTranslated('danger', 'ACCOUNT.MASTER_NOT_EXISTS');
899899

900900
return $response->withJson([], 403);
@@ -1054,7 +1054,7 @@ public function resendVerification(Request $request, Response $response, $args)
10541054
$throttler->logEvent('verification_request', $throttleData);
10551055

10561056
// Load the user, by email address
1057-
$user = $classMapper->staticMethod('user', 'where', 'email', $data['email'])->first();
1057+
$user = $classMapper->getClassMapping('user')::where('email', $data['email'])->first();
10581058

10591059
// Check that the user exists and is not already verified.
10601060
// If there is no user with that email address, or the user exists and is already verified,
@@ -1240,7 +1240,7 @@ public function settings(Request $request, Response $response, $args)
12401240
unset($data['passwordc']);
12411241

12421242
// If new email was submitted, check that the email address is not in use
1243-
if (isset($data['email']) && $data['email'] != $currentUser->email && $classMapper->staticMethod('user', 'findUnique', $data['email'], 'email')) {
1243+
if (isset($data['email']) && $data['email'] != $currentUser->email && $classMapper->getClassMapping('user')::findUnique($data['email'], 'email')) {
12441244
$ms->addMessageTranslated('danger', 'EMAIL.IN_USE', $data);
12451245
$error = true;
12461246
}

app/sprinkles/account/src/Database/Models/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ public function delete($hardDelete = false)
203203
// Remove all user tokens
204204
$this->activities()->delete();
205205
$this->passwordResets()->delete();
206-
$classMapper->staticMethod('verification', 'where', 'user_id', $this->id)->delete();
207-
$classMapper->staticMethod('persistence', 'where', 'user_id', $this->id)->delete();
206+
$classMapper->getClassMapping('verification')::where('user_id', $this->id)->delete();
207+
$classMapper->getClassMapping('persistence')::where('user_id', $this->id)->delete();
208208

209209
// Delete the user
210210
$result = $this->forceDelete();

app/sprinkles/account/src/Log/UserActivityDatabaseHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function write(array $record)
2828
$log->save();
2929

3030
if (isset($record['extra']['user_id'])) {
31-
$user = $this->classMapper->staticMethod('user', 'find', $record['extra']['user_id']);
31+
$user = $this->classMapper->getClassMapping('user')::find($record['extra']['user_id']);
3232
$user->lastActivity()->associate($log);
3333
$user->save();
3434
}

app/sprinkles/account/src/Repository/TokenRepository.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public function cancel($token)
6666
$hash = hash($this->algorithm, $token);
6767

6868
// Find an incomplete reset request for the specified hash
69-
$model = $this->classMapper
70-
->staticMethod($this->modelIdentifier, 'where', 'hash', $hash)
69+
$model = $this->classMapper->getClassMapping($this->modelIdentifier)
70+
::where('hash', $hash)
7171
->where('completed', false)
7272
->first();
7373

@@ -94,8 +94,8 @@ public function complete($token, $userParams = [])
9494
$hash = hash($this->algorithm, $token);
9595

9696
// Find an unexpired, incomplete token for the specified hash
97-
$model = $this->classMapper
98-
->staticMethod($this->modelIdentifier, 'where', 'hash', $hash)
97+
$model = $this->classMapper->getClassMapping($this->modelIdentifier)
98+
::where('hash', $hash)
9999
->where('completed', false)
100100
->where('expires_at', '>', Carbon::now())
101101
->first();
@@ -105,7 +105,7 @@ public function complete($token, $userParams = [])
105105
}
106106

107107
// Fetch user for this token
108-
$user = $this->classMapper->staticMethod('user', 'find', $model->user_id);
108+
$user = $this->classMapper->getClassMapping('user')::find($model->user_id);
109109

110110
if (is_null($user)) {
111111
return false;
@@ -170,8 +170,8 @@ public function create(UserInterface $user, $timeout)
170170
*/
171171
public function exists(UserInterface $user, $token = null)
172172
{
173-
$model = $this->classMapper
174-
->staticMethod($this->modelIdentifier, 'where', 'user_id', $user->id)
173+
$model = $this->classMapper->getClassMapping($this->modelIdentifier)
174+
::where('user_id', $user->id)
175175
->where('completed', false)
176176
->where('expires_at', '>', Carbon::now());
177177

@@ -193,8 +193,8 @@ public function exists(UserInterface $user, $token = null)
193193
*/
194194
protected function removeExisting(UserInterface $user)
195195
{
196-
return $this->classMapper
197-
->staticMethod($this->modelIdentifier, 'where', 'user_id', $user->id)
196+
return $this->classMapper->getClassMapping($this->modelIdentifier)
197+
::where('user_id', $user->id)
198198
->delete();
199199
}
200200

@@ -205,8 +205,8 @@ protected function removeExisting(UserInterface $user)
205205
*/
206206
public function removeExpired()
207207
{
208-
return $this->classMapper
209-
->staticMethod($this->modelIdentifier, 'where', 'completed', false)
208+
return $this->classMapper->getClassMapping($this->modelIdentifier)
209+
::where('completed', false)
210210
->where('expires_at', '<', Carbon::now())
211211
->delete();
212212
}
@@ -224,8 +224,8 @@ protected function generateRandomToken($gen = null)
224224
{
225225
do {
226226
$gen = md5(uniqid(mt_rand(), false));
227-
} while ($this->classMapper
228-
->staticMethod($this->modelIdentifier, 'where', 'hash', hash($this->algorithm, $gen))
227+
} while ($this->classMapper->getClassMapping($this->modelIdentifier)
228+
::where('hash', hash($this->algorithm, $gen))
229229
->first());
230230

231231
return $gen;

app/sprinkles/account/src/Util/Util.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static function randomUniqueUsername(ClassMapper $classMapper, $maxLength
3737
for ($m = 0; $m < 10; $m++) {
3838
// Generate a random phrase with $n adjectives
3939
$suggestion = CoreUtil::randomPhrase($n, $maxLength, $maxTries, '.');
40-
if (!$classMapper->staticMethod('user', 'where', 'user_name', $suggestion)->first()) {
40+
if (!$classMapper->getClassMapping('user')::where('user_name', $suggestion)->first()) {
4141
return $suggestion;
4242
}
4343
}

app/sprinkles/admin/composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
"homepage": "https://alexanderweissman.com"
1212
}
1313
],
14-
"require": {
15-
"php": ">=5.6"
16-
},
1714
"autoload": {
1815
"psr-4": {
1916
"UserFrosting\\Sprinkle\\Admin\\": "src/"

0 commit comments

Comments
 (0)