Skip to content

Commit

Permalink
Merge branch '4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive committed Jun 3, 2024
2 parents c9f7e78 + 229e4e0 commit e4067be
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 46 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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.
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/Former/Form/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ 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
if (lcfirst($label) == $oldLabel) {
$label = str_replace('_', ' ', $label);
}
} else {
$label = (string) $label->toHtml();
$label = $label->toHtml();
}

$attributes['for'] = $for;
Expand Down
4 changes: 2 additions & 2 deletions src/Former/Form/Fields/Choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Former/Form/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Former/Former.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/Former/Framework/Nude.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ public function placeAround($item)
public function prependAppend($field, $prepend, $append)
{
$return = '<div>';
$return .= join(null, $prepend);
$return .= implode('', $prepend);
$return .= $field->render();
$return .= join(null, $append);
$return .= implode('', $append);
$return .= '</div>';

return $return;
Expand Down
4 changes: 2 additions & 2 deletions src/Former/Framework/TwitterBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ public function prependAppend($field, $prepend, $append)
}

$return = '<div class="'.join(' ', $class).'">';
$return .= join(null, $prepend);
$return .= implode('', $prepend);
$return .= $field->render();
$return .= join(null, $append);
$return .= implode('', $append);
$return .= '</div>';

return $return;
Expand Down
4 changes: 2 additions & 2 deletions src/Former/Framework/TwitterBootstrap3.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ public function placeAround($item)
public function prependAppend($field, $prepend, $append)
{
$return = '<div class="input-group">';
$return .= join(null, $prepend);
$return .= implode('', $prepend);
$return .= $field->render();
$return .= join(null, $append);
$return .= implode('', $append);
$return .= '</div>';

return $return;
Expand Down
4 changes: 2 additions & 2 deletions src/Former/Framework/TwitterBootstrap4.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ public function placeAround($item, $place = null)
public function prependAppend($field, $prepend, $append)
{
$return = '<div class="input-group">';
$return .= join(null, $prepend);
$return .= implode('', $prepend);
$return .= $field->render();
$return .= join(null, $append);
$return .= implode('', $append);
$return .= '</div>';

return $return;
Expand Down
2 changes: 1 addition & 1 deletion src/Former/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Former/Traits/Checkable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions tests/Dummy/DummyButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

class DummyButton
{
private $text;

public function __construct($text)
{
$this->text = $text;
Expand Down
2 changes: 1 addition & 1 deletion tests/Fields/RadioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Framework/TwitterBootstrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function createPrependAppendMatcher($prepend = array(), $append = array()
'<label for="foo" class="control-label">Foo</label>'.
'<div class="controls">'.
'<div class="'.implode(' ', $class).'">'.
join(null, $prepend).
implode('', $prepend).
'<input id="foo" type="text" name="foo">'.
join(null, $append).
implode('', $append).
'</div>'.
'</div>'.
'</div>';
Expand Down
4 changes: 2 additions & 2 deletions tests/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public function createPrependAppendMatcher($prepend = array(), $append = array()
'<label for="foo" class="control-label">Foo</label>'.
'<div class="controls">'.
'<div class="'.implode(' ', $class).'">'.
join(null, $prepend).
implode('', $prepend).
'<input id="foo" type="text" name="foo">'.
join(null, $append).
implode('', $append).
'</div>'.
'</div>'.
'</div>';
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCases/FormerTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '*';
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e4067be

Please sign in to comment.