-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fcc1af
commit 7c02e6c
Showing
669 changed files
with
2,602 additions
and
165,967 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/bootstrap/compiled.php | ||
/vendor | ||
composer.phar | ||
composer.lock | ||
.env.local.php | ||
.env.php | ||
.DS_Store | ||
Thumbs.db | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Contribution Guidelines | ||
|
||
Please submit all issues and pull requests to the [laravel/framework](http://github.com/laravel/framework) repository! |
3 changes: 3 additions & 0 deletions
3
URL-Shortener-master/app/Way/Exceptions/NonExistentHashException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php namespace Way\Exceptions; | ||
|
||
class NonExistentHashException extends \Exception {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php namespace Way; | ||
|
||
class Link extends \Eloquent { | ||
|
||
/** | ||
* Fillable fields | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = ['url', 'hash']; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
URL-Shortener-master/app/Way/Repositories/BackendServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php namespace Way\Repositories; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class BackendServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Register bindings with IoC container | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->bind( | ||
'Way\Repositories\LinkRepositoryInterface', | ||
'Way\Repositories\DbLinkRepository' | ||
); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
URL-Shortener-master/app/Way/Repositories/DbLinkRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php namespace Way\Repositories; | ||
|
||
use Way\Link; | ||
|
||
class DbLinkRepository implements LinkRepositoryInterface { | ||
|
||
/** | ||
* Create new link in db | ||
* | ||
* @param array $data | ||
* | ||
* @return mixed | ||
*/ | ||
public function create(array $data) | ||
{ | ||
return Link::create($data); | ||
} | ||
|
||
/** | ||
* Fetch link by hash | ||
* | ||
* @param $hash | ||
* | ||
* @return mixed | ||
*/ | ||
public function byHash($hash) | ||
{ | ||
return Link::whereHash($hash)->first(); | ||
} | ||
|
||
/** | ||
* Fetch link by url | ||
* | ||
* @param $url | ||
* | ||
* @return mixed | ||
*/ | ||
public function byUrl($url) | ||
{ | ||
return Link::whereUrl($url)->first(); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
URL-Shortener-master/app/Way/Repositories/LinkRepositoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php namespace Way\Repositories; | ||
|
||
interface LinkRepositoryInterface { | ||
|
||
/** | ||
* Create new link | ||
* | ||
* @param array $data | ||
*/ | ||
public function create(array $data); | ||
|
||
/** | ||
* Fetch link by hash | ||
* | ||
* @param $hash | ||
*/ | ||
public function byHash($hash); | ||
|
||
/** | ||
* Fetch link by url | ||
* | ||
* @param $url | ||
*/ | ||
public function byUrl($url); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php namespace Way\Shortener\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class Little extends Facade { | ||
|
||
/** | ||
* Get name of binding in IoC container | ||
* | ||
* @return string | ||
*/ | ||
public static function getFacadeAccessor() | ||
{ | ||
return 'little'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php namespace Way\Shortener; | ||
|
||
use Way\Repositories\LinkRepositoryInterface as LinkRepo; | ||
use Way\Utilities\UrlHasher; | ||
use Way\Exceptions\NonExistentHashException; | ||
|
||
class LittleService { | ||
|
||
/** | ||
* @var \Way\Repositories\LinkRepositoryInterface | ||
*/ | ||
protected $linkRepo; | ||
|
||
/** | ||
* @var \Way\Utilities\UrlHasher | ||
*/ | ||
protected $urlHasher; | ||
|
||
/** | ||
* @param LinkRepo $linkRepo | ||
* @param UrlHasher $urlHasher | ||
*/ | ||
public function __construct(LinkRepo $linkRepo, UrlHasher $urlHasher) | ||
{ | ||
$this->linkRepo = $linkRepo; | ||
$this->urlHasher = $urlHasher; | ||
} | ||
|
||
/** | ||
* Save url to db and hash | ||
* | ||
* @param $url | ||
* | ||
* @return string | ||
*/ | ||
public function make($url) | ||
{ | ||
$link = $this->linkRepo->byUrl($url); | ||
|
||
return $link ? $link->hash : $this->makeHash($url); | ||
} | ||
|
||
/** | ||
* Fetch a url by hash | ||
* | ||
* @param $hash | ||
* | ||
* @return mixed | ||
* @throws \Way\Exceptions\NonExistentHashException | ||
*/ | ||
public function getUrlByHash($hash) | ||
{ | ||
$link = $this->linkRepo->byHash($hash); | ||
|
||
if ( ! $link) throw new NonExistentHashException; | ||
|
||
return $link->url; | ||
} | ||
|
||
/** | ||
* Prepare and save new url + hash | ||
* | ||
* @param $url | ||
* @returns string | ||
*/ | ||
private function makeHash($url) | ||
{ | ||
$hash = $this->urlHasher->make($url); | ||
$data = compact('url', 'hash'); | ||
|
||
\Event::fire('link.creating', [$data]); | ||
|
||
$this->linkRepo->create($data); | ||
|
||
return $hash; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
URL-Shortener-master/app/Way/Shortener/LittleServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php namespace Way\Shortener; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class LittleServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Register in IoC container | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->bind('little', 'Way\Shortener\LittleService'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php namespace Way\Utilities; | ||
|
||
class UrlHasher { | ||
|
||
/** | ||
* @var integer | ||
*/ | ||
protected $hashLength; | ||
|
||
/** | ||
* @param integer $hashLength | ||
*/ | ||
public function __construct($hashLength) | ||
{ | ||
$this->hashLength = $hashLength; | ||
} | ||
|
||
/** | ||
* Prepare URL hash | ||
* | ||
* @param $url | ||
* | ||
* @return string | ||
*/ | ||
public function make($url) | ||
{ | ||
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
|
||
return substr(str_shuffle(str_repeat($pool, 5)), 0, $this->hashLength); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
URL-Shortener-master/app/Way/Utilities/UtilitiesServiceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php namespace Way\Utilities; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
use Way\Utilities\UrlHasher; | ||
|
||
class UtilitiesServiceProvider extends ServiceProvider { | ||
|
||
/** | ||
* Register in IoC container | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->bind('Way\Utilities\UrlHasher', function() | ||
{ | ||
$length = 5; | ||
|
||
return new UrlHasher($length); | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.