Skip to content

Commit

Permalink
Merge branch 'laravel:10.x' into 10.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunate authored Jan 10, 2024
2 parents 596e9f5 + 8f48538 commit e50cbcc
Show file tree
Hide file tree
Showing 144 changed files with 3,218 additions and 525 deletions.
160 changes: 160 additions & 0 deletions .github/workflows/queues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: queues

on:
push:
branches:
- master
- '*.x'
pull_request:

jobs:
sync:
runs-on: ubuntu-22.04

strategy:
fail-fast: true

name: Sync Driver

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Queue
env:
QUEUE_CONNECTION: sync

database:
runs-on: ubuntu-22.04

strategy:
fail-fast: true

name: Database Driver

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Queue
env:
DB_CONNECTION: testing
QUEUE_CONNECTION: database

redis:
runs-on: ubuntu-22.04

services:
redis:
image: redis:7.0
ports:
- 6379:6379
options: --entrypoint redis-server

strategy:
fail-fast: true

name: Redis Driver

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Queue
env:
QUEUE_CONNECTION: redis

beanstalkd:
runs-on: ubuntu-22.04

name: Beanstalkd Driver

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/checkout@v3
- name: Download & Extract beanstalkd
run: curl -L https://github.com/beanstalkd/beanstalkd/archive/refs/tags/v1.13.tar.gz | tar xz
- name: Make beanstalkd
run: make
working-directory: beanstalkd-1.13

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, pdo_mysql, :php-psr
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v2
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Daemonize beanstalkd
run: ./beanstalkd-1.13/beanstalkd &

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Queue
env:
QUEUE_CONNECTION: beanstalkd
129 changes: 128 additions & 1 deletion CHANGELOG.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"league/flysystem-sftp-v3": "^3.0",
"mockery/mockery": "^1.5.1",
"nyholm/psr7": "^1.2",
"orchestra/testbench-core": "^8.15.1",
"orchestra/testbench-core": "^8.18",
"pda/pheanstalk": "^4.0",
"phpstan/phpstan": "^1.4.7",
"phpunit/phpunit": "^10.0.7",
Expand All @@ -119,12 +119,15 @@
"psr/simple-cache-implementation": "1.0|2.0|3.0"
},
"conflict": {
"carbonphp/carbon-doctrine-types": ">=3.0",
"doctrine/dbal": ">=4.0",
"tightenco/collect": "<5.5.33"
},
"autoload": {
"files": [
"src/Illuminate/Collections/helpers.php",
"src/Illuminate/Events/functions.php",
"src/Illuminate/Filesystem/functions.php",
"src/Illuminate/Foundation/helpers.php",
"src/Illuminate/Support/helpers.php"
],
Expand Down
16 changes: 8 additions & 8 deletions src/Illuminate/Auth/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,27 +318,27 @@ public function after(callable $callback)
}

/**
* Determine if the given ability should be granted for the current user.
* Determine if all of the given abilities should be granted for the current user.
*
* @param string $ability
* @param iterable|string $abilities
* @param array|mixed $arguments
* @return bool
*/
public function allows($ability, $arguments = [])
public function allows($abilities, $arguments = [])
{
return $this->check($ability, $arguments);
return $this->check($abilities, $arguments);
}

