Ryan Conigliaro | 5f455a7 | 2024-01-03 18:01:34 +0000 | [diff] [blame] | 1 | <?php |
| 2 | /* |
Ryan Conigliaro | a69c69f | 2024-01-03 18:18:58 +0000 | [diff] [blame] | 3 | Example Entity feed for Google Order Redirect. Create build/gen directory for generated proto classes. |
| 4 | Download lastest version of protoc from https://github.com/protocolbuffers/protobuf/releases |
| 5 | Generate proto classes with: |
Ryan Conigliaro | 63775b0 | 2024-01-03 21:16:31 +0000 | [diff] [blame^] | 6 | protoc --php_out=./build/gen --proto_path=../proto/ ../proto/entity.proto |
| 7 | |
| 8 | See https://protobuf.dev/reference/php/php-generated/ for more details. |
Ryan Conigliaro | 5f455a7 | 2024-01-03 18:01:34 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | require dirname(__FILE__).'/vendor/autoload.php'; |
| 12 | |
| 13 | use Madden\Ingestion\EntityFeed; |
| 14 | use Madden\Ingestion\Entity; |
| 15 | use Madden\Ingestion\GeoCoordinates; |
| 16 | use Madden\Ingestion\PostalAddress; |
| 17 | |
| 18 | |
| 19 | function createFeed() { |
| 20 | // Create Entity by using setter methods |
| 21 | $entity = new Entity(); |
| 22 | $entity->setEntityId("merchant-1"); |
| 23 | $entity->setName("Mo's Dinner"); |
| 24 | $entity->setTelephone("+14567891234"); |
| 25 | $entity->setUrl("http://moesdinner.com"); |
| 26 | $entityLocation = new GeoCoordinates(); |
| 27 | $entityLocation->setLatitude(41.525588); |
| 28 | $entityLocation->setLongitude(-90.507067); |
| 29 | $entity->setLocation($entityLocation); |
| 30 | $entityAddress = new PostalAddress(); |
| 31 | $entityAddress->setCountry("US"); |
| 32 | $entityAddress->setLocality("Mountain View"); |
| 33 | $entityAddress->setRegion("CA"); |
| 34 | $entityAddress->setPostalCode("94043"); |
| 35 | $entityAddress->setStreetAddress("1600 Amphitheatre Pkwy"); |
| 36 | $entityLocation->setAddress($entityAddress); |
| 37 | |
Ryan Conigliaro | 45b5336 | 2024-01-03 18:04:21 +0000 | [diff] [blame] | 38 | // Add Entity to feed data |
Ryan Conigliaro | 5f455a7 | 2024-01-03 18:01:34 +0000 | [diff] [blame] | 39 | $feed = new EntityFeed(); |
| 40 | $feed->setData(array($entity)); |
| 41 | |
Ryan Conigliaro | 45b5336 | 2024-01-03 18:04:21 +0000 | [diff] [blame] | 42 | // Serialize to JSON |
Ryan Conigliaro | 5f455a7 | 2024-01-03 18:01:34 +0000 | [diff] [blame] | 43 | return $feed->serializeToJsonString(); |
| 44 | } |
| 45 | |
| 46 | $feedJSON = createFeed(); |
| 47 | echo $feedJSON; |
| 48 | |