Skip to content

Commit

Permalink
Merge tag 'v11.42.0'
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Feb 12, 2025
2 parents 8eda1f4 + 3d76089 commit aef71d6
Show file tree
Hide file tree
Showing 15 changed files with 488 additions and 136 deletions.
6 changes: 3 additions & 3 deletions Concerns/BuildsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function eachById(callable $callback, $count = 1000, $column = null, $ali
* Query lazily, by chunks of the given size.
*
* @param int $chunkSize
* @return \Illuminate\Support\LazyCollection
* @return \Illuminate\Support\LazyCollection<int, TValue>
*
* @throws \InvalidArgumentException
*/
Expand Down Expand Up @@ -282,7 +282,7 @@ public function lazy($chunkSize = 1000)
* @param int $chunkSize
* @param string|null $column
* @param string|null $alias
* @return \Illuminate\Support\LazyCollection
* @return \Illuminate\Support\LazyCollection<int, TValue>
*
* @throws \InvalidArgumentException
*/
Expand All @@ -297,7 +297,7 @@ public function lazyById($chunkSize = 1000, $column = null, $alias = null)
* @param int $chunkSize
* @param string|null $column
* @param string|null $alias
* @return \Illuminate\Support\LazyCollection
* @return \Illuminate\Support\LazyCollection<int, TValue>
*
* @throws \InvalidArgumentException
*/
Expand Down
250 changes: 250 additions & 0 deletions Concerns/BuildsWhereDateClauses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<?php

namespace Illuminate\Database\Concerns;

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

trait BuildsWhereDateClauses
{
/**
* Add a where clause to determine if a "date" column is in the past to the query.
*
* @param array|string $columns
* @return $this
*/
public function wherePast($columns)
{
return $this->wherePastOrFuture($columns, '<', 'and');
}

/**
* Add a where clause to determine if a "date" column is in the past or now to the query.
*
* @param array|string $columns
* @return $this
*/
public function whereNowOrPast($columns)
{
return $this->wherePastOrFuture($columns, '<=', 'and');
}

/**
* Add an "or where" clause to determine if a "date" column is in the past to the query.
*
* @param array|string $columns
* @return $this
*/
public function orWherePast($columns)
{
return $this->wherePastOrFuture($columns, '<', 'or');
}

/**
* Add a where clause to determine if a "date" column is in the past or now to the query.
*
* @param array|string $columns
* @return $this
*/
public function orWhereNowOrPast($columns)
{
return $this->wherePastOrFuture($columns, '<=', 'or');
}

/**
* Add a where clause to determine if a "date" column is in the future to the query.
*
* @param array|string $columns
* @return $this
*/
public function whereFuture($columns)
{
return $this->wherePastOrFuture($columns, '>', 'and');
}

/**
* Add a where clause to determine if a "date" column is in the future or now to the query.
*
* @param array|string $columns
* @return $this
*/
public function whereNowOrFuture($columns)
{
return $this->wherePastOrFuture($columns, '>=', 'and');
}

/**
* Add an "or where" clause to determine if a "date" column is in the future to the query.
*
* @param array|string $columns
* @return $this
*/
public function orWhereFuture($columns)
{
return $this->wherePastOrFuture($columns, '>', 'or');
}

/**
* Add an "or where" clause to determine if a "date" column is in the future or now to the query.
*
* @param array|string $columns
* @return $this
*/
public function orWhereNowOrFuture($columns)
{
return $this->wherePastOrFuture($columns, '>=', 'or');
}

/**
* Add an "where" clause to determine if a "date" column is in the past or future.
*
* @param array|string $columns
* @return $this
*/
protected function wherePastOrFuture($columns, $operator, $boolean)
{
$type = 'Basic';
$value = Carbon::now();

foreach (Arr::wrap($columns) as $column) {
$this->wheres[] = compact('type', 'column', 'boolean', 'operator', 'value');

$this->addBinding($value);
}

return $this;
}

/**
* Add a "where date" clause to determine if a "date" column is today to the query.
*
* @param array|string $columns
* @param string $boolean
* @return $this
*/
public function whereToday($columns, $boolean = 'and')
{
return $this->whereTodayBeforeOrAfter($columns, '=', $boolean);
}

/**
* Add a "where date" clause to determine if a "date" column is before today.
*
* @param array|string $columns
* @return $this
*/
public function whereBeforeToday($columns)
{
return $this->whereTodayBeforeOrAfter($columns, '<', 'and');
}

/**
* Add a "where date" clause to determine if a "date" column is today or before to the query.
*
* @param array|string $columns
* @return $this
*/
public function whereTodayOrBefore($columns)
{
return $this->whereTodayBeforeOrAfter($columns, '<=', 'and');
}

/**
* Add a "where date" clause to determine if a "date" column is after today.
*
* @param array|string $columns
* @return $this
*/
public function whereAfterToday($columns)
{
return $this->whereTodayBeforeOrAfter($columns, '>', 'and');
}

/**
* Add a "where date" clause to determine if a "date" column is today or after to the query.
*
* @param array|string $columns
* @return $this
*/
public function whereTodayOrAfter($columns)
{
return $this->whereTodayBeforeOrAfter($columns, '>=', 'and');
}

/**
* Add an "or where date" clause to determine if a "date" column is today to the query.
*
* @param array|string $columns
* @return $this
*/
public function orWhereToday($columns)
{
return $this->whereToday($columns, 'or');
}

/**
* Add an "or where date" clause to determine if a "date" column is before today.
*
* @param array|string $columns
* @return $this
*/
public function orWhereBeforeToday($columns)
{
return $this->whereTodayBeforeOrAfter($columns, '<', 'or');
}

/**
* Add an "or where date" clause to determine if a "date" column is today or before to the query.
*
* @param array|string $columns
* @param string $boolean
* @return $this
*/
public function orWhereTodayOrBefore($columns)
{
return $this->whereTodayBeforeOrAfter($columns, '<=', 'or');
}

/**
* Add an "or where date" clause to determine if a "date" column is after today.
*
* @param array|string $columns
* @param string $boolean
* @return $this
*/
public function orWhereAfterToday($columns)
{
return $this->whereTodayBeforeOrAfter($columns, '>', 'or');
}

/**
* Add an "or where date" clause to determine if a "date" column is today or after to the query.
*
* @param array|string $columns
* @param string $boolean
* @return $this
*/
public function orWhereTodayOrAfter($columns)
{
return $this->whereTodayBeforeOrAfter($columns, '>=', 'or');
}

/**
* Add a "where date" clause to determine if a "date" column is today or after to the query.
*
* @param array|string $columns
* @param string $operator
* @param string $boolean
* @return $this
*/
protected function whereTodayBeforeOrAfter($columns, $operator, $boolean)
{
$value = Carbon::today()->format('Y-m-d');

foreach (Arr::wrap($columns) as $column) {
$this->addDateBasedWhere('Date', $column, $operator, $value, $boolean);
}

return $this;
}
}
2 changes: 1 addition & 1 deletion Connectors/SQLiteConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function connect(array $config)
return $this->createConnection('sqlite:'.$config['database'], $config, $options);
}

