diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7d2e98d3..ace5d66f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,17 +8,17 @@ jobs: fail-fast: true matrix: os: [ ubuntu-latest, windows-latest ] - php: [ "8.0", "7.4", "7.3", "7.2" ] + php: [ "8.3", "8.2", "8.1", "8.0", "7.4", "7.3", "7.2" ] name: PHP ${{ matrix.php }} - ${{ matrix.os }} runs-on: ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.composer/cache/files key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} diff --git a/README.md b/README.md index 4caddd89..32b7d7e1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Former ## A Laravelish way to create and format forms -[![Build Status](http://img.shields.io/travis/formers/former.svg?style=flat)](https://travis-ci.org/formers/former) [![Latest Stable Version](http://img.shields.io/packagist/v/anahkiasen/former.svg?style=flat)](https://packagist.org/packages/anahkiasen/former) [![Total Downloads](http://img.shields.io/packagist/dt/anahkiasen/former.svg?style=flat)](https://packagist.org/packages/anahkiasen/former) @@ -66,12 +65,8 @@ Add then alias Former's main class by adding its facade to the `aliases` array i 'Former' => 'Former\Facades\Former', -### Table of contents +----- -- [Getting started][] -- [Features][] -- [Usage and Examples][] +### Documentation - [Getting started]: https://github.com/formers/former/wiki/Getting-started - [Features]: https://github.com/formers/former/wiki/Features - [Usage and Examples]: https://github.com/formers/former/wiki/Usage-and-Examples +Please refer to the [wiki](https://github.com/formers/former/wiki) for the full documentation. diff --git a/composer.json b/composer.json index 603ef001..7cbd2908 100644 --- a/composer.json +++ b/composer.json @@ -17,20 +17,20 @@ ], "require": { "php": "^7.2|^8.0", - "anahkiasen/html-object": "~1.4", - "illuminate/config": "^5.1.3|^6.0|^7.0|^8.0", - "illuminate/container": "^5.1.3|^6.0|^7.0|^8.0", - "illuminate/contracts": "^5.1.3|^6.0|^7.0|^8.0", - "illuminate/http": "^5.1.3|^6.0|^7.0|^8.0", - "illuminate/routing": "^5.1.3|^6.0|^7.0|^8.0", - "illuminate/session": "^5.1.3|^6.0|^7.0|^8.0", - "illuminate/translation": "^5.1.3|^6.0|^7.0|^8.0", - "illuminate/support": "^5.1.3|^6.0|^7.0|^8.0" + "illuminate/config": "^5.1.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/container": "^5.1.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/contracts": "^5.1.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/http": "^5.1.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/routing": "^5.1.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/session": "^5.1.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/translation": "^5.1.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/support": "^5.1.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "kylekatarnls/html-object": "^1.5" }, "require-dev": { "phpunit/phpunit": "^8.5", "mockery/mockery": "^1.3", - "illuminate/database": "^5.1.3|^6.0|^7.0|^8.0" + "illuminate/database": "^5.1.3|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0" }, "autoload": { "psr-4": { diff --git a/src/Former/Form/Elements.php b/src/Former/Form/Elements.php index 72ac6c97..99d415e3 100644 --- a/src/Former/Form/Elements.php +++ b/src/Former/Form/Elements.php @@ -62,7 +62,7 @@ public function label($label, $for = null, $attributes = array()) { if (!$label instanceof Htmlable) { $oldLabel = (string) $label; - $label = Helpers::translate($oldLabel); + $label = Helpers::translate($oldLabel, ''); // If there was no change to the label, // then a Laravel translation did not occur @@ -70,7 +70,7 @@ public function label($label, $for = null, $attributes = array()) $label = str_replace('_', ' ', $label); } } else { - $label = (string) $label->toHtml(); + $label = $label->toHtml(); } $attributes['for'] = $for; diff --git a/src/Former/Form/Fields/Choice.php b/src/Former/Form/Fields/Choice.php index 652e217b..c67d4609 100644 --- a/src/Former/Form/Fields/Choice.php +++ b/src/Former/Form/Fields/Choice.php @@ -191,7 +191,7 @@ public function getOption($key, $value) public function getCheckables($choiceType) { - if (!(is_array($this->value) || $this->value instanceof \ArrayAccess)) { + if ($this->value !== null && !(is_array($this->value) || $this->value instanceof \ArrayAccess)) { $this->value = explode(',', $this->value); } @@ -233,7 +233,7 @@ public function getCheckables($choiceType) } // If inline items, add class - $isInline = $this->inline ? ' '.$this->app['former.framework']->getInlineLabelClass($this) : null; + $isInline = $this->inline ? ' '.$this->app['former.framework']->getInlineLabelClass($this) : ''; // In Bootsrap 3, don't append the the checkable type (radio/checkbox) as a class if // rendering inline. diff --git a/src/Former/Form/Group.php b/src/Former/Form/Group.php index 6877547e..c1f2c659 100644 --- a/src/Former/Form/Group.php +++ b/src/Former/Form/Group.php @@ -532,7 +532,7 @@ protected function getHelp() $inline = $this->app['former.framework']->createValidationError($errors); } - return join(null, array($inline, $block)); + return implode('', array($inline, $block)); } /** diff --git a/src/Former/Former.php b/src/Former/Former.php index b6955cd7..17f9363e 100644 --- a/src/Former/Former.php +++ b/src/Former/Former.php @@ -250,7 +250,7 @@ public function getValue($field, $fallback = null) */ public function getPost($name, $fallback = null) { - $name = str_replace(array('[', ']'), array('.', ''), $name); + $name = str_replace(array('[', ']'), array('.', ''), $name ?? ''); $name = trim($name, '.'); $oldValue = $this->app['request']->old($name, $fallback); diff --git a/src/Former/Framework/Nude.php b/src/Former/Framework/Nude.php index 5fab121c..69be716b 100644 --- a/src/Former/Framework/Nude.php +++ b/src/Former/Framework/Nude.php @@ -161,9 +161,9 @@ public function placeAround($item) public function prependAppend($field, $prepend, $append) { $return = '
'; - $return .= join(null, $prepend); + $return .= implode('', $prepend); $return .= $field->render(); - $return .= join(null, $append); + $return .= implode('', $append); $return .= '
'; return $return; diff --git a/src/Former/Framework/TwitterBootstrap.php b/src/Former/Framework/TwitterBootstrap.php index 64ba7453..2d95c424 100644 --- a/src/Former/Framework/TwitterBootstrap.php +++ b/src/Former/Framework/TwitterBootstrap.php @@ -353,9 +353,9 @@ public function prependAppend($field, $prepend, $append) } $return = '
'; - $return .= join(null, $prepend); + $return .= implode('', $prepend); $return .= $field->render(); - $return .= join(null, $append); + $return .= implode('', $append); $return .= '
'; return $return; diff --git a/src/Former/Framework/TwitterBootstrap3.php b/src/Former/Framework/TwitterBootstrap3.php index c6a0a974..583c028c 100644 --- a/src/Former/Framework/TwitterBootstrap3.php +++ b/src/Former/Framework/TwitterBootstrap3.php @@ -406,9 +406,9 @@ public function placeAround($item) public function prependAppend($field, $prepend, $append) { $return = '
'; - $return .= join(null, $prepend); + $return .= implode('', $prepend); $return .= $field->render(); - $return .= join(null, $append); + $return .= implode('', $append); $return .= '
'; return $return; diff --git a/src/Former/Framework/TwitterBootstrap4.php b/src/Former/Framework/TwitterBootstrap4.php index 83c9c202..8b8ba516 100644 --- a/src/Former/Framework/TwitterBootstrap4.php +++ b/src/Former/Framework/TwitterBootstrap4.php @@ -438,9 +438,9 @@ public function placeAround($item, $place = null) public function prependAppend($field, $prepend, $append) { $return = '
'; - $return .= join(null, $prepend); + $return .= implode('', $prepend); $return .= $field->render(); - $return .= join(null, $append); + $return .= implode('', $append); $return .= '
'; return $return; diff --git a/src/Former/Helpers.php b/src/Former/Helpers.php index 5407714f..83ecd8fc 100644 --- a/src/Former/Helpers.php +++ b/src/Former/Helpers.php @@ -58,7 +58,7 @@ public static function translate($key, $fallback = null) { // If nothing was given, return nothing, bitch if (!$key) { - return null; + return $fallback; } // If no fallback, use the key diff --git a/src/Former/Traits/Checkable.php b/src/Former/Traits/Checkable.php index 93fac5a0..e989d249 100644 --- a/src/Former/Traits/Checkable.php +++ b/src/Former/Traits/Checkable.php @@ -304,8 +304,8 @@ protected function items($_items) // Grouped fields if ($this->isGrouped()) { - $attributes['id'] = str_replace('[]', null, $fallback); - $fallback = str_replace('[]', null, $this->name).'[]'; + $attributes['id'] = str_replace('[]', '', $fallback); + $fallback = str_replace('[]', '', $this->name).'[]'; } // If we haven't any name defined for the checkable, try to compute some @@ -361,7 +361,7 @@ protected function createCheckable($item, $fallbackValue = 1) } // If inline items, add class - $isInline = $this->inline ? ' '.$this->app['former.framework']->getInlineLabelClass($this) : null; + $isInline = $this->inline ? ' '.$this->app['former.framework']->getInlineLabelClass($this) : ''; // In Bootsrap 3 or 4 or 5, don't append the the checkable type (radio/checkbox) as a class if // rendering inline. diff --git a/tests/Dummy/DummyButton.php b/tests/Dummy/DummyButton.php index 56e0d000..7a7ab9ce 100644 --- a/tests/Dummy/DummyButton.php +++ b/tests/Dummy/DummyButton.php @@ -3,6 +3,8 @@ class DummyButton { + private $text; + public function __construct($text) { $this->text = $text; diff --git a/tests/Fields/RadioTest.php b/tests/Fields/RadioTest.php index f0fd0f76..fe318995 100644 --- a/tests/Fields/RadioTest.php +++ b/tests/Fields/RadioTest.php @@ -34,7 +34,7 @@ private function matchRadio( 'disabled' => $disabled === 'disabled' ? 'disabled' : null, 'id' => $name, 'type' => 'radio', - 'name' => preg_replace('/[0-9]/', null, $name), + 'name' => preg_replace('/[0-9]/', '', $name), 'checked' => 'checked', 'value' => $value, ); diff --git a/tests/Framework/TwitterBootstrapTest.php b/tests/Framework/TwitterBootstrapTest.php index 0cacaa26..37b5de67 100644 --- a/tests/Framework/TwitterBootstrapTest.php +++ b/tests/Framework/TwitterBootstrapTest.php @@ -44,9 +44,9 @@ public function createPrependAppendMatcher($prepend = array(), $append = array() ''. '
'. '
'. - join(null, $prepend). + implode('', $prepend). ''. - join(null, $append). + implode('', $append). '
'. '
'. ''; diff --git a/tests/GroupTest.php b/tests/GroupTest.php index 63bc08d6..518cb27b 100644 --- a/tests/GroupTest.php +++ b/tests/GroupTest.php @@ -78,9 +78,9 @@ public function createPrependAppendMatcher($prepend = array(), $append = array() ''. '
'. '
'. - join(null, $prepend). + implode('', $prepend). ''. - join(null, $append). + implode('', $append). '
'. '
'. ''; diff --git a/tests/TestCases/FormerTests.php b/tests/TestCases/FormerTests.php index 7b276a7a..fa010b81 100644 --- a/tests/TestCases/FormerTests.php +++ b/tests/TestCases/FormerTests.php @@ -128,7 +128,7 @@ protected function matchField($attributes = array(), $type = 'text', $name = 'fo */ protected function matchLabel($name = 'foo', $field = 'foo', $required = false) { - $text = str_replace('[]', null, $name); + $text = str_replace('[]', '', $name); if ($required) { $text .= '*'; } @@ -664,7 +664,7 @@ public static function findNodes(DOMDocument $dom, array $options, $isHtml = tru foreach ($options['attributes'] as $name => $value) { // match by regexp if like "regexp:/foo/i" - if (preg_match('/^regexp\s*:\s*(.*)/i', $value, $matches)) { + if (!empty($value) && preg_match('/^regexp\s*:\s*(.*)/i', $value, $matches)) { if (!preg_match($matches[1], $node->getAttribute($name))) { $invalid = true; }