Skip to content

Commit

Permalink
Merge pull request #58 from line/support_php_5_4
Browse files Browse the repository at this point in the history
Support PHP 5.4 and PHP 5.5
  • Loading branch information
moznion authored Feb 21, 2017
2 parents e42b62a + 73b50e6 commit 03965e1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: php
php:
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- '7.1'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Please refer [CurlHTTPClient](/src/LINEBot/HTTPClient/CurlHTTPClient.php) that i
Requirements
--

- PHP 5.6 or later
- PHP 5.4 or later

For SDK developers
--
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
}
],
"require": {
"php": ">=5.6"
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": "^4.8.24",
"phpmd/phpmd": "~2.4",
"squizlabs/php_codesniffer": "~2.6",
"apigen/apigen": "~4.1"
"apigen/apigen": "~4.1",
"indigophp/hash-compat": "~1.1.0"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 21 additions & 3 deletions src/LINEBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use LINE\LINEBot\MessageBuilder\TextMessageBuilder;
use LINE\LINEBot\Response;
use LINE\LINEBot\SignatureValidator;
use ReflectionClass;

/**
* A client class of LINE Messaging API.
Expand Down Expand Up @@ -100,14 +101,31 @@ public function replyMessage($replyToken, MessageBuilder $messageBuilder)
*
* This method receives variable texts. It can send text(s) message as bulk.
*
* Exact signature of this method is <code>replyText(string $replyToken, string $text, string[] $extraTexts)</code>.
*
* Means, this method can also receive multiple texts like so;
*
* <code>
* $bot->replyText('reply-text', 'text', 'extra text1', 'extra text2', ...)
* </code>
*
* @param string $replyToken Identifier of destination.
* @param string $text Text of message.
* @param string[] $extraTexts Extra text of message.
* @param string[]|null $extraTexts Extra text of message.
* @return Response
*/
public function replyText($replyToken, $text, ...$extraTexts)
public function replyText($replyToken, $text, $extraTexts = null)
{
$textMessageBuilder = new TextMessageBuilder($text, ...$extraTexts);
$extra = [];
if (!is_null($extraTexts)) {
$args = func_get_args();
$extra = array_slice($args, 2);
}

/** @var TextMessageBuilder $textMessageBuilder */
$ref = new ReflectionClass('LINE\LINEBot\MessageBuilder\TextMessageBuilder');
$textMessageBuilder = $ref->newInstanceArgs(array_merge([$text], $extra));

return $this->replyMessage($replyToken, $textMessageBuilder);
}

Expand Down
5 changes: 4 additions & 1 deletion src/LINEBot/HTTPClient/CurlHTTPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CurlHTTPClient implements HTTPClient
/** @var array */
private $authHeaders;
/** @var array */
private $userAgentHeader = ['User-Agent: LINE-BotSDK-PHP/' . Meta::VERSION];
private $userAgentHeader;

/**
* CurlHTTPClient constructor.
Expand All @@ -47,6 +47,9 @@ public function __construct($channelToken)
$this->authHeaders = [
"Authorization: Bearer $channelToken",
];
$this->userAgentHeader = [
'User-Agent: LINE-BotSDK-PHP/' . Meta::VERSION,
];
}

/**
Expand Down
19 changes: 16 additions & 3 deletions src/LINEBot/MessageBuilder/TextMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,25 @@ class TextMessageBuilder implements MessageBuilder
/**
* TextMessageBuilder constructor.
*
* Exact signature of this constructor is <code>new TextMessageBuilder(string $text, string[] $extraTexts)</code>.
*
* Means, this constructor can also receive multiple messages like so;
*
* <code>
* $textBuilder = new TextMessageBuilder('text', 'extra text1', 'extra text2', ...);
* </code>
*
* @param string $text
* @param string[] $extraTexts
* @param string[]|null $extraTexts
*/
public function __construct($text, ...$extraTexts)
public function __construct($text, $extraTexts = null)
{
$this->texts = array_merge([$text], $extraTexts);
$extra = [];
if (!is_null($extraTexts)) {
$args = func_get_args();
$extra = array_slice($args, 1);
}
$this->texts = array_merge([$text], $extra);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/LINEBot/HTTPClient/CurlHTTPClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

class CurlHTTPClientTest extends \PHPUnit_Framework_TestCase
{
private static $reqMirrorPath = __DIR__ . '/../../../devtool/req_mirror';
private static $reqMirrorPath;
private static $reqMirrorPort;
private static $reqMirrorPID;

public static function setUpBeforeClass()
{
CurlHTTPClientTest::$reqMirrorPath = __DIR__ . '/../../../devtool/req_mirror';

if (file_exists(CurlHTTPClientTest::$reqMirrorPath)) {
if (empty(CurlHTTPClientTest::$reqMirrorPort)) {
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
Expand Down

0 comments on commit 03965e1

Please sign in to comment.