From 770acbe4152095f6e6a7956d8fd0dd0777b7abed Mon Sep 17 00:00:00 2001 From: Sandro Rodrigues Date: Sat, 9 Dec 2017 18:09:35 +0000 Subject: [PATCH] Removed Attributes class and moved methods to helper.php --- CHANGELOG.md | 20 +++++++++++--------- composer.json | 7 +++++-- src/Fields/Field.php | 3 +-- src/Forms/Form.php | 3 +-- src/Utils/Attributes.php | 18 ------------------ src/helpers.php | 11 +++++++++++ tests/unit/Utils/Attributes.php | 21 --------------------- tests/unit/helpers.php | 19 +++++++++++++++++++ 8 files changed, 48 insertions(+), 54 deletions(-) delete mode 100644 src/Utils/Attributes.php create mode 100644 src/helpers.php delete mode 100644 tests/unit/Utils/Attributes.php create mode 100644 tests/unit/helpers.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 434f997..f92ae8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index 98f954c..861f5c1 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Fields/Field.php b/src/Fields/Field.php index 3f9cbad..fb55466 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -8,7 +8,6 @@ use PHPForm\Exceptions\ValidationError; use PHPForm\PHPFormConfig; -use PHPForm\Utils\Attributes; abstract class Field { @@ -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; diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 664a788..cc56c10 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -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 { @@ -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)); diff --git a/src/Utils/Attributes.php b/src/Utils/Attributes.php deleted file mode 100644 index cedf360..0000000 --- a/src/Utils/Attributes.php +++ /dev/null @@ -1,18 +0,0 @@ -assertEquals(Attributes::prettyName("label_name"), 'Label name'); - $this->assertEquals(Attributes::prettyName(""), ''); - } - - public function testSnakeToCamel() - { - $this->assertEquals(Attributes::snakeToCamel("label_name"), 'LabelName'); - $this->assertEquals(Attributes::snakeToCamel("label_with_name"), 'LabelWithName'); - } -} diff --git a/tests/unit/helpers.php b/tests/unit/helpers.php new file mode 100644 index 0000000..910b360 --- /dev/null +++ b/tests/unit/helpers.php @@ -0,0 +1,19 @@ +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'); + } +}