Skip to content

Commit 777b6d3

Browse files
committed
Merge branch '5.6' into 5.7
2 parents 68caec9 + 974605f commit 777b6d3

7 files changed

+172
-35
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"require-dev": {
2929
"illuminate/database": "5.7.*",
3030
"mockery/mockery": "~1.0",
31-
"phpunit/phpunit": "~5.4"
31+
"phpunit/phpunit": "~7.1"
3232
},
3333
"autoload": {
3434
"psr-4": {

phpunit.xml

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
processIsolation="false"
1010
stopOnError="false"
1111
stopOnFailure="false"
12-
syntaxCheck="true"
13-
strict="false"
1412
verbose="true"
1513
>
1614
<testsuites>

src/FormBuilder.php

+47-13
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class FormBuilder
4949
*/
5050
protected $csrfToken;
5151

52+
/**
53+
* Consider Request variables while auto fill.
54+
* @var bool
55+
*/
56+
protected $considerRequest = false;
57+
5258
/**
5359
* The session store implementation.
5460
*
@@ -108,6 +114,7 @@ class FormBuilder
108114
* @param \Illuminate\Contracts\Routing\UrlGenerator $url
109115
* @param \Illuminate\Contracts\View\Factory $view
110116
* @param string $csrfToken
117+
* @param Request $request
111118
*/
112119
public function __construct(HtmlBuilder $html, UrlGenerator $url, Factory $view, $csrfToken, Request $request = null)
113120
{
@@ -190,7 +197,7 @@ public function setModel($model)
190197
{
191198
$this->model = $model;
192199
}
193-
200+
194201
/**
195202
* Get the current model instance on the form builder.
196203
*
@@ -516,7 +523,7 @@ public function week($name, $value = null, $options = [])
516523

517524
return $this->input('week', $name, $value, $options);
518525
}
519-
526+
520527
/**
521528
* Create a file input field.
522529
*
@@ -730,7 +737,7 @@ public function selectMonth($name, $selected = null, $options = [], $format = '%
730737
*/
731738
public function getSelectOption($display, $value, $selected, array $attributes = [], array $optgroupAttributes = [])
732739
{
733-
if (is_array($display)) {
740+
if (is_iterable($display)) {
734741
return $this->optionGroup($display, $value, $selected, $optgroupAttributes, $attributes);
735742
}
736743

@@ -755,7 +762,7 @@ protected function optionGroup($list, $label, $selected, array $attributes = [],
755762
$space = str_repeat("&nbsp;", $level);
756763
foreach ($list as $value => $display) {
757764
$optionAttributes = $optionsAttributes[$value] ?? [];
758-
if (is_array($display)) {
765+
if (is_iterable($display)) {
759766
$html[] = $this->optionGroup($display, $value, $selected, $attributes, $optionAttributes, $level+5);
760767
} else {
761768
$html[] = $this->option($space.$display, $value, $selected, $optionAttributes);
@@ -805,7 +812,7 @@ protected function placeholderOption($display, $selected)
805812
'value' => '',
806813
];
807814

808-
return $this->toHtmlString('<option' . $this->html->attributes($options) . ' hidden="hidden">' . e($display, false) . '</option>');
815+
return $this->toHtmlString('<option' . $this->html->attributes($options) . '>' . e($display, false) . '</option>');
809816
}
810817

811818
/**
@@ -907,7 +914,7 @@ protected function getCheckedState($type, $name, $value, $checked)
907914
return $this->getRadioCheckedState($name, $value, $checked);
908915

909916
default:
910-
return $this->getValueAttribute($name) === $value;
917+
return $this->compareValues($name, $value);
911918
}
912919
}
913920

@@ -960,7 +967,21 @@ protected function getRadioCheckedState($name, $value, $checked)
960967
return $checked;
961968
}
962969

963-
return $this->getValueAttribute($name) === $value;
970+
return $this->compareValues($name, $value);
971+
}
972+
973+
/**
974+
* Determine if the provide value loosely compares to the value assigned to the field.
975+
* Use loose comparison because Laravel model casting may be in affect and therefore
976+
* 1 == true and 0 == false.
977+
*
978+
* @param string $name
979+
* @param string $value
980+
* @return bool
981+
*/
982+
protected function compareValues($name, $value)
983+
{
984+
return $this->getValueAttribute($name) == $value;
964985
}
965986

966987
/**
@@ -1276,7 +1297,7 @@ public function getValueAttribute($name, $value = null)
12761297
if ($hasNullMiddleware
12771298
&& is_null($old)
12781299
&& is_null($value)
1279-
&& ! is_null($this->view->shared('errors'))
1300+
&& !is_null($this->view->shared('errors'))
12801301
&& count($this->view->shared('errors')) > 0
12811302
) {
12821303
return null;
@@ -1297,14 +1318,27 @@ public function getValueAttribute($name, $value = null)
12971318
}
12981319
}
12991320

1321+
/**
1322+
* Take Request in fill process
1323+
* @param bool $consider
1324+
*/
1325+
public function considerRequest($consider = true)
1326+
{
1327+
$this->considerRequest = $consider;
1328+
}
1329+
13001330
/**
13011331
* Get value from current Request
13021332
* @param $name
13031333
* @return array|null|string
13041334
*/
13051335
protected function request($name)
13061336
{
1307-
if (! isset($this->request)) {
1337+
if (!$this->considerRequest) {
1338+
return null;
1339+
}
1340+
1341+
if (!isset($this->request)) {
13081342
return null;
13091343
}
13101344

@@ -1342,16 +1376,16 @@ public function old($name)
13421376
$key = $this->transformKey($name);
13431377
$payload = $this->session->getOldInput($key);
13441378

1345-
if (! is_array($payload)) {
1379+
if (!is_array($payload)) {
13461380
return $payload;
13471381
}
13481382

1349-
if (! in_array($this->type, ['select', 'checkbox'])) {
1350-
if (! isset($this->payload[$key])) {
1383+
if (!in_array($this->type, ['select', 'checkbox'])) {
1384+
if (!isset($this->payload[$key])) {
13511385
$this->payload[$key] = collect($payload);
13521386
}
13531387

1354-
if (! empty($this->payload[$key])) {
1388+
if (!empty($this->payload[$key])) {
13551389
$value = $this->payload[$key]->shift();
13561390
return $value;
13571391
}

src/HtmlBuilder.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function style($url, $attributes = [], $secure = null)
9494
{
9595
$defaults = ['media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet'];
9696

97-
$attributes = array_merge($attributes, $defaults);
97+
$attributes = array_merge($defaults, $attributes);
9898

9999
$attributes['href'] = $this->url->asset($url, $secure);
100100

@@ -455,6 +455,10 @@ protected function attributeElement($key, $value)
455455
return $value ? $key : '';
456456
}
457457

458+
if (is_array($value) && $key === 'class') {
459+
return 'class="' . implode(' ', $value) . '"';
460+
}
461+
458462
if (! is_null($value)) {
459463
return $key . '="' . e($value, false) . '"';
460464
}

tests/FormAccessibleTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Illuminate\Database\Capsule\Manager as Capsule;
1313
use Mockery as m;
1414

15-
class FormAccessibleTest extends PHPUnit_Framework_TestCase
15+
class FormAccessibleTest extends PHPUnit\Framework\TestCase
1616
{
1717
public function setUp()
1818
{
@@ -74,12 +74,12 @@ public function testItCanGetRelatedValueForForms()
7474
$model = new ModelThatUsesForms($this->modelData);
7575
$this->assertEquals($model->getFormValue('address.street'), 'abcde st');
7676
}
77-
77+
7878
public function testItCanUseGetAccessorValuesWhenThereAreNoFormAccessors()
7979
{
8080
$model = new ModelThatUsesForms($this->modelData);
8181
$this->formBuilder->setModel($model);
82-
82+
8383
$this->assertEquals($this->formBuilder->getValueAttribute('email'), '[email protected]');
8484
}
8585

0 commit comments

Comments
 (0)