Skip to content

Commit 2c9dd7b

Browse files
authored
Merge pull request #3 from dipcode-software/feat/helpers
Removed Attributes class and moved methods to helper.php
2 parents 265faf8 + 770acbe commit 2c9dd7b

File tree

8 files changed

+48
-54
lines changed

8 files changed

+48
-54
lines changed

CHANGELOG.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
- Added `TwigRenderer` that integrates `twig/twig`;
1212
- Added fallback template loading support.
1313
- Template packs to facilitate customization and extensibility of templates:
14-
- Added template pack `default` and defined as fallback;
15-
- Added template pack `bootstrap4` that integrates custom elements of Bootstrap v4.0.0-beta.2.
16-
- Added extra arg `label` on method `getContext` of `Widget` class;
17-
- Support to configure renderer and template pack through `Config` singleton class;
14+
- Added abstract class `TemplatePack`;
15+
- Added template pack `DefaultTemplatePack`. Defined as default template pack;
16+
- Added template pack `Bootstrap4TemplatePack` that integrates Bootstrap v4.0.0-beta.2.
17+
- `Config` singleton class allowing:
18+
- Configure custom renderers;
19+
- Configure custom template packs.
20+
- Added extra arg `label` to method `getContext` of `Widget` class.
1821

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

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

3234
## [1.0.1] - 2017-12-07
3335
### Added

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
"squizlabs/php_codesniffer": "*"
2525
},
2626
"autoload": {
27+
"files": [
28+
"src/helpers.php",
29+
"config.php"
30+
],
2731
"psr-4": {
2832
"PHPForm\\" : "src/"
29-
},
30-
"files": ["config.php"]
33+
}
3134
},
3235
"autoload-dev": {
3336
"psr-4": {

src/Fields/Field.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use PHPForm\Exceptions\ValidationError;
1010
use PHPForm\PHPFormConfig;
11-
use PHPForm\Utils\Attributes;
1211

1312
abstract class Field
1413
{
@@ -151,7 +150,7 @@ public function getLabel(string $name = null)
151150
$label = $this->label;
152151

153152
if (is_null($this->label) && !is_null($name)) {
154-
$label = Attributes::prettyName($name);
153+
$label = prettyName($name);
155154
}
156155

157156
return $label;

src/Forms/Form.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPForm\Errors\ErrorList;
1111
use PHPForm\Exceptions\ValidationError;
1212
use PHPForm\Fields\BoundField;
13-
use PHPForm\Utils\Attributes;
1413

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

203-
$method = 'clean' . Attributes::snakeToCamel($field_name);
202+
$method = 'clean' . snakeToCamel($field_name);
204203

205204
if (method_exists($this, $method)) {
206205
$this->cleaned_data[$field_name] = call_user_func(array($this, $method));

src/Utils/Attributes.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/helpers.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
function prettyName($name)
4+
{
5+
return ucfirst(str_replace("_", " ", $name));
6+
}
7+
8+
function snakeToCamel($name)
9+
{
10+
return str_replace(" ", "", ucwords(str_replace("_", " ", $name)));
11+
}

tests/unit/Utils/Attributes.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/unit/helpers.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
namespace PHPForm\Unit;
3+
4+
use PHPUnit\Framework\TestCase;
5+
6+
class HelpersTest extends TestCase
7+
{
8+
public function testPrettyName()
9+
{
10+
$this->assertEquals(prettyName("label_name"), 'Label name');
11+
$this->assertEquals(prettyName(""), '');
12+
}
13+
14+
public function testSnakeToCamel()
15+
{
16+
$this->assertEquals(snakeToCamel("label_name"), 'LabelName');
17+
$this->assertEquals(snakeToCamel("label_with_name"), 'LabelWithName');
18+
}
19+
}

0 commit comments

Comments
 (0)