Skip to content

Commit 82cae41

Browse files
committed
Merge branch '8.x' into 9.x
# Conflicts: # src/Illuminate/Foundation/Application.php
2 parents 0a4539c + 8091f07 commit 82cae41

File tree

14 files changed

+338
-54
lines changed

14 files changed

+338
-54
lines changed

src/Illuminate/Bus/PendingBatch.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,20 @@ public function queue()
226226
return $this->options['queue'] ?? null;
227227
}
228228

229+
/**
230+
* Add additional data into the batch's options array.
231+
*
232+
* @param string $key
233+
* @param mixed $value
234+
* @return $this
235+
*/
236+
public function withOption(string $key, $value)
237+
{
238+
$this->options[$key] = $value;
239+
240+
return $this;
241+
}
242+
229243
/**
230244
* Dispatch the batch.
231245
*

src/Illuminate/Database/Events/MigrationsEnded.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Illuminate\Database\Events;
44

5-
use Illuminate\Contracts\Database\Events\MigrationEvent as MigrationEventContract;
6-
7-
class MigrationsEnded implements MigrationEventContract
5+
class MigrationsEnded extends MigrationsEvent
86
{
97
//
108
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Illuminate\Database\Events;
4+
5+
use Illuminate\Contracts\Database\Events\MigrationEvent as MigrationEventContract;
6+
7+
abstract class MigrationsEvent implements MigrationEventContract
8+
{
9+
/**
10+
* The migration method that was invoked.
11+
*
12+
* @var string
13+
*/
14+
public $method;
15+
16+
/**
17+
* Create a new event instance.
18+
*
19+
* @param string $method
20+
* @return void
21+
*/
22+
public function __construct($method)
23+
{
24+
$this->method = $method;
25+
}
26+
}

src/Illuminate/Database/Events/MigrationsStarted.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace Illuminate\Database\Events;
44

5-
use Illuminate\Contracts\Database\Events\MigrationEvent as MigrationEventContract;
6-
7-
class MigrationsStarted implements MigrationEventContract
5+
class MigrationsStarted extends MigrationsEvent
86
{
97
//
108
}

src/Illuminate/Database/Migrations/Migrator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function runPending(array $migrations, array $options = [])
158158

159159
$step = $options['step'] ?? false;
160160

161-
$this->fireMigrationEvent(new MigrationsStarted);
161+
$this->fireMigrationEvent(new MigrationsStarted('up'));
162162

163163
// Once we have the array of migrations, we will spin through them and run the
164164
// migrations "up" so the changes are made to the databases. We'll then log
@@ -171,7 +171,7 @@ public function runPending(array $migrations, array $options = [])
171171
}
172172
}
173173

174-
$this->fireMigrationEvent(new MigrationsEnded);
174+
$this->fireMigrationEvent(new MigrationsEnded('up'));
175175
}
176176

177177
/**
@@ -265,7 +265,7 @@ protected function rollbackMigrations(array $migrations, $paths, array $options)
265265

266266
$this->requireFiles($files = $this->getMigrationFiles($paths));
267267

268-
$this->fireMigrationEvent(new MigrationsStarted);
268+
$this->fireMigrationEvent(new MigrationsStarted('down'));
269269

270270
// Next we will run through all of the migrations and call the "down" method
271271
// which will reverse each migration in order. This getLast method on the
@@ -287,7 +287,7 @@ protected function rollbackMigrations(array $migrations, $paths, array $options)
287287
);
288288
}
289289

290-
$this->fireMigrationEvent(new MigrationsEnded);
290+
$this->fireMigrationEvent(new MigrationsEnded('down'));
291291

292292
return $rolledBack;
293293
}

src/Illuminate/Database/Schema/Builder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Database\Schema;
44

55
use Closure;
6+
use Illuminate\Container\Container;
67
use Illuminate\Database\Connection;
78
use InvalidArgumentException;
89
use LogicException;
@@ -380,7 +381,7 @@ protected function createBlueprint($table, Closure $callback = null)
380381
return call_user_func($this->resolver, $table, $callback, $prefix);
381382
}
382383

383-
return new Blueprint($table, $callback, $prefix);
384+
return Container::getInstance()->make(Blueprint::class, compact('table', 'callback', 'prefix'));
384385
}
385386

386387
/**

src/Illuminate/Log/LogManager.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ public function driver($driver = null)
112112
return $this->get($this->parseDriver($driver));
113113
}
114114

115-
/**
116-
* @return array
117-
*/
118-
public function getChannels()
119-
{
120-
return $this->channels;
121-
}
122-
123115
/**
124116
* Attempt to get the log from the local cache.
125117
*
@@ -534,6 +526,16 @@ protected function parseDriver($driver)
534526
return $driver;
535527
}
536528

529+
/**
530+
* Get all of the resolved log channels.
531+
*
532+
* @return array
533+
*/
534+
public function getChannels()
535+
{
536+
return $this->channels;
537+
}
538+
537539
/**
538540
* System is unusable.
539541
*

src/Illuminate/Support/Pluralizer.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
namespace Illuminate\Support;
44

5-
use Doctrine\Inflector\CachedWordInflector;
65
use Doctrine\Inflector\Inflector;
7-
use Doctrine\Inflector\Rules\English;
8-
use Doctrine\Inflector\RulesetInflector;
6+
use Doctrine\Inflector\InflectorFactory;
97

108
class Pluralizer
119
{
@@ -136,14 +134,7 @@ public static function inflector()
136134
static $inflector;
137135

138136
if (is_null($inflector)) {
139-
$inflector = new Inflector(
140-
new CachedWordInflector(new RulesetInflector(
141-
English\Rules::getSingularRuleset()
142-
)),
143-
new CachedWordInflector(new RulesetInflector(
144-
English\Rules::getPluralRuleset()
145-
))
146-
);
137+
$inflector = InflectorFactory::createForLanguage('english')->build();
147138
}
148139

149140
return $inflector;

src/Illuminate/Support/Stringable.php

Lines changed: 91 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -775,17 +775,7 @@ public function ucfirst()
775775
*/
776776
public function whenContains($needles, $callback, $default = null)
777777
{
778-
if ($this->contains($needles)) {
779-
$result = $callback($this);
780-
781-
return $result ?? $this;
782-
} elseif ($default) {
783-
$result = $default($this);
784-
785-
return $result ?? $this;
786-
}
787-
788-
return $this;
778+
return $this->when($this->contains($needles), $callback, $default);
789779
}
790780

