2017 © Pedro Pelรกez
 

library callback-bundle

Callback Symfony Twig Extension Bundle

image

tangoman/callback-bundle

Callback Symfony Twig Extension Bundle

  • Sunday, April 8, 2018
  • by Tangoman
  • Repository
  • 0 Watchers
  • 1 Stars
  • 128 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

GH language GH release GH license GH stars PHP CI Visitors, (*1)

TangoMan Callback Twig Extension Bundle

TangoMan Callback Twig Extension Bundle provides simple callback function for twig which avoids unnecessary callbacks to stack up indefinitely in users query string., (*2)

๐Ÿงฉ Purpose of the Callback Class

This class defines a Twig extension that introduces a custom function called callback. Its main job is to generate clean URLs by removing callback parameters from query strings, which can help avoid issues where multiple callbacks get appended indefinitely and make sure users query parameters are not lost in the process., (*3)

๐Ÿ”ง callbackFunction()

public function callbackFunction($route = null, $parameters = [])
  • Behavior:
    • If no route is provided -> use the current request URI.
    • If a route is specified -> generate a full URL using Symfony's router.
  • Core logic:
    • Parses the URL.
    • Removes the callback parameter from the query string.
    • Reconstructs and returns the cleaned URL.

โœจ Real-Life Use Case

Imagine you're building a redirect system where callbacks are passed through URLs. If multiple redirects occur (e.g., login flow, third-party auth, or form submissions), you might get URLs like this:, (*4)

https://example.com/page?callback=https://another.com?callback=...

This class avoids that endless loop by stripping the callback query parameter from the final URL so it stays nice and tidy., (*5)

๐Ÿ“ฆ Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*6)

composer require tangoman/callback-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*7)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*8)

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    // ...

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new TangoMan\CallbackBundle\TangoManCallbackBundle(),
        );

        // ...
    }
}

You don't have to add TangoMan Callback Twig Extension Bundle to the service.yml of your project. twig.extension.callback service will load automatically., (*9)

๐Ÿ› ๏ธ Usage

callback(route = null, parameters = [])

Returns current URI removing callback from query string. Optionally, returns the absolute URL (with scheme and host) for the given route with given parameters, callback will be ignored as well., (*10)

route (optional) parameters (optional)
type string array
default current uri []

Inside your views:, (*11)

By default callback will be defined on user's current page., (*12)

    <a href="{{ path('app_foo_bar', { 'callback': callback() }) }}">
        Your Foo Bar link here
    </a>

But you can optionally redirect user to any route., (*13)

    <a href="{{ path('app_delete_foo', { 'callback': callback('app_trash_bin', { 'slug': 'foo' } ) }) }}">
        Your Foo Bar link here
    </a>

Callback function accepts route name and parameters for desired route., (*14)

Inside your action method:, (*15)

    public function foobarAction(Request $request)
    {
        ...
        // User is redirected to referrer page
        return $this->redirect($request->get('callback'));
        ...
    }

โœ… Tests

TangoMan Callback Twig Extension Bundle provides Makefile script to perform unit tests, in order to fit in your continuous integration workflow., (*16)

Enter following command to install required dependencies and execute unit tests:, (*17)

$ make tests

On windows machine you will need to install cygwin or GnuWin make first to execute make script., (*18)

If you have XDebug installed, you can generate code coverage report with:, (*19)

$ make coverage

๐Ÿ“ Note

Build Status If you find any bug please report here : Issues, (*20)

๐Ÿค Contributing

Thank you for your interest in contributing to TangoMan Callback Twig Extension Bundle., (*21)

Please review the code of conduct and contribution guidelines before starting to work on any features., (*22)

If you want to open an issue, please check first if it was not reported already before creating a new one., (*23)

๐Ÿ“œ License

Copyrights (c) 2025 "Matthias Morin" <mat@tangoman.io>, (*24)

License Distributed under the MIT license., (*25)

If you like TangoMan Callback Twig Extension Bundle please star, follow or tweet:, (*26)

GitHub stars GitHub followers Twitter, (*27)

... And check my other cool projects., (*28)

๐Ÿ‘‹ Let's Build Your Next Project Together !

Looking for an experienced Full-Stack Partner ?, (*29)

Clean code. Clear communication., (*30)

From first sketch to final launch, I've got your back., (*31)

tangoman.io, (*32)

The Versions

08/04 2018

dev-master

9999999-dev

Callback Symfony Twig Extension Bundle

  Sources   Download

MIT GPL-3.0

The Requires

  • php >=5.3.0

 

by Matthias Morin

service twig extension bundle symfony callback

08/04 2018

2.0.1

2.0.1.0

Callback Symfony Twig Extension Bundle

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Matthias Morin

service twig extension bundle symfony callback

11/10 2017

2.0.0

2.0.0.0

Callback Symfony Twig Extension Bundle

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Matthias Morin

service twig extension bundle symfony callback

18/08 2017

1.0.0

1.0.0.0

Callback Symfony Twig Extension Bundle

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

by Matthias Morin

service twig extension bundle symfony callback