update to laravel 5.7 and try getting autologin saved

This commit is contained in:
Kode
2018-10-14 20:50:32 +01:00
parent c3da17befc
commit 6501aacb1b
2402 changed files with 79064 additions and 28971 deletions

View File

@@ -30,7 +30,7 @@ If you're not in the mood to read, [Laracasts](https://laracasts.com) contains o
## Contributing
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions).
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
## Code of Conduct
@@ -42,4 +42,4 @@ If you discover a security vulnerability within Laravel, please send an e-mail t
## License
The Laravel framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

View File

@@ -15,29 +15,30 @@
}
],
"require": {
"php": ">=7.0",
"php": "^7.1.3",
"ext-mbstring": "*",
"ext-openssl": "*",
"doctrine/inflector": "~1.1",
"erusev/parsedown": "~1.7",
"doctrine/inflector": "^1.1",
"dragonmantank/cron-expression": "^2.0",
"erusev/parsedown": "^1.7",
"league/flysystem": "^1.0.8",
"monolog/monolog": "~1.12",
"mtdowling/cron-expression": "~1.0",
"nesbot/carbon": "^1.24.1",
"psr/container": "~1.0",
"monolog/monolog": "^1.12",
"nesbot/carbon": "^1.26.3",
"opis/closure": "^3.1",
"psr/container": "^1.0",
"psr/simple-cache": "^1.0",
"ramsey/uuid": "~3.0",
"swiftmailer/swiftmailer": "~6.0",
"symfony/console": "~3.3",
"symfony/debug": "~3.3",
"symfony/finder": "~3.3",
"symfony/http-foundation": "~3.3",
"symfony/http-kernel": "~3.3",
"symfony/process": "~3.3",
"symfony/routing": "~3.3",
"symfony/var-dumper": "~3.3",
"tijsverkoyen/css-to-inline-styles": "~2.2",
"vlucas/phpdotenv": "~2.2"
"ramsey/uuid": "^3.7",
"swiftmailer/swiftmailer": "^6.0",
"symfony/console": "^4.1",
"symfony/debug": "^4.1",
"symfony/finder": "^4.1",
"symfony/http-foundation": "^4.1",
"symfony/http-kernel": "^4.1",
"symfony/process": "^4.1",
"symfony/routing": "^4.1",
"symfony/var-dumper": "^4.1",
"tijsverkoyen/css-to-inline-styles": "^2.2.1",
"vlucas/phpdotenv": "^2.2"
},
"replace": {
"illuminate/auth": "self.version",
@@ -67,20 +68,25 @@
"illuminate/support": "self.version",
"illuminate/translation": "self.version",
"illuminate/validation": "self.version",
"illuminate/view": "self.version",
"illuminate/view": "self.version"
},
"conflict": {
"tightenco/collect": "<5.5.33"
},
"require-dev": {
"aws/aws-sdk-php": "~3.0",
"doctrine/dbal": "~2.5",
"aws/aws-sdk-php": "^3.0",
"doctrine/dbal": "^2.6",
"filp/whoops": "^2.1.4",
"mockery/mockery": "~1.0",
"orchestra/testbench-core": "3.5.*",
"pda/pheanstalk": "~3.0",
"phpunit/phpunit": "~6.0",
"league/flysystem-cached-adapter": "^1.0",
"mockery/mockery": "^1.0",
"moontoast/math": "^1.1",
"orchestra/testbench-core": "3.7.*",
"pda/pheanstalk": "^3.0",
"phpunit/phpunit": "^7.0",
"predis/predis": "^1.1.1",
"symfony/css-selector": "~3.3",
"symfony/dom-crawler": "~3.3"
"symfony/css-selector": "^4.1",
"symfony/dom-crawler": "^4.1",
"true/punycode": "^2.1"
},
"autoload": {
"files": [
@@ -101,27 +107,29 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.5-dev"
"dev-master": "5.7-dev"
}
},
"suggest": {
"ext-pcntl": "Required to use all features of the queue worker.",
"ext-posix": "Required to use all features of the queue worker.",
"aws/aws-sdk-php": "Required to use the SQS queue driver and SES mail driver (~3.0).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.5).",
"fzaninotto/faker": "Required to use the eloquent factory builder (~1.4).",
"guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (~6.0).",
"laravel/tinker": "Required to use the tinker console command (~1.0).",
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (~1.0).",
"league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (~1.0).",
"league/flysystem-cached-adapter": "Required to use Flysystem caching (~1.0).",
"nexmo/client": "Required to use the Nexmo transport (~1.0).",
"pda/pheanstalk": "Required to use the beanstalk queue driver (~3.0).",
"predis/predis": "Required to use the redis cache and queue drivers (~1.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (~3.0).",
"symfony/css-selector": "Required to use some of the crawler integration testing tools (~3.3).",
"symfony/dom-crawler": "Required to use most of the crawler integration testing tools (~3.3).",
"symfony/psr-http-message-bridge": "Required to psr7 bridging features (~1.0)."
"aws/aws-sdk-php": "Required to use the SQS queue driver and SES mail driver (^3.0).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).",
"fzaninotto/faker": "Required to use the eloquent factory builder (^1.4).",
"guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (^6.0).",
"laravel/tinker": "Required to use the tinker console command (^1.0).",
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
"league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).",
"league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (^1.0).",
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).",
"moontoast/math": "Required to use ordered UUIDs (^1.1).",
"nexmo/client": "Required to use the Nexmo transport (^1.0).",
"pda/pheanstalk": "Required to use the beanstalk queue driver (^3.0).",
"predis/predis": "Required to use the redis cache and queue drivers (^1.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^3.0).",
"symfony/css-selector": "Required to use some of the crawler integration testing tools (^4.1).",
"symfony/dom-crawler": "Required to use most of the crawler integration testing tools (^4.1).",
"symfony/psr-http-message-bridge": "Required to psr7 bridging features (^1.0)."
},
"config": {
"sort-packages": true

View File

@@ -2,6 +2,9 @@
namespace Illuminate\Auth\Access;
use Exception;
use ReflectionClass;
use ReflectionFunction;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use InvalidArgumentException;
@@ -108,7 +111,7 @@ class Gate implements GateContract
{
if (is_callable($callback)) {
$this->abilities[$ability] = $callback;
} elseif (is_string($callback) && Str::contains($callback, '@')) {
} elseif (is_string($callback)) {
$this->abilities[$ability] = $this->buildAbilityCallback($ability, $callback);
} else {
throw new InvalidArgumentException("Callback must be a callable or a 'Class@method' string.");
@@ -122,7 +125,7 @@ class Gate implements GateContract
*
* @param string $name
* @param string $class
* @param array $abilities
* @param array|null $abilities
* @return $this
*/
public function resource($name, $class, array $abilities = null)
@@ -151,7 +154,11 @@ class Gate implements GateContract
protected function buildAbilityCallback($ability, $callback)
{
return function () use ($ability, $callback) {
list($class, $method) = Str::parseCallback($callback);
if (Str::contains($callback, '@')) {
[$class, $method] = Str::parseCallback($callback);
} else {
$class = $callback;
}
$policy = $this->resolvePolicy($class);
@@ -167,7 +174,9 @@ class Gate implements GateContract
return $result;
}
return $policy->{$method}(...func_get_args());
return isset($method)
? $policy->{$method}(...func_get_args())
: $policy(...func_get_args());
};
}
@@ -294,14 +303,12 @@ class Gate implements GateContract
* @param array|mixed $arguments
* @return mixed
*/
protected function raw($ability, $arguments = [])
public function raw($ability, $arguments = [])
{
if (! $user = $this->resolveUser()) {
return false;
}
$arguments = Arr::wrap($arguments);
$user = $this->resolveUser();
// First we will call the "before" callbacks for the Gate. If any of these give
// back a non-null response, we will immediately return that result in order
// to let the developers override all checks for some authorization cases.
@@ -316,17 +323,94 @@ class Gate implements GateContract
// After calling the authorization callback, we will call the "after" callbacks
// that are registered with the Gate, which allows a developer to do logging
// if that is required for this application. Then we'll return the result.
$this->callAfterCallbacks(
return $this->callAfterCallbacks(
$user, $ability, $arguments, $result
);
}
return $result;
/**
* Determine whether the callback/method can be called with the given user.
*
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @param \Closure|string|array $class
* @param string|null $method
* @return bool
*/
protected function canBeCalledWithUser($user, $class, $method = null)
{
if (! is_null($user)) {
return true;
}
if (! is_null($method)) {
return $this->methodAllowsGuests($class, $method);
}
if (is_array($class)) {
$className = is_string($class[0]) ? $class[0] : get_class($class[0]);
return $this->methodAllowsGuests($className, $class[1]);
}
return $this->callbackAllowsGuests($class);
}
/**
* Determine if the given class method allows guests.
*
* @param string $class
* @param string $method
* @return bool
*/
protected function methodAllowsGuests($class, $method)
{
try {
$reflection = new ReflectionClass($class);
$method = $reflection->getMethod($method);
} catch (Exception $e) {
return false;
}
if ($method) {
$parameters = $method->getParameters();
return isset($parameters[0]) && $this->parameterAllowsGuests($parameters[0]);
}
return false;
}
/**
* Determine if the callback allows guests.
*
* @param callable $callback
* @param array $arguments
* @return bool
*/
protected function callbackAllowsGuests($callback)
{
$parameters = (new ReflectionFunction($callback))->getParameters();
return isset($parameters[0]) && $this->parameterAllowsGuests($parameters[0]);
}
/**
* Determine if the given parameter allows guests.
*
* @param \ReflectionParameter $parameter
* @return bool
*/
protected function parameterAllowsGuests($parameter)
{
return ($parameter->getClass() && $parameter->allowsNull()) ||
($parameter->isDefaultValueAvailable() && is_null($parameter->getDefaultValue()));
}
/**
* Resolve and call the appropriate authorization callback.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @param string $ability
* @param array $arguments
* @return bool
@@ -341,7 +425,7 @@ class Gate implements GateContract
/**
* Call all of the before callbacks and return if a result is given.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @param string $ability
* @param array $arguments
* @return bool|null
@@ -351,6 +435,10 @@ class Gate implements GateContract
$arguments = array_merge([$user, $ability], [$arguments]);
foreach ($this->beforeCallbacks as $before) {
if (! $this->canBeCalledWithUser($user, $before)) {
continue;
}
if (! is_null($result = $before(...$arguments))) {
return $result;
}
@@ -368,17 +456,23 @@ class Gate implements GateContract
*/
protected function callAfterCallbacks($user, $ability, array $arguments, $result)
{
$arguments = array_merge([$user, $ability, $result], [$arguments]);
foreach ($this->afterCallbacks as $after) {
$after(...$arguments);
if (! $this->canBeCalledWithUser($user, $after)) {
continue;
}
$afterResult = $after($user, $ability, $result, $arguments);
$result = $result ?? $afterResult;
}
return $result;
}
/**
* Resolve the callable for the given ability and arguments.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @param string $ability
* @param array $arguments
* @return callable
@@ -391,12 +485,13 @@ class Gate implements GateContract
return $callback;
}
if (isset($this->abilities[$ability])) {
if (isset($this->abilities[$ability]) &&
$this->canBeCalledWithUser($user, $this->abilities[$ability])) {
return $this->abilities[$ability];
}
return function () {
return false;
return null;
};
}
@@ -468,18 +563,9 @@ class Gate implements GateContract
return $result;
}
$ability = $this->formatAbilityToMethod($ability);
$method = $this->formatAbilityToMethod($ability);
// If this first argument is a string, that means they are passing a class name
// to the policy. We will remove the first argument from this argument array
// because this policy already knows what type of models it can authorize.
if (isset($arguments[0]) && is_string($arguments[0])) {
array_shift($arguments);
}
return is_callable([$policy, $ability])
? $policy->{$ability}($user, ...$arguments)
: false;
return $this->callPolicyMethod($policy, $method, $user, $arguments);
};
}
@@ -494,11 +580,42 @@ class Gate implements GateContract
*/
protected function callPolicyBefore($policy, $user, $ability, $arguments)
{
if (method_exists($policy, 'before')) {
if (! method_exists($policy, 'before')) {
return null;
}
if ($this->canBeCalledWithUser($user, $policy, 'before')) {
return $policy->before($user, $ability, ...$arguments);
}
}
/**
* Call the appropriate method on the given policy.
*
* @param mixed $policy
* @param string $method
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @param array $arguments
* @return mixed
*/
protected function callPolicyMethod($policy, $method, $user, array $arguments)
{
// If this first argument is a string, that means they are passing a class name
// to the policy. We will remove the first argument from this argument array
// because this policy already knows what type of models it can authorize.
if (isset($arguments[0]) && is_string($arguments[0])) {
array_shift($arguments);
}
if (! is_callable([$policy, $method])) {
return null;
}
if ($this->canBeCalledWithUser($user, $policy, $method)) {
return $policy->{$method}($user, ...$arguments);
}
}
/**
* Format the policy ability into a method name.
*

View File

@@ -39,6 +39,6 @@ class Response
*/
public function __toString()
{
return $this->message();
return (string) $this->message();
}
}

View File

@@ -94,7 +94,7 @@ class AuthManager implements FactoryContract
return $this->{$driverMethod}($name, $config);
}
throw new InvalidArgumentException("Auth guard driver [{$name}] is not defined.");
throw new InvalidArgumentException("Auth driver [{$config['driver']}] for guard [{$name}] is not defined.");
}
/**

View File

@@ -13,18 +13,27 @@ class AuthenticationException extends Exception
*/
protected $guards;
/**
* The path the user should be redirected to.
*
* @var string
*/
protected $redirectTo;
/**
* Create a new authentication exception.
*
* @param string $message
* @param array $guards
* @param string|null $redirectTo
* @return void
*/
public function __construct($message = 'Unauthenticated.', array $guards = [])
public function __construct($message = 'Unauthenticated.', array $guards = [], $redirectTo = null)
{
parent::__construct($message);
$this->guards = $guards;
$this->redirectTo = $redirectTo;
}
/**
@@ -36,4 +45,14 @@ class AuthenticationException extends Exception
{
return $this->guards;
}
/**
* Get the path the user should be redirected to.
*
* @return string
*/
public function redirectTo()
{
return $this->redirectTo;
}
}

