Converts a Step into a JSON-encodable structure.

@param Step  $step
@param array $options

@return array
5748
public function serialize(Step $step, array $options = [])
    {
        $serialized = [
            'id' => $step->getUuid(),
            'parameters' => $this->serializeParameters($step),
            'picking' => $this->serializePicking($step),
            'items' => $this->serializeItems($step, $options),
        ];

        if (!empty($step->getTitle())) {
            $serialized['title'] = $step->getTitle();
        }
        if (!empty($step->getDescription())) {
            $serialized['description'] = $step->getDescription();
        }

        return $serialized;
    }
297425
protected function encodeOptions(array $options) {
        if (0 === count($options)) {
            return "{}";
        }
        ksort($options);
        $output = json_encode($options, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
        return str_replace("\n", "\n        ", $output);
    }
1346938
public static function encodeJson($value, int $options = JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION): string
    {
        return \json_encode($value, $options);
    }
1113129
public function format(array $steps)
    {
        return implode(
            array_map(
                function (StepNode $step) {
                    return $this->getStepText($step) . $this->getArguments($step);
                },
                $steps
            )
        );
    }
1097361
public static function fromJson($json, int $options = 0)
    {
        $result = json_decode($json, true, 512, $options);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new JsonDecodeException(json_last_error_msg());
        }

        return new static(\is_array($result) ? $result : []);
    }
87375
protected function convertArgs($step)
    {
        if ($step instanceof Operator) {
            $arguments = $step->getArguments();
        } else {
            $arguments = $step;
        }

        if (is_array($arguments)) {
            $values = [];
            foreach ($arguments as $key => $args) {
                if ($args instanceof Operator) {
                    if (is_string($key)) {
                        $values[$key] = [$this->cmd.$args->getOperatorName() => $this->convertArgs($args)];
                    } else {
                        $values[] = [$this->cmd.$args->getOperatorName() => $this->convertArgs($args)];
                    }
                } else {
                    if (is_string($key)) {
                        $values[$key] = $this->convertArgs($args);
                    } else {
                        $values[] = $args;
                    }
                }
            }

            return $values;

        } elseif ($arguments instanceof Operator) {
            return [$this->cmd.$arguments->getOperatorName() => $this->convertArgs($arguments)];
        } else {
            return $arguments;
        }
    }
1321960
private function deserializeStep(Path $path, $data, array &$stepIds, array $options = [])
    {
        if (in_array(Options::REFRESH_UUID, $options)) {
            $step = new Step();
        } else {
            $step = $this->stepRepo->findOneBy(['uuid' => $data['id']]) ?? new Step();
            $step->setUuid($data['id']);
        }

        $step->setPath($path);

        $stepIds[] = $step->getUuid();

        if (isset($data['title'])) {
            $step->setTitle($data['title']);
        }
        if (isset($data['description'])) {
            $step->setDescription($data['description']);
        }
        if (isset($data['poster'])) {
            $step->setPoster($data['poster']['url']);
        }

        if (isset($data['display'])) {
            if (isset($data['display']['numbering'])) {
                $step->setNumbering($data['display']['numbering']);
            }
            if (isset($data['display']['height'])) {
                $step->setActivityHeight($data['display']['height']);
            }
        }

        /* Set primary resource */
        $resource = isset($data['primaryResource']['id']) ?
            $this->resourceNodeRepo->findOneBy(['uuid' => $data['primaryResource']['id']]) :
            null;
        $step->setResource($resource);

        if (isset($data['showResourceHeader'])) {
            $step->setShowResourceHeader($data['showResourceHeader']);
        }

        // Set secondary resources
        if (isset($data['secondaryResources'])) {
            $step->emptySecondaryResources();

            foreach ($data['secondaryResources'] as $index => $resourceData) {
                $secondaryResource = new SecondaryResource();
                $secondaryResource->setOrder($index);

                /** @var ResourceNode $resource */
                $resource = $this->resourceNodeRepo->findOneBy(['uuid' => $resourceData['id']]);
                $secondaryResource->setResource($resource);

                $step->addSecondaryResource($secondaryResource);
            }
        }

        // Set children steps
        if (isset($data['children'])) {
            $step->emptyChildren();

            foreach ($data['children'] as $childIndex => $childData) {
                $child = $this->deserializeStep($path, $childData, $stepIds, $options);

                $child->setOrder($childIndex);
                $step->addChild($child);
            }
        }

        return $step;
    }
