From c81f7ca0661b33920bb5d6d5e29bc4380942e0d2 Mon Sep 17 00:00:00 2001 From: Vlasta Neubauer Date: Fri, 4 May 2018 16:48:41 +0200 Subject: [PATCH] Handlers for most types --- build.xml | 99 ++++++++++++++++++++++++++ build/codesniffer/ruleset.xml | 90 +++++++++++++++++++++++ build/phpstan/phpstan.neon | 8 +++ build/spell-checker/custom.dic | 7 ++ build/spell-checker/spell-checker.neon | 21 ++++++ composer.json | 36 ++++++++++ src/Country/CountryType.php | 30 ++++++++ src/Email/EmailAddressType.php | 55 ++++++++++++++ src/Email/EmailHeaderType.php | 30 ++++++++ src/Enum/IntEnumType.php | 59 +++++++++++++++ src/Enum/StringEnumType.php | 59 +++++++++++++++ src/Http/HttpHeaderType.php | 30 ++++++++ src/Http/HttpMethodType.php | 30 ++++++++ src/Http/HttpResponseStatusType.php | 30 ++++++++ src/Language/EncodingType.php | 30 ++++++++ src/Language/LanguageType.php | 30 ++++++++ src/Language/Locale/LocaleType.php | 55 ++++++++++++++ src/Language/ScriptType.php | 30 ++++++++ src/Money/CurrencyType.php | 30 ++++++++ src/Time/DateTimeType.php | 46 ++++++++++++ src/Time/DateTimeUnitType.php | 30 ++++++++ src/Time/DateType.php | 46 ++++++++++++ src/Time/DayOfWeekType.php | 30 ++++++++ src/Time/MonthType.php | 30 ++++++++ src/Time/TimeType.php | 46 ++++++++++++ src/Web/DomainType.php | 55 ++++++++++++++ src/Web/HostType.php | 55 ++++++++++++++ src/Web/TldType.php | 30 ++++++++ src/Web/UriSchemeType.php | 30 ++++++++ src/Web/UrlType.php | 55 ++++++++++++++ src/embeddables.yaml | 25 +++++++ 31 files changed, 1237 insertions(+) create mode 100644 build.xml create mode 100644 build/codesniffer/ruleset.xml create mode 100644 build/phpstan/phpstan.neon create mode 100644 build/spell-checker/custom.dic create mode 100644 build/spell-checker/spell-checker.neon create mode 100644 composer.json create mode 100644 src/Country/CountryType.php create mode 100644 src/Email/EmailAddressType.php create mode 100644 src/Email/EmailHeaderType.php create mode 100644 src/Enum/IntEnumType.php create mode 100644 src/Enum/StringEnumType.php create mode 100644 src/Http/HttpHeaderType.php create mode 100644 src/Http/HttpMethodType.php create mode 100644 src/Http/HttpResponseStatusType.php create mode 100644 src/Language/EncodingType.php create mode 100644 src/Language/LanguageType.php create mode 100644 src/Language/Locale/LocaleType.php create mode 100644 src/Language/ScriptType.php create mode 100644 src/Money/CurrencyType.php create mode 100644 src/Time/DateTimeType.php create mode 100644 src/Time/DateTimeUnitType.php create mode 100644 src/Time/DateType.php create mode 100644 src/Time/DayOfWeekType.php create mode 100644 src/Time/MonthType.php create mode 100644 src/Time/TimeType.php create mode 100644 src/Web/DomainType.php create mode 100644 src/Web/HostType.php create mode 100644 src/Web/TldType.php create mode 100644 src/Web/UriSchemeType.php create mode 100644 src/Web/UrlType.php create mode 100644 src/embeddables.yaml diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..bdcc49c --- /dev/null +++ b/build.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build/codesniffer/ruleset.xml b/build/codesniffer/ruleset.xml new file mode 100644 index 0000000..547fa19 --- /dev/null +++ b/build/codesniffer/ruleset.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + testClass + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tests/ + + + + /exceptions/ + /tests/ + + + + + + + + + + + diff --git a/build/phpstan/phpstan.neon b/build/phpstan/phpstan.neon new file mode 100644 index 0000000..706d7bf --- /dev/null +++ b/build/phpstan/phpstan.neon @@ -0,0 +1,8 @@ + +parameters: + ignoreErrors: + # strange + - '~^Parameter #1 $value of static method Dogma\Math\Decimal\Decimal::parse() expects string, string|int|null given.~' + + # misleading + - '~^Parameter #1 $value of class Dogma\Math\Decimal\Decimal constructor expects string|int, int|string|Dogma\Math\Decimal\Decimal given.~' # if (!$x instanceof C) diff --git a/build/spell-checker/custom.dic b/build/spell-checker/custom.dic new file mode 100644 index 0000000..24e6720 --- /dev/null +++ b/build/spell-checker/custom.dic @@ -0,0 +1,7 @@ + +# code +inflector +instanceof +iso +tld +uri diff --git a/build/spell-checker/spell-checker.neon b/build/spell-checker/spell-checker.neon new file mode 100644 index 0000000..652096e --- /dev/null +++ b/build/spell-checker/spell-checker.neon @@ -0,0 +1,21 @@ + +directories: + - build + - src + - tests + - // + +dictionariesByFileName: [] + +dictionariesByFileExtension: + neon: en custom + php: en php custom + +dictionaryDirectories: + - build/spell-checker + - vendor/spell-checker + +checkLocalIgnores: true + +dictionaryFilesToCheck: + - custom.dic diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..167405b --- /dev/null +++ b/composer.json @@ -0,0 +1,36 @@ +{ + "name": "dogma/dogma-doctrine", + "type": "library", + "description": "Doctrine type handlers for Dogma types.", + "homepage": "http://github.com/paranoiq/dogma-doctrine", + "license": ["BSD-3-Clause"], + "authors": [ + { + "name": "Vlasta Neubauer", + "homepage": "http://www.paranoiq.cz" + } + ], + "require": { + "php-64bit": "^7.1.0", + "doctrine/orm": "~2.6", + "tracy/tracy": "~2.4" + }, + "require-dev": { + "consistence/coding-standard": "~2.3", + "jakub-onderka/php-console-highlighter": "~0.3", + "jakub-onderka/php-parallel-lint": "~0.8", + "nette/tester": "~1.7", + "phing/phing": "~2.16", + "phpstan/phpstan": "~0.8", + "slevomat/coding-standard": "~4.3", + "squizlabs/php_codesniffer": "~3.2", + "spell-checker/spell-checker": "~0.3", + "spell-checker/dictionary-en": "~0.1" + }, + "autoload": { + "classmap": ["src"] + }, + "config": { + "bin-dir": "bin" + } +} diff --git a/src/Country/CountryType.php b/src/Country/CountryType.php new file mode 100644 index 0000000..841371a --- /dev/null +++ b/src/Country/CountryType.php @@ -0,0 +1,30 @@ +getValue() : $value; + } + + public function requiresSQLCommentHint(AbstractPlatform $platform): bool + { + return true; + } + +} diff --git a/src/Email/EmailHeaderType.php b/src/Email/EmailHeaderType.php new file mode 100644 index 0000000..fd26f93 --- /dev/null +++ b/src/Email/EmailHeaderType.php @@ -0,0 +1,30 @@ +getEnumClass(); + + return $enumClass::get($value); + } + + /** + * @param \Dogma\Enum\IntEnum|int|null $value + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @return int|null + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int + { + return $value instanceof IntEnum ? $value->getValue() : $value; + } + + public function requiresSQLCommentHint(AbstractPlatform $platform): bool + { + return true; + } + +} diff --git a/src/Enum/StringEnumType.php b/src/Enum/StringEnumType.php new file mode 100644 index 0000000..f6fa0b0 --- /dev/null +++ b/src/Enum/StringEnumType.php @@ -0,0 +1,59 @@ +getEnumClass(); + + return $enumClass::get($value); + } + + /** + * @param \Dogma\Enum\StringEnum|string|null $value + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @return string|null + */ + public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string + { + return $value instanceof StringEnum ? $value->getValue() : $value; + } + + public function requiresSQLCommentHint(AbstractPlatform $platform): bool + { + return true; + } + +} diff --git a/src/Http/HttpHeaderType.php b/src/Http/HttpHeaderType.php new file mode 100644 index 0000000..ee3218d --- /dev/null +++ b/src/Http/HttpHeaderType.php @@ -0,0 +1,30 @@ +getValue() : $value; + } + + public function requiresSQLCommentHint(AbstractPlatform $platform): bool + { + return true; + } + +} diff --git a/src/Language/ScriptType.php b/src/Language/ScriptType.php new file mode 100644 index 0000000..42398d5 --- /dev/null +++ b/src/Language/ScriptType.php @@ -0,0 +1,30 @@ +getName() : $value; + } + + public function requiresSQLCommentHint(AbstractPlatform $platform): bool + { + return true; + } + +} diff --git a/src/Web/HostType.php b/src/Web/HostType.php new file mode 100644 index 0000000..4fc5ff9 --- /dev/null +++ b/src/Web/HostType.php @@ -0,0 +1,55 @@ +format() : $value; + } + + public function requiresSQLCommentHint(AbstractPlatform $platform): bool + { + return true; + } + +} diff --git a/src/Web/TldType.php b/src/Web/TldType.php new file mode 100644 index 0000000..8338ec5 --- /dev/null +++ b/src/Web/TldType.php @@ -0,0 +1,30 @@ +getValue() : $value; + } + + public function requiresSQLCommentHint(AbstractPlatform $platform): bool + { + return true; + } + +} diff --git a/src/embeddables.yaml b/src/embeddables.yaml new file mode 100644 index 0000000..26728de --- /dev/null +++ b/src/embeddables.yaml @@ -0,0 +1,25 @@ + +Dogma\Geolocation\Position: + type: embeddable + fields: + latitude: { type: float } + longitude: { type: float } + +Dogma\Math\FloatInterval: + type: embeddable + fields: + start: { type: float } + end: { type: float } + +Dogma\Math\IntInterval: + type: embeddable + fields: + start: { type: integer } + end: { type: integer } + +Dogma\Math\Vector3: + type: embeddable + fields: + x: { type: float } + y: { type: float } + z: { type: float }