isStringable example

/** * Sanitizes a param. * * The return value is an array with the sanitized value and a boolean * indicating if the original value was kept (allowing to use the sanitized value to explain the query). * * @return array{0: mixed, 1: bool, 2: bool} */
    private function sanitizeParam(mixed $var, ?\Throwable $error): array
    {
        if (\is_object($var)) {
            return [$o = new ObjectParameter($var$error), false, $o->isStringable() && !$error];
        }

        if ($error) {
            return ['⚠ ' . $error->getMessage(), false, false];
        }

        if (\is_array($var)) {
            $a = [];
            $explainable = $runnable = true;
            foreach ($var as $k => $v) {
                [$value$e$r] = $this->sanitizeParam($v, null);
                

        $this->assertSame('abc', LazyString::resolve('abc'));
        $this->assertSame('1', LazyString::resolve(true));
        $this->assertSame('', LazyString::resolve(false));
        $this->assertSame('123', LazyString::resolve(123));
        $this->assertSame('123.456', LazyString::resolve(123.456));
        $this->assertStringContainsString('hello', LazyString::resolve(new \Exception('hello')));
    }

    public function testIsStringable()
    {
        $this->assertTrue(LazyString::isStringable('abc'));
        $this->assertTrue(LazyString::isStringable(true));
        $this->assertTrue(LazyString::isStringable(false));
        $this->assertTrue(LazyString::isStringable(123));
        $this->assertTrue(LazyString::isStringable(123.456));
        $this->assertTrue(LazyString::isStringable(new \Exception('hello')));
    }

    public function testIsNotStringable()
    {
        $this->assertFalse(LazyString::isStringable(null));
        $this->assertFalse(LazyString::isStringable([]));
        
$s->attr['file'] = $f;
                    $s->attr['line'] = $r->getStartLine();
                } else {
                    unset($s->attr['file']);
                    unset($s->attr['line']);
                }

                if ($error = $o->getError()) {
                    return [Caster::PREFIX_VIRTUAL.'⚠' => $error->getMessage()];
                }

                if ($o->isStringable()) {
                    return [Caster::PREFIX_VIRTUAL.'__toString()' => (string) $o->getObject()];
                }

                return [Caster::PREFIX_VIRTUAL.'⚠' => sprintf('Object of class "%s" could not be converted to string.', $o->getClass())];
            },
        ];
    }

    private function sanitizeQueries(string $connectionName, array $queries): array
    {
        foreach ($queries as $i => $query) {
            
Home | Imprint | This part of the site doesn't use cookies.