Skip to content

Commit f95a7bb

Browse files
committed
V2 merge
1 parent 4f1a87b commit f95a7bb

9 files changed

+462
-260
lines changed

README.md

+43-41
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ A library to auto convert URLs to links.
1313
* [Scheme](#scheme)
1414
* [Link Builder](#link-builder)
1515

16+
## Requirement
17+
18+
- Version 2.x require PHP 8.0 or higher.
19+
- Version 1.x supports PHP 5.3 to 7.4
20+
1621
## Installation via Composer
1722

1823
Add this to composer.json require block.
1924

2025
``` json
2126
{
2227
"require": {
23-
"asika/autolink": "1.*"
28+
"asika/autolink": "^2.0"
2429
}
2530
}
2631
```
@@ -29,35 +34,35 @@ Add this to composer.json require block.
2934

3035
This is a quick start to convert URL to link:
3136

32-
``` php
33-
use Asika\Autolink\Linker;
37+
```php
38+
use Asika\Autolink\AutolinkStatic;
3439

35-
$text = Linker::convert($text);
36-
$text = Linker::convertEmail($text);
40+
$text = AutolinkStatic::convert($text);
41+
$text = AutolinkStatic::convertEmail($text);
3742
```
3843

3944
## Use Autolink Object
4045

4146
Create the object:
4247

43-
``` php
48+
```php
4449
use Asika\Autolink\Autolink;
4550

46-
$autolink = new Autolink;
51+
$autolink = new Autolink();
4752
```
4853

4954
Create with options.
5055

51-
``` php
52-
$options = array(
56+
```php
57+
$options = [
5358
'strip_scheme' => false,
5459
'text_limit' => false,
5560
'auto_title' => false,
5661
'escape' => true,
5762
'link_no_scheme' => false
58-
);
63+
];
5964

60-
$schemes = array('http', 'https', 'skype', 'itunes');
65+
$schemes = ['http', 'https', 'skype', 'itunes'];
6166

6267
$autolink = new Autolink($options, $schemes);
6368
```
@@ -79,7 +84,7 @@ http://example.com/?foo[1]=a&foo[2]=b
7984

8085
We convert all URLs.
8186

82-
``` php
87+
```php
8388
$text = $autolink->convert($text);
8489
```
8590

@@ -98,13 +103,13 @@ This is URL with multi-level query:
98103

99104
### Add Attributes
100105

101-
``` php
102-
$text = $autolink->convert($text, array('class' => 'center'));
106+
```php
107+
$text = $autolink->convert($text, ['class' => 'center']);
103108
```
104109

105110
All link will add this attributes:
106111

107-
``` php
112+
```php
108113
This is Simple URL:
109114
<a href="http://www.google.com.tw" class="center">http://www.google.com.tw</a>
110115

@@ -116,7 +121,7 @@ This is SSL URL:
116121

117122
Email url has no scheme, we use anoter method to convert them, and it will add `mailto:` at begin of `href`.
118123

119-
``` php
124+
```php
120125
$text = $aurolink->convertEmail($text);
121126
```
122127

@@ -133,7 +138,7 @@ Output
133138

134139
We can set this option by constructor or setter:
135140

136-
``` php
141+
```php
137142
$auitolink->textLimit(50);
138143

139144
$text = $autolink->convert($text);
@@ -147,19 +152,17 @@ http://campus.asukademy.com/learning/job/84-fin...
147152

148153
Use Your own limit handler by set a callback:
149154

150-
``` php
151-
$auitolink->textLimit(function($url)
152-
{
155+
```php
156+
$auitolink->textLimit(function($url) {
153157
return substr($url, 0, 50) . '...';
154158
});
155159
```
156160

157161
Or use `\Asika\Autolink\LinkHelper::shorten()` Pretty handler:
158162

159-
``` php
160-
$auitolink->textLimit(function($url)
161-
{
162-
return \Asika\Autolink\LinkHelper::shorten($url, 15, 6);
163+
```php
164+
$auitolink->textLimit(function($url) {
165+
return \Asika\Autolink\Autolink::shortenUrl($url, 15, 6);
163166
});
164167
```
165168

@@ -172,8 +175,8 @@ http://campus.asukademy.com/....../84-find-interns......
172175
### `auto_title`
173176

174177
Use AutoTitle to force add title on anchor element.
175-
176-
``` php
178+
179+
```php
177180
$autolink->autoTitle(true);
178181

179182
$text = $autolink->convert($text);
@@ -189,7 +192,7 @@ Output:
189192

190193
Strip Scheme on link text:
191194

192-
``` php
195+
```php
193196
$auitolink->stripScheme(true);
194197

195198
$text = $autolink->convert($text);
@@ -203,9 +206,13 @@ Output
203206

204207
### `escape`
205208

206-
Strip Scheme on link text:
209+
Auto escape URL, default is `true`:
210+
211+
```php
212+
$auitolink->autoEscape(false);
213+
214+
$text = $autolink->convert($text);
207215

208-
``` php
209216
$auitolink->autoEscape(true);
210217

211218
$text = $autolink->convert($text);
@@ -215,14 +222,15 @@ Output
215222

216223
``` html
217224
<a href="http://www.google.com.tw?foo=bar&yoo=baz" >http://www.google.com.tw?foo=bar&yoo=baz</a>
225+
<a href="http://www.google.com.tw?foo=bar&amp;yoo=baz" >http://www.google.com.tw?foo=bar&amp;yoo=baz</a>
218226
```
219227

220228
### `link_no_scheme`
221229

222230
Convert URL which no scheme. If you pass `TRUE` to this option, Autolink will use
223231
`http` as default scheme, you can also provide your own default scheme.
224232

225-
``` php
233+
```php
226234
$auitolink->linkNoScheme('https');
227235

228236
$text = $autolink->convert('www.google.com.tw');
@@ -238,9 +246,8 @@ Output
238246

239247
You can add new scheme to convert URL begin with it, for example: `vnc://example.com`
240248

241-
``` php
242-
$autolink->addScheme('skype')
243-
->addScheme('vnc');
249+
```php
250+
$autolink->addScheme('skype', 'vnc');
244251
```
245252

246253
Default schemes is `http, https, ftp, ftps`.
@@ -249,15 +256,10 @@ Default schemes is `http, https, ftp, ftps`.
249256

250257
If you don't want to use `<a>` element as your link, you can set a callback to build link HTML.
251258

252-
``` php
253-
$autolink->setLinkBuilder(function($url, $attribs)
254-
{
259+
```php
260+
$autolink->setLinkBuilder(function(string $url, array $attribs) {
255261
$attribs['src'] = htmlspecialchars($url);
256262

257-
return (string) new \Windwalker\Dom\HtmlElement('img', null, $attribs);
263+
return \Asika\Autolink\HtmlBuilder::create('img', $attribs, null);
258264
});
259265
```
260-
261-
See: [Windwalker Dom Package](https://github.com/ventoviro/windwalker-dom)
262-
263-

composer.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
"homepage": "https://github.com/asika32764/php-autolink",
1717
"minimum-stability": "beta",
1818
"require": {
19-
"php": ">=5.3",
20-
"windwalker/dom": "~2.0||~3.0"
19+
"php": ">=8.0"
2120
},
2221
"require-dev": {
23-
"windwalker/test": "~2.0||~3.0",
24-
"windwalker/utilities": "~2.0||~3.0",
25-
"phpunit/phpunit": "^7.0||^8.0||^9.0"
22+
"windwalker/test": "^4.0",
23+
"windwalker/utilities": "^4.0",
24+
"phpunit/phpunit": "^8.0||^9.0||^10.0"
2625
},
2726
"autoload": {
2827
"psr-4": {
@@ -31,7 +30,7 @@
3130
},
3231
"config": {
3332
"platform": {
34-
"php": "7.1.5"
33+
"php": "8.0.5"
3534
}
3635
},
3736
"license": "MIT"

0 commit comments

Comments
 (0)