Skip to content

Commit e19d55e

Browse files
authored
Merge pull request #18 from nojimage/develop
twitter-text 2.0
2 parents a2a1fb1 + cdf5093 commit e19d55e

32 files changed

+1673
-2261
lines changed

README.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ Cochrane, this library has been improved and made more complete by Nick Pope.
1717
</a>
1818
</p>
1919

20+
## Requirements ##
21+
22+
- PHP 5.3 or higher
23+
- ext-mbstring
24+
- ext-intl
25+
26+
If the necessary extensions are not installed on the server, please install it additionally or use [symfony/polyfill](https://github.com/symfony/polyfill).
27+
28+
## Install ##
29+
30+
You can install this library into your application using [Composer](https://getcomposer.org/).
31+
32+
```
33+
composer require nojimage/twitter-text-php
34+
```
35+
2036
## Features ##
2137

2238
### Autolink ##
@@ -47,6 +63,43 @@ Cochrane, this library has been improved and made more complete by Nick Pope.
4763
- Validate different twitter text elements.
4864
- Support for international character sets.
4965

66+
### Parser ###
67+
68+
- Parses a given tweet text with the weighted character count configuration.
69+
70+
## Length validation ##
71+
72+
twitter-text 2.0 introduces configuration files that define how Tweets are parsed for length. This allows for backwards compatibility and flexibility going forward. Old-style traditional 140-character parsing is defined by the v1.json configuration file, whereas v2.json is updated for "weighted" Tweets where ranges of Unicode code points can have independent weights aside from the default weight. The sum of all code points, each weighted appropriately, should not exceed the max weighted length.
73+
74+
Some old methods from twitter-text-php 1.0 have been marked deprecated, such as the `Twitter\Text\Validator::isValidTweetText()`, `Twitter\Text\Validator::getTweetLength()` method. The new API is based on the following method, `Twitter\Text\Parser::parseTweet()`
75+
76+
```(php)
77+
$result = \Twitter\Text\Parser::parseTweet($text);
78+
```
79+
80+
This method takes a string as input and returns a results object that contains information about the string. `Twitter\Text\ParseResults` object includes:
81+
82+
- `weightedLength`: the overall length of the tweet with code points
83+
weighted per the ranges defined in the configuration file.
84+
85+
- `permillage`: indicates the proportion (per thousand) of the weighted
86+
length in comparison to the max weighted length. A value > 1000
87+
indicates input text that is longer than the allowable maximum.
88+
89+
- `valid`: indicates if input text length corresponds to a valid
90+
result.
91+
92+
- `displayRangeStart, displayRangeEnd`: An array of two unicode code point
93+
indices identifying the inclusive start and exclusive end of the
94+
displayable content of the Tweet. For more information, see
95+
the description of `display_text_range` here:
96+
[Tweet updates](https://developer.twitter.com/en/docs/tweets/tweet-updates)
97+
98+
- `validRangeStart, validRangeRnd`: An array of two unicode code point
99+
indices identifying the inclusive start and exclusive end of the valid
100+
content of the Tweet. For more information on the extended Tweet
101+
payload see [Tweet updates](https://developer.twitter.com/en/docs/tweets/tweet-updates)
102+
50103
## Examples ##
51104

52105
For examples, please see `tests/example.php` which you can view in a browser or
@@ -59,9 +112,7 @@ repository:
59112

60113
https://github.com/twitter/twitter-text
61114

62-
https://github.com/symfony/Yaml
63-
64-
Both requirements already included in `composer.json`, so you should just need to run:
115+
`twitter/twitter-text` already included in `composer.json`, so you should just need to run:
65116

66117
curl -s https://getcomposer.org/installer | php
67118
php composer.phar install

compat/Twitter/Autolink.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

compat/Twitter/Extractor.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

compat/Twitter/HitHighlighter.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

compat/Twitter/Validator.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,28 @@
3131
"type": "package",
3232
"package": {
3333
"name": "twitter/twitter-text",
34-
"version": "1.14.7",
34+
"version": "2.0.3",
3535
"source": {
3636
"url": "https://github.com/twitter/twitter-text.git",
3737
"type": "git",
38-
"reference": "v1.14.7"
38+
"reference": "v2.0.3"
3939
}
4040
}
4141
}
4242
],
4343
"require": {
44-
"php": ">=5.3.3"
44+
"php": ">=5.3.3",
45+
"ext-mbstring": "*",
46+
"ext-intl": "*"
4547
},
4648
"require-dev": {
47-
"php": ">=5.3.3",
4849
"symfony/yaml": "~2.6.0",
49-
"phpunit/phpunit": "4.8.*|5.7.*",
50-
"twitter/twitter-text": "^1.14.7"
50+
"phpunit/phpunit": "4.8.*|5.7.*|6.5.*",
51+
"twitter/twitter-text": "^2.0.0"
5152
},
5253
"autoload": {
5354
"psr-0": {
54-
"Twitter\\Text\\": "lib/",
55-
"Twitter_": "compat/"
55+
"Twitter\\Text\\": "lib/"
5656
}
5757
},
5858
"scripts": {

0 commit comments

Comments
 (0)