Skip to content

Commit 940b18f

Browse files
committed
Merge branch '8.x'
# Conflicts: # src/Illuminate/Database/Query/Builder.php
2 parents 4a57b48 + 1f70040 commit 940b18f

File tree

11 files changed

+448
-145
lines changed

11 files changed

+448
-145
lines changed

src/Illuminate/Auth/Access/Gate.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Auth\Access;
44

5+
use Closure;
56
use Exception;
67
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
78
use Illuminate\Contracts\Container\Container;
@@ -117,6 +118,64 @@ public function has($ability)
117118
return true;
118119
}
119120

121+
/**
122+
* Perform an on-demand authorization check. Throw an authorization exception if the condition or callback is false.
123+
*
124+
* @param \Illuminate\Auth\Access\Response|\Closure|bool $condition
125+
* @param string|null $message
126+
* @param string|null $code
127+
* @return \Illuminate\Auth\Access\Response
128+
*
129+
* @throws \Illuminate\Auth\Access\AuthorizationException
130+
*/
131+
public function allowIf($condition, $message = null, $code = null)
132+
{
133+
return $this->authorizeOnDemand($condition, $message, $code, true);
134+
}
135+
136+
/**
137+
* Perform an on-demand authorization check. Throw an authorization exception if the condition or callback is true.
138+
*
139+
* @param \Illuminate\Auth\Access\Response|\Closure|bool $condition
140+
* @param string|null $message
141+
* @param string|null $code
142+
* @return \Illuminate\Auth\Access\Response
143+
*
144+
* @throws \Illuminate\Auth\Access\AuthorizationException
145+
*/
146+
public function denyIf($condition, $message = null, $code = null)
147+
{
148+
return $this->authorizeOnDemand($condition, $message, $code, false);
149+
}
150+
151+
/**
152+
* Authorize a given condition or callback.
153+
*
154+
* @param \Illuminate\Auth\Access\Response|\Closure|bool $condition
155+
* @param string|null $message
156+
* @param string|null $code
157+
* @param bool $allowWhenResponseIs
158+
* @return \Illuminate\Auth\Access\Response
159+
*
160+
* @throws \Illuminate\Auth\Access\AuthorizationException
161+
*/
162+
protected function authorizeOnDemand($condition, $message, $code, $allowWhenResponseIs)
163+
{
164+
$user = $this->resolveUser();
165+
166+
if ($condition instanceof Closure) {
167+
$response = $this->canBeCalledWithUser($user, $condition)
168+
? $condition($user)
169+
: new Response(false, $message, $code);
170+
} else {
171+
$response = $condition;
172+
}
173+
174+
return with($response instanceof Response ? $response : new Response(
175+
(bool) $response === $allowWhenResponseIs, $message, $code
176+
))->authorize();
177+
}
178+
120179
/**
121180
* Define a new ability.
122181
*

src/Illuminate/Database/Eloquent/Concerns/GuardsAttributes.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ public function isGuarded($key)
217217
protected function isGuardableColumn($key)
218218
{
219219
if (! isset(static::$guardableColumns[get_class($this)])) {
220-
static::$guardableColumns[get_class($this)] = $this->getConnection()
220+
$columns = $this->getConnection()
221221
->getSchemaBuilder()
222222
->getColumnListing($this->getTable());
223+
224+
if (empty($columns)) {
225+
return true;
226+
}
227+
static::$guardableColumns[get_class($this)] = $columns;
223228
}
224229

225230
return in_array($key, static::$guardableColumns[get_class($this)]);

src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,21 @@ public function compileSelect(Builder $query)
3131
return parent::compileSelect($query);
3232
}
3333

34-
// If an offset is present on the query, we will need to wrap the query in
35-
// a big "ANSI" offset syntax block. This is very nasty compared to the
36-
// other database systems but is necessary for implementing features.
3734
if (is_null($query->columns)) {
3835
$query->columns = ['*'];
3936
}
4037

38+
$components = $this->compileComponents($query);
39+
40+
if (! empty($components['orders'])) {
41+
return parent::compileSelect($query)." offset {$query->offset} rows fetch next {$query->limit} rows only";
42+
}
43+
44+
// If an offset is present on the query, we will need to wrap the query in
45+
// a big "ANSI" offset syntax block. This is very nasty compared to the
46+
// other database systems but is necessary for implementing features.
4147
return $this->compileAnsiOffset(
42-
$query, $this->compileComponents($query)
48+
$query, $components
4349
);
4450
}
4551

src/Illuminate/Support/Facades/Auth.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @method static \Illuminate\Contracts\Auth\UserProvider|null createUserProvider(string $provider = null)
1515
* @method static \Symfony\Component\HttpFoundation\Response|null onceBasic(string $field = 'email',array $extraConditions = [])
1616
* @method static bool attempt(array $credentials = [], bool $remember = false)
17+
* @method static bool hasUser()
1718
* @method static bool check()
1819
* @method static bool guest()
1920
* @method static bool once(array $credentials = [])

src/Illuminate/Support/Facades/Gate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @method static \Illuminate\Auth\Access\Gate guessPolicyNamesUsing(callable $callback)
99
* @method static \Illuminate\Auth\Access\Response authorize(string $ability, array|mixed $arguments = [])
1010
* @method static \Illuminate\Auth\Access\Response inspect(string $ability, array|mixed $arguments = [])
11+
* @method static \Illuminate\Auth\Access\Response allowIf(\Closure|bool $condition, string|null $message = null, mixed $code = null)
12+
* @method static \Illuminate\Auth\Access\Response denyIf(\Closure|bool $condition, string|null $message = null, mixed $code = null)
1113
* @method static \Illuminate\Contracts\Auth\Access\Gate after(callable $callback)
1214
* @method static \Illuminate\Contracts\Auth\Access\Gate before(callable $callback)
1315
* @method static \Illuminate\Contracts\Auth\Access\Gate define(string $ability, callable|string $callback)

0 commit comments

Comments
 (0)