Skip to content

Commit

Permalink
Release v2.0 (#3)
Browse files Browse the repository at this point in the history
* Add support of Laravel 5.5. Update namespace
  • Loading branch information
Anton Komarev authored Sep 9, 2017
1 parent b3bd356 commit 4fee069
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 72 deletions.
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ disabled:
- concat_without_spaces
- phpdoc_no_package
- logical_not_operators_with_successor_space
- length_ordered_imports
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ sudo: false
php:
- 7.0
- 7.1
- 7.2

env:
global:
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to `laravel-optimus` will be documented in this file.

## [2.0.0] - 2017-09-09

### Added

- Laravel 5.5 support
- Service provider and facade auto-discovery

### Changed

- Namespace `Cog\Optimus` renamed to `Cog\Laravel\Optimus`

## 1.0.0 - 2017-01-01

Initial release

[2.0.0]: https://github.com/cybercog/laravel-optimus/compare/1.0.0...2.0.0
65 changes: 48 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![cog-laravel-optimus-3](https://cloud.githubusercontent.com/assets/1849174/21738350/6c08b624-d494-11e6-9895-94e7d5f39010.png)
![cog-laravel-optimus](https://user-images.githubusercontent.com/1849174/28744713-5b28fffa-746f-11e7-8ca2-0e2a612bc19c.png)

<p align="center">
<a href="https://travis-ci.org/cybercog/laravel-optimus"><img src="https://img.shields.io/travis/cybercog/laravel-optimus/master.svg?style=flat-square" alt="Build Status"></a>
Expand All @@ -11,11 +11,30 @@

Laravel wrapper for the [Optimus Library](https://github.com/jenssegers/optimus) by [Jens Segers](https://github.com/jenssegers) with multiple connections support. Optimus is a small open-source library that generates short, unique, non-sequential ids from numbers. With this library, you can transform your internal id's to obfuscated integers based on Knuth's integer hash. It is similar to Hashids, but will generate integers instead of random strings. It is also super fast.

## Contents

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Change log](#change-log)
- [Upgrading](#upgrading)
- [Contributing](#contributing)
- [Testing](#testing)
- [Security](#security)
- [Credits](#credits)
- [Alternatives](#alternatives)
- [License](#license)
- [About CyberCog](#about-cybercog)

## Features

- Designed to work with Laravel Eloquent models.
- Configurable multiple connections support.
- Dependency Injection ready.
- Includes Facade.
- Following PHP Standard Recommendations:
- [PSR-1 (Basic Coding Standard)](http://www.php-fig.org/psr/psr-1/).
- [PSR-2 (Coding Style Guide)](http://www.php-fig.org/psr/psr-2/).
- [PSR-4 (Autoloading Standard)](http://www.php-fig.org/psr/psr-4/).
- Covered with unit tests.
Expand All @@ -28,19 +47,23 @@ First, pull in the package through Composer.
$ composer require cybercog/laravel-optimus
```

And then include the service provider within `app/config/app.php`.
**If you are using Laravel 5.5 you can skip register package part.**

#### Register package on Laravel 5.4 and lower

Include the service provider within `app/config/app.php`.

```php
'providers' => [
Cog\Optimus\Providers\OptimusServiceProvider::class,
Cog\Laravel\Optimus\Providers\OptimusServiceProvider::class,
],
```

If you want you can use the [facade](http://laravel.com/docs/facades). Add the reference in `config/app.php` to your aliases array.

```php
'aliases' => [
'Optimus' => Cog\Optimus\Facades\Optimus::class,
'Optimus' => Cog\Laravel\Optimus\Facades\Optimus::class,
],
```

Expand All @@ -49,7 +72,7 @@ If you want you can use the [facade](http://laravel.com/docs/facades). Add the r
Laravel Optimus requires connection configuration. To get started, you'll need to publish config file:

```sh
$ php artisan vendor:publish --provider="Cog\Optimus\Providers\OptimusServiceProvider" --tag="config"
$ php artisan vendor:publish --provider="Cog\Laravel\Optimus\Providers\OptimusServiceProvider" --tag="config"
```

This will create a `config/optimus.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.
Expand Down Expand Up @@ -99,21 +122,21 @@ Here you can see an example of just how simple this package is to use. Out of th
#### Encode ID

```php
Cog\Optimus\Facades\Optimus::encode(20); // 1535832388
Cog\Laravel\Optimus\Facades\Optimus::encode(20); // 1535832388
```

#### Decode ID

```php
Cog\Optimus\Facades\Optimus::decode(1535832388); // 20
Cog\Laravel\Optimus\Facades\Optimus::decode(1535832388); // 20
```

#### Alter Optimus connection

The Optimus manager will behave like it is a `Jenssegers\Optimus\Optimus`. If you want to call specific connections, you can do that with the connection method:

```php
use Cog\Optimus\Facades\Optimus;
use Cog\Laravel\Optimus\Facades\Optimus;

// Writing this…
Optimus::connection('main')->encode($id);
Expand All @@ -136,7 +159,7 @@ Optimus::setDefaultConnection('alternative'); // The default is now alternative.
If you prefer to use dependency injection over facades like me, then you can inject the manager:

```php
use Cog\Optimus\OptimusManager;
use Cog\Laravel\Optimus\OptimusManager;

class Foo
{
Expand All @@ -156,6 +179,18 @@ class Foo
app()->make('Foo')->bar(20);
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Upgrading

Please see [UPGRADING](UPGRADING.md) for detailed upgrade instructions.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Testing

Run the tests with:
Expand All @@ -164,10 +199,6 @@ Run the tests with:
$ vendor/bin/phpunit
```

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Expand All @@ -184,12 +215,9 @@ Package was inspired by [Laravel Hashids](https://github.com/vinkla/laravel-hash

This package is a wrapper for [Optimus Library](https://github.com/jenssegers/optimus).

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Alternatives

- [vinkla/laravel-hashids](https://github.com/vinkla/laravel-hashids)
- [propaganistas/laravel-fakeid](https://github.com/Propaganistas/Laravel-FakeId)

*Feel free to add more alternatives as Pull Request.*
Expand All @@ -202,4 +230,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re

[CyberCog](http://www.cybercog.ru) is a Social Unity of enthusiasts. Research best solutions in product & software development is our passion.

- [Follow us on Twitter](https://twitter.com/cybercog)
- [Read our articles on Medium](https://medium.com/cybercog)

<a href="http://cybercog.ru"><img src="https://cloud.githubusercontent.com/assets/1849174/18418932/e9edb390-7860-11e6-8a43-aa3fad524664.png" alt="CyberCog"></a>
30 changes: 20 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@
"docs": "https://github.com/cybercog/laravel-optimus/wiki"
},
"require": {
"graham-campbell/manager": "^2.5",
"illuminate/contracts": "~5.2.0|~5.3.0|~5.4.0",
"illuminate/support": "~5.2.0|~5.3.0|~5.4.0",
"jenssegers/optimus": "^0.2.2",
"php": "^7.0"
"php": "^7.0",
"graham-campbell/manager": "^3.0",
"illuminate/contracts": "~5.2|~5.3|~5.4|~5.5",
"illuminate/support": "~5.2|~5.3|~5.4|~5.5",
"jenssegers/optimus": "^0.2.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^1.11",
"graham-campbell/testbench": "^3.3",
"graham-campbell/testbench": "^4.0",
"mockery/mockery": "^0.9.8",
"orchestra/testbench": "~3.4.0",
"phpunit/phpunit": "^5.7"
"orchestra/testbench": "~3.4.0|~3.5.0",
"phpunit/phpunit": "^6.2"
},
"autoload": {
"psr-4": {
"Cog\\Optimus\\": "src/"
"Cog\\Laravel\\Optimus\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Cog\\Optimus\\Tests\\": "tests/"
"Cog\\Tests\\Laravel\\Optimus\\": "tests/"
}
},
"scripts": {
Expand All @@ -63,6 +63,16 @@
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Cog\\Laravel\\Optimus\\Providers\\OptimusServiceProvider"
],
"aliases": {
"Optimus": "Cog\\Laravel\\Optimus\\Facades\\Optimus"
}
}
},
"minimum-stability": "dev",
"prefer-stable" : true
}
6 changes: 3 additions & 3 deletions src/Facades/Optimus.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

declare(strict_types=1);

namespace Cog\Optimus\Facades;
namespace Cog\Laravel\Optimus\Facades;

use Illuminate\Support\Facades\Facade;

/**
* Class Optimus.
*
* @package Cog\Optimus\Facades
* @package Cog\Laravel\Optimus\Facades
*/
class Optimus extends Facade
{
Expand All @@ -27,7 +27,7 @@ class Optimus extends Facade
*
* @return string
*/
protected static function getFacadeAccessor() : string
protected static function getFacadeAccessor(): string
{
return 'optimus';
}
Expand Down
10 changes: 5 additions & 5 deletions src/OptimusFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

declare(strict_types=1);

namespace Cog\Optimus;
namespace Cog\Laravel\Optimus;

use Jenssegers\Optimus\Optimus;

/**
* Class OptimusFactory.
*
* @package Cog\Optimus
* @package Cog\Laravel\Optimus
*/
class OptimusFactory
{
Expand All @@ -28,7 +28,7 @@ class OptimusFactory
* @param array $config
* @return \Jenssegers\Optimus\Optimus
*/
public function make(array $config) : Optimus
public function make(array $config): Optimus
{
$config = $this->getConfig($config);

Expand All @@ -43,7 +43,7 @@ public function make(array $config) : Optimus
*
* @throws \InvalidArgumentException
*/
protected function getConfig(array $config) : array
protected function getConfig(array $config): array
{
return [
'prime' => array_get($config, 'prime', 0),
Expand All @@ -58,7 +58,7 @@ protected function getConfig(array $config) : array
* @param array $config
* @return \Jenssegers\Optimus\Optimus
*/
protected function getClient(array $config) : Optimus
protected function getClient(array $config): Optimus
{
return new Optimus($config['prime'], $config['inverse'], $config['random']);
}
Expand Down
16 changes: 8 additions & 8 deletions src/OptimusManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

declare(strict_types=1);

namespace Cog\Optimus;
namespace Cog\Laravel\Optimus;

use Jenssegers\Optimus\Optimus;
use GrahamCampbell\Manager\AbstractManager;
Expand All @@ -20,22 +20,22 @@
/**
* Class OptimusManager.
*
* @package Cog\Optimus
* @package Cog\Laravel\Optimus
*/
class OptimusManager extends AbstractManager
{
/**
* The factory instance.
*
* @var \Cog\Optimus\OptimusFactory
* @var \Cog\Laravel\Optimus\OptimusFactory
*/
private $factory;

/**
* Create a new Optimus manager instance.
*
* @param \Illuminate\Contracts\Config\Repository $config
* @param \Cog\Optimus\OptimusFactory $factory
* @param \Cog\Laravel\Optimus\OptimusFactory $factory
* @return void
*/
public function __construct(Repository $config, OptimusFactory $factory)
Expand All @@ -51,7 +51,7 @@ public function __construct(Repository $config, OptimusFactory $factory)
* @param array $config
* @return \Jenssegers\Optimus\Optimus
*/
protected function createConnection(array $config) : Optimus
protected function createConnection(array $config): Optimus
{
return $this->factory->make($config);
}
Expand All @@ -61,17 +61,17 @@ protected function createConnection(array $config) : Optimus
*
* @return string
*/
protected function getConfigName() : string
protected function getConfigName(): string
{
return 'optimus';
}

/**
* Get the factory instance.
*
* @return \Cog\Optimus\OptimusFactory
* @return \Cog\Laravel\Optimus\OptimusFactory
*/
public function getFactory() : OptimusFactory
public function getFactory(): OptimusFactory
{
return $this->factory;
}
Expand Down
Loading

0 comments on commit 4fee069

Please sign in to comment.