PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / google / ramsey / collection / src / Tool / ValueToStringTrait.php

ValueToStringTrait.php in Media Cloud Sync 1.4.1, at includes/sdk/google/ramsey/collection/src/Tool/ValueToStringTrait.php

81 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the ramsey/collection library
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12 declare (strict_types=1);
13 namespace Dudlewebs\WPMCS\GCP\Ramsey\Collection\Tool;
14
15 use DateTimeInterface;
16 use function assert;
17 use function get_resource_type;
18 use function is_array;
19 use function is_bool;
20 use function is_callable;
21 use function is_object;
22 use function is_resource;
23 use function is_scalar;
24 /**
25 * Provides functionality to express a value as string
26 */
27 trait ValueToStringTrait
28 {
29 /**
30 * Returns a string representation of the value.
31 *
32 * - null value: `'NULL'`
33 * - boolean: `'TRUE'`, `'FALSE'`
34 * - array: `'Array'`
35 * - scalar: converted-value
36 * - resource: `'(type resource #number)'`
37 * - object with `__toString()`: result of `__toString()`
38 * - object DateTime: ISO 8601 date
39 * - object: `'(className Object)'`
40 * - anonymous function: same as object
41 *
42 * @param mixed $value the value to return as a string.
43 */
44 protected function toolValueToString(mixed $value) : string
45 {
46 // null
47 if ($value === null) {
48 return 'NULL';
49 }
50 // boolean constants
51 if (is_bool($value)) {
52 return $value ? 'TRUE' : 'FALSE';
53 }
54 // array
55 if (is_array($value)) {
56 return 'Array';
57 }
58 // scalar types (integer, float, string)
59 if (is_scalar($value)) {
60 return (string) $value;
61 }
62 // resource
63 if (is_resource($value)) {
64 return '(' . get_resource_type($value) . ' resource #' . (int) $value . ')';
65 }
66 // From here, $value should be an object.
67 assert(is_object($value));
68 // __toString() is implemented
69 if (is_callable([$value, '__toString'])) {
70 /** @var string */
71 return $value->__toString();
72 }
73 // object of type \DateTime
74 if ($value instanceof DateTimeInterface) {
75 return $value->format('c');
76 }
77 // unknown type
78 return '(' . $value::class . ' Object)';
79 }
80 }
81