2017 © Pedro Peláez
 

symfony-bundle hashids-bundle

Integrates hashids/hashids in a Symfony project

image

roukmoute/hashids-bundle

Integrates hashids/hashids in a Symfony project

  • Tuesday, March 27, 2018
  • by roukmoute
  • Repository
  • 1 Watchers
  • 22 Stars
  • 11,617 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 19 Versions
  • 11 % Grown

The README.md

SymfonyInsight Scrutinizer Code Quality Packagist Downloads, (*1)

HashidsBundle

Integrates hashids/hashids in a Symfony project., (*2)

Installation using composer

These commands requires you to have Composer installed globally.
Open a command console, enter your project directory and execute the following commands to download the latest stable version of this bundle:, (*3)

Using Symfony Flex

    composer config extra.symfony.allow-contrib true
    composer req roukmoute/hashids-bundle

Using Symfony Framework only

    composer require roukmoute/hashids-bundle

If this has not been done automatically, enable the bundle by adding the following line in the config/bundles.php file of your project:, (*4)

<?php

return [
    …,
    Roukmoute\HashidsBundle\RoukmouteHashidsBundle::class => ['all' => true],
];

Configuration

The configuration (config/packages/roukmoute_hashids.yaml) looks as follows :, (*5)

roukmoute_hashids:

    # if set, the hashids will differ from everyone else's
    salt:            ""

    # if set, will generate minimum length for the id
    # 0 — meaning hashes will be the shortest possible length
    min_hash_length: 0

    # if set, will use only characters of alphabet string
    alphabet:        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

    # if set to true, it will continue with the next available param converters
    passthrough:     false

    # if set to true, it tries to convert all arguments passed to the controller
    auto_convert:    false

Usage


use Hashids\HashidsInterface; public function postShow(HashidsInterface $hashids): Response { $hashids->… }

Next it's the same things of official documentation., (*6)

Hashids Converter

Converter Name: hashids.converter, (*7)

The hashids converter attempts to convert any attribute set in the route into an integer parameter., (*8)

You could use hashid or id:, (*9)

/**
 * @Route("/users/{hashid}")
 */
public function getAction(int $user)
{
}

or, (*10)

/**
 * @Route("/users/{id}")
 */
public function getAction(int $user)
{
}

You could have several hashids in the same URL prefixed with _hash_., (*11)

/**
 * @Route("/users/{_hash_user}/status/{_hash_status}")
 */
public function getAction(int $user, int $status)
{
}

The keys must be the same as in parameters controller:, (*12)

/**
 *                          _hash_user _hash_status
 *                                 ↕            ↕
 * public function getAction(int $user, int $status)
 */

You will receive a LogicException if a hash could not be decoded correctly., (*13)

Using auto_convert

auto_convert tries to convert all arguments in controller., (*14)

roukmoute_hashids:
  auto_convert: true

Base on the example above:, (*15)

/**
 * @Route("/users/{user}/status/{status}")
 */
public function getAction(int $user, int $status)
{
}

It will not be possible to get an exception of type LogicException from the bundle if it is activated., (*16)

Using passthrough

passthrough allows to continue with the next available param converters.
So if you would like to retrieve an object instead of an integer, just active passthrough :, (*17)

roukmoute_hashids:
    passthrough: true

Base on the example above:, (*18)

/**
 * @Route("/users/{hashid}")
 */
public function getAction(User $user)
{
}

As you can see, the passthrough feature allows to use DoctrineParamConverter or any another ParamConverterInterface you would have created., (*19)

Twig Extension

Usage

{{ path('users.show', {'hashid': user.id | hashids_encode }) }}
{{ app.request.query.get('hashid') | hashids_decode }}

The Versions

27/03 2018

dev-master

9999999-dev

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mathias STRASSER

27/03 2018

v2.0.0

2.0.0.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mathias STRASSER

27/03 2018

v2.0.x-dev

2.0.9999999.9999999-dev

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mathias STRASSER

20/03 2018
16/03 2018
02/03 2018
02/03 2018
26/02 2018

v1.4.3

1.4.3.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mathias STRASSER

22/09 2017

v1.4.2

1.4.2.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mathias STRASSER

28/04 2017

v1.4.1

1.4.1.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER

12/03 2017

v1.4.0

1.4.0.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER

09/12 2016

v1.3.3

1.3.3.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER

15/11 2016

v1.3.2

1.3.2.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER

15/11 2016

v1.3.1

1.3.1.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER

02/11 2016

v1.3

1.3.0.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER

01/11 2016

v1.2.1

1.2.1.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER

31/10 2016

v1.2

1.2.0.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER

19/09 2016

v1.1

1.1.0.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER

14/06 2016

v1.0

1.0.0.0

Integrates hashids/hashids in a Symfony project

  Sources   Download

MIT

The Requires

 

by Mathias STRASSER