View File

@@ -33,6 +33,7 @@ class AuthMakeCommand extends Command
protected $views = [
'auth/login.stub' => 'auth/login.blade.php',
'auth/register.stub' => 'auth/register.blade.php',
'auth/verify.stub' => 'auth/verify.blade.php',
'auth/passwords/email.stub' => 'auth/passwords/email.blade.php',
'auth/passwords/reset.stub' => 'auth/passwords/reset.blade.php',
'layouts/app.stub' => 'layouts/app.blade.php',

View File

@@ -2,61 +2,63 @@
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Login</div>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Login') }}</div>
<div class="panel-body">
<form class="form-horizontal" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
@csrf
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="form-group row">
<label for="email" class="col-sm-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
<div class="form-group row">
<div class="col-md-6 offset-md-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
<label class="form-check-label" for="remember">
{{ __('Remember Me') }}
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
Login
{{ __('Login') }}
</button>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
{{ __('Forgot Your Password?') }}
</a>
</div>
</div>

View File

@@ -2,39 +2,39 @@
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Reset Password</div>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Reset Password') }}</div>
<div class="panel-body">
<div class="card-body">
@if (session('status'))
<div class="alert alert-success">
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
<form class="form-horizontal" method="POST" action="{{ route('password.email') }}">
{{ csrf_field() }}
<form method="POST" action="{{ route('password.email') }}">
@csrf
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required>
@if ($errors->has('email'))
<span class="help-block">
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Send Password Reset Link
{{ __('Send Password Reset Link') }}
</button>
</div>
</div>

View File

@@ -2,62 +2,57 @@
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Reset Password</div>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Reset Password') }}</div>
<div class="panel-body">
<form class="form-horizontal" method="POST" action="{{ route('password.request') }}">
{{ csrf_field() }}
<div class="card-body">
<form method="POST" action="{{ route('password.update') }}">
@csrf
<input type="hidden" name="token" value="{{ $token }}">
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ $email or old('email') }}" required autofocus>
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ $email ?? old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
@if ($errors->has('password_confirmation'))
<span class="help-block">
<strong>{{ $errors->first('password_confirmation') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Reset Password
{{ __('Reset Password') }}
</button>
</div>
</div>

View File

@@ -2,69 +2,69 @@
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="panel-body">
<form class="form-horizontal" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="card-body">
<form method="POST" action="{{ route('register') }}">
@csrf
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>
<input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name') }}" required autofocus>
@if ($errors->has('name'))
<span class="help-block">
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required>
@if ($errors->has('email'))
<span class="help-block">
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
Register
{{ __('Register') }}
</button>
</div>
</div>

View File

@@ -0,0 +1,24 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Verify Your Email Address') }}</div>
<div class="card-body">
@if (session('resent'))
<div class="alert alert-success" role="alert">
{{ __('A fresh verification link has been sent to your email address.') }}
</div>
@endif
{{ __('Before proceeding, please check your email for a verification link.') }}
{{ __('If you did not receive the email') }}, <a href="{{ route('verification.resend') }}">{{ __('click here to request another') }}</a>.
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@@ -2,14 +2,14 @@
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Dashboard</div>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Dashboard</div>
<div class="panel-body">
<div class="card-body">
@if (session('status'))
<div class="alert alert-success">
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif

View File

@@ -1,8 +1,7 @@
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
@@ -10,60 +9,62 @@
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<!-- Fonts -->
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
<div id="app">
<nav class="navbar navbar-default navbar-static-top">
<nav class="navbar navbar-expand-md navbar-light navbar-laravel">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="{{ url('/') }}">
{{ config('app.name', 'Laravel') }}
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Collapsed Hamburger -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse" aria-expanded="false">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Branding Image -->
<a class="navbar-brand" href="{{ url('/') }}">
{{ config('app.name', 'Laravel') }}
</a>
</div>
<div class="collapse navbar-collapse" id="app-navbar-collapse">
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<!-- Left Side Of Navbar -->
<ul class="nav navbar-nav">
&nbsp;
<ul class="navbar-nav mr-auto">
</ul>
<!-- Right Side Of Navbar -->
<ul class="nav navbar-nav navbar-right">
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
@guest
<li><a href="{{ route('login') }}">Login</a></li>
<li><a href="{{ route('register') }}">Register</a></li>
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
<li class="nav-item">
@if (Route::has('register'))
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
@endif
</li>
@else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" v-pre>
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
@csrf
</form>
</div>
</li>
@endguest
</ul>
@@ -71,10 +72,9 @@
</div>
</nav>
@yield('content')
<main class="py-4">
@yield('content')
</main>
</div>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}"></script>
</body>
</html>

View File

@@ -4,6 +4,7 @@ namespace Illuminate\Auth;
use Illuminate\Support\Str;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
@@ -110,7 +111,13 @@ class DatabaseUserProvider implements UserProvider
$query = $this->conn->table($this->table);
foreach ($credentials as $key => $value) {
if (! Str::contains($key, 'password')) {
if (Str::contains($key, 'password')) {
continue;
}
if (is_array($value) || $value instanceof Arrayable) {
$query->whereIn($key, $value);
} else {
$query->where($key, $value);
}
}

View File

@@ -4,6 +4,7 @@ namespace Illuminate\Auth;
use Illuminate\Support\Str;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
@@ -76,7 +77,7 @@ class EloquentUserProvider implements UserProvider
/**
* Update the "remember me" token for the given user in storage.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param \Illuminate\Contracts\Auth\Authenticatable|\Illuminate\Database\Eloquent\Model $user
* @param string $token
* @return void
*/
@@ -113,7 +114,13 @@ class EloquentUserProvider implements UserProvider
$query = $this->createModel()->newQuery();
foreach ($credentials as $key => $value) {
if (! Str::contains($key, 'password')) {
if (Str::contains($key, 'password')) {
continue;
}
if (is_array($value) || $value instanceof Arrayable) {
$query->whereIn($key, $value);
} else {
$query->where($key, $value);
}
}

View File

@@ -4,6 +4,13 @@ namespace Illuminate\Auth\Events;
class Attempting
{
/**
* The authentication guard name.
*
* @var string
*/
public $guard;
/**
* The credentials for the user.
*
@@ -21,12 +28,14 @@ class Attempting
/**
* Create a new event instance.
*
* @param string $guard
* @param array $credentials
* @param bool $remember
* @return void
*/
public function __construct($credentials, $remember)
public function __construct($guard, $credentials, $remember)
{
$this->guard = $guard;
$this->remember = $remember;
$this->credentials = $credentials;
}

View File

@@ -8,6 +8,13 @@ class Authenticated
{
use SerializesModels;
/**
* The authentication guard name.
*
* @var string
*/
public $guard;
/**
* The authenticated user.
*
@@ -18,11 +25,13 @@ class Authenticated
/**
* Create a new event instance.
*
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function __construct($user)
public function __construct($guard, $user)
{
$this->user = $user;
$this->guard = $guard;
}
}

View File

@@ -4,6 +4,13 @@ namespace Illuminate\Auth\Events;
class Failed
{
/**
* The authentication guard name.
*
* @var string
*/
public $guard;
/**
* The user the attempter was trying to authenticate as.
*
@@ -21,13 +28,15 @@ class Failed
/**
* Create a new event instance.
*
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @param array $credentials
* @return void
*/
public function __construct($user, $credentials)
public function __construct($guard, $user, $credentials)
{
$this->user = $user;
$this->guard = $guard;
$this->credentials = $credentials;
}
}

View File

@@ -8,6 +8,13 @@ class Login
{
use SerializesModels;
/**
* The authentication guard name.
*
* @var string
*/
public $guard;
/**
* The authenticated user.
*
@@ -25,13 +32,15 @@ class Login
/**
* Create a new event instance.
*
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param bool $remember
* @return void
*/
public function __construct($user, $remember)
public function __construct($guard, $user, $remember)
{
$this->user = $user;
$this->guard = $guard;
$this->remember = $remember;
}
}

View File

@@ -8,6 +8,13 @@ class Logout
{
use SerializesModels;
/**
* The authentication guard name.
*
* @var string
*/
public $guard;
/**
* The authenticated user.
*
@@ -18,11 +25,13 @@ class Logout
/**
* Create a new event instance.
*
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
public function __construct($user)
public function __construct($guard, $user)
{
$this->user = $user;
$this->guard = $guard;
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Illuminate\Auth\Events;
use Illuminate\Queue\SerializesModels;
class Verified
{
use SerializesModels;
/**
* The verified user.
*
* @var \Illuminate\Contracts\Auth\MustVerifyEmail
*/
public $user;
/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\MustVerifyEmail $user
* @return void
*/
public function __construct($user)
{
$this->user = $user;
}
}

View File

@@ -25,7 +25,7 @@ trait GuardHelpers
protected $provider;
/**
* Determine if the current user is authenticated.
* Determine if current user is authenticated. If not, throw an exception.
*
* @return \Illuminate\Contracts\Auth\Authenticatable
*
@@ -40,6 +40,16 @@ trait GuardHelpers
throw new AuthenticationException;
}
/**
* Determine if the guard has a user instance.
*
* @return bool
*/
public function hasUser()
{
return ! is_null($this->user);
}
/**
* Determine if the current user is authenticated.
*

View File

@@ -0,0 +1,22 @@
<?php
namespace Illuminate\Auth\Listeners;
use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\Auth\MustVerifyEmail;
class SendEmailVerificationNotification
{
/**
* Handle the event.
*
* @param \Illuminate\Auth\Events\Registered $event
* @return void
*/
public function handle(Registered $event)
{
if ($event->user instanceof MustVerifyEmail && ! $event->user->hasVerifiedEmail()) {
$event->user->sendEmailVerificationNotification();
}
}
}

View File

@@ -38,7 +38,7 @@ class Authenticate
*/
public function handle($request, Closure $next, ...$guards)
{
$this->authenticate($guards);
$this->authenticate($request, $guards);
return $next($request);
}
@@ -46,15 +46,16 @@ class Authenticate
/**
* Determine if the user is logged in to any of the given guards.
*
* @param \Illuminate\Http\Request $request
* @param array $guards
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
*/
protected function authenticate(array $guards)
protected function authenticate($request, array $guards)
{
if (empty($guards)) {
return $this->auth->authenticate();
$guards = [null];
}
foreach ($guards as $guard) {
@@ -63,6 +64,19 @@ class Authenticate
}
}
throw new AuthenticationException('Unauthenticated.', $guards);
throw new AuthenticationException(
'Unauthenticated.', $guards, $this->redirectTo($request)
);
}
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string
*/
protected function redirectTo($request)
{
//
}
}

View File

@@ -31,10 +31,11 @@ class AuthenticateWithBasicAuth
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @param string|null $field
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
public function handle($request, Closure $next, $guard = null, $field = null)
{
return $this->auth->guard($guard)->basic() ?: $next($request);
return $this->auth->guard($guard)->basic($field ?: 'email') ?: $next($request);
}
}

