From 7fadb09ca25e8511baa60800efbd084f43d546e6 Mon Sep 17 00:00:00 2001 From: ksimka <m.kochkin@wamba.com> Date: Fri, 20 May 2016 11:52:52 +0300 Subject: [PATCH] Replace `strlen` with `mb_strlen`, require `mbstring`. --- composer.json | 1 + src/Message/Message.php | 2 +- src/Model/Button.php | 2 +- src/Model/Generic/Element.php | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index d37e279..d51a842 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ }, "require": { "php": ">=5.5.9", + "ext-mbstring": "*", "guzzlehttp/guzzle": "^6.2" }, "require-dev": { diff --git a/src/Message/Message.php b/src/Message/Message.php index c1f35c0..9ce5124 100644 --- a/src/Message/Message.php +++ b/src/Message/Message.php @@ -34,7 +34,7 @@ public function __construct($recipientId, $messageData, $notificationType = Noti { $this->recipient = $recipientId; - if (is_string($messageData) && strlen($messageData) > 320) { + if (is_string($messageData) && mb_strlen($messageData) > 320) { throw new \InvalidArgumentException('The text message should not exceed 320 characters'); } diff --git a/src/Model/Button.php b/src/Model/Button.php index 041f82f..42c740c 100644 --- a/src/Model/Button.php +++ b/src/Model/Button.php @@ -41,7 +41,7 @@ public function getTitle() */ protected function validateTitleSize($title) { - if (strlen($title) > 20) { + if (mb_strlen($title) > 20) { throw new \InvalidArgumentException('A call to action title field should not exceed 20 characters'); } } diff --git a/src/Model/Generic/Element.php b/src/Model/Generic/Element.php index cdcb394..f5f7cf6 100644 --- a/src/Model/Generic/Element.php +++ b/src/Model/Generic/Element.php @@ -105,11 +105,11 @@ public function jsonSerialize() private function validateElement() { - if (strlen($this->title) > 45) { + if (mb_strlen($this->title) > 45) { throw new \InvalidArgumentException('In a generic element, the "title" field should not exceed 45 characters'); } - if (!empty($this->subtitle) && strlen($this->subtitle) > 80) { + if (!empty($this->subtitle) && mb_strlen($this->subtitle) > 80) { throw new \InvalidArgumentException('In a generic element, the "subtitle" field should not exceed 80 characters'); }