All Projects → roukmoute → hashids-bundle

roukmoute / hashids-bundle

Licence: MIT license
Integrates hashids/hashids in a Symfony project

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to hashids-bundle

laravel-hashids
Laravel package for Hashids
Stars: ✭ 52 (+20.93%)
Mutual labels:  hashids
SlackBundle
SlackBundle for Symfony2 with Guzzle-Integration
Stars: ✭ 39 (-9.3%)
Mutual labels:  symfony-bundle
PRRecaptchaBundle
Recaptcha v3 bundle for Symfony
Stars: ✭ 14 (-67.44%)
Mutual labels:  symfony-bundle
gulp-rev-versions-bundle
A bundle that allows symfony to get the version of assets versioned with gulp-rev
Stars: ✭ 13 (-69.77%)
Mutual labels:  symfony-bundle
LiipSearchBundle
[DEPRECATED] Google XML API for searching is discontinued
Stars: ✭ 35 (-18.6%)
Mutual labels:  symfony-bundle
SonataDashboardBundle
[Abandoned] Provides a Dashboard management through container and block services
Stars: ✭ 17 (-60.47%)
Mutual labels:  symfony-bundle
Hashid Rails
Use Hashids (http://hashids.org/ruby/) in your Rails app ActiveRecord models.
Stars: ✭ 225 (+423.26%)
Mutual labels:  hashids
EasyAdminPlusBundle
EasyAdminPlusBundle is a Symfony 4 wrapper for the amazing EasyCorp/EasyAdminBundle
Stars: ✭ 39 (-9.3%)
Mutual labels:  symfony-bundle
django-hashids
Non-intrusive hashids library for Django
Stars: ✭ 26 (-39.53%)
Mutual labels:  hashids
SonataDoctrineMongoDBAdminBundle
Symfony Sonata / Integrate Doctrine MongoDB ODM into the SonataAdminBundle
Stars: ✭ 64 (+48.84%)
Mutual labels:  symfony-bundle
SonataTimelineBundle
[Abandoned] Integrates SpyTimelineBundle into Sonata
Stars: ✭ 24 (-44.19%)
Mutual labels:  symfony-bundle
SensioBuzzBundle
No description or website provided.
Stars: ✭ 89 (+106.98%)
Mutual labels:  symfony-bundle
hashids.sql
PL/pgSQL implementation of hashids library
Stars: ✭ 40 (-6.98%)
Mutual labels:  hashids
sonata-multiupload-bundle
No description or website provided.
Stars: ✭ 29 (-32.56%)
Mutual labels:  symfony-bundle
LiipImagineSerializationBundle
Provides integration between LiipImagineBundle and JMSSerializerBundle
Stars: ✭ 24 (-44.19%)
Mutual labels:  symfony-bundle
symfony-rest-api-bundle
Integrates the MediaMonks REST API Spec in Symfony
Stars: ✭ 17 (-60.47%)
Mutual labels:  symfony-bundle
apisearch-bundle
⛵ Apisearch Symfony-Drift Bundle
Stars: ✭ 23 (-46.51%)
Mutual labels:  symfony-bundle
hashed-asset-bundle
Apply an asset version based on a hash of the asset for symfony/asset
Stars: ✭ 24 (-44.19%)
Mutual labels:  symfony-bundle
jsonrpc-bundle
JSON-RPC server for Symfony: exposes services registered in the service container as JSON-RPC-webservices
Stars: ✭ 31 (-27.91%)
Mutual labels:  symfony-bundle
stampie-bundle
stampie.github.io/
Stars: ✭ 26 (-39.53%)
Mutual labels:  symfony-bundle

SymfonyInsight Scrutinizer Code Quality Packagist Downloads

HashidsBundle

Integrates hashids/hashids in a Symfony project.

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:

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:

<?php

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

Configuration

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

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.

Hashids Converter

Converter Name: hashids.converter

The hashids converter attempts to convert any attribute set in the route into an integer parameter.

You could use hashid or id:

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

or

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

You could have several hashids in the same URL prefixed with _hash_.

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

The keys must be the same as in parameters controller:

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

You will receive a LogicException if a hash could not be decoded correctly.

Using auto_convert

auto_convert tries to convert all arguments in controller.

roukmoute_hashids:
  auto_convert: true

Base on the example above:

/**
 * @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.

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 :

roukmoute_hashids:
    passthrough: true

Base on the example above:

/**
 * @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.

Twig Extension

Usage

{{ path('users.show', {'hashid': user.id | hashids_encode }) }}
{{ app.request.query.get('hashid') | hashids_decode }}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].