From f256d5a91823eed9b6ec50cff5547aaaf9c4f6c3 Mon Sep 17 00:00:00 2001 From: Will Sabol Date: Tue, 27 Feb 2024 22:00:59 -0600 Subject: [PATCH 1/5] append comment to the Response element --- src/Twilio/TwiML/TwiML.php | 2 ++ src/Twilio/TwiML/Voice/Comment.php | 22 +++++++++++++++++++ src/Twilio/TwiML/VoiceResponse.php | 12 +++++++++- tests/Twilio/Unit/TwiML/Voice/CommentTest.php | 21 ++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/Twilio/TwiML/Voice/Comment.php create mode 100644 tests/Twilio/Unit/TwiML/Voice/CommentTest.php diff --git a/src/Twilio/TwiML/TwiML.php b/src/Twilio/TwiML/TwiML.php index 6e8ceb4a79..de5a21c468 100644 --- a/src/Twilio/TwiML/TwiML.php +++ b/src/Twilio/TwiML/TwiML.php @@ -115,6 +115,8 @@ private function buildElement(TwiML $twiml, DOMDocument $document): DOMElement { foreach ($twiml->children as $child) { if (\is_string($child)) { $element->appendChild($document->createTextNode($child)); + } elseif (\is_a($child, "Twilio\TwiML\Voice\Comment")) { + $element->appendChild($document->createComment($child->children[0])); } else { $element->appendChild($this->buildElement($child, $document)); } diff --git a/src/Twilio/TwiML/Voice/Comment.php b/src/Twilio/TwiML/Voice/Comment.php new file mode 100644 index 0000000000..6151304724 --- /dev/null +++ b/src/Twilio/TwiML/Voice/Comment.php @@ -0,0 +1,22 @@ +nest(new Voice\Refer($attributes)); } -} \ No newline at end of file + + /** + * Add Comment child. + * + * @param string $message The content of the comment + * @return Voice\Comment Child element. + */ + public function comment($message): Voice\Comment { + return $this->nest(new Voice\Comment($message)); + } +} diff --git a/tests/Twilio/Unit/TwiML/Voice/CommentTest.php b/tests/Twilio/Unit/TwiML/Voice/CommentTest.php new file mode 100644 index 0000000000..0c6a4d02bc --- /dev/null +++ b/tests/Twilio/Unit/TwiML/Voice/CommentTest.php @@ -0,0 +1,21 @@ +comment('this is a comment'); + + $this->compareXml('', $response); + } + public function testSketchyCommentToResponse(): void { + $response = new VoiceResponse(); + $response->comment('this is --- a sketchy ---- comment'); + + $this->compareXml('', $response); + } +} From 1a1bc3433dbeacdf1d6a5e0ded43d7a74d981b79 Mon Sep 17 00:00:00 2001 From: Will Sabol Date: Tue, 17 Jun 2025 16:10:49 -0500 Subject: [PATCH 2/5] replace string class reference with ::class in TwiML comment handling --- src/Twilio/TwiML/TwiML.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Twilio/TwiML/TwiML.php b/src/Twilio/TwiML/TwiML.php index de5a21c468..1468e5b3ac 100644 --- a/src/Twilio/TwiML/TwiML.php +++ b/src/Twilio/TwiML/TwiML.php @@ -115,7 +115,7 @@ private function buildElement(TwiML $twiml, DOMDocument $document): DOMElement { foreach ($twiml->children as $child) { if (\is_string($child)) { $element->appendChild($document->createTextNode($child)); - } elseif (\is_a($child, "Twilio\TwiML\Voice\Comment")) { + } elseif (\is_a($child, \Twilio\TwiML\Voice\Comment::class)) { $element->appendChild($document->createComment($child->children[0])); } else { $element->appendChild($this->buildElement($child, $document)); From e5cb4c5fa6d3aec76f58ff63ffa425c99258b26c Mon Sep 17 00:00:00 2001 From: Will Sabol Date: Tue, 17 Jun 2025 16:21:16 -0500 Subject: [PATCH 3/5] Moved changes out of auto-generated files/directories --- src/Twilio/TwiML/{Voice => }/Comment.php | 4 +--- src/Twilio/TwiML/TwiML.php | 2 +- src/Twilio/TwiML/VoiceResponse.php | 10 ---------- tests/Twilio/Unit/TwiML/{Voice => }/CommentTest.php | 7 ++++--- 4 files changed, 6 insertions(+), 17 deletions(-) rename src/Twilio/TwiML/{Voice => }/Comment.php (88%) rename tests/Twilio/Unit/TwiML/{Voice => }/CommentTest.php (74%) diff --git a/src/Twilio/TwiML/Voice/Comment.php b/src/Twilio/TwiML/Comment.php similarity index 88% rename from src/Twilio/TwiML/Voice/Comment.php rename to src/Twilio/TwiML/Comment.php index 6151304724..30ef84b07a 100644 --- a/src/Twilio/TwiML/Voice/Comment.php +++ b/src/Twilio/TwiML/Comment.php @@ -1,8 +1,6 @@ children as $child) { if (\is_string($child)) { $element->appendChild($document->createTextNode($child)); - } elseif (\is_a($child, \Twilio\TwiML\Voice\Comment::class)) { + } elseif (\is_a($child, \Twilio\TwiML\Comment::class)) { $element->appendChild($document->createComment($child->children[0])); } else { $element->appendChild($this->buildElement($child, $document)); diff --git a/src/Twilio/TwiML/VoiceResponse.php b/src/Twilio/TwiML/VoiceResponse.php index 3c8cf915b6..86a4f2adae 100644 --- a/src/Twilio/TwiML/VoiceResponse.php +++ b/src/Twilio/TwiML/VoiceResponse.php @@ -219,14 +219,4 @@ public function stop(): Voice\Stop { public function refer($attributes = []): Voice\Refer { return $this->nest(new Voice\Refer($attributes)); } - - /** - * Add Comment child. - * - * @param string $message The content of the comment - * @return Voice\Comment Child element. - */ - public function comment($message): Voice\Comment { - return $this->nest(new Voice\Comment($message)); - } } diff --git a/tests/Twilio/Unit/TwiML/Voice/CommentTest.php b/tests/Twilio/Unit/TwiML/CommentTest.php similarity index 74% rename from tests/Twilio/Unit/TwiML/Voice/CommentTest.php rename to tests/Twilio/Unit/TwiML/CommentTest.php index 0c6a4d02bc..b9c04a476f 100644 --- a/tests/Twilio/Unit/TwiML/Voice/CommentTest.php +++ b/tests/Twilio/Unit/TwiML/CommentTest.php @@ -1,20 +1,21 @@ comment('this is a comment'); + $response->nest(new Comment('this is a comment')); $this->compareXml('', $response); } public function testSketchyCommentToResponse(): void { $response = new VoiceResponse(); - $response->comment('this is --- a sketchy ---- comment'); + $response->nest(new Comment('this is --- a sketchy ---- comment')); $this->compareXml('', $response); } From b866b6025872e730a2ae80b2665b909e33df4814 Mon Sep 17 00:00:00 2001 From: Will Sabol Date: Tue, 17 Jun 2025 16:21:16 -0500 Subject: [PATCH 4/5] Moved changes out of auto-generated files/directories --- src/Twilio/TwiML/{Voice => }/Comment.php | 4 +--- src/Twilio/TwiML/TwiML.php | 2 +- src/Twilio/TwiML/VoiceResponse.php | 12 +----------- tests/Twilio/Unit/TwiML/{Voice => }/CommentTest.php | 7 ++++--- 4 files changed, 7 insertions(+), 18 deletions(-) rename src/Twilio/TwiML/{Voice => }/Comment.php (88%) rename tests/Twilio/Unit/TwiML/{Voice => }/CommentTest.php (74%) diff --git a/src/Twilio/TwiML/Voice/Comment.php b/src/Twilio/TwiML/Comment.php similarity index 88% rename from src/Twilio/TwiML/Voice/Comment.php rename to src/Twilio/TwiML/Comment.php index 6151304724..30ef84b07a 100644 --- a/src/Twilio/TwiML/Voice/Comment.php +++ b/src/Twilio/TwiML/Comment.php @@ -1,8 +1,6 @@ children as $child) { if (\is_string($child)) { $element->appendChild($document->createTextNode($child)); - } elseif (\is_a($child, \Twilio\TwiML\Voice\Comment::class)) { + } elseif (\is_a($child, \Twilio\TwiML\Comment::class)) { $element->appendChild($document->createComment($child->children[0])); } else { $element->appendChild($this->buildElement($child, $document)); diff --git a/src/Twilio/TwiML/VoiceResponse.php b/src/Twilio/TwiML/VoiceResponse.php index 3c8cf915b6..6cb9a059fb 100644 --- a/src/Twilio/TwiML/VoiceResponse.php +++ b/src/Twilio/TwiML/VoiceResponse.php @@ -219,14 +219,4 @@ public function stop(): Voice\Stop { public function refer($attributes = []): Voice\Refer { return $this->nest(new Voice\Refer($attributes)); } - - /** - * Add Comment child. - * - * @param string $message The content of the comment - * @return Voice\Comment Child element. - */ - public function comment($message): Voice\Comment { - return $this->nest(new Voice\Comment($message)); - } -} +} \ No newline at end of file diff --git a/tests/Twilio/Unit/TwiML/Voice/CommentTest.php b/tests/Twilio/Unit/TwiML/CommentTest.php similarity index 74% rename from tests/Twilio/Unit/TwiML/Voice/CommentTest.php rename to tests/Twilio/Unit/TwiML/CommentTest.php index 0c6a4d02bc..b9c04a476f 100644 --- a/tests/Twilio/Unit/TwiML/Voice/CommentTest.php +++ b/tests/Twilio/Unit/TwiML/CommentTest.php @@ -1,20 +1,21 @@ comment('this is a comment'); + $response->nest(new Comment('this is a comment')); $this->compareXml('', $response); } public function testSketchyCommentToResponse(): void { $response = new VoiceResponse(); - $response->comment('this is --- a sketchy ---- comment'); + $response->nest(new Comment('this is --- a sketchy ---- comment')); $this->compareXml('', $response); } From a49a99563165dcdcd5f0360654129312017c522f Mon Sep 17 00:00:00 2001 From: Will Sabol Date: Tue, 17 Jun 2025 16:27:34 -0500 Subject: [PATCH 5/5] Revert VoiceResponse.php