create json rpc request
@param object $object
@throws JsonRpcExeption
551958
public function handleJsonRpc($object) {
        try {
            $input  = $this->getJsonRequest();
            $method = $this->getField($input, 'method', null);
            $params = $this->getField($input, 'params', null);
            $id     = intval($this->getField($input, 'id', null));
            // json rpc error
            if (!($method && $id)) {
                if (!$id) {
                    $id = $this->extractId();
                }
                if (!$method) {
                    $error = "no method";
                } else if (!$id) {
                    $error = "no id";
                } else {
                    $error = "unknown reason";
                }
                throw new JsonRpcExeption(103,  "Invalid Request: $error");
            }
            // fix params (if params is null set it to empty array)
            $params = $params ?? [];
            
            // if params is object change it to array
            if (is_object($params)) {
                if (count(get_object_vars($params)) == 0) {
                    $params = [];
                } else {
                    $params = get_object_vars($params);
                }
            }
            
            // call Service Method
            $class = get_class($object);
            $methods = get_class_methods($class);
            if (strcmp($method, "system.describe") == 0) {
                echo json_encode($this->serviceDescription($object));
            } else if (!in_array($method, $methods) && !in_array("__call", $methods)) {
                // __call will be called for any method that's missing
                $msg = "Procedure `" . $method . "' not found";
                throw new JsonRpcExeption(104, $msg);
            } else {
                if (in_array("__call", $methods) && !in_array($method, $methods)) {
                    $result = call_user_func_array(array($object, $method), $params);
                    echo response($result, $id, null);
                } else {
                    $method_object = new \ReflectionMethod($class, $method);
                    $num_got = count($params);
                    $num_expect = $method_object->getNumberOfParameters();
                    if ($num_got != $num_expect) {
                        $msg = "Wrong number of parameters. Got $num_got expect $num_expect";
                        throw new JsonRpcExeption(105, $msg);
                    } else {
                        try {
                            $result = call_user_func_array(array($object, $method), $params);
                            echo $this->response($result, $id, null);
                        } catch (\Exception $e) {
                            throw new JsonRpcExeption(105, $e->getMessage());
                        }
                    }
                }
            }
        } catch (JsonRpcExeption $e) {
            // exteption with error code
            $msg = $e->getMessage();
            $code = $e->code();
            if ($code = 101) { // parse error;
                $id = $this->extractId();
            }
            echo $this->response(null, $id, array("code"=>$code, "message"=>$msg));
        } catch (Exception $e) {
            //catch all exeption from user code
            $msg = $e->getMessage();
            echo $this->response(null, $id, array("code"=>200, "message"=>$msg));
        }
        ob_end_flush();
    }
1078544
private function serializeObjectRecursively($object): array
    {
        $reflection = new ReflectionClass($object);
        $properties = $reflection->getProperties();

        $data = [];
        foreach ($properties as $property) {
            $name = $property->getName();

            $property->setAccessible(true);
            $value = $property->getValue($object);
            $property->setAccessible(false);

            $data[$name] = $this->serializeValue($value);
        }

        return [
            'class' => get_class($object),
            'payload' => $data,
        ];
    }
434609
private static Response createResponse(Object object) {
    if (object == null) {
      return Response.ok().build();
    }

    if (object instanceof Response) {
      return (Response) object;
    }

    if (object instanceof Response.Status) {
      Response.Status s = (Response.Status) object;
      switch (s) {
        case OK:
          return Response.ok().build();
        case ACCEPTED:
          return Response.accepted().build();
        case NO_CONTENT:
          return Response.noContent().build();
        default:
          return createErrorResponse(
              new S3Exception("Response status is invalid", S3ErrorCode.INTERNAL_ERROR));
      }
    }

    // Need to explicitly encode the string as XML because Jackson will not do it automatically.
    XmlMapper mapper = new XmlMapper();
    try {
      return Response.ok(mapper.writeValueAsString(object)).build();
    } catch (JsonProcessingException e) {
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
          .entity("Failed to encode XML: " + e.getMessage()).build();
    }
  }
37394
public function writeObject($object)
    {
        // Loop each element and write the name of the property.
        foreach ($object as $key => &$value) {
            // skip variables starting with an _ private transient
            if( $key[0] == "_") continue;
            $this->_stream->writeUTF($key);
            $this->writeTypeMarker($value);
        }

        // Write the end object flag
        $this->_stream->writeInt(0);
        $this->_stream->writeByte(Zend_Amf_Constants::AMF0_OBJECTTERM);
        return $this;
    }
284751
public function routeByObject($object) : array
    {
        Assert::isObject($object, "Passed non object value to Commmand Bus: " . TypeDescriptor::createFromVariable($object)->toString() . ". Did you wanted to use convertAndSend?");

        $className = get_class($object);
        if (!array_key_exists($className, $this->classNameToChannelNameMapping)) {
            throw ConfigurationException::create("Can't send command to {$className}. No Command Handler defined for it. Have you forgot to add @CommandHandler to method or @MessageEndpoint to class?");
        }

        return $this->classNameToChannelNameMapping[$className];
    }
