Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/8.x' into 8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 14, 2021
2 parents 98c3d03 + 7d56eff commit 19f338e
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/src/Illuminate/Collections/ @JosephSilber
/tests/Support/SupportCollectionTest/ @JosephSilber
/tests/Support/SupportLazyCollectionTest/ @JosephSilber
/tests/Support/SupportLazyCollectionIsLazyTest/ @JosephSilber
2 changes: 2 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Version | Security Fixes Until
--- | ---
8 | September 8th, 2021
7 | March 3rd, 2021
6 (LTS) | September 3rd, 2022
5.8 | February 26th, 2020
5.7 | September 4th, 2019
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ public function reduce(callable $callback, $initial = null)
* Reduce an associative collection to a single value.
*
* @param callable $callback
* @param mixed $initial
* @param mixed $initial
* @return mixed
*/
public function reduceWithKeys(callable $callback, $initial = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ public function reduce(callable $callback, $initial = null)
* Reduce an associative collection to a single value.
*
* @param callable $callback
* @param mixed $initial
* @param mixed $initial
* @return mixed
*/
public function reduceWithKeys(callable $callback, $initial = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Relations/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery,
/**
* Get a relationship join table hash.
*
* @param bool $incrementJoinCount
* @param bool $incrementJoinCount
* @return string
*/
public function getRelationCountHash($incrementJoinCount = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UrlGenerationException extends Exception
* Create a new exception for missing route parameters.
*
* @param \Illuminate\Routing\Route $route
* @param array $parameters
* @param array $parameters
* @return static
*/
public static function forMissingParameters(Route $route, array $parameters = [])
Expand Down
16 changes: 12 additions & 4 deletions src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,14 @@ function tap($value, $callback = null)
*
* @throws \Throwable
*/
function throw_if($condition, $exception, ...$parameters)
function throw_if($condition, $exception = 'RuntimeException', ...$parameters)
{
if ($condition) {
throw (is_string($exception) ? new $exception(...$parameters) : $exception);
if (is_string($exception) && class_exists($exception)) {
$exception = new $exception(...$parameters);
}

throw is_string($exception) ? new RuntimeException($exception) : $exception;
}

return $condition;
Expand All @@ -298,10 +302,14 @@ function throw_if($condition, $exception, ...$parameters)
*
* @throws \Throwable
*/
function throw_unless($condition, $exception, ...$parameters)
function throw_unless($condition, $exception = 'RuntimeException', ...$parameters)
{
if (! $condition) {
throw (is_string($exception) ? new $exception(...$parameters) : $exception);
if (is_string($exception) && class_exists($exception)) {
$exception = new $exception(...$parameters);
}

throw is_string($exception) ? new RuntimeException($exception) : $exception;
}

return $condition;
Expand Down
3 changes: 1 addition & 2 deletions src/Illuminate/Testing/AssertableJsonString.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ public function assertSubset(array $data, $strict = false)
/**
* Reorder associative array keys to make it easy to compare arrays.
*
* @param array $data
*
* @param array $data
* @return array
*/
protected function reorderAssocKeys(array $data)
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,10 @@ public function compileString($value)
$result = $this->addFooters($result);
}

return $result;
return str_replace(
['##BEGIN-COMPONENT-CLASS##', '##END-COMPONENT-CLASS##'],
'',
$result);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/View/Compilers/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ protected function compileSelfClosingTags(string $value)

$attributes = $this->getAttributesFromAttributeString($matches['attributes']);

return $this->componentString($matches[1], $attributes)."\n@endcomponentClass ";
return $this->componentString($matches[1], $attributes)."\n@endComponentClass##END-COMPONENT-CLASS##";
}, $value);
}

Expand Down Expand Up @@ -230,7 +230,7 @@ protected function componentString(string $component, array $attributes)
$parameters = $data->all();
}

return " @component('{$class}', '{$component}', [".$this->attributesToString($parameters, $escapeBound = false).'])
return "##BEGIN-COMPONENT-CLASS##@component('{$class}', '{$component}', [".$this->attributesToString($parameters, $escapeBound = false).'])
<?php $component->withAttributes(['.$this->attributesToString($attributes->all(), $escapeAttributes = $class !== DynamicComponent::class).']); ?>';
}

Expand Down Expand Up @@ -384,7 +384,7 @@ public function partitionDataAndAttributes($class, array $attributes)
*/
protected function compileClosingTags(string $value)
{
return preg_replace("/<\/\s*x[-\:][\w\-\:\.]*\s*>/", ' @endcomponentClass ', $value);
return preg_replace("/<\/\s*x[-\:][\w\-\:\.]*\s*>/", ' @endComponentClass##END-COMPONENT-CLASS##', $value);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions tests/Integration/View/BladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ public function test_rendering_the_same_dynamic_component_with_different_attribu
$this->assertSame('<span class="text-medium">
Hello Taylor
</span>
<span >
<span >
Hello Samuel
</span>', trim($view));
}

public function test_inline_link_type_attributes_dont_add_extra_spacing_at_end()
{
$view = View::make('uses-link')->render();

$this->assertSame('This is a sentence with a <a href="https://laravel.com">link</a>.', trim($view));
}

public function test_appendable_attributes()
{
$view = View::make('uses-appendable-panel', ['name' => 'Taylor', 'withInjectedValue' => true])->render();
Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/View/templates/components/link.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@props(['href'])

<a href="{{ $href }}">{{ $slot }}</a>
1 change: 1 addition & 0 deletions tests/Integration/View/templates/uses-link.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a sentence with a <x-link href="https://laravel.com">link</x-link>.
56 changes: 55 additions & 1 deletion tests/Support/SupportHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Env;
use Illuminate\Support\Optional;
use LogicException;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use RuntimeException;
Expand Down Expand Up @@ -362,10 +363,63 @@ public function testTap()
}

public function testThrow()
{
$this->expectException(LogicException::class);

throw_if(true, new LogicException);
}

public function testThrowDefaultException()
{
$this->expectException(RuntimeException::class);

throw_if(true);
}

public function testThrowExceptionWithMessage()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('test');

throw_if(true, 'test');
}

public function testThrowExceptionAsStringWithMessage()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('test');

throw_if(true, LogicException::class, 'test');
}

public function testThrowUnless()
{
$this->expectException(LogicException::class);

throw_unless(false, new LogicException);
}

public function testThrowUnlessDefaultException()
{
$this->expectException(RuntimeException::class);

throw_unless(false);
}

public function testThrowUnlessExceptionWithMessage()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('test');

throw_unless(false, 'test');
}

public function testThrowUnlessExceptionAsStringWithMessage()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage('test');

throw_if(true, new RuntimeException);
throw_unless(false, LogicException::class, 'test');
}

public function testThrowReturnIfNotThrown()
Expand Down
Loading

0 comments on commit 19f338e

Please sign in to comment.