Skip to content

Commit 17c1d2e

Browse files
committed
Merge branch 'master' into fix/choice-type-name
2 parents b3cddd2 + 0dbb803 commit 17c1d2e

File tree

12 files changed

+155
-35
lines changed

12 files changed

+155
-35
lines changed

.github/workflows/test.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@ env:
99

1010
jobs:
1111
test:
12-
name: "Build"
12+
name: "Lara ${{ matrix.laravel }} PHP ${{ matrix.php }} Unit ${{ matrix.phpunit }}"
1313
runs-on: ubuntu-latest
1414
strategy:
15-
max-parallel: 12
15+
max-parallel: 6 # 12
1616
fail-fast: false
1717
matrix:
18-
php: ['7.4', '8.0', '8.1', '8.2']
19-
package-release: [dist]
18+
laravel: [9, 10, 11]
19+
php: ['8.1', '8.2', '8.3']
20+
phpunit: [9, 10]
21+
exclude:
22+
- {laravel: 11, php: '8.1'}
23+
- {laravel: 9, phpunit: 10}
24+
- {phpunit: 9}
25+
include:
26+
- {laravel: 9, php: '8.1', phpunit: 9}
27+
- {laravel: 9, php: '8.2', phpunit: 9}
28+
- {laravel: 9, php: '8.3', phpunit: 9}
2029
steps:
2130
- name: Checkout repository
2231
uses: actions/checkout@v3
@@ -37,21 +46,21 @@ jobs:
3746
uses: actions/cache@v3
3847
with:
3948
path: ${{ steps.composer-cache.outputs.dir }}
40-
key: composer-${{ runner.os }}-${{ matrix.php }}-${{ matrix.package-release }}-${{ hashFiles('**/composer.json') }}
49+
key: composer-${{ runner.os }}-${{ matrix.php }}-${{ matrix.laravel }}-${{ hashFiles('**/composer.json') }}
4150
restore-keys: |
42-
composer-${{ runner.os }}-${{ matrix.php }}-${{ matrix.package-release }}-${{ env.cache-name }}-
43-
composer-${{ runner.os }}-${{ matrix.php }}-${{ matrix.package-release }}-
51+
composer-${{ runner.os }}-${{ matrix.php }}-${{ matrix.laravel }}-${{ env.cache-name }}-
52+
composer-${{ runner.os }}-${{ matrix.php }}-${{ matrix.laravel }}-
4453
composer-${{ runner.os }}-${{ matrix.php }}-
4554
composer-${{ runner.os }}-
4655
4756
- name: Install composer dependencies
48-
run: composer install --no-progress --no-interaction --prefer-${{ matrix.package-release }}
57+
run: composer require --no-progress --no-interaction illuminate/database:^${{ matrix.laravel }}.0 illuminate/validation:^${{ matrix.laravel }}.0 phpunit/phpunit:^${{ matrix.phpunit }}.0
4958

5059
- name: Run unit tests
5160
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
5261

