1. <?php
  2. /**
  3. * Serializes an object of an API endpoint for internal use.
  4. *
  5. * @param mixed $object The object to serialize.
  6. * @return string The serialized string, or false on failure.
  7. */
  8. function serializeApiEndpointObject($object)
  9. {
  10. if (is_object($object)) {
  11. $serialized = serialize($object); // Serialize the object
  12. return $serialized;
  13. } else {
  14. return false; // Not an object
  15. }
  16. }
  17. // Example usage:
  18. // Assuming you have an API endpoint object
  19. class MyApiEndpoint {
  20. public $name = "Example Endpoint";
  21. public $version = 1.0;
  22. public $parameters = ["param1" => "value1", "param2" => "value2"];
  23. }
  24. $endpoint = new MyApiEndpoint();
  25. $serializedEndpoint = serializeApiEndpointObject($endpoint);
  26. if ($serializedEndpoint !== false) {
  27. echo "Serialized Endpoint: " . $serializedEndpoint . "\n";
  28. } else {
  29. echo "Error: Invalid object.\n";
  30. }
  31. ?>

Add your comment