972655
public function toJson($options = 0)
    {
        return [
            'id' => $this->job->getId(),
            'data' => $this->job->getData(),
            'stats' => $this->stats,
        ];
    }
1257182
public function json(array $data = array(), $options = JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
    {

        if (!headers_sent())
        {
            header('Cache-Control: no-cache, must-revalidate');
            header('Expires: Tue, 19 May 1981 18:00:00 GMT');
            header('Content-type: application/json; charset=utf-8');
        }

        /**
         * @var \Deimos\Helper\Helpers\Json $json
         */
        $json = clone $this->helper->json();
        $json->setOption((array)$options);

        return $json->encode($data);

    }
1053012
private function deserializeParameters(Step $step, array $parameters)
    {
        $this->sipe('maxAttempts', 'setMaxAttempts', $parameters, $step);
        $this->sipe('duration', 'setDuration', $parameters, $step);
    }
565335
protected function create($step)
    {
        foreach (array('names', 'identifier') as $key) {
            if (!isset($step->dsl[$key])) {
                throw new \Exception("The '$key' key is missing in a object state group creation definition");
            }
        }

        $objectStateService = $this->repository->getObjectStateService();

        $objectStateGroupIdentifier = $this->referenceResolver->resolveReference($step->dsl['identifier']);
        $objectStateGroupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct($objectStateGroupIdentifier);
        $objectStateGroupCreateStruct->defaultLanguageCode = $this->getLanguageCode($step); // was: self::DEFAULT_LANGUAGE_CODE;

        foreach ($step->dsl['names'] as $languageCode => $name) {
            $objectStateGroupCreateStruct->names[$languageCode] = $name;
        }
        if (isset($step->dsl['descriptions'])) {
            foreach ($step->dsl['descriptions'] as $languageCode => $description) {
                $objectStateGroupCreateStruct->descriptions[$languageCode] = $description;
            }
        }

        $objectStateGroup = $objectStateService->createObjectStateGroup($objectStateGroupCreateStruct);

        $this->setReferences($objectStateGroup, $step);

        return $objectStateGroup;
    }
1275242
public function encode($data, $options = 0) {
        $json = null;

        if ($data instanceof IArrayable) {
            $json = @json_encode($data->toArray(), $options);
        } else if ($data instanceof IJsonable) {
            $json = $data->toJson($options);
        } else if (is_array($data) || is_object($data)) {
            $json =  @json_encode($data, $options);
        } else {
            throw new InvalidDataTypeException(
                s('Can not convert data of type "%s" to json.', get_type($data))
            );
        }

        if ($json === false) {
            throw new JsonEncodeException(json_last_error_msg(), $data);
        }

        return $json;
    }
668450
protected function processStep(Node\Step $step)
    {
        $result = [
            'keyword' => $step->getKeyword(),
            'name' => $step->getName(),
            'line' => $step->getLine(),
            'match' => $step->getMatch(),
            'result' => $step->getProcessedResult(),
            'arguments' => $this->processArguments($step->getArguments()),
        ];

        if (count($step->getEmbeddings())) {
            $result['embeddings'] = $step->getEmbeddings();
        }

        return $result;
    }
391901
protected function redirectToStep( $step )
    {
        $routeMatch = $this->getEvent()
                           ->getRouteMatch();

        return $this->redirect()
                    ->toRoute( $routeMatch->getMatchedRouteName(),
                               ArrayUtils::merge(
                                   $routeMatch->getParams(),
                                   array( 'step' => $step )
                               ) );
    }
1067664
private function serializeUserProgression(Step $step)
    {
        $user = $this->tokenStorage->getToken()->getUser();
        $userProgression = 'anon.' !== $user ?
            $this->userProgressionRepo->findOneBy(['step' => $step, 'user' => $user]) :
            null;
        $data = [
            'status' => empty($userProgression) ? 'unseen' : $userProgression->getStatus(),
        ];

        return $data;
    }
1361759
static function NextStep($step)
    {
        $keys = array_keys(self::Steps());
        $index = array_search($step, $keys);
        if ($index !== false && $index < count($keys) - 1)
        {
           return $keys[$index + 1];
        }
        return null;
    }
1346405
def step_definition(step_name):
    
    if not orca.is_step(step_name):
        abort(404)

    filename, lineno, source = \
        orca.get_step(step_name).func_source_data()
    html = highlight(source, PythonLexer(), HtmlFormatter())
    return jsonify(filename=filename, lineno=lineno, text=source, html=html)