800690
public static function createAdapterObject($object)
    {
        $wrapperObject = self::create($object, null, function ($method, $arguments, $result) {
            $data['method']    = $method;
            $data['arguments'] = $arguments;

            $appType = php_sapi_name();
            if ($appType == 'cli') {
                $processName = @cli_get_process_title();
                if (strpos($processName, 'msf') !== false) {
                    $appType = 'msf';
                }
            } else {
                $appType = 'web';
            }

            if ($appType != 'msf' && $result instanceof \Generator) {
                $data['result'] = $result->getReturn();
                return $data;
            }

            $data['result'] = $result;
            return $data;
        });

        return $wrapperObject;
    }
809817
public static function log($object)
    {
        $cwd = getcwd();
        $log = $cwd.'/producer.log';

        foreach (func_get_args() as $object) {
            if (is_array($object)) {
                $msg = 'array('.count($object).'):'.json_encode($object);
            } elseif (is_object($object) && !method_exists($object, '__toString')) {
                $msg = 'object('.get_class($object).'):'.json_encode($object);
            } else {
                $msg = $object;
            }
            file_put_contents($log, '>  '.trim($msg)."\n", FILE_APPEND);
        }
    }
955500
private function validateDataType($object, string $path)
    {
        if (!is_object($object)) {
            $exception = SerializerLogicException::createWrongDataType(gettype($object), $path);

            $this->logger->error('serialize: {exception}', ['exception' => $exception->getMessage()]);

            throw $exception;
        }
    }
18726
public static function createFromObject($object)
    {
        $isFromBase = (static::class === self::class);

        if (!is_object($object)) {
            throw new \Exception('Expecting an object');
        }

        //Test type if it's set
        if (property_exists($object, 'type') && !empty($object->type)) {
            if (array_key_exists($object->type, self::$validatorRegistry)) {
                if (is_object($object->type) || is_array($object->type) || $object->type === null) {
                    throw new \Exception('Expecting string for type');
                }
                $className = self::$validatorRegistry[$object->type];
                $validator = new $className();
            /*} elseif (class_exists(__NAMESPACE__ . '\\' . $object->type)) {
                //if already loaded
                $className = __NAMESPACE__ . '\\' . $object->type;
                $validator = new $className();
            } elseif (class_exists(__NAMESPACE__ . '\\' . $object->type . 'Validator')) {
                //if already loaded
                $className = __NAMESPACE__ . '\\' . $object->type . 'Validator';
                $validator = new $className();*/
            } else {
                $className = $object->type . 'Validator';

                try {
                    //prevent fatal error
                    new \ReflectionClass($className);
                    //attempt to create class
                    $validator = new $className();
                } catch (\Exception $e) {
                    //Wont catch the fatal error
                    throw new \Exception(sprintf(
                        'Incorrect type "%s" from "%s"',
                        $object->type,
                        static::class
                    ));
                }
            }
        } elseif (($validator = static::createFromObjectForAdditional($object)) !== null) {
            return $validator;
        } elseif (!$isFromBase
            || (isset($object->type) && !empty($object->type) && $object->type == static::$type)
        ) {
            $validator = new static();
        } else {
            throw new \Exception(sprintf(
                'Type is required when creating from "%s"',
                self::class
            ));
        }

        //For each Validator's attribute
        foreach (array_merge(
            $validator::getTypeAttributes(),
            $validator::$commonAttributes
        ) as $attribute) {
            //Check if provided object contains this attribute
            if (property_exists($object, $attribute)) {
                if ($attribute == 'properties') {
                    //get properties as array
                    $properties = $object->{$attribute};

                    $createdProperties = new \stdClass();

                    foreach ($properties as $key => $property) {
                        //TODO remove
                        //if (!is_object($property)) {
                        //    throw new \Exception(sprintf(
                        //        'Expected object for property value "%s"',
                        //        $key
                        //    ));
                        //}

                        $createdProperties->{$key} =
                        BaseValidator::createFromObject($property);
                    }
                    //push to class
                    $validator->{$attribute} = $createdProperties;
                } elseif ($attribute == 'items' || $attribute == 'not') {
                    $validator->{$attribute} = BaseValidator::createFromObject(
                        $object->{$attribute}
                    );
                } else {
                    //Use attributes value in Validator object
                    $validator->{$attribute} = $object->{$attribute};
                }
            }
        }

        return $validator;
    }
1349885
protected function _throw($object)
    {
        $error = $object->errorInfo();
        throw new \RuntimeException(
            sprintf(
                'PDO operation returned SQLSTATE %s: Error %s (%s)',
                $error[0],
                $error[1],
                $error[2]
            )
        );
    }
1178661
private function getJsonRequest() {
        $request = $this->getRawPostData();
        if ($request == "") {
            throw new JsonRpcExeption(101, "Parse Error: no data");
        }
        $encoding = mb_detect_encoding($request, 'auto');
        if ($encoding != 'UTF-8') {
            $request = iconv($encoding, 'UTF-8', $request);
        }
        $request = json_decode($request);
        if ($request == NULL) { // parse error
            $error = $this->getJsonError();
            throw new JsonRpcExeption(101, "Parse Error: $error");
        }
        return $request;
    }