/**
* Determine if the given ability should be denied for the current user.
* Determine if any of the given abilities should be denied for the current user.
*
* @param string $ability
* @param iterable|string $abilities
* @param array|mixed $arguments
* @return bool
*/
public function denies($ability, $arguments = [])
public function denies($abilities, $arguments = [])
{
return ! $this->allows($ability, $arguments);
return ! $this->allows($abilities, $arguments);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions src/Illuminate/Bus/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ public function recordSuccessfulJob(string $jobId)
{
$counts = $this->decrementPendingJobs($jobId);

if ($this->hasProgressCallbacks()) {
$batch = $this->fresh();

collect($this->options['progress'])->each(function ($handler) use ($batch) {
$this->invokeHandlerCallback($handler, $batch);
});
}

if ($counts->pendingJobs === 0) {
$this->repository->markAsFinished($this->id);
}
Expand Down Expand Up @@ -283,6 +291,16 @@ public function finished()
return ! is_null($this->finishedAt);
}

/**
* Determine if the batch has "progress" callbacks.
*
* @return bool
*/
public function hasProgressCallbacks()
{
return isset($this->options['progress']) && ! empty($this->options['progress']);
}

/**
* Determine if the batch has "success" callbacks.
*
Expand Down Expand Up @@ -328,6 +346,14 @@ public function recordFailedJob(string $jobId, $e)
$this->cancel();
}

if ($this->hasProgressCallbacks() && $this->allowsFailures()) {
$batch = $this->fresh();

collect($this->options['progress'])->each(function ($handler) use ($batch, $e) {
$this->invokeHandlerCallback($handler, $batch, $e);
});
}

if ($counts->failedJobs === 1 && $this->hasCatchCallbacks()) {
$batch = $this->fresh();

Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Bus/DynamoBatchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function get($limit = 50, $before = null)
':id' => array_filter(['S' => $before]),
]),
'Limit' => $limit,
'ScanIndexForward' => false,
]);

return array_map(
Expand Down
28 changes: 28 additions & 0 deletions src/Illuminate/Bus/PendingBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\Conditionable;
use Laravel\SerializableClosure\SerializableClosure;
use Throwable;

class PendingBatch
{
use Conditionable;

/**
* The IoC container instance.
*
Expand Down Expand Up @@ -71,6 +74,31 @@ public function add($jobs)
return $this;
}

/**
* Add a callback to be executed after a job in the batch have executed successfully.
*
* @param callable $callback
* @return $this
*/
public function progress($callback)
{
$this->options['progress'][] = $callback instanceof Closure
? new SerializableClosure($callback)
: $callback;

return $this;
}

/**
* Get the "progress" callbacks that have been registered with the pending batch.
*
* @return array
*/
public function progressCallbacks()
{
return $this->options['progress'] ?? [];
}

/**
* Add a callback to be executed after all jobs in the batch have executed successfully.
*
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Cache/ArrayLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public function release()
*/
protected function getCurrentOwner()
{
if (! $this->exists()) {
return null;
}

return $this->store->locks[$this->name]['owner'];
}

Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Cache/DynamoDbStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function add($key, $value, $seconds)
],
'ExpressionAttributeValues' => [
':now' => [
'N' => (string) Carbon::now()->getTimestamp(),
'N' => (string) $this->currentTime(),
],
],
]);
Expand Down Expand Up @@ -326,7 +326,7 @@ public function increment($key, $value = 1)
],
'ExpressionAttributeValues' => [
':now' => [
'N' => (string) Carbon::now()->getTimestamp(),
'N' => (string) $this->currentTime(),
],
':amount' => [
'N' => (string) $value,
Expand Down Expand Up @@ -371,7 +371,7 @@ public function decrement($key, $value = 1)
],
'ExpressionAttributeValues' => [
':now' => [
'N' => (string) Carbon::now()->getTimestamp(),
'N' => (string) $this->currentTime(),
],
':amount' => [
'N' => (string) $value,
Expand Down Expand Up @@ -469,7 +469,7 @@ protected function toTimestamp($seconds)
{
return $seconds > 0
? $this->availableAt($seconds)
: Carbon::now()->getTimestamp();
: $this->currentTime();
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,11 @@ protected function getPayload($key)
// just return null. Otherwise, we'll get the contents of the file and get
// the expiration UNIX timestamps from the start of the file's contents.
try {
$expire = substr(
$contents = $this->files->get($path, true), 0, 10
);
if (is_null($contents = $this->files->get($path, true))) {
return $this->emptyPayload();
}

$expire = substr($contents, 0, 10);
} catch (Exception) {
return $this->emptyPayload();
}
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,7 @@ public static function keyBy($array, $keyBy)
*/
public static function prependKeysWith($array, $prependWith)
{
return Collection::make($array)->mapWithKeys(function ($item, $key) use ($prependWith) {
return [$prependWith.$key => $item];
})->all();
return static::mapWithKeys($array, fn ($item, $key) => [$prependWith.$key => $item]);
}

/**
Expand Down
Loading

0 comments on commit e50cbcc

Please sign in to comment.