Skip to content

Commit

Permalink
8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberroland committed Dec 7, 2023
1 parent 92d08dd commit a03fa9a
Show file tree
Hide file tree
Showing 35 changed files with 515 additions and 248 deletions.
1 change: 1 addition & 0 deletions lam-packaging/debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ main license and authors:

lib/3rdParty/composer/beberlei G 2013 Benjamin Eberlei
lib/3rdParty/composer/brick B Benjamin Morel
lib/3rdParty/composer/carbonphp B 2023 Carbon
lib/3rdParty/composer/christian-riesen B Christian Riesen
lib/3rdParty/composer/composer B Nils Adermann, Jordi Boggiano
lib/3rdParty/composer/doctrine B Doctrine Project
Expand Down
108 changes: 89 additions & 19 deletions lam/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lam/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ main license and authors:

lib/3rdParty/composer/beberlei G 2013 Benjamin Eberlei
lib/3rdParty/composer/brick B Benjamin Morel
lib/3rdParty/composer/carbonphp B 2023 Carbon
lib/3rdParty/composer/christian-riesen B Christian Riesen
lib/3rdParty/composer/composer B Nils Adermann, Jordi Boggiano
lib/3rdParty/composer/doctrine B Doctrine Project
Expand Down
21 changes: 21 additions & 0 deletions lam/lib/3rdParty/composer/carbonphp/carbon-doctrine-types/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Carbon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# carbonphp/carbon-doctrine-types

Types to use Carbon in Doctrine

## Documentation

[Check how to use in the official Carbon documentation](https://carbon.nesbot.com/symfony/)

This package is an externalization of [src/Carbon/Doctrine](https://github.com/briannesbitt/Carbon/tree/2.71.0/src/Carbon/Doctrine)
from `nestbot/carbon` package.

Externalization allows to better deal with different versions of dbal. With
version 4.0 of dbal, it no longer sustainable to be compatible with all version
using a single code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "carbonphp/carbon-doctrine-types",
"description": "Types to use Carbon in Doctrine",
"type": "library",
"keywords": [
"date",
"time",
"DateTime",
"Carbon",
"Doctrine"
],
"require": {
"php": "^7.4 || ^8.0"
},
"require-dev": {
"doctrine/dbal": "^3.7.0",
"nesbot/carbon": "^2.71.0 || ^3.0.0",
"phpunit/phpunit": "^10.3"
},
"conflict": {
"doctrine/dbal": "<3.7.0 || >=4.0.0"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Carbon\\Doctrine\\": "src/Carbon/Doctrine/"
}
},
"authors": [
{
"name": "KyleKatarn",
"email": "[email protected]"
}
],
"minimum-stability": "dev"
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/**
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Carbon\Doctrine;

use Doctrine\DBAL\Platforms\AbstractPlatform;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Carbon\Doctrine;

class CarbonImmutableType extends DateTimeImmutableType implements CarbonDoctrineType
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Carbon\Doctrine;

class CarbonType extends DateTimeType implements CarbonDoctrineType
{
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?php

/**
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Carbon\Doctrine;

use Carbon\Carbon;
Expand All @@ -23,6 +14,14 @@
*/
trait CarbonTypeConverter
{
/**
* This property differentiates types installed by carbonphp/carbon-doctrine-types
* from the ones embedded previously in nesbot/carbon source directly.
*
* @readonly
*/
public bool $external = true;

/**
* @return class-string<T>
*/
Expand All @@ -31,20 +30,9 @@ protected function getCarbonClassName(): string
return Carbon::class;
}

/**
* @return string
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
$precision = $fieldDeclaration['precision'] ?: 10;

if ($fieldDeclaration['secondPrecision'] ?? false) {
$precision = 0;
}

if ($precision === 10) {
$precision = DateTimeDefaultPrecision::get();
}
$precision = $fieldDeclaration['precision'] ?? DateTimeDefaultPrecision::get();

$type = parent::getSQLDeclaration($fieldDeclaration, $platform);

Expand Down Expand Up @@ -90,7 +78,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
if (!$date) {
throw ConversionException::conversionFailedFormat(
$value,
$this->getName(),
$this->getTypeName(),
'Y-m-d H:i:s.u or any format supported by '.$class.'::parse()',
$error
);
Expand All @@ -101,10 +89,8 @@ public function convertToPHPValue($value, AbstractPlatform $platform)

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @return string|null
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
if ($value === null) {
return $value;
Expand All @@ -116,8 +102,16 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)

throw ConversionException::conversionFailedInvalidType(
$value,
$this->getName(),
$this->getTypeName(),
['null', 'DateTime', 'Carbon']
);
}

private function getTypeName(): string
{
$chunks = explode('\\', static::class);
$type = preg_replace('/Type$/', '', end($chunks));

return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $type));
}
}
Loading

0 comments on commit a03fa9a

Please sign in to comment.