Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elliottlandsborough/laravel-base-encode
Base encode and decode integers with your own specified base
https://github.com/elliottlandsborough/laravel-base-encode
Last synced: about 1 month ago
JSON representation
Base encode and decode integers with your own specified base
- Host: GitHub
- URL: https://github.com/elliottlandsborough/laravel-base-encode
- Owner: ElliottLandsborough
- Created: 2015-02-25T21:41:20.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-18T02:58:58.000Z (about 7 years ago)
- Last Synced: 2024-04-06T20:21:22.624Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Laravel Baser
### Base encode and decode integers with your own specified base
[View the package](https://packagist.org/packages/elliottlan/laravel-baser) at packagist.org
#### Requirements
- Laravel
- PHP#### Limits
- Currently only supports integers from 1 to 100000000000000000000000000000 (on 64 bit machines)
#### Installation
1. Include the composer package
```
composer require elliottlan/laravel-baser
```
2. Add this line to 'Providers' in config/app.php
```
Elliottlan\LaravelBaser\LaravelBaserServiceProvider::class,
```
3. Add this line to 'Aliases' in config/app.php
```
'Baser' => Elliottlan\LaravelBaser\Facades\Baser::class,
```
4. Use 'Base' at the top of a controller
```
use Baser;
```
5. Try an example out
```
echo Baser::getTokenFromInt(436432278698); // 7GnTmBA
```#### Usage examples
##### Encode an int
```php
echo Baser::getTokenFromInt(436432278698); // 7GnTmBA
```##### Decode a token
```php
echo Baser::getIntFromToken('7GnTmBA'); // 436432278698
```##### Use big maths (requires php-bcmath)
```php
// calculate above the 32bit limit on old machines
echo Baser::bcMath()->getTokenFromInt(19598531548); // lolrly
echo Baser::bcMath()->getIntFromToken('lolrly'); // 19598531548
```##### Define a codeset and encode/decode
```php
// set codeset to 'ABCEFGHKMNPRSTUVW1235789'
echo Baser::setCodeset('ABCEFGHKMNPRSTUVW1235789')->getTokenFromInt(646464); // B82MA
echo Baser::setCodeset('ABCEFGHKMNPRSTUVW1235789')->getIntFromToken('B82MA'); // 646464
```##### Everything
```php
echo Baser::setCodeset('ABC')->bcMath()->getTokenFromInt(1337);
```##### Simple URL Shortening service using this package
[Controller](https://github.com/ElliottLandsborough/Laravel-5-URL-Shorterner/blob/master/app/Http/Controllers/UrlController.php)
[Model](https://github.com/ElliottLandsborough/Laravel-5-URL-Shorterner/blob/master/app/Url.php)
[Migration](https://github.com/ElliottLandsborough/Laravel-5-URL-Shorterner/blob/master/database/migrations/2015_02_13_221304_create_url_table.php)