53-
- name: Upload to Scrutinizer
54-
continue-on-error: true
55-
run: |
56-
composer global require scrutinizer/ocular
57-
~/.composer/vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover
62+
# - name: Upload to Scrutinizer
63+
# continue-on-error: true
64+
# run: |
65+
# composer global require scrutinizer/ocular
66+
# ~/.composer/vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kris/laravel-form-builder",
33
"description": "Laravel form builder - symfony like",
4-
"keywords": ["laravel", "form", "builder","symfony"],
4+
"keywords": ["laravel", "form", "builder", "symfony"],
55
"license": "MIT",
66
"authors": [
77
{
@@ -10,13 +10,14 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=7.4",
14-
"laravelcollective/html": "^6",
15-
"illuminate/database": "^6 || ^7 || ^8 || ^9 || ^10",
16-
"illuminate/validation": "^6 || ^7 || ^8 || ^9 || ^10"
13+
"php": "^8.0",
14+
"rdx/laravelcollective-html": "^6",
15+
"illuminate/database": "^6 || ^7 || ^8 || ^9 || ^10 || ^11",
16+
"illuminate/validation": "^6 || ^7 || ^8 || ^9 || ^10 || ^11"
1717
},
1818
"require-dev": {
19-
"orchestra/testbench": "^6.13 || ^7.0 || ^8"
19+
"orchestra/testbench": "^6.13 || ^7 || ^8 || ^9",
20+
"phpunit/phpunit": "^10.0"
2021
},
2122
"extra": {
2223
"branch-alias": {

phpstan-extension.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
-
3+
class: Kris\LaravelFormBuilder\PhpStan\FormGetFieldExtension
4+
tags:
5+
- phpstan.broker.dynamicMethodReturnTypeExtension

src/Kris/LaravelFormBuilder/Fields/ChildFormType.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44

55
use Kris\LaravelFormBuilder\Form;
66

7+
/**
8+
* @template TFormType of Form
9+
*
10+
* @extends ParentType<FormField>
11+
*/
712
class ChildFormType extends ParentType
813
{
914

1015
/**
1116
* @var Form
17+
* @phpstan-var TFormType
1218
*/
1319
protected $form;
1420

@@ -22,6 +28,7 @@ protected function getTemplate()
2228

2329
/**
2430
* @return Form
31+
* @phpstan-return TFormType
2532
*/
2633
public function getForm()
2734
{
@@ -96,6 +103,7 @@ protected function createChildren()
96103

97104
/**
98105
* @return Form
106+
* @phpstan-return TFormType
99107
* @throws \Exception
100108
*/
101109
protected function getClassFromOptions()
@@ -116,7 +124,7 @@ protected function getClassFromOptions()
116124
$options = [
117125
'model' => $this->getOption($this->valueProperty) ?: $this->parent->getModel(),
118126
'name' => $this->name,
119-
'language_name' => $this->parent->getLanguageName(),
127+
'language_name' => $this->getOption('language_name') ?: $this->parent->getLanguageName(),
120128
'translation_template' => $this->parent->getTranslationTemplate(),
121129
];
122130

src/Kris/LaravelFormBuilder/Fields/ChoiceType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Support\Arr;
66

7+
/**
8+
* @extends ParentType<FormField>
9+
*/
710
class ChoiceType extends ParentType
811
{
912
/**

src/Kris/LaravelFormBuilder/Fields/CollectionType.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Support\Collection;
77

8+
/**
9+
* @template TType of FormField
10+
*
11+
* @extends ParentType<TType>
12+
*/
813
class CollectionType extends ParentType
914
{
1015
/**
1116
* Contains template for a collection element.
1217
*
1318
* @var FormField
19+
* @phpstan-var TType
1420
*/
1521
protected $proto;
1622

@@ -49,6 +55,7 @@ protected function getDefaults()
4955
* Get the prototype object.
5056
*
5157
* @return FormField
58+
* @phpstan-return TType
5259
* @throws \Exception
5360
*/
5461
public function prototype()
@@ -237,6 +244,10 @@ protected function setupChild(FormField $field, $name, $value = null)
237244
['attr' => array_merge(['id' => $newFieldName], $this->getOption('attr'))]
238245
);
239246

247+
if (isset($firstFieldOptions['label'])) {
248+
$firstFieldOptions['label'] = value($firstFieldOptions['label'], $value, $field);
249+
}
250+
240251
$field->setName($newFieldName);
241252
$field->setOptions($firstFieldOptions);
242253

@@ -249,7 +260,6 @@ protected function setupChild(FormField $field, $name, $value = null)
249260

250261
$field->setValue($value);
251262

252-
253263
return $field;
254264
}
255265

src/Kris/LaravelFormBuilder/Fields/ParentType.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
use Illuminate\Support\Arr;
66
use Kris\LaravelFormBuilder\Form;
77

8+
/**
9+
* @template TChildType of FormField
10+
*/
811
abstract class ParentType extends FormField
912
{
1013

1114
/**
1215
* @var FormField[]
16+
* @phpstan-var TChildType[]
1317
*/
1418
protected $children;
1519

@@ -71,6 +75,7 @@ public function render(array $options = [], $showLabel = true, $showField = true
7175
* Get all children of the choice field.
7276
*
7377
* @return mixed
78+
* @phpstan-return TChildType[]
7479
*/
7580
public function getChildren()
7681
{
@@ -81,6 +86,7 @@ public function getChildren()
8186
* Get a child of the choice field.
8287
*
8388
* @return mixed
89+
* @phpstan-return ?TChildType
8490
*/
8591
public function getChild($key)
8692
{
@@ -152,6 +158,7 @@ public function isRendered()
152158
*
153159
* @param string $name
154160
* @return FormField
161+
* @phpstan-return TChildType
155162
*/
156163
public function __get($name)
157164
{

src/Kris/LaravelFormBuilder/Fields/RepeatedType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Support\Arr;
66

7+
/**
8+
* @extends ParentType<FormField>
9+
*/
710
class RepeatedType extends ParentType
811
{
912

src/Kris/LaravelFormBuilder/FormBuilder.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ public function fireEvent($event)
5656
/**
5757
* Create a Form instance.
5858
*
59-
* @param string $formClass The name of the class that inherits \Kris\LaravelFormBuilder\Form.
60-
* @param array $options|null
61-
* @param array $data|null
62-
* @return Form
59+
* @template T
60+
* @param class-string<T> $formClass
61+
* @param array<string, mixed> $options
62+
* @param array<string, mixed> $data
63+
* @return T
6364
*/
6465
public function create($formClass, array $options = [], array $data = [])
6566
{

src/Kris/LaravelFormBuilder/FormBuilderServiceProvider.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Collective\Html\HtmlBuilder;
88
use Illuminate\Support\ServiceProvider;
99
use InvalidArgumentException;
10-
use Kris\LaravelFormBuilder\Traits\ValidatesWhenResolved;
1110
use Kris\LaravelFormBuilder\Form;
11+
use Kris\LaravelFormBuilder\Traits\ValidatesWhenResolved;
1212

1313
class FormBuilderServiceProvider extends ServiceProvider
1414
{
@@ -105,15 +105,15 @@ public function boot()
105105
__DIR__ . '/../../config/config.php' => config_path('laravel-form-builder.php')
106106
]);
107107

108-
$form = $this->app[static::FORM_ABSTRACT];
109-
110-
$form->macro('customLabel', function($name, $value, $options = [], $escape_html = true) use ($form) {
111-
if (isset($options['for']) && $for = $options['for']) {
112-
unset($options['for']);
113-
return $form->label($for, $value, $options, $escape_html);
114-
}
108+
$this->callAfterResolving(static::FORM_ABSTRACT, function (LaravelForm $form) {
109+
$form->macro('customLabel', function($name, $value, $options = [], $escapeHtml = true) use ($form) {
110+
if (isset($options['for']) && $for = $options['for']) {
111+
unset($options['for']);
112+
return $form->label($for, $value, $options, $escapeHtml);
113+
}
115114

116-
return $form->label($name, $value, $options, $escape_html);
115+
return $form->label($name, $value, $options, $escapeHtml);
116+
});
117117
});
118118
}
119119

0 commit comments

Comments
 (0)