Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Use Carbon instead of time() #15544

Merged
merged 1 commit into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Illuminate/Cache/DatabaseStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Exception;
use Carbon\Carbon;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;
Expand Down Expand Up @@ -77,7 +78,7 @@ public function get($key)
$cache = (object) $cache;
}

if (time() >= $cache->expiration) {
if (Carbon::now()->timestamp >= $cache->expiration) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use getTime() function here?

$this->forget($key);

return;
Expand Down Expand Up @@ -186,7 +187,7 @@ protected function incrementOrDecrement($key, $value, Closure $callback)
*/
protected function getTime()
{
return time();
return Carbon::now()->timestamp;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Cache;

use Exception;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Contracts\Cache\Store;
Expand Down Expand Up @@ -73,7 +74,7 @@ protected function getPayload($key)
// If the current time is greater than expiration timestamps we will delete
// the file and return null. This helps clean up the old files and keeps
// this directory much cleaner for us as old files aren't hanging out.
if (time() >= $expire) {
if (Carbon::now()->timestamp >= $expire) {
$this->forget($key);

return ['data' => null, 'time' => null];
Expand All @@ -84,7 +85,7 @@ protected function getPayload($key)
// Next, we'll extract the number of minutes that are remaining for a cache
// so that we can properly retain the time for things like the increment
// operation that may be performed on the cache.
$time = ($expire - time()) / 60;
$time = ($expire - Carbon::now()->timestamp) / 60;

return compact('data', 'time');
}
Expand Down Expand Up @@ -213,7 +214,7 @@ protected function path($key)
*/
protected function expiration($minutes)
{
$time = time() + (int) ($minutes * 60);
$time = Carbon::now()->timestamp + (int) ($minutes * 60);

if ($minutes === 0 || $time > 9999999999) {
return 9999999999;
Expand Down
5 changes: 3 additions & 2 deletions src/Illuminate/Cache/RateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Cache;

use Carbon\Carbon;
use Illuminate\Contracts\Cache\Repository as Cache;

class RateLimiter
Expand Down Expand Up @@ -39,7 +40,7 @@ public function tooManyAttempts($key, $maxAttempts, $decayMinutes = 1)
}

if ($this->attempts($key) > $maxAttempts) {
$this->cache->add($key.':lockout', time() + ($decayMinutes * 60), $decayMinutes);
$this->cache->add($key.':lockout', Carbon::now()->timestamp + ($decayMinutes * 60), $decayMinutes);

$this->resetAttempts($key);

Expand Down Expand Up @@ -120,6 +121,6 @@ public function clear($key)
*/
public function availableIn($key)
{
return $this->cache->get($key.':lockout') - time();
return $this->cache->get($key.':lockout') - Carbon::now()->timestamp;
}
}
3 changes: 2 additions & 1 deletion src/Illuminate/Cookie/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Cookie;

use Carbon\Carbon;
use Illuminate\Support\Arr;
use Symfony\Component\HttpFoundation\Cookie;
use Illuminate\Contracts\Cookie\QueueingFactory as JarContract;
Expand Down Expand Up @@ -52,7 +53,7 @@ public function make($name, $value, $minutes = 0, $path = null, $domain = null,
{
list($path, $domain, $secure) = $this->getPathAndDomain($path, $domain, $secure);

$time = ($minutes == 0) ? 0 : time() + ($minutes * 60);
$time = ($minutes == 0) ? 0 : Carbon::now()->timestamp + ($minutes * 60);

return new Cookie($name, $value, $time, $path, $domain, $secure, $httpOnly);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/Console/DownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Foundation\Console;

use Carbon\Carbon;
use Illuminate\Console\Command;

class DownCommand extends Command
Expand Down Expand Up @@ -44,7 +45,7 @@ public function fire()
protected function getDownFilePayload()
{
return [
'time' => time(),
'time' => Carbon::now()->timestamp,
'message' => $this->option('message'),
'retry' => $this->getRetryTime(),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Foundation\Http\Middleware;

use Closure;
use Carbon\Carbon;
use Illuminate\Foundation\Application;
use Symfony\Component\HttpFoundation\Cookie;
use Illuminate\Contracts\Encryption\Encrypter;
Expand Down Expand Up @@ -134,7 +135,7 @@ protected function addCookieToResponse($request, $response)

$response->headers->setCookie(
new Cookie(
'XSRF-TOKEN', $request->session()->token(), time() + 60 * $config['lifetime'],
'XSRF-TOKEN', $request->session()->token(), Carbon::now()->timestamp + 60 * $config['lifetime'],
$config['path'], $config['domain'], $config['secure'], false
)
);
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Queue/Console/RestartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Queue\Console;

use Carbon\Carbon;
use Illuminate\Console\Command;

class RestartCommand extends Command
Expand All @@ -27,7 +28,7 @@ class RestartCommand extends Command
*/
public function fire()
{
$this->laravel['cache']->forever('illuminate:queue:restart', time());
$this->laravel['cache']->forever('illuminate:queue:restart', Carbon::now()->timestamp);

$this->info('Broadcasting queue restart signal.');
}
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Queue/Jobs/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Queue\Jobs;

use DateTime;
use Carbon\Carbon;
use Illuminate\Support\Arr;

abstract class Job
Expand Down Expand Up @@ -188,7 +189,7 @@ protected function getSeconds($delay)
*/
protected function getTime()
{
return time();
return Carbon::now()->timestamp;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Queue;

use DateTime;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use InvalidArgumentException;
use Illuminate\Container\Container;
Expand Down Expand Up @@ -153,7 +154,7 @@ protected function getSeconds($delay)
*/
protected function getTime()
{
return time();
return Carbon::now()->timestamp;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Routing/Middleware/ThrottleRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Routing\Middleware;

use Closure;
use Carbon\Carbon;
use Illuminate\Cache\RateLimiter;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -102,7 +103,7 @@ protected function addHeaders(Response $response, $maxAttempts, $remainingAttemp

if (! is_null($retryAfter)) {
$headers['Retry-After'] = $retryAfter;
$headers['X-RateLimit-Reset'] = time() + $retryAfter;
$headers['X-RateLimit-Reset'] = Carbon::now()->timestamp + $retryAfter;
}

$response->headers->add($headers);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Session/CookieSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function read($sessionId)
$value = $this->request->cookies->get($sessionId) ?: '';

if (! is_null($decoded = json_decode($value, true)) && is_array($decoded)) {
if (isset($decoded['expires']) && time() <= $decoded['expires']) {
if (isset($decoded['expires']) && Carbon::now()->timestamp <= $decoded['expires']) {
return $decoded['data'];
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Session/DatabaseSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function write($sessionId, $data)
*/
protected function getDefaultPayload($data)
{
$payload = ['payload' => base64_encode($data), 'last_activity' => time()];
$payload = ['payload' => base64_encode($data), 'last_activity' => Carbon::now()->timestamp];

if (! $container = $this->container) {
return $payload;
Expand Down Expand Up @@ -164,7 +164,7 @@ public function destroy($sessionId)
*/
public function gc($lifetime)
{
$this->getQuery()->where('last_activity', '<=', time() - $lifetime)->delete();
$this->getQuery()->where('last_activity', '<=', Carbon::now()->timestamp - $lifetime)->delete();
}

/**
Expand Down