https://github.com/tangoman75/callbackbundle
TangoMan Callback Twig Extension Bundle provides simple callbacks manager for twig, avoids unnecessary callbacks to stack up indefinitely
https://github.com/tangoman75/callbackbundle
avoids-unnecessary-callbacks bundle callback callback-manager extension service symfony tangoman-callbackbundle twig
Last synced: 10 months ago
JSON representation
TangoMan Callback Twig Extension Bundle provides simple callbacks manager for twig, avoids unnecessary callbacks to stack up indefinitely
- Host: GitHub
- URL: https://github.com/tangoman75/callbackbundle
- Owner: TangoMan75
- License: mit
- Created: 2017-08-18T15:53:06.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2025-07-11T13:53:07.000Z (12 months ago)
- Last Synced: 2025-08-19T23:14:07.165Z (10 months ago)
- Topics: avoids-unnecessary-callbacks, bundle, callback, callback-manager, extension, service, symfony, tangoman-callbackbundle, twig
- Language: PHP
- Homepage:
- Size: 48.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://github.com/TangoMan75/CallbackBundle/releases)


[](https://github.com/TangoMan75/CallbackBundle/actions/workflows/php.yml)

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.
🧩 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.
🔧 `callbackFunction()`
-----------------------
```php
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:
```
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.
📦 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:
```bash
composer require tangoman/callback-bundle
```
This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.
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:
```php
Your Foo Bar link here
```
But you can optionally redirect user to any route.
```twig
Your Foo Bar link here
```
Callback function accepts route name and parameters for desired route.
Inside your action method:
```php
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.
Enter following command to install required dependencies and execute unit tests:
```bash
$ make tests
```
On windows machine you will need to install [cygwin](http://www.cygwin.com/) or [GnuWin make](http://gnuwin32.sourceforge.net/packages/make.htm) first to execute make script.
If you have XDebug installed, you can generate code coverage report with:
```bash
$ make coverage
```
📝 Note
=======
[](https://travis-ci.org/TangoMan75/CallbackBundle)
If you find any bug please report here : [Issues](https://github.com/TangoMan75/CallbackBundle/issues/new)
🤝 Contributing
---------------
Thank you for your interest in contributing to **TangoMan Callback Twig Extension Bundle**.
Please review the [code of conduct](./CODE_OF_CONDUCT.md) and [contribution guidelines](./CONTRIBUTING.md) before starting to work on any features.
If you want to open an issue, please check first if it was not [reported already](https://github.com/TangoMan75/CallBackBundle/issues) before creating a new one.
📜 License
----------
Copyrights (c) 2025 "Matthias Morin" <mat@tangoman.io>
[](LICENSE)
Distributed under the MIT license.
If you like **TangoMan Callback Twig Extension Bundle** please star, follow or tweet:
[](https://github.com/TangoMan75/CallBackBundle/stargazers)
[](https://github.com/TangoMan75)
[](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2FTangoMan75%2FCallBackBundle)
... And check my other cool projects.
👋 Let's Build Your Next Project Together !
-------------------------------------------
Looking for an experienced Full-Stack Partner ?
Clean code. Clear communication.
From first sketch to final launch, I've got your back.
[](https://tangoman.io)