View File

@@ -5,17 +5,9 @@ namespace Illuminate\Auth\Middleware;
use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Contracts\Auth\Factory as Auth;
class Authorize
{
/**
* The authentication factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* The gate instance.
*
@@ -26,13 +18,11 @@ class Authorize
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
public function __construct(Auth $auth, Gate $gate)
public function __construct(Gate $gate)
{
$this->auth = $auth;
$this->gate = $gate;
}
@@ -42,7 +32,7 @@ class Authorize
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string $ability
* @param array|null $models
* @param array|null ...$models
* @return mixed
*
* @throws \Illuminate\Auth\AuthenticationException
@@ -50,8 +40,6 @@ class Authorize
*/
public function handle($request, Closure $next, $ability, ...$models)
{
$this->auth->authenticate();
$this->gate->authorize($ability, $this->getGateArguments($request, $models));
return $next($request);
@@ -84,7 +72,7 @@ class Authorize
*/
protected function getModel($request, $model)
{
return $this->isClassName($model) ? $model : $request->route($model);
return $this->isClassName($model) ? trim($model) : $request->route($model, $model);
}
/**

View File

@@ -0,0 +1,30 @@
<?php
namespace Illuminate\Auth\Middleware;
use Closure;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Contracts\Auth\MustVerifyEmail;
class EnsureEmailIsVerified
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle($request, Closure $next)
{
if (! $request->user() ||
($request->user() instanceof MustVerifyEmail &&
! $request->user()->hasVerifiedEmail())) {
return $request->expectsJson()
? abort(403, 'Your email address is not verified.')
: Redirect::route('verification.notice');
}
return $next($request);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Illuminate\Auth;
trait MustVerifyEmail
{
/**
* Determine if the user has verified their email address.
*
* @return bool
*/
public function hasVerifiedEmail()
{
return ! is_null($this->email_verified_at);
}
/**
* Mark the given user's email as verified.
*
* @return bool
*/
public function markEmailAsVerified()
{
return $this->forceFill([
'email_verified_at' => $this->freshTimestamp(),
])->save();
}
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification()
{
$this->notify(new Notifications\VerifyEmail);
}
}

View File

@@ -2,6 +2,7 @@
namespace Illuminate\Auth\Notifications;
use Illuminate\Support\Facades\Lang;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
@@ -14,6 +15,13 @@ class ResetPassword extends Notification
*/
public $token;
/**
* The callback that should be used to build the mail message.
*
* @var \Closure|null
*/
public static $toMailCallback;
/**
* Create a notification instance.
*
@@ -44,9 +52,25 @@ class ResetPassword extends Notification
*/
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
}
return (new MailMessage)
->line('You are receiving this email because we received a password reset request for your account.')
->action('Reset Password', url(config('app.url').route('password.reset', $this->token, false)))
->line('If you did not request a password reset, no further action is required.');
->subject(Lang::getFromJson('Reset Password Notification'))
->line(Lang::getFromJson('You are receiving this email because we received a password reset request for your account.'))
->action(Lang::getFromJson('Reset Password'), url(config('app.url').route('password.reset', $this->token, false)))
->line(Lang::getFromJson('If you did not request a password reset, no further action is required.'));
}
/**
* Set a callback that should be used when building the notification mail message.
*
* @param \Closure $callback
* @return void
*/
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Illuminate\Auth\Notifications;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Lang;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
class VerifyEmail extends Notification
{
/**
* The callback that should be used to build the mail message.
*
* @var \Closure|null
*/
public static $toMailCallback;
/**
* Get the notification's channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable);
}
return (new MailMessage)
->subject(Lang::getFromJson('Verify Email Address'))
->line(Lang::getFromJson('Please click the button below to verify your email address.'))
->action(
Lang::getFromJson('Verify Email Address'),
$this->verificationUrl($notifiable)
)
->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
}
/**
* Get the verification URL for the given notifiable.
*
* @param mixed $notifiable
* @return string
*/
protected function verificationUrl($notifiable)
{
return URL::temporarySignedRoute(
'verification.verify', Carbon::now()->addMinutes(60), ['id' => $notifiable->getKey()]
);
}
/**
* Set a callback that should be used when building the notification mail message.
*
* @param \Closure $callback
* @return void
*/
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
}
}

View File

