Skip to content

Commit 4d30594

Browse files
committed
initial upload. 0___o
0 parents  commit 4d30594

File tree

75 files changed

+12253
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+12253
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/docker/dbdata
2+
/vendor
3+
.env
4+
.phpunit.result.cache
5+
/.idea
6+
/.vscode

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM php:8-fpm
2+
3+
RUN apt-get update \
4+
&& apt-get -y install libzip-dev zlib1g-dev git zip unzip libicu-dev g++ libbz2-dev libmemcached-dev \
5+
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
6+
7+
RUN docker-php-ext-configure zip && docker-php-ext-install pdo pdo_mysql zip bz2 intl
8+
9+
# Get latest Composer
10+
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
11+
12+
# Set working directory
13+
WORKDIR /var/www
14+
15+
RUN chown -R www-data:www-data /var/www
16+
17+
# Expose port 9000 and start php-fpm server
18+
EXPOSE 9000
19+
CMD ["php-fpm"]

README.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
2+
<br />
3+
<br />
4+
5+
<div align="center">
6+
<a href="https://github.com/YorCreative">
7+
<img src="content/logo.png" alt="Logo" width="128" height="128">
8+
</a>
9+
</div>
10+
11+
<h3 align="center">Laravel URL Shortener</h3>
12+
13+
A Laravel URL Shortener package that provides URL redirects with optional protected url passwords, url expirations, open
14+
limits before expiration, ability to set feature activation dates and click tracking out of the box for your Laravel
15+
applications.
16+
17+
## Installation
18+
19+
install the package via composer:
20+
21+
```bash
22+
composer require yorcreative/laravel-urlshortener
23+
```
24+
25+
Publish the packages assets.
26+
```bash
27+
php artisan vendor:publish --provider="YorCreative\UrlShortener\UrlShortenerServiceProvider"
28+
```
29+
30+
Run migrations.
31+
```bash
32+
php artisan migrate
33+
```
34+
35+
## Usage
36+
37+
Building Short Urls
38+
39+
```php
40+
/**
41+
* Basic
42+
*/
43+
$url = UrlService::shorten('something-extremely-long.com/even/longer?ref=with&some=thingelselonger')
44+
->build();
45+
// http(s)://host/prefix/identifier;
46+
47+
/**
48+
* Advanced
49+
*/
50+
$url = UrlService::shorten('something-extremely-long.com/even/longer?ref=with&some=thingelselonger')
51+
->withActivation(Carbon::now()->addHour()->timestamp)
52+
->withExpiration(Carbon::now()->addDay()->timestamp)
53+
->withOpenLimit(2)
54+
->withOwnership(Model::find(1))
55+
->withPassword('password')
56+
->build();
57+
// http(s)://host/prefix/identifier;
58+
```
59+
60+
Getting Click Information
61+
62+
```php
63+
$clicks = ClickService::get()->toArray();
64+
65+
dd($clicks);
66+
[
67+
'results' => [
68+
[
69+
'id' => ...,
70+
'created_at' => ...,
71+
'short_url' => [
72+
'id' => ...,
73+
'identifier' => ...,
74+
'hashed' => ...,
75+
'plain_text' => ...,
76+
'limit' => ...,
77+
'created_at' => ...,
78+
'updated_at' =>> ...
79+
],
80+
'location' => [
81+
'id' => ...,
82+
'ip' => ...,
83+
'countryName' => ...,
84+
'countryCode' => ...,
85+
'regionCode' => ...,
86+
'regionName' => ...,
87+
'cityName' => ...,
88+
'zipCode' => ...,
89+
'isoCode' => ...,
90+
'postalCode' => ...,
91+
'latitude' => ...,
92+
'longitude' => ...,
93+
'metroCode' => ...,
94+
'areaCode' => ...,
95+
'timezone' => ...,
96+
'created_at' => ...,
97+
'updated_at' => ...
98+
],
99+
'outcome' => [
100+
'id' => ...,
101+
'name' => ...,
102+
'alias' => ...,
103+
]
104+
]
105+
],
106+
'total' => 1
107+
];
108+
```
109+
110+
Getting Click Information and Filtering on Ownership
111+
112+
```php
113+
$clicks = ClickService::get([
114+
'ownership' => [
115+
Model::find(1),
116+
Model::find(2)
117+
]
118+
]);
119+
```
120+
121+
122+
Filter on Outcome
123+
124+
```php
125+
$clicks = ClickService::get([
126+
'outcome' => [
127+
1, // successful_routed
128+
2, // successful_protected
129+
3, // failure_password
130+
4, // failure_expiration
131+
5 // failure_limit
132+
]
133+
]);
134+
```
135+
Filter on the Click's YorShortUrl Status
136+
137+
```php
138+
$clicks = ClickService::get([
139+
'status' => [
140+
'active',
141+
'expired',
142+
'expiring' // within 30 minutes of expiring
143+
]
144+
]);
145+
```
146+
147+
Filtered on YorShortUrl Identifier(s)
148+
149+
```php
150+
$clicks = ClickService::get([
151+
'identifier' => [
152+
'xyz',
153+
'yxz'
154+
]
155+
]);
156+
```
157+
158+
Iterate Through Results With Batches
159+
160+
```php
161+
$clicks = ClickService::get([
162+
'limit' => 500
163+
'offset' => 1500
164+
]);
165+
166+
$clicks->get('results');
167+
$clicks->get('total');
168+
```
169+
170+
Putting it all Together
171+
172+
```php
173+
/**
174+
* Get the successfully routed clicks for all active short urls that are owned by Model IDs 1,2,3 and 4.
175+
* Set the offset of results by 1500 clicks and limit by the results by 500.
176+
*/
177+
$clicks = ClickService::get([
178+
'ownership' => Model::whereIn('id', [1,2,3,4])->get()->toArray(),
179+
'outcome' => [
180+
3 // successful_routed
181+
],
182+
'status' => [
183+
'active'
184+
],
185+
'limit' => 500
186+
'offset' => 1500
187+
]);
188+
```
189+
190+
## Testing
191+
192+
```bash
193+
composer test
194+
```
195+
196+
## Credits
197+
198+
- [Yorda](https://github.com/yordadev)
199+
- [All Contributors](../../contributors)
200+

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "yorcreative/laravel-urlshortener",
3+
"description": "A laravel url shortener package that provides internal url redirects with passwords, url expirations, open limits before expiration and click tracking out of the box.",
4+
"type": "library",
5+
"keywords": [
6+
"laravel",
7+
"framework",
8+
"url",
9+
"shortener",
10+
"url shortener",
11+
"laravel url shortener",
12+
"laravel url"
13+
],
14+
"minimum-stability": "dev",
15+
"require": {
16+
"php": "^8.1",
17+
"ext-pdo_sqlite": "*",
18+
"illuminate/contracts": "^9.0",
19+
"stevebauman/location": "*"
20+
},
21+
"require-dev": {
22+
"laravel/pint": "^1.0",
23+
"orchestra/testbench": "^7.0",
24+
"phpunit/phpunit": "^9.5"
25+
},
26+
"autoload": {
27+
"psr-4": {
28+
"YorCreative\\UrlShortener\\": "src/"
29+
}
30+
},
31+
"autoload-dev": {
32+
"psr-4": {
33+
"YorCreative\\UrlShortener\\": "src/",
34+
"YorCreative\\UrlShortener\\Tests\\": "tests"
35+
}
36+
},
37+
"scripts": {
38+
"test": "vendor/bin/phpunit",
39+
"lint": "vendor/bin/pint"
40+
}
41+
}

0 commit comments

Comments
 (0)