$path = realpath($config['database']);
$path = realpath($config['database']) ?: realpath(base_path($config['database']));

// Here we'll verify that the SQLite database exists before going any further
// as the developer probably wants to know if the database exists and this
Expand Down
23 changes: 16 additions & 7 deletions Console/DbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Illuminate\Support\ConfigurationUrlParser;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use UnexpectedValueException;

Expand Down Expand Up @@ -44,13 +45,21 @@ public function handle()
return Command::FAILURE;
}

(new Process(
array_merge([$this->getCommand($connection)], $this->commandArguments($connection)),
null,
$this->commandEnvironment($connection)
))->setTimeout(null)->setTty(true)->mustRun(function ($type, $buffer) {
$this->output->write($buffer);
});
try {
(new Process(
array_merge([$command = $this->getCommand($connection)], $this->commandArguments($connection)),
null,
$this->commandEnvironment($connection)
))->setTimeout(null)->setTty(true)->mustRun(function ($type, $buffer) {
$this->output->write($buffer);
});
} catch (ProcessFailedException $e) {
throw_unless($e->getProcess()->getExitCode() === 127, $e);

$this->error("{$command} not found in path.");

return Command::FAILURE;
}

return 0;
}
Expand Down
26 changes: 26 additions & 0 deletions Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ class Builder implements BuilderContract
*/
protected $afterQueryCallbacks = [];

/**
* The callbacks that should be invoked on clone.
*
* @var array
*/
protected $onCloneCallbacks = [];

/**
* Create a new Eloquent query builder instance.
*
Expand Down Expand Up @@ -317,6 +324,8 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
if ($column instanceof Closure && is_null($operator)) {
$column($query = $this->model->newQueryWithoutRelationships());

$this->eagerLoad = array_merge($this->eagerLoad, $query->getEagerLoads());

$this->query->addNestedWhereQuery($query->getQuery(), $boolean);
} else {
$this->query->where(...func_get_args());
Expand Down Expand Up @@ -2188,6 +2197,19 @@ public function clone()
return clone $this;
}

/**
* Register a closure to be invoked on a clone.
*
* @param \Closure $callback
* @return $this
*/
public function onClone(Closure $callback)
{
$this->onCloneCallbacks[] = $callback;

return $this;
}

/**
* Force a clone of the underlying query builder when cloning.
*
Expand All @@ -2196,5 +2218,9 @@ public function clone()
public function __clone()
{
$this->query = clone $this->query;

foreach ($this->onCloneCallbacks as $onCloneCallback) {
$onCloneCallback($this);
}
}
}
2 changes: 1 addition & 1 deletion Eloquent/Casts/AsEnumArrayObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AsEnumArrayObject implements Castable
/**
* Get the caster class to use when casting from / to this cast target.
*
* @template TEnum
* @template TEnum of \UnitEnum
*
* @param array{class-string<TEnum>} $arguments
* @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Database\Eloquent\Casts\ArrayObject<array-key, TEnum>, iterable<TEnum>>
Expand Down
2 changes: 1 addition & 1 deletion Eloquent/Casts/AsEnumCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AsEnumCollection implements Castable
/**
* Get the caster class to use when casting from / to this cast target.
*
* @template TEnum of \UnitEnum|\BackedEnum
* @template TEnum of \UnitEnum
*
* @param array{class-string<TEnum>} $arguments
* @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\Collection<array-key, TEnum>, iterable<TEnum>>
Expand Down
Loading

0 comments on commit aef71d6

Please sign in to comment.