@@ -146,7 +146,7 @@ class PasswordBroker implements PasswordBrokerContract
public function validateNewPassword(array $credentials)
{
if (isset($this->passwordValidator)) {
list($password, $confirm) = [
[$password, $confirm] = [
$credentials['password'],
$credentials['password_confirmation'],
];
@@ -167,7 +167,7 @@ class PasswordBroker implements PasswordBrokerContract
*/
protected function validatePasswordWithDefaults(array $credentials)
{
list($password, $confirm) = [
[$password, $confirm] = [
$credentials['password'],
$credentials['password_confirmation'],
];

View File

@@ -39,7 +39,7 @@ class PasswordBrokerManager implements FactoryContract
/**
* Attempt to get the broker from the local cache.
*
* @param string $name
* @param string|null $name
* @return \Illuminate\Contracts\Auth\PasswordBroker
*/
public function broker($name = null)

View File

@@ -21,7 +21,7 @@ class Recaller
*/
public function __construct($recaller)
{
$this->recaller = $recaller;
$this->recaller = @unserialize($recaller, ['allowed_classes' => false]) ?: $recaller;
}
/**

View File

@@ -4,6 +4,7 @@ namespace Illuminate\Auth;
use RuntimeException;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Session\Session;
use Illuminate\Contracts\Auth\UserProvider;
@@ -90,7 +91,7 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
* @param string $name
* @param \Illuminate\Contracts\Auth\UserProvider $provider
* @param \Illuminate\Contracts\Session\Session $session
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Symfony\Component\HttpFoundation\Request|null $request
* @return void
*/
public function __construct($name,
@@ -127,10 +128,8 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
// First we will try to load the user using the identifier in the session if
// one exists. Otherwise we will check for a "remember me" cookie in this
// request, and if one exists, attempt to retrieve the user using that.
if (! is_null($id)) {
if ($this->user = $this->provider->retrieveById($id)) {
$this->fireAuthenticatedEvent($this->user);
}
if (! is_null($id) && $this->user = $this->provider->retrieveById($id)) {
$this->fireAuthenticatedEvent($this->user);
}
// If the user is null, but we decrypt a "recaller" cookie we can attempt to
@@ -330,6 +329,7 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
* Get the response for basic authentication.
*
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
*/
protected function failedBasicResponse()
@@ -494,7 +494,7 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
}
if (isset($this->events)) {
$this->events->dispatch(new Events\Logout($user));
$this->events->dispatch(new Events\Logout($this->name, $user));
}
// Once we have fired the logout event we will clear the users out of memory
@@ -533,6 +533,30 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
$this->provider->updateRememberToken($user, $token);
}
/**
* Invalidate other sessions for the current user.
*
* The application must be using the AuthenticateSession middleware.
*
* @param string $password
* @param string $attribute
* @return bool|null
*/
public function logoutOtherDevices($password, $attribute = 'password')
{
if (! $this->user()) {
return;
}
$result = tap($this->user()->forceFill([
$attribute => Hash::make($password),
]))->save();
$this->queueRecallerCookie($this->user());
return $result;
}
/**
* Register an authentication attempt event listener.
*
@@ -557,7 +581,7 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
{
if (isset($this->events)) {
$this->events->dispatch(new Events\Attempting(
$credentials, $remember
$this->name, $credentials, $remember
));
}
}
@@ -572,7 +596,9 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
protected function fireLoginEvent($user, $remember = false)
{
if (isset($this->events)) {
$this->events->dispatch(new Events\Login($user, $remember));
$this->events->dispatch(new Events\Login(
$this->name, $user, $remember
));
}
}
@@ -585,7 +611,9 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
protected function fireAuthenticatedEvent($user)
{
if (isset($this->events)) {
$this->events->dispatch(new Events\Authenticated($user));
$this->events->dispatch(new Events\Authenticated(
$this->name, $user
));
}
}
@@ -599,7 +627,9 @@ class SessionGuard implements StatefulGuard, SupportsBasicAuth
protected function fireFailedEvent($user, array $credentials)
{
if (isset($this->events)) {
$this->events->dispatch(new Events\Failed($user, $credentials));
$this->events->dispatch(new Events\Failed(
$this->name, $user, $credentials
));
}
}

View File

@@ -36,14 +36,16 @@ class TokenGuard implements Guard
*
* @param \Illuminate\Contracts\Auth\UserProvider $provider
* @param \Illuminate\Http\Request $request
* @param string $inputKey
* @param string $storageKey
* @return void
*/
public function __construct(UserProvider $provider, Request $request)
public function __construct(UserProvider $provider, Request $request, $inputKey = 'api_token', $storageKey = 'api_token')
{
$this->request = $request;
$this->provider = $provider;
$this->inputKey = 'api_token';
$this->storageKey = 'api_token';
$this->inputKey = $inputKey;
$this->storageKey = $storageKey;
}
/**

View File

@@ -14,11 +14,11 @@
}
],
"require": {
"php": ">=7.0",
"illuminate/contracts": "5.5.*",
"illuminate/http": "5.5.*",
"illuminate/queue": "5.5.*",
"illuminate/support": "5.5.*"
"php": "^7.1.3",
"illuminate/contracts": "5.7.*",
"illuminate/http": "5.7.*",
"illuminate/queue": "5.7.*",
"illuminate/support": "5.7.*"
},
"autoload": {
"psr-4": {
@@ -27,13 +27,13 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.5-dev"
"dev-master": "5.7-dev"
}
},
"suggest": {
"illuminate/console": "Required to use the auth:clear-resets command (5.5.*).",
"illuminate/queue": "Required to fire login / logout events (5.5.*).",
"illuminate/session": "Required to use the session based guard (5.5.*)."
"illuminate/console": "Required to use the auth:clear-resets command (5.7.*).",
"illuminate/queue": "Required to fire login / logout events (5.7.*).",
"illuminate/session": "Required to use the session based guard (5.7.*)."
},
"config": {
"sort-packages": true

View File

@@ -65,7 +65,10 @@ class BroadcastManager implements FactoryContract
$attributes = $attributes ?: ['middleware' => ['web']];
$this->app['router']->group($attributes, function ($router) {
$router->post('/broadcasting/auth', '\\'.BroadcastController::class.'@authenticate');
$router->match(
['get', 'post'], '/broadcasting/auth',
'\\'.BroadcastController::class.'@authenticate'
);
});
}
@@ -140,7 +143,7 @@ class BroadcastManager implements FactoryContract
/**
* Get a driver instance.
*
* @param string $name
* @param string|null $name
* @return mixed
*/
public function driver($name = null)
@@ -209,10 +212,16 @@ class BroadcastManager implements FactoryContract
*/
protected function createPusherDriver(array $config)
{
return new PusherBroadcaster(
new Pusher($config['key'], $config['secret'],
$config['app_id'], $config['options'] ?? [])
$pusher = new Pusher(
$config['key'], $config['secret'],
$config['app_id'], $config['options'] ?? []
);
if ($config['log'] ?? false) {
$pusher->setLogger($this->app->make(LoggerInterface::class));
}
return new PusherBroadcaster($pusher);
}
/**

View File

@@ -2,6 +2,8 @@
namespace Illuminate\Broadcasting\Broadcasters;
use Exception;
use ReflectionClass;
use ReflectionFunction;
use Illuminate\Support\Str;
use Illuminate\Container\Container;
@@ -22,7 +24,7 @@ abstract class Broadcaster implements BroadcasterContract
/**
* The binding registrar instance.
*
* @var BindingRegistrar
* @var \Illuminate\Contracts\Routing\BindingRegistrar
*/
protected $bindingRegistrar;
@@ -30,10 +32,10 @@ abstract class Broadcaster implements BroadcasterContract
* Register a channel authenticator.
*
* @param string $channel
* @param callable $callback
* @param callable|string $callback
* @return $this
*/
public function channel($channel, callable $callback)
public function channel($channel, $callback)
{
$this->channels[$channel] = $callback;
@@ -46,6 +48,7 @@ abstract class Broadcaster implements BroadcasterContract
* @param \Illuminate\Http\Request $request
* @param string $channel
* @return mixed
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
protected function verifyUserCanAccessChannel($request, $channel)
@@ -57,7 +60,9 @@ abstract class Broadcaster implements BroadcasterContract
$parameters = $this->extractAuthParameters($pattern, $channel, $callback);
if ($result = $callback($request->user(), ...$parameters)) {
$handler = $this->normalizeChannelHandlerToCallable($callback);
if ($result = $handler($request->user(), ...$parameters)) {
return $this->validAuthenticationResponse($request, $result);
}
}
@@ -70,12 +75,12 @@ abstract class Broadcaster implements BroadcasterContract
*
* @param string $pattern
* @param string $channel
* @param callable $callback
* @param callable|string $callback
* @return array
*/
protected function extractAuthParameters($pattern, $channel, $callback)
{
$callbackParameters = (new ReflectionFunction($callback))->getParameters();
$callbackParameters = $this->extractParameters($callback);
return collect($this->extractChannelKeys($pattern, $channel))->reject(function ($value, $key) {
return is_numeric($key);
@@ -84,6 +89,44 @@ abstract class Broadcaster implements BroadcasterContract
})->values()->all();
}
/**
* Extracts the parameters out of what the user passed to handle the channel authentication.
*
* @param callable|string $callback
* @return \ReflectionParameter[]
*
* @throws \Exception
*/
protected function extractParameters($callback)
{
if (is_callable($callback)) {
return (new ReflectionFunction($callback))->getParameters();
} elseif (is_string($callback)) {
return $this->extractParametersFromClass($callback);
}
throw new Exception('Given channel handler is an unknown type.');
}
/**
* Extracts the parameters out of a class channel's "join" method.
*
* @param string $callback
* @return \ReflectionParameter[]
*
* @throws \Exception
*/
protected function extractParametersFromClass($callback)
{
$reflection = new ReflectionClass($callback);
if (! $reflection->hasMethod('join')) {
throw new Exception('Class based channel must define a "join" method.');
}
return $reflection->getMethod('join')->getParameters();
}
/**
* Extract the channel keys from the incoming channel name.
*
@@ -140,6 +183,7 @@ abstract class Broadcaster implements BroadcasterContract
* @param mixed $value
* @param array $callbackParameters
* @return mixed
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
protected function resolveImplicitBindingIfPossible($key, $value, $callbackParameters)
@@ -201,4 +245,19 @@ abstract class Broadcaster implements BroadcasterContract
return $this->bindingRegistrar;
}
/**
* Normalize the given callback into a callable.
*
* @param mixed $callback
* @return callable|\Closure
*/
protected function normalizeChannelHandlerToCallable($callback)
{
return is_callable($callback) ? $callback : function (...$args) use ($callback) {
return Container::getInstance()
->make($callback)
->join(...$args);
};
}
}

View File

@@ -33,6 +33,7 @@ class PusherBroadcaster extends Broadcaster
*
* @param \Illuminate\Http\Request $request
* @return mixed
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
public function auth($request)
@@ -62,25 +63,34 @@ class PusherBroadcaster extends Broadcaster
{
if (Str::startsWith($request->channel_name, 'private')) {
return $this->decodePusherResponse(
$this->pusher->socket_auth($request->channel_name, $request->socket_id)
$request, $this->pusher->socket_auth($request->channel_name, $request->socket_id)
);
}
return $this->decodePusherResponse(
$request,
$this->pusher->presence_auth(
$request->channel_name, $request->socket_id, $request->user()->getAuthIdentifier(), $result)
$request->channel_name, $request->socket_id,
$request->user()->getAuthIdentifier(), $result
)
);
}
/**
* Decode the given Pusher response.
*
* @param \Illuminate\Http\Request $request
* @param mixed $response
* @return array
*/
protected function decodePusherResponse($response)
protected function decodePusherResponse($request, $response)
{
return json_decode($response, true);
if (! $request->input('callback', false)) {
return json_decode($response, true);
}
return response()->json(json_decode($response, true))
->withCallback($request->callback);
}
/**

View File

@@ -27,7 +27,7 @@ class RedisBroadcaster extends Broadcaster
* Create a new broadcaster instance.
*
* @param \Illuminate\Contracts\Redis\Factory $redis
* @param string $connection
* @param string|null $connection
* @return void
*/
public function __construct(Redis $redis, $connection = null)
@@ -41,6 +41,7 @@ class RedisBroadcaster extends Broadcaster
*
* @param \Illuminate\Http\Request $request
* @return mixed
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
public function auth($request)

View File

@@ -14,12 +14,12 @@
}
],
"require": {
"php": ">=7.0",
"psr/log": "~1.0",
"illuminate/bus": "5.5.*",
"illuminate/contracts": "5.5.*",
"illuminate/queue": "5.5.*",
"illuminate/support": "5.5.*"
"php": "^7.1.3",
"psr/log": "^1.0",
"illuminate/bus": "5.7.*",
"illuminate/contracts": "5.7.*",
"illuminate/queue": "5.7.*",
"illuminate/support": "5.7.*"
},
"autoload": {
"psr-4": {
@@ -28,11 +28,11 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.5-dev"
"dev-master": "5.7-dev"
}
},
"suggest": {
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (~3.0)."
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^3.0)."
},
"config": {
"sort-packages": true

View File

@@ -14,10 +14,10 @@
}
],
"require": {
"php": ">=7.0",
"illuminate/contracts": "5.5.*",
"illuminate/pipeline": "5.5.*",
"illuminate/support": "5.5.*"
"php": "^7.1.3",
"illuminate/contracts": "5.7.*",
"illuminate/pipeline": "5.7.*",
"illuminate/support": "5.7.*"
},
"autoload": {
"psr-4": {
@@ -26,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.5-dev"
"dev-master": "5.7-dev"
}
},
"config": {

View File

@@ -23,9 +23,7 @@ class ArrayStore extends TaggableStore implements Store
*/
public function get($key)
{
if (array_key_exists($key, $this->storage)) {
return $this->storage[$key];
}
return $this->storage[$key] ?? null;
}
/**

View File

@@ -61,7 +61,7 @@ class CacheManager implements FactoryContract
/**
* Get a cache driver instance.
*
* @param string $driver
* @param string|null $driver
* @return mixed
*/
public function driver($driver = null)

View File

@@ -64,15 +64,19 @@ class ClearCommand extends Command
'cache:clearing', [$this->argument('store'), $this->tags()]
);
$this->cache()->flush();
$successful = $this->cache()->flush();
$this->flushFacades();
if (! $successful) {
return $this->error('Failed to clear cache. Make sure you have the appropriate permissions.');
}
$this->laravel['events']->fire(
'cache:cleared', [$this->argument('store'), $this->tags()]
);
$this->info('Cache cleared successfully.');
$this->info('Application cache cleared!');
}
/**
@@ -82,7 +86,11 @@ class ClearCommand extends Command
*/
public function flushFacades()
{
foreach ($this->files->files(storage_path('framework/cache')) as $file) {
if (! $this->files->exists($storagePath = storage_path('framework/cache'))) {
return;
}
foreach ($this->files->files($storagePath) as $file) {
if (preg_match('/facade-.*\.php$/', $file)) {
$this->files->delete($file);
}
@@ -119,7 +127,7 @@ class ClearCommand extends Command
protected function getArguments()
{
return [
['store', InputArgument::OPTIONAL, 'The name of the store you would like to clear.'],
['store', InputArgument::OPTIONAL, 'The name of the store you would like to clear'],
];
}
@@ -131,7 +139,7 @@ class ClearCommand extends Command
protected function getOptions()
{
return [
['tags', null, InputOption::VALUE_OPTIONAL, 'The cache tags you would like to clear.', null],
['tags', null, InputOption::VALUE_OPTIONAL, 'The cache tags you would like to clear', null],
];
}
}

View File

@@ -4,8 +4,10 @@ namespace Illuminate\Cache;
use Closure;
use Exception;
use Illuminate\Support\Str;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Support\InteractsWithTime;
use Illuminate\Database\PostgresConnection;
use Illuminate\Database\ConnectionInterface;
class DatabaseStore implements Store
@@ -78,7 +80,7 @@ class DatabaseStore implements Store
return;
}
return unserialize($cache->value);
return $this->unserialize($cache->value);
}
/**
@@ -93,7 +95,7 @@ class DatabaseStore implements Store
{
$key = $this->prefix.$key;
$value = serialize($value);
$value = $this->serialize($value);
$expiration = $this->getTime() + (int) ($minutes * 60);
@@ -157,7 +159,7 @@ class DatabaseStore implements Store
$cache = is_array($cache) ? (object) $cache : $cache;
$current = unserialize($cache->value);
$current = $this->unserialize($cache->value);
// Here we'll call this callback function that was given to the function which
// is used to either increment or decrement the function. We use a callback
@@ -172,7 +174,7 @@ class DatabaseStore implements Store
// since database cache values are encrypted by default with secure storage
// that can't be easily read. We will return the new value after storing.
$this->table()->where('key', $prefixed)->update([
'value' => serialize($new),
'value' => $this->serialize($new),
]);
return $new;
@@ -221,7 +223,9 @@ class DatabaseStore implements Store
*/
public function flush()
{
return (bool) $this->table()->delete();
$this->table()->delete();
return true;
}
/**
@@ -253,4 +257,36 @@ class DatabaseStore implements Store
{
return $this->prefix;
}
/**
* Serialize the given value.
*
* @param mixed $value
* @return string
*/
protected function serialize($value)
{
$result = serialize($value);
if ($this->connection instanceof PostgresConnection && Str::contains($result, "\0")) {
$result = base64_encode($result);
}
return $result;
}
/**
* Unserialize the given value.
*
* @param string $value
* @return mixed
*/
protected function unserialize($value)
{
if ($this->connection instanceof PostgresConnection && ! Str::contains($value, [':', ';'])) {
$value = base64_decode($value);
}
return unserialize($value);
}
}

View File

@@ -91,7 +91,7 @@ class FileStore implements Store
$raw = $this->getPayload($key);
return tap(((int) $raw['data']) + $value, function ($newValue) use ($key, $raw) {
$this->put($key, $newValue, $raw['time']);
$this->put($key, $newValue, $raw['time'] ?? 0);
});
}

View File

