Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added `TwigRenderer` that integrates `twig/twig`;
- Added fallback template loading support.
- Template packs to facilitate customization and extensibility of templates:
- Added template pack `default` and defined as fallback;
- Added template pack `bootstrap4` that integrates custom elements of Bootstrap v4.0.0-beta.2.
- Added extra arg `label` on method `getContext` of `Widget` class;
- Support to configure renderer and template pack through `Config` singleton class;
- Added abstract class `TemplatePack`;
- Added template pack `DefaultTemplatePack`. Defined as default template pack;
- Added template pack `Bootstrap4TemplatePack` that integrates Bootstrap v4.0.0-beta.2.
- `Config` singleton class allowing:
- Configure custom renderers;
- Configure custom template packs.
- Added extra arg `label` to method `getContext` of `Widget` class.

### Changed
- Class name `PHPFormConfig` to `Config` and moved to `src/` directory;
- `BoundField` attribute name `choices` changed to `options`;
- `BoundField` attribute `options` now return an array instead of formated string;
- `Widgets`, `labelTag` and `ErrorList` now render through default renderer instead of formatter `fleshgrinder/format`;
- `CheckboxSelectMultiple` and `RadioSelect` widget wrapped in an unordered list tag instead of previous `div`;
- Method name `getSubWidgets` to `getOptions` in `Widgets` class;
- Method name `getSubWidgets` to `getOptions` in `Widgets` class and now returns an array instead of formated string.

### Removed:
- Method `asUL` from `ErrorList` class;
- `config.php` and `templates.php` files;
- Static method `flatatt` from `Attributes` class;
- `PHPFormConfig` class. Use new `Config` class instead to configure `PHPForm`;
- `\Utils\Attributes` class. All static methods, except `flatattr` which is no longer used, where migrated to `helpers.php`;
- Method `asUL` from `ErrorList` class.

## [1.0.1] - 2017-12-07
### Added
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
"squizlabs/php_codesniffer": "*"
},
"autoload": {
"files": [
"src/helpers.php",
"config.php"
],
"psr-4": {
"PHPForm\\" : "src/"
},
"files": ["config.php"]
}
},
"autoload-dev": {
"psr-4": {
Expand Down
3 changes: 1 addition & 2 deletions src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use PHPForm\Exceptions\ValidationError;
use PHPForm\PHPFormConfig;
use PHPForm\Utils\Attributes;

abstract class Field
{
Expand Down Expand Up @@ -151,7 +150,7 @@ public function getLabel(string $name = null)
$label = $this->label;

if (is_null($this->label) && !is_null($name)) {
$label = Attributes::prettyName($name);
$label = prettyName($name);
}

return $label;
Expand Down
3 changes: 1 addition & 2 deletions src/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPForm\Errors\ErrorList;
use PHPForm\Exceptions\ValidationError;
use PHPForm\Fields\BoundField;
use PHPForm\Utils\Attributes;

abstract class Form implements ArrayAccess, Iterator, Countable
{
Expand Down Expand Up @@ -200,7 +199,7 @@ private function cleanFields()
try {
$this->cleaned_data[$field_name] = $field->clean($value);

$method = 'clean' . Attributes::snakeToCamel($field_name);
$method = 'clean' . snakeToCamel($field_name);

if (method_exists($this, $method)) {
$this->cleaned_data[$field_name] = call_user_func(array($this, $method));
Expand Down
18 changes: 0 additions & 18 deletions src/Utils/Attributes.php

This file was deleted.

11 changes: 11 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

function prettyName($name)
{
return ucfirst(str_replace("_", " ", $name));
}

function snakeToCamel($name)
{
return str_replace(" ", "", ucwords(str_replace("_", " ", $name)));
}
21 changes: 0 additions & 21 deletions tests/unit/Utils/Attributes.php

This file was deleted.

19 changes: 19 additions & 0 deletions tests/unit/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace PHPForm\Unit;

use PHPUnit\Framework\TestCase;

class HelpersTest extends TestCase
{
public function testPrettyName()
{
$this->assertEquals(prettyName("label_name"), 'Label name');
$this->assertEquals(prettyName(""), '');
}

public function testSnakeToCamel()
{
$this->assertEquals(snakeToCamel("label_name"), 'LabelName');
$this->assertEquals(snakeToCamel("label_with_name"), 'LabelWithName');
}
}