Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 150
Zeile 1... Zeile 1...
1
<?php
1
<?php
Zeile 2... Zeile 2...
2
 
2
 
Zeile 3... Zeile 3...
3
namespace Illuminate\Database\Eloquent\Concerns;
3
namespace Illuminate\Database\Eloquent\Concerns;
-
 
4
 
-
 
5
use BackedEnum;
-
 
6
use Brick\Math\BigDecimal;
4
 
7
use Brick\Math\Exception\MathException as BrickMathException;
5
use BackedEnum;
8
use Brick\Math\RoundingMode;
6
use Carbon\CarbonImmutable;
9
use Carbon\CarbonImmutable;
7
use Carbon\CarbonInterface;
10
use Carbon\CarbonInterface;
8
use DateTimeImmutable;
11
use DateTimeImmutable;
Zeile 21... Zeile 24...
21
use Illuminate\Database\Eloquent\Relations\Relation;
24
use Illuminate\Database\Eloquent\Relations\Relation;
22
use Illuminate\Database\LazyLoadingViolationException;
25
use Illuminate\Database\LazyLoadingViolationException;
23
use Illuminate\Support\Arr;
26
use Illuminate\Support\Arr;
24
use Illuminate\Support\Carbon;
27
use Illuminate\Support\Carbon;
25
use Illuminate\Support\Collection as BaseCollection;
28
use Illuminate\Support\Collection as BaseCollection;
-
 
29
use Illuminate\Support\Exceptions\MathException;
26
use Illuminate\Support\Facades\Crypt;
30
use Illuminate\Support\Facades\Crypt;
27
use Illuminate\Support\Facades\Date;
31
use Illuminate\Support\Facades\Date;
28
use Illuminate\Support\Str;
32
use Illuminate\Support\Str;
29
use InvalidArgumentException;
33
use InvalidArgumentException;
30
use LogicException;
34
use LogicException;
31
use ReflectionClass;
35
use ReflectionClass;
32
use ReflectionMethod;
36
use ReflectionMethod;
33
use ReflectionNamedType;
37
use ReflectionNamedType;
34
use RuntimeException;
-
 
35
use TypeError;
-
 
Zeile 36... Zeile 38...
36
 
38
 
37
trait HasAttributes
39
trait HasAttributes
38
{
40
{
39
    /**
41
    /**
Zeile 1320... Zeile 1322...
1320
     * @param  int  $decimals
1322
     * @param  int  $decimals
1321
     * @return string
1323
     * @return string
1322
     */
1324
     */
1323
    protected function asDecimal($value, $decimals)
1325
    protected function asDecimal($value, $decimals)
1324
    {
1326
    {
-
 
1327
        try {
-
 
1328
            return (string) BigDecimal::of($value)->toScale($decimals, RoundingMode::HALF_UP);
1325
        if (extension_loaded('bcmath')) {
1329
        } catch (BrickMathException $e) {
1326
            return bcadd($value, 0, $decimals);
1330
            throw new MathException('Unable to cast value to a decimal.', previous: $e);
1327
        }
1331
        }
1328
 
-
 
1329
        if (! is_numeric($value)) {
-
 
1330
            throw new TypeError('$value must be numeric.');
-
 
1331
        }
-
 
1332
 
-
 
1333
        if (is_string($value) && Str::contains($value, 'e', true)) {
-
 
1334
            throw new RuntimeException('The "decimal" model cast is unable to handle string based floats with exponents.');
-
 
1335
        }
-
 
1336
 
-
 
1337
        [$int, $fraction] = explode('.', $value) + [1 => ''];
-
 
1338
 
-
 
1339
        return Str::of($int)->padLeft('1', '0').'.'.Str::of($fraction)->limit($decimals, '')->padRight($decimals, '0');
-
 
1340
    }
1332
    }
Zeile 1341... Zeile 1333...
1341
 
1333
 
1342
    /**
1334
    /**
1343
     * Return a timestamp as DateTime object with time set to 00:00:00.
1335
     * Return a timestamp as DateTime object with time set to 00:00:00.