@@ -3,9 +3,10 @@
namespace Illuminate\Cache;
use Illuminate\Support\InteractsWithTime;
use Illuminate\Contracts\Cache\Lock as LockContract;
use Illuminate\Contracts\Cache\LockTimeoutException;
abstract class Lock
abstract class Lock implements LockContract
{
use InteractsWithTime;
@@ -43,6 +44,13 @@ abstract class Lock
*/
abstract public function acquire();
/**
* Release the lock.
*
* @return void
*/
abstract public function release();
/**
* Attempt to acquire the lock.
*
@@ -68,6 +76,7 @@ abstract class Lock
* @param int $seconds
* @param callable|null $callback
* @return bool
*
* @throws \Illuminate\Contracts\Cache\LockTimeoutException
*/
public function block($seconds, $callback = null)

View File

@@ -47,7 +47,7 @@ class MemcachedConnector
{
$memcached = $this->createMemcachedInstance($connectionId);
if (count($credentials) == 2) {
if (count($credentials) === 2) {
$this->setCredentials($memcached, $credentials);
}
@@ -78,7 +78,7 @@ class MemcachedConnector
*/
protected function setCredentials($memcached, $credentials)
{
list($username, $password) = $credentials;
[$username, $password] = $credentials;
$memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);

View File

@@ -2,9 +2,7 @@
namespace Illuminate\Cache;
use Illuminate\Contracts\Cache\Lock as LockContract;
class MemcachedLock extends Lock implements LockContract
class MemcachedLock extends Lock
{
/**
* The Memcached instance.

View File

@@ -12,6 +12,13 @@ class MemcachedStore extends TaggableStore implements LockProvider, Store
{
use InteractsWithTime;
/**
* The maximum value that can be specified as an expiration delta.
*
* @var int
*/
const REALTIME_MAXDELTA_IN_MINUTES = 43200;
/**
* The Memcached instance.
*
@@ -103,7 +110,9 @@ class MemcachedStore extends TaggableStore implements LockProvider, Store
*/
public function put($key, $value, $minutes)
{
$this->memcached->set($this->prefix.$key, $value, $this->toTimestamp($minutes));
$this->memcached->set(
$this->prefix.$key, $value, $this->calculateExpiration($minutes)
);
}
/**
@@ -121,7 +130,9 @@ class MemcachedStore extends TaggableStore implements LockProvider, Store
$prefixedValues[$this->prefix.$key] = $value;
}
$this->memcached->setMulti($prefixedValues, $this->toTimestamp($minutes));
$this->memcached->setMulti(
$prefixedValues, $this->calculateExpiration($minutes)
);
}
/**
@@ -134,7 +145,9 @@ class MemcachedStore extends TaggableStore implements LockProvider, Store
*/
public function add($key, $value, $minutes)
{
return $this->memcached->add($this->prefix.$key, $value, $this->toTimestamp($minutes));
return $this->memcached->add(
$this->prefix.$key, $value, $this->calculateExpiration($minutes)
);
}
/**
@@ -206,6 +219,17 @@ class MemcachedStore extends TaggableStore implements LockProvider, Store
return $this->memcached->flush();
}
/**
* Get the expiration time of the key.
*
* @param int $minutes
* @return int
*/
protected function calculateExpiration($minutes)
{
return $this->toTimestamp($minutes);
}
/**
* Get the UNIX timestamp for the given number of minutes.
*

View File

@@ -32,10 +32,9 @@ class RateLimiter
*
* @param string $key
* @param int $maxAttempts
* @param float|int $decayMinutes
* @return bool
*/
public function tooManyAttempts($key, $maxAttempts, $decayMinutes = 1)
public function tooManyAttempts($key, $maxAttempts)
{
if ($this->attempts($key) >= $maxAttempts) {
if ($this->cache->has($key.':timer')) {

View File

@@ -2,9 +2,7 @@
namespace Illuminate\Cache;
use Illuminate\Contracts\Cache\Lock as LockContract;
class RedisLock extends Lock implements LockContract
class RedisLock extends Lock
{
/**
* The Redis factory implementation.

View File

@@ -22,7 +22,7 @@ class RedisTaggedCache extends TaggedCache
*
* @param string $key
* @param mixed $value
* @param \DateTime|float|int $minutes
* @param \DateTime|float|int|null $minutes
* @return void
*/
public function put($key, $value, $minutes = null)
@@ -32,6 +32,34 @@ class RedisTaggedCache extends TaggedCache
parent::put($key, $value, $minutes);
}
/**
* Increment the value of an item in the cache.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function increment($key, $value = 1)
{
$this->pushStandardKeys($this->tags->getNamespace(), $key);
parent::increment($key, $value);
}
/**
* Decrement the value of an item in the cache.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function decrement($key, $value = 1)
{
$this->pushStandardKeys($this->tags->getNamespace(), $key);
parent::decrement($key, $value);
}
/**
* Store an item in the cache indefinitely.
*
@@ -49,14 +77,14 @@ class RedisTaggedCache extends TaggedCache
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
$this->deleteForeverKeys();
$this->deleteStandardKeys();
parent::flush();
return parent::flush();
}
/**

View File

@@ -172,7 +172,7 @@ class Repository implements CacheContract, ArrayAccess
*/
public function pull($key, $default = null)
{
return tap($this->get($key, $default), function ($value) use ($key) {
return tap($this->get($key, $default), function () use ($key) {
$this->forget($key);
});
}
@@ -182,13 +182,15 @@ class Repository implements CacheContract, ArrayAccess
*
* @param string $key
* @param mixed $value
* @param \DateTimeInterface|\DateInterval|float|int $minutes
* @param \DateTimeInterface|\DateInterval|float|int|null $minutes
* @return void
*/
public function put($key, $value, $minutes = null)
{
if (is_array($key)) {
return $this->putMany($key, $value);
$this->putMany($key, $value);
return;
}
if (! is_null($minutes = $this->getMinutes($minutes))) {
@@ -419,7 +421,7 @@ class Repository implements CacheContract, ArrayAccess
throw new BadMethodCallException('This cache store does not support tagging.');
}
$cache = $this->store->tags($names);
$cache = $this->store->tags(is_array($names) ? $names : func_get_args());
if (! is_null($this->events)) {
$cache->setEventDispatcher($this->events);

View File

@@ -42,7 +42,7 @@ class TaggedCache extends Repository
}
/**
* Increment the value of an item in the cache.
* Decrement the value of an item in the cache.
*
* @param string $key
* @param mixed $value
@@ -56,11 +56,13 @@ class TaggedCache extends Repository
/**
* Remove all items from the cache.
*
* @return void
* @return bool
*/
public function flush()
{
$this->tags->reset();
return true;
}
/**

View File

@@ -14,9 +14,9 @@
}
],
"require": {
"php": ">=7.0",
"illuminate/contracts": "5.5.*",
"illuminate/support": "5.5.*"
"php": "^7.1.3",
"illuminate/contracts": "5.7.*",
"illuminate/support": "5.7.*"
},
"autoload": {
"psr-4": {
@@ -25,13 +25,13 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.5-dev"
"dev-master": "5.7-dev"
}
},
"suggest": {
"illuminate/database": "Required to use the database cache driver (5.5.*).",
"illuminate/filesystem": "Required to use the file cache driver (5.5.*).",
"illuminate/redis": "Required to use the redis cache driver (5.5.*)."
"illuminate/database": "Required to use the database cache driver (5.7.*).",
"illuminate/filesystem": "Required to use the file cache driver (5.7.*).",
"illuminate/redis": "Required to use the redis cache driver (5.7.*)."
},
"config": {
"sort-packages": true

View File

@@ -65,7 +65,7 @@ class Repository implements ArrayAccess, ConfigContract
foreach ($keys as $key => $default) {
if (is_numeric($key)) {
list($key, $default) = [$default, null];
[$key, $default] = [$default, null];
}
$config[$key] = Arr::get($this->items, $key, $default);

View File

@@ -14,9 +14,9 @@
}
],
"require": {
"php": ">=7.0",
"illuminate/contracts": "5.5.*",
"illuminate/support": "5.5.*"
"php": "^7.1.3",
"illuminate/contracts": "5.7.*",
"illuminate/support": "5.7.*"
},
"autoload": {
"psr-4": {
@@ -25,7 +25,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.5-dev"
"dev-master": "5.7-dev"
}
},
"config": {

View File

@@ -16,6 +16,7 @@ use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Illuminate\Contracts\Console\Application as ApplicationContract;
class Application extends SymfonyApplication implements ApplicationContract
@@ -163,18 +164,28 @@ class Application extends SymfonyApplication implements ApplicationContract
*
* @param string $command
* @param array $parameters
* @param \Symfony\Component\Console\Output\OutputInterface $outputBuffer
* @param \Symfony\Component\Console\Output\OutputInterface|null $outputBuffer
* @return int
*
* @throws \Symfony\Component\Console\Exception\CommandNotFoundException
*/
public function call($command, array $parameters = [], $outputBuffer = null)
{
$parameters = collect($parameters)->prepend($command);
if (is_subclass_of($command, SymfonyCommand::class)) {
$command = $this->laravel->make($command)->getName();
}
if (! $this->has($command)) {
throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $command));
}
array_unshift($parameters, $command);
$this->lastOutput = $outputBuffer ?: new BufferedOutput;
$this->setCatchExceptions(false);
$result = $this->run(new ArrayInput($parameters->toArray()), $this->lastOutput);
$result = $this->run(new ArrayInput($parameters), $this->lastOutput);
$this->setCatchExceptions(true);
@@ -188,7 +199,9 @@ class Application extends SymfonyApplication implements ApplicationContract
*/
public function output()
{
return $this->lastOutput ? $this->lastOutput->fetch() : '';
return $this->lastOutput && method_exists($this->lastOutput, 'fetch')
? $this->lastOutput->fetch()
: '';
}
/**
@@ -246,7 +259,7 @@ class Application extends SymfonyApplication implements ApplicationContract
}
/**
* Get the default input definitions for the applications.
* Get the default input definition for the application.
*
* This is used to add the --env option to every available command.
*

View File

@@ -2,6 +2,7 @@
namespace Illuminate\Console;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Support\Arrayable;
use Symfony\Component\Console\Helper\Table;
@@ -108,7 +109,7 @@ class Command extends SymfonyCommand
// the command we'll set the arguments and the options on this command.
$this->setDescription($this->description);
$this->setHidden($this->hidden);
$this->setHidden($this->isHidden());
if (! isset($this->signature)) {
$this->specifyParameters();
@@ -122,20 +123,15 @@ class Command extends SymfonyCommand
*/
protected function configureUsingFluentDefinition()
{
list($name, $arguments, $options) = Parser::parse($this->signature);
[$name, $arguments, $options] = Parser::parse($this->signature);
parent::__construct($this->name = $name);
// After parsing the signature we will spin through the arguments and options
// and set them on this command. These will already be changed into proper
// instances of these "InputArgument" and "InputOption" Symfony classes.
foreach ($arguments as $argument) {
$this->getDefinition()->addArgument($argument);
}
foreach ($options as $option) {
$this->getDefinition()->addOption($option);
}
$this->getDefinition()->addArguments($arguments);
$this->getDefinition()->addOptions($options);
}
/**
@@ -166,8 +162,12 @@ class Command extends SymfonyCommand
*/
public function run(InputInterface $input, OutputInterface $output)
{
$this->output = $this->laravel->make(
OutputStyle::class, ['input' => $input, 'output' => $output]
);
return parent::run(
$this->input = $input, $this->output = new OutputStyle($input, $output)
$this->input = $input, $this->output
);
}
@@ -245,7 +245,7 @@ class Command extends SymfonyCommand
* Get the value of a command argument.
*
* @param string|null $key
* @return string|array
* @return string|array|null
*/
public function argument($key = null)
{
@@ -280,8 +280,8 @@ class Command extends SymfonyCommand
/**
* Get the value of a command option.
*
* @param string $key
* @return string|array
* @param string|null $key
* @return string|array|null
*/
public function option($key = null)
{
@@ -318,8 +318,8 @@ class Command extends SymfonyCommand
* Prompt the user for input.
*
* @param string $question
* @param string $default
* @return string
* @param string|null $default
* @return mixed
*/
public function ask($question, $default = null)
{
@@ -331,8 +331,8 @@ class Command extends SymfonyCommand
*
* @param string $question
* @param array $choices
* @param string $default
* @return string
* @param string|null $default
* @return mixed
*/
public function anticipate($question, array $choices, $default = null)
{
@@ -344,8 +344,8 @@ class Command extends SymfonyCommand
*
* @param string $question
* @param array $choices
* @param string $default
* @return string
* @param string|null $default
* @return mixed
*/
public function askWithCompletion($question, array $choices, $default = null)
{
@@ -361,7 +361,7 @@ class Command extends SymfonyCommand
*
* @param string $question
* @param bool $fallback
* @return string
* @return mixed
*/
public function secret($question, $fallback = true)
{
@@ -377,9 +377,9 @@ class Command extends SymfonyCommand
*
* @param string $question
* @param array $choices
* @param string $default
* @param mixed $attempts
* @param bool $multiple
* @param string|null $default
* @param mixed|null $attempts
* @param bool|null $multiple
* @return string
*/
public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null)
@@ -421,7 +421,7 @@ class Command extends SymfonyCommand
* Write a string as information output.
*
* @param string $string
* @param null|int|string $verbosity
* @param int|string|null $verbosity
* @return void
*/
public function info($string, $verbosity = null)
@@ -434,7 +434,7 @@ class Command extends SymfonyCommand
*
* @param string $string
* @param string $style
* @param null|int|string $verbosity
* @param int|string|null $verbosity
* @return void
*/
public function line($string, $style = null, $verbosity = null)
@@ -448,7 +448,7 @@ class Command extends SymfonyCommand
* Write a string as comment output.
*
* @param string $string
* @param null|int|string $verbosity
* @param int|string|null $verbosity
* @return void
*/
public function comment($string, $verbosity = null)
@@ -460,7 +460,7 @@ class Command extends SymfonyCommand
* Write a string as question output.
*
* @param string $string
* @param null|int|string $verbosity
* @param int|string|null $verbosity
* @return void
*/
public function question($string, $verbosity = null)
@@ -472,7 +472,7 @@ class Command extends SymfonyCommand
* Write a string as error output.
*
* @param string $string
* @param null|int|string $verbosity
* @param int|string|null $verbosity
* @return void
*/
public function error($string, $verbosity = null)
@@ -484,7 +484,7 @@ class Command extends SymfonyCommand
* Write a string as warning output.
*
* @param string $string
* @param null|int|string $verbosity
* @param int|string|null $verbosity
* @return void
*/
public function warn($string, $verbosity = null)
@@ -506,9 +506,11 @@ class Command extends SymfonyCommand
*/
public function alert($string)
{
$this->comment(str_repeat('*', strlen($string) + 12));
$length = Str::length(strip_tags($string)) + 12;
$this->comment(str_repeat('*', $length));
$this->comment('* '.$string.' *');
$this->comment(str_repeat('*', strlen($string) + 12));
$this->comment(str_repeat('*', $length));
$this->output->newLine();
}
@@ -527,7 +529,7 @@ class Command extends SymfonyCommand
/**
* Get the verbosity level in terms of Symfony's OutputInterface level.
*
* @param string|int $level
* @param string|int|null $level
* @return int
*/
protected function parseVerbosity($level = null)
@@ -564,7 +566,7 @@ class Command extends SymfonyCommand
/**
* Get the output implementation.
*
* @return \Symfony\Component\Console\Output\OutputInterface
* @return \Illuminate\Console\OutputStyle
*/
public function getOutput()
{

View File

@@ -56,7 +56,9 @@ abstract class GeneratorCommand extends Command
// First we will check to see if the class already exists. If it does, we don't want
// to create the class and overwrite the user's code. So, we will bail out so the
// code is untouched. Otherwise, we will continue generating this class' files.
if ((! $this->hasOption('force') || ! $this->option('force')) && $this->alreadyExists($this->getNameInput())) {
if ((! $this->hasOption('force') ||
! $this->option('force')) &&
$this->alreadyExists($this->getNameInput())) {
$this->error($this->type.' already exists!');
return false;
@@ -169,7 +171,7 @@ abstract class GeneratorCommand extends Command
{
$stub = str_replace(
['DummyNamespace', 'DummyRootNamespace', 'NamespacedDummyUserModel'],
[$this->getNamespace($name), $this->rootNamespace(), config('auth.providers.users.model')],
[$this->getNamespace($name), $this->rootNamespace(), $this->userProviderModel()],
$stub
);
@@ -221,6 +223,20 @@ abstract class GeneratorCommand extends Command
return $this->laravel->getNamespace();
}
/**
* Get the model for the default guard's user provider.
*
* @return string|null
*/
protected function userProviderModel()
{
$guard = config('auth.defaults.guard');
$provider = config("auth.guards.{$guard}.provider");
return config("auth.providers.{$provider}.model");
}
/**
* Get the console command arguments.
*

View File

@@ -35,6 +35,8 @@ class Parser
*
* @param string $expression
* @return string
*
* @throws \InvalidArgumentException
*/
protected static function name($expression)
{
@@ -80,7 +82,7 @@ class Parser
*/
protected static function parseArgument($token)
{
list($token, $description) = static::extractDescription($token);
[$token, $description] = static::extractDescription($token);
switch (true) {
case Str::endsWith($token, '?*'):
@@ -106,7 +108,7 @@ class Parser
*/
protected static function parseOption($token)
{
list($token, $description) = static::extractDescription($token);
[$token, $description] = static::extractDescription($token);
$matches = preg_split('/\s*\|\s*/', $token, 2);

View File

@@ -0,0 +1,81 @@
<?php
namespace Illuminate\Console\Scheduling;
use Illuminate\Contracts\Cache\Factory as Cache;
class CacheEventMutex implements EventMutex
{
/**
* The cache repository implementation.
*
* @var \Illuminate\Contracts\Cache\Factory
*/
public $cache;
/**
* The cache store that should be used.
*
* @var string|null
*/
public $store;
/**
* Create a new overlapping strategy.
*
* @param \Illuminate\Contracts\Cache\Factory $cache
* @return void
*/
public function __construct(Cache $cache)
{
$this->cache = $cache;
}
/**
* Attempt to obtain an event mutex for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return bool
*/
public function create(Event $event)
{
return $this->cache->store($this->store)->add(
$event->mutexName(), true, $event->expiresAt
);
}
/**
* Determine if an event mutex exists for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return bool
*/
public function exists(Event $event)
{
return $this->cache->store($this->store)->has($event->mutexName());
}
/**
* Clear the event mutex for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return void
*/
public function forget(Event $event)
{
$this->cache->store($this->store)->forget($event->mutexName());
}
/**
* Specify the cache store that should be used.
*
* @param string $store
* @return $this
*/
public function useStore($store)
{
$this->store = $store;
return $this;
}
}

View File

@@ -1,61 +0,0 @@
<?php
namespace Illuminate\Console\Scheduling;
use Illuminate\Contracts\Cache\Repository as Cache;
class CacheMutex implements Mutex
{
/**
* The cache repository implementation.
*
* @var \Illuminate\Contracts\Cache\Repository
*/
public $cache;
/**
* Create a new overlapping strategy.
*
* @param \Illuminate\Contracts\Cache\Repository $cache
* @return void
*/
public function __construct(Cache $cache)
{
$this->cache = $cache;
}
/**
* Attempt to obtain a mutex for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return bool
*/
public function create(Event $event)
{
return $this->cache->add(
$event->mutexName(), true, $event->expiresAt
);
}
/**
* Determine if a mutex exists for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return bool
*/
public function exists(Event $event)
{
return $this->cache->has($event->mutexName());
}
/**
* Clear the mutex for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return void
*/
public function forget(Event $event)
{
$this->cache->forget($event->mutexName());
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace Illuminate\Console\Scheduling;
use DateTimeInterface;
use Illuminate\Contracts\Cache\Factory as Cache;
class CacheSchedulingMutex implements SchedulingMutex
{
/**
* The cache factory implementation.
*
* @var \Illuminate\Contracts\Cache\Factory
*/
public $cache;
/**
* The cache store that should be used.
*
* @var string|null
*/
public $store;
/**
* Create a new scheduling strategy.
*
* @param \Illuminate\Contracts\Cache\Factory $cache
* @return void
*/
public function __construct(Cache $cache)
{
$this->cache = $cache;
}
/**
* Attempt to obtain a scheduling mutex for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @param \DateTimeInterface $time
* @return bool
*/
public function create(Event $event, DateTimeInterface $time)
{
return $this->cache->store($this->store)->add(
$event->mutexName().$time->format('Hi'), true, 60
);
}
/**
* Determine if a scheduling mutex exists for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @param \DateTimeInterface $time
* @return bool
*/
public function exists(Event $event, DateTimeInterface $time)
{
return $this->cache->store($this->store)->has(
$event->mutexName().$time->format('Hi')
);
}
/**
* Specify the cache store that should be used.
*
* @param string $store
* @return $this
*/
public function useStore($store)
{
$this->store = $store;
return $this;
}
}

View File

@@ -25,14 +25,14 @@ class CallbackEvent extends Event
/**
* Create a new event instance.
*
* @param \Illuminate\Console\Scheduling\Mutex $mutex
* @param \Illuminate\Console\Scheduling\EventMutex $mutex
* @param string $callback
* @param array $parameters
* @return void
*
* @throws \InvalidArgumentException
*/
public function __construct(Mutex $mutex, $callback, array $parameters = [])
public function __construct(EventMutex $mutex, $callback, array $parameters = [])
{
if (! is_string($callback) && ! is_callable($callback)) {
throw new InvalidArgumentException(
@@ -71,7 +71,9 @@ class CallbackEvent extends Event
parent::callBeforeCallbacks($container);
try {
$response = $container->call($this->callback, $this->parameters);
$response = is_object($this->callback)
? $container->call([$this->callback, '__invoke'], $this->parameters)
: $container->call($this->callback, $this->parameters);
} finally {
$this->removeMutex();
@@ -98,6 +100,8 @@ class CallbackEvent extends Event
*
* @param int $expiresAt
* @return $this
*
* @throws \LogicException
*/
public function withoutOverlapping($expiresAt = 1440)
{
@@ -116,6 +120,26 @@ class CallbackEvent extends Event
});
}
/**
* Allow the event to only run on one server for each cron expression.
*
* @return $this
*
* @throws \LogicException
*/
public function onOneServer()
{
if (! isset($this->description)) {
throw new LogicException(
"A scheduled event name is required to only run on one server. Use the 'name' method before 'onOneServer'."
);
}
$this->onOneServer = true;
return $this;
}
/**
* Get the mutex name for the scheduled command.
*

View File

@@ -4,6 +4,7 @@ namespace Illuminate\Console\Scheduling;
use Closure;
use Cron\CronExpression;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use GuzzleHttp\Client as HttpClient;
use Illuminate\Contracts\Mail\Mailer;
@@ -27,7 +28,7 @@ class Event
*
* @var string
*/
public $expression = '* * * * * *';
public $expression = '* * * * *';
/**
* The timezone the date should be evaluated on.
@@ -64,6 +65,13 @@ class Event
*/
public $withoutOverlapping = false;
/**
* Indicates if the command should only be allowed to run on one server for each cron expression.
*
* @var bool
*/
public $onOneServer = false;
/**
* The amount of time the mutex should be valid.
*
@@ -128,20 +136,20 @@ class Event
public $description;
/**
* The mutex implementation.
* The event mutex implementation.
*
* @var \Illuminate\Console\Scheduling\Mutex
* @var \Illuminate\Console\Scheduling\EventMutex
*/
public $mutex;
/**
* Create a new event instance.
*
* @param \Illuminate\Console\Scheduling\Mutex $mutex
* @param \Illuminate\Console\Scheduling\EventMutex $mutex
* @param string $command
* @return void
*/
public function __construct(Mutex $mutex, $command)
public function __construct(EventMutex $mutex, $command)
{
$this->mutex = $mutex;
$this->command = $command;
@@ -330,6 +338,18 @@ class Event
return true;
}
/**
* Ensure that the output is stored on disk in a log file.
*
* @return $this
*/
public function storeOutput()
{
$this->ensureOutputIsBeingCaptured();
return $this;
}
/**
* Send the output of the command to a given location.
*
@@ -370,7 +390,7 @@ class Event
{
$this->ensureOutputIsBeingCapturedForEmail();
$addresses = is_array($addresses) ? $addresses : [$addresses];
$addresses = Arr::wrap($addresses);
return $this->then(function (Mailer $mailer) use ($addresses, $onlyIfOutputExists) {
$this->emailOutput($mailer, $addresses, $onlyIfOutputExists);
@@ -394,8 +414,20 @@ class Event
* Ensure that output is being captured for email.
*
* @return void
*
* @deprecated See ensureOutputIsBeingCaptured.
*/
protected function ensureOutputIsBeingCapturedForEmail()
{
$this->ensureOutputIsBeingCaptured();
}
/**
* Ensure that the command output is being captured.
*
* @return void
*/
protected function ensureOutputIsBeingCaptured()
{
if (is_null($this->output) || $this->output == $this->getDefaultOutput()) {
$this->sendOutputTo(storage_path('logs/schedule-'.sha1($this->mutexName()).'.log'));
@@ -450,6 +482,18 @@ class Event
});
}
/**
* Register a callback to ping a given URL before the job runs if the given condition is true.
*
* @param bool $value
* @param string $url
* @return $this
*/
public function pingBeforeIf($value, $url)
{
return $value ? $this->pingBefore($url) : $this;
}
/**
* Register a callback to ping a given URL after the job runs.
*
@@ -463,6 +507,18 @@ class Event
});
}
/**
* Register a callback to ping a given URL after the job runs if the given condition is true.
*
* @param bool $value
* @param string $url
* @return $this
*/
public function thenPingIf($value, $url)
{
return $value ? $this->thenPing($url) : $this;
}
/**
* State that the command should run in background.
*
@@ -532,6 +588,18 @@ class Event
});
}
/**
* Allow the event to only run on one server for each cron expression.
*
* @return $this
*/
public function onOneServer()
{
$this->onOneServer = true;
return $this;
}
/**
* Register a callback to further filter the schedule.
*
@@ -649,7 +717,7 @@ class Event
{
return Carbon::instance(CronExpression::factory(
$this->getExpression()
)->getNextRunDate($currentTime, $nth, $allowCurrentDate));
)->getNextRunDate($currentTime, $nth, $allowCurrentDate, $this->timezone));
}
/**
@@ -663,12 +731,12 @@ class Event
}
/**
* Set the mutex implementation to be used.
* Set the event mutex implementation to be used.
*
* @param \Illuminate\Console\Scheduling\Mutex $mutex
* @param \Illuminate\Console\Scheduling\EventMutex $mutex
* @return $this
*/
public function preventOverlapsUsing(Mutex $mutex)
public function preventOverlapsUsing(EventMutex $mutex)
{
$this->mutex = $mutex;

View File

@@ -2,10 +2,10 @@
namespace Illuminate\Console\Scheduling;
interface Mutex
interface EventMutex
{
/**
* Attempt to obtain a mutex for the given event.
* Attempt to obtain an event mutex for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return bool
@@ -13,7 +13,7 @@ interface Mutex
public function create(Event $event);
/**
* Determine if a mutex exists for the given event.
* Determine if an event mutex exists for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return bool
@@ -21,7 +21,7 @@ interface Mutex
public function exists(Event $event);
/**
* Clear the mutex for the given event.
* Clear the event mutex for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return void

View File

@@ -2,6 +2,7 @@
namespace Illuminate\Console\Scheduling;
use DateTimeInterface;
use Illuminate\Console\Application;
use Illuminate\Container\Container;
use Illuminate\Support\ProcessUtils;
@@ -17,11 +18,18 @@ class Schedule
protected $events = [];
/**
* The mutex implementation.
* The event mutex implementation.
*
* @var \Illuminate\Console\Scheduling\Mutex
* @var \Illuminate\Console\Scheduling\EventMutex
*/
protected $mutex;
protected $eventMutex;
/**
* The scheduling mutex implementation.
*
* @var \Illuminate\Console\Scheduling\SchedulingMutex
*/
protected $schedulingMutex;
/**
* Create a new schedule instance.
@@ -32,22 +40,26 @@ class Schedule
{
$container = Container::getInstance();
$this->mutex = $container->bound(Mutex::class)
? $container->make(Mutex::class)
: $container->make(CacheMutex::class);
$this->eventMutex = $container->bound(EventMutex::class)
? $container->make(EventMutex::class)
: $container->make(CacheEventMutex::class);
$this->schedulingMutex = $container->bound(SchedulingMutex::class)
? $container->make(SchedulingMutex::class)
: $container->make(CacheSchedulingMutex::class);
}
/**
* Add a new callback event to the schedule.
*
* @param string|callable $callback
* @param array $parameters
* @param array $parameters
* @return \Illuminate\Console\Scheduling\CallbackEvent
*/
public function call($callback, array $parameters = [])
{
$this->events[] = $event = new CallbackEvent(
$this->mutex, $callback, $parameters
$this->eventMutex, $callback, $parameters
);
return $event;
@@ -76,15 +88,18 @@ class Schedule
*
* @param object|string $job
* @param string|null $queue
* @param string|null $connection
* @return \Illuminate\Console\Scheduling\CallbackEvent
*/
public function job($job, $queue = null)
public function job($job, $queue = null, $connection = null)
{
return $this->call(function () use ($job, $queue) {
return $this->call(function () use ($job, $queue, $connection) {
$job = is_string($job) ? resolve($job) : $job;
if ($job instanceof ShouldQueue) {
dispatch($job)->onQueue($queue);
dispatch($job)
->onConnection($connection ?? $job->connection)
->onQueue($queue ?? $job->queue);
} else {
dispatch_now($job);
}
@@ -104,7 +119,7 @@ class Schedule
$command .= ' '.$this->compileParameters($parameters);
}
$this->events[] = $event = new Event($this->mutex, $command);
$this->events[] = $event = new Event($this->eventMutex, $command);
return $event;
}
@@ -130,6 +145,18 @@ class Schedule
})->implode(' ');
}
/**
* Determine if the server is allowed to run this event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @param \DateTimeInterface $time
* @return bool
*/
public function serverShouldRun(Event $event, DateTimeInterface $time)
{
return $this->schedulingMutex->create($event, $time);
}
/**
* Get all of the events on the schedule that are due.
*
@@ -150,4 +177,23 @@ class Schedule
{
return $this->events;
}
/**
* Specify the cache store that should be used to store mutexes.
*
* @param string $store
* @return $this
*/
public function useCache($store)
{
if ($this->eventMutex instanceof CacheEventMutex) {
$this->eventMutex->useStore($store);
}
if ($this->schedulingMutex instanceof CacheSchedulingMutex) {
$this->schedulingMutex->useStore($store);
}
return $this;
}
}

View File

@@ -2,6 +2,7 @@
namespace Illuminate\Console\Scheduling;
use Illuminate\Support\Carbon;
use Illuminate\Console\Command;
class ScheduleRunCommand extends Command
@@ -27,6 +28,20 @@ class ScheduleRunCommand extends Command
*/
protected $schedule;
/**
* The 24 hour timestamp this scheduler command started running.
*
* @var \Illuminate\Support\Carbon;
*/
protected $startedAt;
/**
* Check if any events ran.
*
* @var bool
*/
protected $eventsRan = false;
/**
* Create a new command instance.
*
@@ -37,6 +52,8 @@ class ScheduleRunCommand extends Command
{
$this->schedule = $schedule;
$this->startedAt = Carbon::now();
parent::__construct();
}
@@ -47,22 +64,52 @@ class ScheduleRunCommand extends Command
*/
public function handle()
{
$eventsRan = false;
foreach ($this->schedule->dueEvents($this->laravel) as $event) {
if (! $event->filtersPass($this->laravel)) {
continue;
}
$this->line('<info>Running scheduled command:</info> '.$event->getSummaryForDisplay());
if ($event->onOneServer) {
$this->runSingleServerEvent($event);
} else {
$this->runEvent($event);
}
$event->run($this->laravel);
$eventsRan = true;
$this->eventsRan = true;
}
if (! $eventsRan) {
if (! $this->eventsRan) {
$this->info('No scheduled commands are ready to run.');
}
}
/**
* Run the given single server event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return void
*/
protected function runSingleServerEvent($event)
{
if ($this->schedule->serverShouldRun($event, $this->startedAt)) {
$this->runEvent($event);
} else {
$this->line('<info>Skipping command (has already run on another server):</info> '.$event->getSummaryForDisplay());
}
}
/**
* Run the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @return void
*/
protected function runEvent($event)
{
$this->line('<info>Running scheduled command:</info> '.$event->getSummaryForDisplay());
$event->run($this->laravel);
$this->eventsRan = true;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Illuminate\Console\Scheduling;
use DateTimeInterface;
interface SchedulingMutex
{
/**
* Attempt to obtain a scheduling mutex for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @param \DateTimeInterface $time
* @return bool
*/
public function create(Event $event, DateTimeInterface $time);
/**
* Determine if a scheduling mutex exists for the given event.
*
* @param \Illuminate\Console\Scheduling\Event $event
* @param \DateTimeInterface $time
* @return bool
*/
public function exists(Event $event, DateTimeInterface $time);
}

View File

@@ -14,10 +14,10 @@
}
],
"require": {
"php": ">=7.0",
"illuminate/contracts": "5.5.*",
"illuminate/support": "5.5.*",
"symfony/console": "~3.3"
"php": "^7.1.3",
"illuminate/contracts": "5.7.*",
"illuminate/support": "5.7.*",
"symfony/console": "^4.1"
},
"autoload": {
"psr-4": {
@@ -26,13 +26,13 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.5-dev"
"dev-master": "5.7-dev"
}
},
"suggest": {
"guzzlehttp/guzzle": "Required to use the ping methods on schedules (~6.0).",
"mtdowling/cron-expression": "Required to use scheduling component (~1.0).",
"symfony/process": "Required to use scheduling component (~3.3)."
"dragonmantank/cron-expression": "Required to use scheduling component (^2.0).",
"guzzlehttp/guzzle": "Required to use the ping methods on schedules (^6.0).",
"symfony/process": "Required to use scheduling component (^4.1)."
},
"config": {
"sort-packages": true

View File

@@ -122,8 +122,10 @@ class BoundMethod
/**
* Get the proper reflection instance for the given callback.
*
* @param callable|string $callback
* @param callable|string $callback
* @return \ReflectionFunctionAbstract
*
* @throws \ReflectionException
*/
protected static function getCallReflector($callback)
{
@@ -152,6 +154,10 @@ class BoundMethod
$dependencies[] = $parameters[$parameter->name];
unset($parameters[$parameter->name]);
} elseif ($parameter->getClass() && array_key_exists($parameter->getClass()->name, $parameters)) {
$dependencies[] = $parameters[$parameter->getClass()->name];
unset($parameters[$parameter->getClass()->name]);
} elseif ($parameter->getClass()) {
$dependencies[] = $container->make($parameter->getClass()->name);
} elseif ($parameter->isDefaultValueAvailable()) {

View File

@@ -3,10 +3,12 @@
namespace Illuminate\Container;
use Closure;
use Exception;
use ArrayAccess;
use LogicException;
use ReflectionClass;
use ReflectionParameter;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Contracts\Container\Container as ContainerContract;
@@ -134,12 +136,18 @@ class Container implements ArrayAccess, ContainerContract
/**
* Define a contextual binding.
*
* @param string $concrete
* @param array|string $concrete
* @return \Illuminate\Contracts\Container\ContextualBindingBuilder
*/
public function when($concrete)
{
return new ContextualBindingBuilder($this, $this->getAlias($concrete));
$aliases = [];
foreach (Arr::wrap($concrete) as $c) {
$aliases[] = $this->getAlias($c);
}
return new ContextualBindingBuilder($this, $aliases);
}
/**
@@ -271,13 +279,28 @@ class Container implements ArrayAccess, ContainerContract
/**
* Bind a callback to resolve with Container::call.
*
* @param string $method
* @param array|string $method
* @param \Closure $callback
* @return void
*/
public function bindMethod($method, $callback)
{
$this->methodBindings[$method] = $callback;
$this->methodBindings[$this->parseBindMethod($method)] = $callback;
}
/**
* Get the method to be bound in class@method format.
*
* @param array|string $method
* @return string
*/
protected function parseBindMethod($method)
{
if (is_array($method)) {
return $method[0].'@'.$method[1];
}
return $method;
}
/**
@@ -591,11 +614,15 @@ class Container implements ArrayAccess, ContainerContract
*/
public function get($id)
{
if ($this->has($id)) {
try {
return $this->resolve($id);
}
} catch (Exception $e) {
if ($this->has($id)) {
throw $e;
}
throw new EntryNotFoundException;
throw new EntryNotFoundException;
}
}
/**
@@ -1166,7 +1193,7 @@ class Container implements ArrayAccess, ContainerContract
* Set the shared instance of the container.
*
* @param \Illuminate\Contracts\Container\Container|null $container
* @return static
* @return \Illuminate\Contracts\Container\Container|static
*/
public static function setInstance(ContainerContract $container = null)
{

View File

@@ -2,6 +2,7 @@
namespace Illuminate\Container;
use Illuminate\Support\Arr;
use Illuminate\Contracts\Container\ContextualBindingBuilder as ContextualBindingBuilderContract;
class ContextualBindingBuilder implements ContextualBindingBuilderContract
@@ -31,7 +32,7 @@ class ContextualBindingBuilder implements ContextualBindingBuilderContract
* Create a new contextual binding builder.
*
* @param \Illuminate\Container\Container $container
* @param string $concrete
* @param string|array $concrete
* @return void
*/
public function __construct(Container $container, $concrete)
@@ -61,8 +62,8 @@ class ContextualBindingBuilder implements ContextualBindingBuilderContract
*/
public function give($implementation)
{
$this->container->addContextualBinding(
$this->concrete, $this->needs, $implementation
);
foreach (Arr::wrap($this->concrete) as $concrete) {
$this->container->addContextualBinding($concrete, $this->needs, $implementation);
}
}
}

View File

@@ -14,9 +14,10 @@
}
],
"require": {
"php": ">=7.0",
"illuminate/contracts": "5.5.*",
"psr/container": "~1.0"
"php": "^7.1.3",
"illuminate/contracts": "5.7.*",
"illuminate/support": "5.7.*",
"psr/container": "^1.0"
},
"autoload": {
"psr-4": {
@@ -25,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "5.5-dev"
"dev-master": "5.7-dev"
}
},
"config": {

View File

@@ -93,6 +93,15 @@ interface Gate
*/
public function authorize($ability, $arguments = []);
/**
* Get the raw result from the authorization callback.
*
* @param string $ability
* @param array|mixed $arguments
* @return mixed
*/
public function raw($ability, $arguments = []);
/**
* Get a policy instance for a given class.
*

View File

@@ -0,0 +1,27 @@
<?php
namespace Illuminate\Contracts\Auth;
interface MustVerifyEmail
{
/**
* Determine if the user has verified their email address.
*
* @return bool
*/
public function hasVerifiedEmail();
/**
* Mark the given user's email as verified.
*
* @return bool
*/
public function markEmailAsVerified();
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification();
}

View File

@@ -7,7 +7,7 @@ interface Factory
/**
* Get a broadcaster implementation by name.
*
* @param string $name
* @param string|null $name
* @return void
*/
public function connection($name = null);

View File

@@ -2,14 +2,12 @@
namespace Illuminate\Contracts\Broadcasting;
use Illuminate\Broadcasting\Channel;
interface ShouldBroadcast
{
/**
* Get the channels the event should broadcast on.
*
* @return Channel|Channel[]
* @return \Illuminate\Broadcasting\Channel|\Illuminate\Broadcasting\Channel[]
*/
public function broadcastOn();
}

View File

@@ -21,6 +21,22 @@ interface Dispatcher
*/
public function dispatchNow($command, $handler = null);
/**
* Determine if the given command has a handler.
*
* @param mixed $command
* @return bool
*/
public function hasCommandHandler($command);
/**
* Retrieve the handler for a command.
*
* @param mixed $command
* @return bool|mixed
*/
public function getCommandHandler($command);
/**
* Set the pipes commands should be piped through before dispatching.
*
@@ -28,4 +44,12 @@ interface Dispatcher
* @return $this
*/
public function pipeThrough(array $pipes);
/**
* Map a command to a handler.
*
* @param array $map
* @return $this
*/
public function map(array $map);
}

View File

@@ -5,13 +5,14 @@ namespace Illuminate\Contracts\Console;
interface Application
{
/**
* Call a console application command.
* Run an Artisan console command by name.
*
* @param string $command
* @param array $parameters
* @param \Symfony\Component\Console\Output\OutputInterface|null $outputBuffer
* @return int
*/
public function call($command, array $parameters = []);
public function call($command, array $parameters = [], $outputBuffer = null);
/**
* Get the output from the last command.

View File

@@ -8,7 +8,7 @@ interface Kernel
* Handle an incoming console command.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Symfony\Component\Console\Output\OutputInterface|null $output
* @return int
*/
public function handle($input, $output = null);
@@ -18,9 +18,10 @@ interface Kernel
*
* @param string $command
* @param array $parameters
* @param \Symfony\Component\Console\Output\OutputInterface|null $outputBuffer
* @return int
*/
public function call($command, array $parameters = []);
public function call($command, array $parameters = [], $outputBuffer = null);
/**
* Queue an Artisan console command by name.

View File

@@ -93,7 +93,7 @@ interface Container extends ContainerInterface
/**
* Define a contextual binding.
*
* @param string $concrete
* @param string|array $concrete
* @return \Illuminate\Contracts\Container\ContextualBindingBuilder
*/
public function when($concrete);

View File

@@ -12,11 +12,13 @@ interface Factory
* @param int $minutes
* @param string $path
* @param string $domain
* @param bool $secure
* @param bool|null $secure
* @param bool $httpOnly
* @param bool $raw
* @param string|null $sameSite
* @return \Symfony\Component\HttpFoundation\Cookie
*/
public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = false, $httpOnly = true);
public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = null, $httpOnly = true, $raw = false, $sameSite = null);
/**
* Create a cookie that lasts "forever" (five years).
@@ -25,11 +27,13 @@ interface Factory
* @param string $value
* @param string $path
* @param string $domain
* @param bool $secure
* @param bool|null $secure
* @param bool $httpOnly
* @param bool $raw
* @param string|null $sameSite
* @return \Symfony\Component\HttpFoundation\Cookie
*/
public function forever($name, $value, $path = null, $domain = null, $secure = false, $httpOnly = true);
public function forever($name, $value, $path = null, $domain = null, $secure = null, $httpOnly = true, $raw = false, $sameSite = null);
/**
* Expire the given cookie.

View File

@@ -20,6 +20,13 @@ class ModelIdentifier
*/
public $id;
/**
* The relationships loaded on the model.
*
* @var array
*/
public $relations;
/**
* The connection name of the model.
*
@@ -32,13 +39,15 @@ class ModelIdentifier
*
* @param string $class
* @param mixed $id
* @param array $relations
* @param mixed $connection
* @return void
*/
public function __construct($class, $id, $connection)
public function __construct($class, $id, array $relations, $connection)
{
$this->id = $id;
$this->class = $class;
$this->relations = $relations;
$this->connection = $connection;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Illuminate\Contracts\Filesystem;
use Exception;
class FileExistsException extends Exception
{
//
}

View File

@@ -36,6 +36,16 @@ interface Filesystem
*/
public function get($path);
/**
* Get a resource to read the file.
*
* @param string $path
* @return resource|null The path resource or null on failure.
*
* @throws FileNotFoundException
*/
public function readStream($path);
/**
* Write the contents of a file.
*
@@ -46,6 +56,19 @@ interface Filesystem
*/
public function put($path, $contents, $options = []);
/**
* Write a new file using a stream.
*
* @param string $path
* @param resource $resource
* @param mixed $options
* @return bool
*
* @throws \InvalidArgumentException If $resource is not a file handle.
* @throws FileExistsException
*/
public function writeStream($path, $resource, array $options = []);
/**
* Get the visibility for the given path.
*
@@ -59,7 +82,7 @@ interface Filesystem
*
* @param string $path
* @param string $visibility
* @return void
* @return bool
*/
public function setVisibility($path, $visibility);

View File

@@ -28,12 +28,19 @@ interface Application extends Container
public function environment();
/**
* Determine if we are running in the console.
* Determine if the application is running in the console.
*
* @return bool
*/
public function runningInConsole();
/**
* Determine if the application is running unit tests.
*
* @return bool
*/
public function runningUnitTests();
/**
* Determine if the application is currently down for maintenance.
*
@@ -52,11 +59,10 @@ interface Application extends Container
* Register a service provider with the application.
*
* @param \Illuminate\Support\ServiceProvider|string $provider
* @param array $options
* @param bool $force
* @return \Illuminate\Support\ServiceProvider
*/
public function register($provider, $options = [], $force = false);
public function register($provider, $force = false);
/**
* Register a deferred provider and service.

View File

@@ -4,6 +4,14 @@ namespace Illuminate\Contracts\Hashing;
interface Hasher
{
/**
* Get information about the given hashed value.
*
* @param string $hashedValue
* @return array
*/
public function info($hashedValue);
/**
* Hash the given value.
*

View File

@@ -1,98 +0,0 @@
<?php
namespace Illuminate\Contracts\Logging;
interface Log
{
/**
* Log an alert message to the logs.
*
* @param string $message
* @param array $context
* @return void
*/
public function alert($message, array $context = []);
/**
* Log a critical message to the logs.
*
* @param string $message
* @param array $context
* @return void
*/
public function critical($message, array $context = []);
/**
* Log an error message to the logs.
*
* @param string $message
* @param array $context
* @return void
*/
public function error($message, array $context = []);
/**
* Log a warning message to the logs.
*
* @param string $message
* @param array $context
* @return void
*/
public function warning($message, array $context = []);
/**
* Log a notice to the logs.
*
* @param string $message
* @param array $context
* @return void
*/
public function notice($message, array $context = []);
/**
* Log an informational message to the logs.
*
* @param string $message
* @param array $context
* @return void
*/
public function info($message, array $context = []);
/**
* Log a debug message to the logs.
*
* @param string $message
* @param array $context
* @return void
*/
public function debug($message, array $context = []);
/**
* Log a message to the logs.
*
* @param string $level
* @param string $message
* @param array $context
* @return void
*/
public function log($level, $message, array $context = []);
/**
* Register a file log handler.
*
* @param string $path
* @param string $level
* @return void
*/
public function useFiles($path, $level = 'debug');
/**
* Register a daily file log handler.
*
* @param string $path
* @param int $days
* @param string $level
* @return void
*/
public function useDailyFiles($path, $days = 0, $level = 'debug');
}

View File

@@ -7,7 +7,7 @@ interface MailQueue
/**
* Queue a new e-mail message for sending.
*
* @param string|array|MailableContract $view
* @param string|array|\Illuminate\Contracts\Mail\Mailable $view
* @param string $queue
* @return mixed
*/
@@ -17,7 +17,7 @@ interface MailQueue
* Queue a new e-mail message for sending after (n) seconds.
*
* @param \DateTimeInterface|\DateInterval|int $delay
* @param string|array|MailableContract $view
* @param string|array|\Illuminate\Contracts\Mail\Mailable $view
* @param string $queue
* @return mixed
*/

View File

@@ -32,7 +32,7 @@ interface Mailer
/**
* Send a new message using a view.
*
* @param string|array|MailableContract $view
* @param string|array|\Illuminate\Contracts\Mail\Mailable $view
* @param array $data
* @param \Closure|string $callback
* @return void

View File

@@ -4,6 +4,20 @@ namespace Illuminate\Contracts\Queue;
interface Job
{
/**
* Get the job identifier.
*
* @return string
*/
public function getJobId();
/**
* Get the decoded body of the job.
*
* @return array
*/
public function payload();
/**
* Fire the job.
*
@@ -15,7 +29,7 @@ interface Job
* Release the job back into the queue.
*
* @param int $delay
* @return mixed
* @return void
*/
public function release($delay = 0);

View File

@@ -18,6 +18,13 @@ interface QueueableCollection
*/
public function getQueueableIds();
/**
* Get the relationships of the entities being queued.
*
* @return array
*/
public function getQueueableRelations();
/**
* Get the connection of the entities being queued.
*

View File

@@ -11,6 +11,13 @@ interface QueueableEntity
*/
public function getQueueableId();
/**
* Get the relationships for the entity.
*
* @return array
*/
public function getQueueableRelations();
/**
* Get the connection of the entity.
*

View File

@@ -0,0 +1,35 @@
<?php
namespace Illuminate\Contracts\Redis;
use Closure;
interface Connection
{
/**
* Subscribe to a set of given channels for messages.
*
* @param array|string $channels
* @param \Closure $callback
* @return void
*/
public function subscribe($channels, Closure $callback);
/**
* Subscribe to a set of given channels with wildcards.
*
* @param array|string $channels
* @param \Closure $callback
* @return void
*/
public function psubscribe($channels, Closure $callback);
/**
* Run a command against the Redis database.
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public function command($method, array $parameters = []);
}

View File

@@ -5,7 +5,7 @@ namespace Illuminate\Contracts\Routing;
interface ResponseFactory
{
/**
* Return a new response from the application.
* Create a new response instance.
*
* @param string $content
* @param int $status
@@ -15,7 +15,16 @@ interface ResponseFactory
public function make($content = '', $status = 200, array $headers = []);
/**
* Return a new view response from the application.
* Create a new "no content" response.
*
* @param int $status
* @param array $headers
* @return \Illuminate\Http\Response
*/
public function noContent($status = 204, array $headers = []);
/**
* Create a new response for a given view.
*
* @param string $view
* @param array $data
@@ -26,7 +35,7 @@ interface ResponseFactory
public function view($view, $data = [], $status = 200, array $headers = []);
/**
* Return a new JSON response from the application.
* Create a new JSON response instance.
*
* @param string|array $data
* @param int $status
@@ -37,7 +46,7 @@ interface ResponseFactory
public function json($data = [], $status = 200, array $headers = [], $options = 0);
/**
* Return a new JSONP response from the application.
* Create a new JSONP response instance.
*
* @param string $callback
* @param string|array $data
@@ -49,7 +58,7 @@ interface ResponseFactory
public function jsonp($callback, $data = [], $status = 200, array $headers = [], $options = 0);
/**
* Return a new streamed response from the application.
* Create a new streamed response instance.
*
* @param \Closure $callback
* @param int $status
@@ -58,11 +67,22 @@ interface ResponseFactory
*/
public function stream($callback, $status = 200, array $headers = []);
/**
* Create a new streamed response instance as a file download.
*
* @param \Closure $callback
* @param string|null $name
* @param array $headers
* @param string|null $disposition
* @return \Symfony\Component\HttpFoundation\StreamedResponse
*/
public function streamDownload($callback, $name = null, array $headers = [], $disposition = 'attachment');
/**
* Create a new file download response.
*
* @param \SplFileInfo|string $file
* @param string $name
* @param string|null $name
* @param array $headers
* @param string|null $disposition
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse

Some files were not shown because too many files have changed in this diff Show More