1138235
public static function install($request, $object)
    {
        $spa = Tenant_SpaService::installFromRepository($object->id);
        return Tenant_Shortcuts_SpaManager($spa)->apply($spa, 'create');
    }
45095
public function getRequestString($object): string
    {
        $this->assertValid($object, ValidationException::RESPONSE);

        return $this->serializeBodyObject($object);
    }
327207
public static function createObjectUrl($bucket, $object = null) {
    $gs_filename = self::createGcsFilename($bucket, $object);
    return CloudStorageTools::getPublicUrl($gs_filename, true);
  }
1120507
public function fromResource($object, ResourceObject $resource)
    {
        $context = $this->createContext(get_class($object));

        $this->identifierHandler->setIdentifier($object, $resource->getId(), $context);

        foreach ($this->handlers as $handler)
        {
            $handler->fromResource($object, $resource, $context);
        }
    }
1079710
protected function doExtract($object)
    {
        $originalFieldNames = $this->metadata->getOriginalFieldNames();

        /*
        $filter = $object instanceof FilterProviderInterface
            ? $object->getFilter()
            : $this->filterComposite;
        */

        $data = [];
        if (! $this->metadata->hasCustomHydrator()) {

            $this->executeMethods($object, $this->metadata->getPreExtractListeners());

            foreach ($originalFieldNames as $originalFieldName) {
                $mappedFieldName = $this->metadata->getMappedFieldName($originalFieldName);

                if ($this->metadata->isNotManaged($mappedFieldName)) {
                    continue;
                }

                if ($this->metadata->isValueObject($mappedFieldName)) {
                    continue;
                }

                /*if ($filter && !$filter->filter($mappedFieldName)) {
                    continue;
                }*/

                try {
                    $value = $this->memberAccessStrategy->getValue($object, $mappedFieldName);             
                } catch (NotFoundMemberException $e) {
                    continue;
                }

                if (null === $value) {
                    $data[$originalFieldName] = null;
                    continue;
                }

                if ($fieldClass = $this->metadata->getClassOfMappedField($mappedFieldName)) {
                    $fieldHydrator = $this->objectManager->createHydratorFor($fieldClass);
                    $fieldValue = $value;

                    /*if (! is_array($fieldValue)) {
                        throw new ObjectMappingException(
                            sprintf(
                                'Cannot hydrate field "%s" of class "%s" from raw data.'
                                . ' Raw data should be an array but got "%s".', 
                                $mappedFieldName,
                                $fieldClass,
                                is_object($fieldValue) ? get_class($fieldValue) : gettype($fieldValue)
                                )
                        );
                    }   */
                    
                    reset($fieldValue);
                    if (0 !== count($fieldValue) && ! is_numeric(key($fieldValue))) {
                        $fieldRawData = $fieldHydrator->extract($fieldValue);
                        $data[$originalFieldName] = $fieldRawData;                              
                    } else {

                        $fieldRawData = [];
                        foreach ($fieldValue as $itemFieldValue) {              
                            $fieldRawData[] = $fieldHydrator->extract($itemFieldValue);                
                        }
                        $data[$originalFieldName] = $fieldRawData;
                    }   
                } else {
                    $value = $this->extractValue($mappedFieldName, $value, $object, $data);
                    $data[$originalFieldName] = $value;    
                }
            }
        } else {
            list($customHydratorClass, , $customExtractMethod) = $this->metadata->getCustomHydratorInfo();            
            $this->executeMethod($object, new ClassMetadata\Model\Method($customHydratorClass, $customExtractMethod, [$object]));
        }

        //Value objects extraction.
        foreach ($this->metadata->getFieldsWithValueObjects() as $mappedFieldName) {

            if ($this->metadata->isNotManaged($mappedFieldName)) {
                continue;
            }

            $info = $this->metadata->getValueObjectInfo($mappedFieldName);
            list($voClassName, $voResource, $voResourceType) = $info;

            $valueObjectHydrator = $this->objectManager->createHydratorFor($voClassName);
            $objectKey = $this->pushRuntimeConfiguration($mappedFieldName, $object, $voClassName, $voResourceType, $voResource);

            $valueObject = $this->memberAccessStrategy->getValue($object, $mappedFieldName);
            $valueObjectData = $valueObjectHydrator->extract($valueObject, $objectKey);
            $this->popRuntimeConfiguration();

            $data = array_merge($data, $valueObjectData);
        }

        $this->executeMethods($object, $this->metadata->getPostExtractListeners());

        return $data;
    }
381900
public function toResource($object): ResourceObject
    {
        $context = $this->createContext(get_class($object));

        $id   = $this->identifierHandler->getIdentifier($object, $context);
        $type = $this->resolveType($object, $context);

        $resource = new ResourceObject($id, $type);

        foreach ($this->handlers as $handler)
        {
            $handler->toResource($object, $resource, $context);
        }

        return $resource;
    }