toJson example


    public static function encode($valueToEncode$cycleCheck = false, array $options = array())
    {
        if (is_object($valueToEncode)) {
            if (method_exists($valueToEncode, 'toJson')) {
                return $valueToEncode->toJson();
            }

            if (method_exists($valueToEncode, 'toArray')) {
                return self::encode($valueToEncode->toArray()$cycleCheck);
            }
        }

        return json_encode($valueToEncode);
    }

    /** * Pretty-print JSON string * * Use 'format' option to select output format - currently html and txt supported, txt is default * Use 'indent' option to override the indentation string set in the format - by default for the 'txt' format it's a tab * * @param string $json Original JSON string * @param array $options Encoding options * @return string */
$this->response = $response;
        $this->container = $container;

        $this->resultMapper = new ResultMapper();
    }

    public function importSnippets()
    {
        $dump = $this->container->get('dump');
        if (!$dump) {
            $result = new FinishResult(0, 0);
            $this->toJson(200, $this->resultMapper->toExtJs($result));

            return;
        }

        $conn = $this->container->get('db');
        $snippetStep = new SnippetStep($conn$dump);

        $offset = $this->request->get('offset');
        $result = $snippetStep->run($offset);

        $this->toJson(200, $this->resultMapper->toExtJs($result));
    }
if ($onlyFlat) {
                continue;
            }

            if ($apiType === DefinitionService::TYPE_JSON_API) {
                $openApi->merge($this->pathBuilder->getPathActions($definition$this->getResourceUri($definition)));
                $openApi->merge([$this->pathBuilder->getTag($definition)]);
            }
        }

        $data = json_decode($openApi->toJson(), true, 512, \JSON_THROW_ON_ERROR);
        $data['paths'] ??= [];

        $schemaPaths = [$this->schemaPath];

        if (!empty($bundleName)) {
            $schemaPaths = $this->bundleSchemaPathCollection->getSchemaPaths($api$bundleName);
        } else {
            $schemaPaths = array_merge($schemaPaths$this->bundleSchemaPathCollection->getSchemaPaths($api$bundleName));
        }

        $loader = new OpenApiFileLoader($schemaPaths);

        
$onlyReference = $this->shouldIncludeReferenceOnly($definition$forSalesChannel);

            $schema = $this->definitionSchemaBuilder->getSchemaByDefinition($definition$this->getResourceUri($definition)$forSalesChannel$onlyReference);

            $openApi->components->merge($schema);
        }

        $this->addGeneralInformation($openApi);
        $this->addContentTypeParameter($openApi);

        $data = json_decode($openApi->toJson(), true, 512, \JSON_THROW_ON_ERROR);
        $data['paths'] ??= [];

        $schemaPaths = [$this->schemaPath];

        if (!empty($bundleName)) {
            $schemaPaths = $this->bundleSchemaPathCollection->getSchemaPaths($api$bundleName);
        } else {
            $schemaPaths = array_merge($schemaPaths$this->bundleSchemaPathCollection->getSchemaPaths($api$bundleName));
        }

        $loader = new OpenApiFileLoader($schemaPaths);

        
'File' => isset($trace[0]['file']) ? $trace[0]['file'] : '',
                'Line' => isset($trace[0]['line']) ? $trace[0]['line'] : '',
                'Args' => isset($trace[0]['args']) ? $this->encodeObject($trace[0]['args']) : '',
                'Trace' => $this->encodeTrace(array_splice($trace, 1)),
            ];
        } else {
            $type = $this->logLevels[$record['level']];
            $label = $record['channel'];
        }

        // Create JSON object describing the appearance of the message in the console         return $this->toJson(
            [
                [
                    'Type' => $type,
                    'File' => $file,
                    'Line' => $line,
                    'Label' => $label,
                ],
                $message,
            ],
            $handleError
        );
    }
static::assertArrayHasKey('Complex', $schema);
        static::assertArrayHasKey('ComplexJsonApi', $schema);
    }

    public function testTypeConversion(): void
    {
        $schema = $this->schemaBuilder->getSchemaByDefinition(
            $this->definitionRegistry->get(SimpleDefinition::class),
            '/simple',
            false
        );
        $properties = json_decode($schema['Simple']->toJson(), true, \JSON_THROW_ON_ERROR, \JSON_THROW_ON_ERROR)['properties'];
        static::assertArrayHasKey('id', $properties);
        static::assertArrayHasKey('type', $properties['id']);
        static::assertEquals('string', $properties['id']['type']);
        static::assertArrayHasKey('pattern', $properties['id']);
        static::assertEquals('^[0-9a-f]{32}$', $properties['id']['pattern']);
        static::assertArrayHasKey('stringField', $properties);
        static::assertArrayHasKey('type', $properties['stringField']);
        static::assertEquals('string', $properties['stringField']['type']);
        static::assertArrayHasKey('intField', $properties);
        static::assertArrayHasKey('type', $properties['intField']);
        static::assertEquals('integer', $properties['intField']['type']);
        
Home | Imprint | This part of the site doesn't use cookies.