791781
/**
@@ -798,17 +788,7 @@ public function whenContains($needles, $callback, $default = null)
798788
*/
799789
public function whenContainsAll(array $needles, $callback, $default = null)
800790
{
801-
if ($this->containsAll($needles)) {
802-
$result = $callback($this);
803-
804-
return $result ?? $this;
805-
} elseif ($default) {
806-
$result = $default($this);
807-
808-
return $result ?? $this;
809-
}
810-
811-
return $this;
791+
return $this->when($this->containsAll($needles), $callback, $default);
812792
}
813793

814794
/**
@@ -845,6 +825,95 @@ public function whenNotEmpty($callback)
845825
return $this;
846826
}
847827

828+
/**
829+
* Execute the given callback if the string ends with a given substring.
830+
*
831+
* @param string|array $needles
832+
* @param callable $callback
833+
* @param callable|null $default
834+
* @return static
835+
*/
836+
public function whenEndsWith($needles, $callback, $default = null)
837+
{
838+
return $this->when($this->endsWith($needles), $callback, $default);
839+
}
840+
841+
/**
842+
* Execute the given callback if the string is an exact match with the given value.
843+
*
844+
* @param string $value
845+
* @param callable $callback
846+
* @param callable|null $default
847+
* @return static
848+
*/
849+
public function whenExactly($value, $callback, $default = null)
850+
{
851+
return $this->when($this->exactly($value), $callback, $default);
852+
}
853+
854+
/**
855+
* Execute the given callback if the string matches a given pattern.
856+
*
857+
* @param string|array $pattern
858+
* @param callable $callback
859+
* @param callable|null $default
860+
* @return static
861+
*/
862+
public function whenIs($pattern, $callback, $default = null)
863+
{
864+
return $this->when($this->is($pattern), $callback, $default);
865+
}
866+
867+
/**
868+
* Execute the given callback if the string is 7 bit ASCII.
869+
*
870+
* @param callable $callback
871+
* @param callable|null $default
872+
* @return static
873+
*/
874+
public function whenIsAscii($callback, $default = null)
875+
{
876+
return $this->when($this->isAscii(), $callback, $default);
877+
}
878+
879+
/**
880+
* Execute the given callback if the string is a valid UUID.
881+
*
882+
* @param callable $callback
883+
* @param callable|null $default
884+
* @return static
885+
*/
886+
public function whenIsUuid($callback, $default = null)
887+
{
888+
return $this->when($this->isUuid(), $callback, $default);
889+
}
890+
891+
/**
892+
* Execute the given callback if the string starts with a given substring.
893+
*
894+
* @param string|array $needles
895+
* @param callable $callback
896+
* @param callable|null $default
897+
* @return static
898+
*/
899+
public function whenStartsWith($needles, $callback, $default = null)
900+
{
901+
return $this->when($this->startsWith($needles), $callback, $default);
902+
}
903+
904+
/**
905+
* Execute the given callback if the string matches the given pattern.
906+
*
907+
* @param string $pattern
908+
* @param callable $callback
909+
* @param callable|null $default
910+
* @return static
911+
*/
912+
public function whenTest($pattern, $callback, $default = null)
913+
{
914+
return $this->when($this->test($pattern), $callback, $default);
915+
}
916+
848917
/**
849918
* Limit the number of words in a string.
850919
*

src/Illuminate/Validation/Rules/Enum.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Validation\Rules;
44

55
use Illuminate\Contracts\Validation\Rule;
6+
use TypeError;
67

78
class Enum implements Rule
89
{
@@ -37,7 +38,11 @@ public function passes($attribute, $value)
3738
return false;
3839
}
3940

40-
return ! is_null($this->type::tryFrom($value));
41+
try {
42+
return ! is_null($this->type::tryFrom($value));
43+
} catch (TypeError $e) {
44+
return false;
45+
}
4146
}
4247

4348
/**

0 commit comments

Comments
 (0)