Skip to content

Commit

Permalink
Laravel 6 support (formers#591)
Browse files Browse the repository at this point in the history
Thanks @stayallive!
  • Loading branch information
stayallive authored and claar committed Sep 4, 2019
1 parent 94378a3 commit 9f919b8
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 69 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3
- nightly

# This triggers builds to run on the new TravisCI infrastructure.
Expand All @@ -14,10 +15,9 @@ cache:
directories:
- $HOME/.composer/cache


before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-dist --dev
- travis_retry composer install --no-interaction --prefer-dist

matrix:
allow_failures:
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
"require": {
"php": ">=5.4.0",
"anahkiasen/html-object": "~1.4",
"illuminate/config": "~5.0",
"illuminate/container": "~5.0",
"illuminate/http": "~5.0",
"illuminate/routing": "~5.0",
"illuminate/session": "~5.0",
"illuminate/translation": "~5.0"
"illuminate/config": "~5.0|^6.0",
"illuminate/container": "~5.0|^6.0",
"illuminate/http": "~5.0|^6.0",
"illuminate/routing": "~5.0|^6.0",
"illuminate/session": "~5.0|^6.0",
"illuminate/translation": "~5.0|^6.0",
"illuminate/support": "~5.0|^6.0"
},
"require-dev": {
"phpunit/phpunit": "~4",
"mockery/mockery": "~0.9.1",
"illuminate/database": "~5.0"
"illuminate/database": "~5.0|^6.0"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 4 additions & 3 deletions src/Former/Form/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Former\Traits\FormerObject;
use Illuminate\Container\Container;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -70,9 +71,9 @@ public function __call($method, $parameters)
{
// Dynamically add buttons to an actions block
if ($this->isButtonMethod($method)) {
$text = array_get($parameters, 0);
$link = array_get($parameters, 1);
$attributes = array_get($parameters, 2);
$text = Arr::get($parameters, 0);
$link = Arr::get($parameters, 1);
$attributes = Arr::get($parameters, 2);
if (!$attributes and is_array($link)) {
$attributes = $link;
}
Expand Down
25 changes: 13 additions & 12 deletions src/Former/Form/Fields/Choice.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use HtmlObject\Element;
use HtmlObject\Input;
use Illuminate\Container\Container;
use Illuminate\Support\Str;

/**
* Everything list-related (select, multiselect, ...)
Expand Down Expand Up @@ -80,13 +81,13 @@ public function __construct(Container $app, $type, $name, $label, $choices, $sel
if ($choices) {
$this->choices($choices);
}

parent::__construct($app, $type, $name, $label, $selected, $attributes);

$this->setChoiceType();

// Nested models population
if (str_contains($this->name, '.') and is_array($this->value) and !empty($this->value) and is_string($this->value[key($this->value)])) {
if (Str::contains($this->name, '.') and is_array($this->value) and !empty($this->value) and is_string($this->value[key($this->value)])) {
$this->fromQuery($this->value);
$this->value = $selected ?: null;
}
Expand Down Expand Up @@ -129,7 +130,7 @@ public function getSelect()
$field->multiple();
$name .= '[]';
}

$field->setAttribute('name', $name);

$field->nest($this->getOptions());
Expand All @@ -140,7 +141,7 @@ public function getSelect()
public function getOptions()
{
$children = [];

// Add placeholder text if any
if ($placeholder = $this->getPlaceholder()) {
$children[] = $placeholder;
Expand Down Expand Up @@ -226,7 +227,7 @@ public function getCheckables($choiceType)
if ($this->options['isMultiple']) {
$name .= '[]';
}

if(!isset($attributes['id'])) {
$attributes['id'] = $this->id.'_'.count($children);
}
Expand All @@ -239,7 +240,7 @@ public function getCheckables($choiceType)
$class = $this->app['former']->framework() == 'TwitterBootstrap3' ? trim($isInline) : $choiceType.$isInline;

$element = Input::create($choiceType, $name, $inputValue, $attributes);

// $element->setAttribute('name', $name);

if ($this->hasValue($inputValue)) {
Expand All @@ -253,7 +254,7 @@ public function getCheckables($choiceType)
$labelElement = Element::create('label', $rendered.$label);
$element = $labelElement->for($attributes['id'])->class($class);
}

// If BS3, if checkables are stacked, wrap them in a div with the checkable type
if (!$isInline && $this->app['former']->framework() == 'TwitterBootstrap3') {
$wrapper = Element::create('div', $element->render())->class($choiceType);
Expand All @@ -266,7 +267,7 @@ public function getCheckables($choiceType)
$children[] = $element;
}
$field->nest($children);

return $field;
}

Expand Down Expand Up @@ -412,7 +413,7 @@ public function placeholder($placeholder)

return $this;
}

/**
* Set isMultiple
*
Expand All @@ -426,7 +427,7 @@ public function multiple($isMultiple = true)

return $this;
}

/**
* Set isExpanded
*
Expand Down Expand Up @@ -484,5 +485,5 @@ public function getChoices()
{
return $this->choices;
}

}
3 changes: 2 additions & 1 deletion src/Former/Form/Fields/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Former\Traits\Field;
use HtmlObject\Element;
use Illuminate\Container\Container;
use Illuminate\Support\Str;

/**
* Everything list-related (select, multiselect, ...)
Expand Down Expand Up @@ -67,7 +68,7 @@ public function __construct(Container $app, $type, $name, $label, $options, $sel
parent::__construct($app, $type, $name, $label, $selected, $attributes);

// Nested models population
if (str_contains($this->name, '.') and is_array($this->value) and !empty($this->value) and is_string($this->value[key($this->value)])) {
if (Str::contains($this->name, '.') and is_array($this->value) and !empty($this->value) and is_string($this->value[key($this->value)])) {
$this->fromQuery($this->value);
$this->value = $selected ?: null;
}
Expand Down
13 changes: 7 additions & 6 deletions src/Former/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Former\Populator;
use Former\Traits\FormerObject;
use Illuminate\Container\Container;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -111,10 +112,10 @@ public function __construct(Container $app, $url, Populator $populator)
*/
public function openForm($type, $parameters)
{
$action = array_get($parameters, 0);
$method = array_get($parameters, 1, 'POST');
$attributes = array_get($parameters, 2, array());
$secure = array_get($parameters, 3, null);
$action = Arr::get($parameters, 0);
$method = Arr::get($parameters, 1, 'POST');
$attributes = Arr::get($parameters, 2, array());
$secure = Arr::get($parameters, 3, null);

// Fetch errors if asked for
if ($this->app['former']->getOption('fetch_errors')) {
Expand Down Expand Up @@ -334,7 +335,7 @@ protected function findRouteMethod($name)
// Get string by uses
} else {
foreach ($this->app['router']->getRoutes() as $route) {
$routeUses = method_exists($route, 'getOption') ? $route->getOption('_uses') : array_get($route->getAction(), 'controller');
$routeUses = method_exists($route, 'getOption') ? $route->getOption('_uses') : Arr::get($route->getAction(), 'controller');
if ($action = $routeUses) {
if ($action == $name) {
break;
Expand All @@ -345,7 +346,7 @@ protected function findRouteMethod($name)

// Get method
$methods = method_exists($route, 'getMethods') ? $route->getMethods() : $route->methods();
$method = array_get($methods, 0);
$method = Arr::get($methods, 0);

return $method;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Former/Form/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use HtmlObject\Element;
use HtmlObject\Traits\Tag;
use Illuminate\Container\Container;
use Illuminate\Support\Arr;

/**
* Helper class to build groups
Expand Down Expand Up @@ -430,8 +431,8 @@ protected function getLabel($field = null)
*/
protected function getHelp()
{
$inline = array_get($this->help, 'inline');
$block = array_get($this->help, 'block');
$inline = Arr::get($this->help, 'inline');
$block = Arr::get($this->help, 'block');

// Replace help text with error if any found
$errors = $this->app['former']->getErrors();
Expand Down
9 changes: 5 additions & 4 deletions src/Former/Former.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Former\Exceptions\InvalidFrameworkException;
use Former\Traits\Field;
use Illuminate\Container\Container;
use Illuminate\Support\Arr;
use Illuminate\Support\MessageBag;
use Illuminate\Contracts\Validation\Validator;

Expand Down Expand Up @@ -148,12 +149,12 @@ public function __call($method, $parameters)
// Checking for any supplementary classes
$modifiers = explode('_', $method);
$method = array_pop($modifiers);

// Dispatch to the different Form\Fields
$field = $this->dispatch->toFields($method, $parameters);
$field->setModifiers($modifiers);
$field->addClass('');

// Else bind field
$this->app->instance('former.field', $field);

Expand Down Expand Up @@ -481,13 +482,13 @@ public function getErrors($name = null)
public function getRules($name)
{
// Check the rules for the name as given
$ruleset = array_get($this->rules, $name);
$ruleset = Arr::get($this->rules, $name);

// If no rules found, convert to dot notation and try again
if (is_null($ruleset)) {
$name = str_replace(array('[', ']'), array('.', ''), $name);
$name = trim($name, '.');
$ruleset = array_get($this->rules, $name);
$ruleset = Arr::get($this->rules, $name);
}

return $ruleset;
Expand Down
7 changes: 4 additions & 3 deletions src/Former/Framework/TwitterBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Former\Traits\Framework;
use HtmlObject\Element;
use Illuminate\Container\Container;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -287,7 +288,7 @@ public function createIcon($iconType, $attributes = array(), $iconSettings = arr
}

// Create tag
$tag = array_get($iconSettings, 'tag', $this->iconTag);
$tag = Arr::get($iconSettings, 'tag', $this->iconTag);
$icon = Element::create($tag, null, $attributes);

// White icons ignore user overrides to use legacy Bootstrap styling
Expand All @@ -298,8 +299,8 @@ public function createIcon($iconType, $attributes = array(), $iconSettings = arr
$set = null;
$prefix = 'icon';
} else {
$set = array_get($iconSettings, 'set', $this->iconSet);
$prefix = array_get($iconSettings, 'prefix', $this->iconPrefix);
$set = Arr::get($iconSettings, 'set', $this->iconSet);
$prefix = Arr::get($iconSettings, 'prefix', $this->iconPrefix);
}
$icon->addClass("$set $prefix-$iconType");

Expand Down
17 changes: 9 additions & 8 deletions src/Former/MethodDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Closure;
use Illuminate\Container\Container;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -145,8 +146,8 @@ public function toGroup($method, $parameters)
// Create opener
$group = new Form\Group(
$this->app,
array_get($parameters, 0, null),
array_get($parameters, 1, null)
Arr::get($parameters, 0, null),
Arr::get($parameters, 1, null)
);

// Set custom group as true
Expand Down Expand Up @@ -190,12 +191,12 @@ public function toFields($method, $parameters)
$field = new $class(
$this->app,
$method,
array_get($parameters, 0),
array_get($parameters, 1),
array_get($parameters, 2),
array_get($parameters, 3),
array_get($parameters, 4),
array_get($parameters, 5)
Arr::get($parameters, 0),
Arr::get($parameters, 1),
Arr::get($parameters, 2),
Arr::get($parameters, 3),
Arr::get($parameters, 4),
Arr::get($parameters, 5)
);

return $field;
Expand Down
2 changes: 1 addition & 1 deletion src/Former/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function get($field, $fallback = null)
}

// Plain array
if (is_array($this->items) and !str_contains($field, '[')) {
if (is_array($this->items) and !Str::contains($field, '[')) {
return parent::get($field, $fallback);
}

Expand Down
Loading

0 comments on commit 9f919b8

Please sign in to comment.