From ab59405050889dce0341925daba8cd8e2dd2d881 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Sun, 3 Mar 2019 08:52:02 -0800 Subject: [PATCH] Fix #97, #98, 101, 102 --- README.md | 3 ++- src/Support/FieldOptimizer.php | 1 - src/Support/FieldTransformer.php | 11 +++++++++-- src/Support/Str.php | 17 ++++++++++++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6c42312..5089af1 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,8 @@ Checkout our channel on change-log in v2.3 branch and document it in the CrestApps-site repository. For any help, my email can be found in the `composer.json` file, feel free to send me an email. +- Please start by ***Staring*** this package on GitHub. - Sharing this projects with others is your way of saying keep improvements and new awesome feature coming. - Report any bugs or send us any comments, idea, thought that you may have about this project as an issue on GitHub. diff --git a/src/Support/FieldOptimizer.php b/src/Support/FieldOptimizer.php index eb0f8b0..756c4c9 100644 --- a/src/Support/FieldOptimizer.php +++ b/src/Support/FieldOptimizer.php @@ -209,7 +209,6 @@ protected function optimizeBoolean() protected function optimizePrimaryKey() { if ($this->field->isPrimary()) { - $this->field->isNullable = false; if ($this->meta == null) { diff --git a/src/Support/FieldTransformer.php b/src/Support/FieldTransformer.php index f141f7d..3a67d67 100644 --- a/src/Support/FieldTransformer.php +++ b/src/Support/FieldTransformer.php @@ -92,17 +92,24 @@ public static function fromString($str, $localeGroup = 'generic', array $languag if (str_contains($fieldName, ':')) { // Handle the following format // name:a;html-type:select;options:first|second|third|fourth - if (!str_is('*name*:*', $fieldName)) { + if (!Str::is('*name*:*', $fieldName)) { throw new Exception('The "name" property was not provided and is required!'); } $parts = Arr::fromString($fieldName, ';'); foreach ($parts as $part) { - if (!str_is('*:*', $part) || count($properties = Arr::fromString($part, ':')) < 2) { + if (!Str::is('*:*', $part) || count($properties = Arr::fromString($part, ':')) < 2) { throw new Exception('Each provided property should use the following format "key:value"'); } list($key, $value) = $properties; + + if(Str::startsWith($key, 'is-')){ + $field[$key] = Str::stringToBool($value); + } else { + $field[$key] = $value; + } + $field[$key] = $value; if ($key == 'options') { $options = Arr::fromString($value, '|'); diff --git a/src/Support/Str.php b/src/Support/Str.php index 9e157fd..a39a630 100644 --- a/src/Support/Str.php +++ b/src/Support/Str.php @@ -126,7 +126,22 @@ public static function trimStart($subject, $search) return $subject; } - + + /** + * Check a string for a positive keyword + * + * @param string $str + * + * @return array + */ + public static function stringToBool($str) + { + if (is_bool($str)) { + return $str; + } + return in_array(strtolower($str), ['true', 'yes', '1', 'valid', 'correct']); + } + /** * Checks if a string matches at least one given pattern *