diff --git a/.gitignore b/.gitignore index e5f92a9..8d29d2b 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,4 @@ node_modules/ composer.lock .claude/ +CLAUDE.md diff --git a/.markdownlint.yaml b/.markdownlint.yaml index c339e06..fe14661 100644 --- a/.markdownlint.yaml +++ b/.markdownlint.yaml @@ -1,4 +1,18 @@ -# Example markdownlint YAML configuration with all properties set to their default value +######################################################################### + # + # █▀▀▄ ▀ ▀▀█▀▀ ▀█ █ + # █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ ▄▀▀▄ ▄▀▀▄ █ █▀▀▄ ▄▀▀▄ █▄▀ + # █ █ █ ▀▄ █ █ █ █ █ █ █ █ █ █ █ ▄▄█ █ + # █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █ ▀▄▄▀ ▀▄▄▀ ▄█▄ █▄▄▀ ▀▄▄▀ █ + # + ######### Customizable developer toolbar for Symfony projects ######## + # + # @author Marcin Orlowski + # @copyright 2025-2026 Marcin Orlowski + # @license https://opensource.org/license/mit MIT + # @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony + # +######################################################################### # Default state for all rules default: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 02bf1e2..4522a9b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,28 +1,34 @@ -################################################################################## -# -# Laravel API Response Builder PHPStan config file -# -# @author Marcin Orlowski -# @copyright 2016-2025 Marcin Orlowski -# @license http://www.opensource.org/licenses/mit-license.php MIT -# @link https://github.com/MarcinOrlowski/laravel-api-response-builder -# -################################################################################## +######################################################################### + # + # █▀▀▄ ▀ ▀▀█▀▀ ▀█ █ + # █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ ▄▀▀▄ ▄▀▀▄ █ █▀▀▄ ▄▀▀▄ █▄▀ + # █ █ █ ▀▄ █ █ █ █ █ █ █ █ █ █ █ ▄▄█ █ + # █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █ ▀▄▄▀ ▀▄▄▀ ▄█▄ █▄▄▀ ▀▄▄▀ █ + # + ######### Customizable developer toolbar for Symfony projects ######## + # + # @author Marcin Orlowski + # @copyright 2025-2026 Marcin Orlowski + # @license https://opensource.org/license/mit MIT + # @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony + # +######################################################################### + # # Using pre-commit hooks # # # To improve quality of your commit, it's recommended to use "pre-commit" -# (http://pre-commit.com) hooks, that will block your commits unless all tests -# pass. This project comes with template configuration file -# `.pre-commit-config.yaml.dist`. +# (http://pre-commit.com) hooks, that will block your commits unless all tests pass. # # Brief installation instruction: # -# * Ensure you got Python installed -# * Install pre-commit: `pip install pre-commit` -# * Go to your Logisim-evolution source code root directory -# * Copy provided config file template: `cp .pre-commit-config.yaml.dist .pre-commit-config.yaml` +# * Install pipx: https://pypi.org/project/pipx/ +# * Run `pipx ensurepath` +# * Install pre-commit: `pipx install pre-commit` # * Plug hooks into Git pipeline: `pre-commit install` +# * Update hooks to most recent version: `pre-commit autoupdate` +# +# To commit with hooks not run, use `--no-verify` while doing `git commit` # # See `pre-commit` official installation docs too: https://pre-commit.com/#install # diff --git a/CHANGES.md b/CHANGES.md index 59bbf33..715ea5e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,9 +1,15 @@ +![img](img/banner.webp) + # Changelog -## 1.6.0 (TBD) +## 2.0.0 (2026-01-30) +- [#044] Renamed package to `marcin-orlowski/disco-toolbar-symfony` +- [#047] Rebranded from DiscoDevBar to DiscoToolbar +- [#041] Added Symfony 8 support +- [#042] Added project logo! - [#035] Added customizable background colors for breathing stripes -- [#033] Added close widget type to dismiss devbar +- [#033] Added close widget type to dismiss toolbar ## 1.5.2 (2025-12-12) diff --git a/LICENSE b/LICENSE index 2d8da46..bd019d8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2025 Marcin Orlowski +Copyright (c) 2025-2026 Marcin Orlowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 57d63dc..20b9797 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,40 @@ -```ascii -▄▀▀▄ ▄▀█ █▀▀▄ ▀ █▀▀▄ █▀▀▄ -▀▄▄ █▀█▀▄ █ ▄▀▀▄ █▀▀▄ █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ █ ▄▀▀▄ █ █ █▀▀▄ ▄▀▀▄ █▄▀ - █ █ █ █ █ █ ▀█▀ █ █ █ █ █ █ █ █ █ ▀▄ █ █ █ █ █ █▀▀ █ █ █ █ ▄▄█ █ -▀▄▄▀ ▀▄▄█ █ █ █ ▀▄▄▀ █ █ ▀▄▄█ █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █▄▄▀ ▀▄▄▀ ▀▄▀ █▄▄▀ ▀▄▄▀ █ - ▄▄▄▀ ▄▄▄▀ - - Customizable developer toolbar for Symfony projects -``` - +![img](img/banner.webp) -[![Latest Stable Version](https://poser.pugx.org/marcin-orlowski/symfony-discodevbar/v)](https://packagist.org/packages/marcin-orlowski/symfony-discodevbar) -[![Monthly Downloads](https://poser.pugx.org/marcin-orlowski/symfony-discodevbar/d/monthly)](https://packagist.org/packages/marcin-orlowski/symfony-discodevbar) -[![License](https://poser.pugx.org/marcin-orlowski/symfony-discodevbar/license)](https://packagist.org/packages/marcin-orlowski/symfony-discodevbar) +[![Latest Stable Version](https://poser.pugx.org/marcin-orlowski/disco-toolbar-symfony/v)](https://packagist.org/packages/marcin-orlowski/disco-toolbar-symfony) +[![Monthly Downloads](https://poser.pugx.org/marcin-orlowski/disco-toolbar-symfony/d/monthly)](https://packagist.org/packages/marcin-orlowski/disco-toolbar-symfony) +[![License](https://poser.pugx.org/marcin-orlowski/disco-toolbar-symfony/license)](https://packagist.org/packages/marcin-orlowski/disco-toolbar-symfony) # Welcome! -**DiscoDevBar** is a developer tool that adds a customizable toolbar/banner to your Symfony application, -providing all-time access to essential development resources right from your browser. Perfect for -streamlining your development workflow by keeping frequently-used tools, admin panels, and services -just one click away. +**DiscoToolbar** is a customizable toolbar for your Symfony application, providing all-time access to +essential resources right from your browser. Perfect for streamlining your workflow by keeping +frequently-used tools, admin panels, and services just one click away. + +> **NOTE:** This package is also available for Laravel framework! +> See [project page](https://github.com/MarcinOrlowski/php-discotoolbar-laravel) for more information! -## What is DiscoDevBar? +## What is DiscoToolbar? -DiscoDevBar creates a persistent banner (typically placed at the top of your layout) that displays +DiscoToolbar creates a persistent banner (typically placed at the top of your layout) that displays during development. It's highly configurable via YAML, allowing you to create custom buttons and links to anything you need: admin panels, database tools, email catchers, API documentation, or -any other development resource. +any other resource. -![img](img/disco-devbar.png) +![img](img/disco-toolbar.webp) ### Perfect for Docker Environments Since configuration is YAML-based, it's incredibly easy to generate dynamically when setting up new -development environments. When using Docker or similar containerization, port numbers often change -between setups - but with DiscoDevBar, you can regenerate the configuration file on each environment +environments. When using Docker or similar containerization, port numbers often change +between setups - but with DiscoToolbar, you can regenerate the configuration file on each environment startup, ensuring all links always point to the correct ports and services. ## Features - **Fully customizable via YAML** - Easy to configure and regenerate for different environments - **Flexible widget system** - Create buttons with Font Awesome icons, emoji, text labels, or any combination -- **Display anything** - Add links to admin panels, database tools, email catchers, API docs, or any development resource +- **Display anything** - Add links to admin panels, database tools, email catchers, API docs, or any resource - **Action buttons** - Direct access to frequently-used tools and services - **Environment-aware** - Only loads in development environment, zero production overhead - **Dynamic configuration** - Perfect for Docker setups where ports change - regenerate config on startup @@ -50,14 +43,14 @@ startup, ensuring all links always point to the correct ports and services. ## Requirements - PHP 8.1 or higher -- Symfony 6.4+ or 7.0+ +- Symfony 6.4+, 7.0+, or 8.0+ ## Installation Install via Composer: ```bash -composer require marcinorlowski/symfony-discodevbar --dev +composer require --dev marcin-orlowski/disco-toolbar-symfony ``` Register the bundle in `config/bundles.php`: @@ -65,7 +58,7 @@ Register the bundle in `config/bundles.php`: ```php return [ // ... other bundles - MarcinOrlowski\DiscoDevBar\DiscoDevBarBundle::class => ['dev' => true], + MarcinOrlowski\DiscoToolbar\DiscoToolbarBundle::class => ['dev' => true], ]; ``` @@ -80,10 +73,10 @@ php bin/console assets:install --symlink Create a configuration file in your project root with widget configuration. The bundle will automatically detect and load the first file found (in order of preference): -- `.disco-devbar.yaml` (recommended) -- `.disco-devbar.yml` +- `.disco.yaml` (recommended) +- `.disco.yml` -Example configuration that produces devbar shown in the screenshot above: +Example configuration that produces toolbar shown in the screenshot above: ```yaml widgets: @@ -121,26 +114,26 @@ widgets: ### Widget Properties -| Property | Type | Required | Description | -|-------------|:--------:|:--------:|--------------------------------------------------------------------------------| -| `type` | `string` | | Widget type: `link` (default) or `close` (dismisses devbar). | -| `icon`* | `string` | | Optional icon to display. Can be Font Awesome class or emoji/text. | -| `icon_type` | `string` | | Icon type: `fa` (Font Awesome, default) or `text` (emoji/plain text). | -| `text`* | `string` | | Optional widget label to display alongside icon. | -| `url` | `string` | * | Link URL to redirect to once widget is clicked. | -| `target` | `string` | | Link target (e.g., `_blank`). Default: no target | -| `title` | `string` | | Tooltip text. If not given, `url` is shown. | -| `expand` | `bool` | | Set to `true` to make widget expand and fill available space. Default `false`. | +| Property | Type | Required | Description | +|-------------|:--------:|:--------:|---------------------------------------------------------------------------------| +| `type` | `string` | | Widget type: `link` (default) or `close` (dismisses toolbar). | +| `icon`* | `string` | | Optional icon to display. Can be Font Awesome class or emoji/text. | +| `icon_type` | `string` | | Icon type: `fa` (Font Awesome, default) or `text` (emoji/plain text). | +| `text`* | `string` | | Optional widget label to display alongside icon. | +| `url` | `string` | * | Link URL to redirect to once widget is clicked. | +| `target` | `string` | | Link target (e.g., `_blank`). Default: no target | +| `title` | `string` | | Tooltip text. If not given, `url` is shown. | +| `expand` | `bool` | | Set to `true` to make widget expand and fill available space. Default `false`. | *) Either `icon` or `text` must be provided or exception will be thrown. ### Font Awesome Icons -DiscoDevBar supports Font Awesome icons for widgets. You have two options for including Font Awesome: +DiscoToolbar supports Font Awesome icons for widgets. You have two options for including Font Awesome: #### Option 1: Automatic Inclusion (Recommended for Quick Setup) -Enable automatic Font Awesome inclusion from CDN in your `.disco-devbar.yaml` configuration file: +Enable automatic Font Awesome inclusion from CDN in your `.disco.yaml` configuration file: ```yaml font_awesome: @@ -166,7 +159,7 @@ your project, use Option 2 instead to avoid version conflicts. #### Option 2: Manual Setup (Recommended if Font Awesome Already Installed) If your application already includes Font Awesome (via NPM, CDN, or other means), simply use Font Awesome icon -classes in your widget configuration. DiscoDevBar will use your existing Font Awesome installation. +classes in your widget configuration. DiscoToolbar will use your existing Font Awesome installation. **Example:** @@ -198,11 +191,11 @@ widgets: ## Usage -Include the devbar template in your base layout: +Include the toolbar template in your base layout: ```twig {% if app.environment == 'dev' %} - {% include '@DiscoDevBar/devbar.html.twig' %} + {% include '@DiscoToolbar/toolbar.html.twig' %} {% endif %} ``` @@ -210,7 +203,7 @@ Include the devbar template in your base layout: ### Background Colors -Customize the breathing stripes background colors in your `.disco-devbar.yaml`: +Customize the breathing stripes background colors in your `.disco.yaml`: ```yaml bg_color_light: '#b71c1c' @@ -220,15 +213,15 @@ bg_color_dark: '#8e0000' ### Custom CSS The bundle includes default styling. To customize, override the CSS after importing bundle assets or -create your own styles targeting `.disco-devbar` classes. +create your own styles targeting `.disco-toolbar` classes. ### Custom Template Override the default template by creating: -`templates/bundles/DiscoDevBarBundle/devbar.html.twig` +`templates/bundles/DiscoToolbarBundle/toolbar.html.twig` ## License -- Written and copyrighted ©2025 by Marcin Orlowski -- DiscoDevBar is open-source software licensed under +- Written and copyrighted ©2025-2026 by Marcin Orlowski +- DiscoToolbar is open-source software licensed under the [MIT license](http://opensource.org/licenses/MIT) diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml index 6f919d7..daa2da5 100644 --- a/Resources/config/services.yaml +++ b/Resources/config/services.yaml @@ -1,15 +1,32 @@ + +######################################################################### + # + # █▀▀▄ ▀ ▀▀█▀▀ ▀█ █ + # █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ ▄▀▀▄ ▄▀▀▄ █ █▀▀▄ ▄▀▀▄ █▄▀ + # █ █ █ ▀▄ █ █ █ █ █ █ █ █ █ █ █ ▄▄█ █ + # █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █ ▀▄▄▀ ▀▄▄▀ ▄█▄ █▄▄▀ ▀▄▄▀ █ + # + ######### Customizable developer toolbar for Symfony projects ######## + # + # @author Marcin Orlowski + # @copyright 2025-2026 Marcin Orlowski + # @license https://opensource.org/license/mit MIT + # @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony + # +######################################################################### + services: _defaults: autowire: true autoconfigure: true - MarcinOrlowski\DiscoDevBar\: + MarcinOrlowski\DiscoToolbar\: resource: '../../src/' exclude: '../../src/{DependencyInjection,Dto}' - MarcinOrlowski\DiscoDevBar\Service\DiscoDevBarService: + MarcinOrlowski\DiscoToolbar\Service\DiscoToolbarService: arguments: $projectDir: '%kernel.project_dir%' - MarcinOrlowski\DiscoDevBar\Twig\DiscoDevBarExtension: + MarcinOrlowski\DiscoToolbar\Twig\DiscoToolbarExtension: tags: ['twig.extension'] diff --git a/Resources/public/devbar.css b/Resources/public/toolbar.css similarity index 80% rename from Resources/public/devbar.css rename to Resources/public/toolbar.css index 245bab0..ba4c472 100644 --- a/Resources/public/devbar.css +++ b/Resources/public/toolbar.css @@ -1,5 +1,5 @@ -/* DiscoDevBar for development environment */ -.disco-devbar { +/* DiscoToolbar - Customizable toolbar for Symfony */ +.disco-toolbar { position: fixed; top: 0; left: 0; @@ -11,7 +11,7 @@ overflow: hidden; } -.disco-devbar::before { +.disco-toolbar::before { content: ''; position: absolute; inset: 0; @@ -37,11 +37,11 @@ } } -.disco-devbar-error { +.disco-toolbar-error { background: #d32f2f; } -.disco-devbar-error::before { +.disco-toolbar-error::before { background: repeating-linear-gradient( 45deg, #d32f2f, @@ -51,7 +51,7 @@ ); } -.disco-devbar-content { +.disco-toolbar-content { position: relative; max-width: 1100px; margin: 0 auto; @@ -65,7 +65,7 @@ } /* DiscoDevBar title - centered */ -.disco-devbar-title { +.disco-toolbar-title { position: absolute; left: 50%; transform: translateX(-50%); @@ -75,7 +75,7 @@ } /* Left container - aligns content to left */ -.disco-devbar-container-left { +.disco-toolbar-container-left { display: flex; align-items: center; white-space: nowrap; @@ -85,13 +85,13 @@ } /* Left container with expand - grows to fill space */ -.disco-devbar-container-left.disco-devbar-container-expand { +.disco-toolbar-container-left.disco-toolbar-container-expand { flex: 1 1 auto; min-width: 0; } /* Right container - aligns content to right */ -.disco-devbar-container-right { +.disco-toolbar-container-right { display: flex; align-items: center; white-space: nowrap; @@ -101,26 +101,26 @@ } /* Right container with expand - grows to fill space */ -.disco-devbar-container-right.disco-devbar-container-expand { +.disco-toolbar-container-right.disco-toolbar-container-expand { flex: 1 1 auto; min-width: 0; } /* Widget wrapper */ -.disco-devbar-widget { +.disco-toolbar-widget { display: inline-flex; align-items: center; flex-shrink: 0; } /* Expandable widget wrapper - grows to fill available space */ -.disco-devbar-widget-expand { +.disco-toolbar-widget-expand { flex: 1 1 0; min-width: 0; } /* DiscoDevBar links */ -.disco-devbar-link { +.disco-toolbar-link { color: white; text-decoration: none; font-weight: bold; @@ -130,56 +130,56 @@ } /* Content wrapper inside link - handles padding and hover */ -.disco-devbar-link-content { +.disco-toolbar-link-content { display: inline-flex; align-items: center; padding: 6px 8px; transition: all 0.2s ease; } -.disco-devbar-link:hover .disco-devbar-link-content { +.disco-toolbar-link:hover .disco-toolbar-link-content { background-color: orange; color: black; text-decoration: underline; } /* DiscoDevBar separators */ -.disco-devbar-separator { +.disco-toolbar-separator { margin: 0 2px; } /* Icon spacing in links */ -.disco-devbar-link-content i { +.disco-toolbar-link-content i { margin-right: 4px; } /* Plain text in devbar (non-link) */ -.disco-devbar-text { +.disco-toolbar-text { color: white; font-weight: normal; padding: 6px 8px; } /* Adjust top navigation when DiscoDevBar is present (public pages only) */ -body:has(.disco-devbar):not(:has(.wrapper)) .top-nav { +body:has(.disco-toolbar):not(:has(.wrapper)) .top-nav { top: 40px; transition: top 0.3s ease; } /* Adjust content padding when DiscoDevBar is present (public pages only - exclude EasyAdmin) */ -body:has(.disco-devbar):not(:has(.wrapper)) .content { +body:has(.disco-toolbar):not(:has(.wrapper)) .content { padding-top: calc(var(--header-height) + 40px + 40px); /* header height + DiscoDevBar height + original padding */ } /* Adjust content padding on mobile when DiscoDevBar is present (public pages only - exclude EasyAdmin) */ @media (max-width: 768px) { - body:has(.disco-devbar):not(:has(.wrapper)) .content { + body:has(.disco-toolbar):not(:has(.wrapper)) .content { padding-top: calc(var(--header-height-mobile) + 40px + 40px); } } /* Push down entire EasyAdmin layout to avoid overlap with DiscoDevBar */ -body:has(.disco-devbar) .wrapper { +body:has(.disco-toolbar) .wrapper { padding-top: 40px; } @@ -189,14 +189,14 @@ body:has(.disco-devbar) .wrapper { } /* Fix flash messages appearing under DiscoDevBar in EasyAdmin */ -body:has(.disco-devbar) #flash-messages { +body:has(.disco-toolbar) #flash-messages { position: relative; z-index: 1002; /* Higher than DiscoDevBar (1001) */ margin-top: 0; /* Reset any default margin */ } /* Special handling for login page where flash messages use absolute positioning */ -body.page-login:has(.disco-devbar) #flash-messages { +body.page-login:has(.disco-toolbar) #flash-messages { top: 40px; /* Height of DiscoDevBar */ } diff --git a/Resources/views/devbar.html.twig b/Resources/views/devbar.html.twig deleted file mode 100644 index b8b4625..0000000 --- a/Resources/views/devbar.html.twig +++ /dev/null @@ -1,94 +0,0 @@ -{# DiscoDevBar Template #} -{# This template displays DiscoDevBar with links to various tools and information #} -{# Show with `{% if app.environment == 'dev' %}` condition #} - -{% set banner_data = debug_banner_data() %} - - - - - diff --git a/Resources/views/toolbar.html.twig b/Resources/views/toolbar.html.twig new file mode 100644 index 0000000..678ca9f --- /dev/null +++ b/Resources/views/toolbar.html.twig @@ -0,0 +1,94 @@ +{# DiscoToolbar Template #} +{# This template displays DiscoToolbar with links to various tools and information #} +{# Show with `{% if app.environment == 'dev' %}` condition #} + +{% set toolbar_data = disco_toolbar_data() %} + + + + +
+
+ {% if toolbar_data.hasError %} +
+ + + Disco Toolbar + + + · + + v{{ toolbar_data.version ?? 'N/A' }} * {{ toolbar_data.errorMessage }} + +
+ {% else %} +
+ {% for widget in toolbar_data.left %} + {% if not loop.first %} + · + {% endif %} + {% if widget.type == 'close' %} + + + + + + {% else %} + + + + {% if widget.icon %} + {% if widget.iconType.value == 'fa' %} + + {% else %} + {{ widget.icon }} + {% endif %} + {% endif %} + {% if widget.text %}{{ widget.text }}{% endif %} + + + + {% endif %} + {% endfor %} +
+
+ {% for widget in toolbar_data.right %} + {% if not loop.first %} + · + {% endif %} + {% if widget.type == 'close' %} + + + + + + {% else %} + + + + {% if widget.icon %} + {% if widget.iconType.value == 'fa' %} + + {% else %} + {{ widget.icon }} + {% endif %} + {% endif %} + {% if widget.text %}{{ widget.text }}{% endif %} + + + + {% endif %} + {% endfor %} +
+ {% endif %} +
+
diff --git a/composer.json b/composer.json index 8e379bf..2c92fbe 100644 --- a/composer.json +++ b/composer.json @@ -1,15 +1,18 @@ { - "name": "marcin-orlowski/symfony-discodevbar", - "description": "Development toolbar/banner for Symfony project", + "name": "marcin-orlowski/disco-toolbar-symfony", + "description": "Customizable toolbar for Symfony projects", "type": "symfony-bundle", - "version": "1.6.0", + "version": "2.0.0", "license": "MIT", + "provide": { + "marcin-orlowski/discotoolbar-symfony": "self.version", + "marcin-orlowski/discotoolbar": "self.version" + }, "keywords": [ "symfony", - "devbar", - "debug", "toolbar", - "worktree", + "disco", + "navigation", "development" ], "authors": [ @@ -21,20 +24,19 @@ "minimum-stability": "stable", "require": { "php": ">=8.1", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/yaml": "^6.4|^7.0", - "symfony/twig-bundle": "^6.4|^7.0" + "symfony/dependency-injection": "^6.4|^7.0|^8.0", + "symfony/http-kernel": "^6.4|^7.0|^8.0", + "symfony/yaml": "^6.4|^7.0|^8.0", + "symfony/twig-bundle": "^6.4|^7.0|^8.0" }, "require-dev": { "phpstan/phpstan": "^2.0", "phpstan/phpstan-symfony": "^2.0", - "phpunit/phpunit": "^10.5", "squizlabs/php_codesniffer": "^3.13" }, "autoload": { "psr-4": { - "MarcinOrlowski\\DiscoDevBar\\": "src/" + "MarcinOrlowski\\DiscoToolbar\\": "src/" } }, "scripts": { @@ -65,13 +67,6 @@ "lint:md": [ "Composer\\Config::disableProcessTimeout", "markdownlint --config .markdownlint.yaml --ignore vendor --ignore node_modules **/*.md" - ], - "test": [ - "@composer test:unit" - ], - "test:unit": [ - "Composer\\Config::disableProcessTimeout", - "@php vendor/bin/phpunit --group unit --display-warnings --display-deprecations --display-notices --display-errors --display-phpunit-deprecations" ] } } diff --git a/img/banner.webp b/img/banner.webp new file mode 100644 index 0000000..33e0549 Binary files /dev/null and b/img/banner.webp differ diff --git a/img/disco-devbar.png b/img/disco-devbar.png deleted file mode 100644 index c0f9aec..0000000 Binary files a/img/disco-devbar.png and /dev/null differ diff --git a/img/disco-toolbar.webp b/img/disco-toolbar.webp new file mode 100644 index 0000000..20ea873 Binary files /dev/null and b/img/disco-toolbar.webp differ diff --git a/package-lock.json b/package-lock.json index 7329ee3..d5d1ee4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "symfony-discodevbar", + "name": "disco-toolbar-symfony", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "symfony-discodevbar", + "name": "disco-toolbar-symfony", "version": "1.0.0", "devDependencies": { "markdownlint-cli2": "^0.8.1", diff --git a/package.json b/package.json index ab0de4d..bb17a3c 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "symfony-discodevbar", + "name": "disco-toolbar-symfony", "version": "1.0.0", "private": true, - "description": "Development toolbar/banner for Symfony projects", + "description": "Customizable toolbar for Symfony projects", "scripts": { "lint:css": "stylelint \"Resources/public/**/*.css\"", "lint:css:fix": "stylelint \"Resources/public/**/*.css\" --fix", diff --git a/phpstan.neon b/phpstan.neon index 593cb04..c9463b5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,11 +1,19 @@ -################################################################################## -# -# Disco DevBar -# -# @author Marcin Orlowski -# @copyright 2025 Marcin Orlowski -# -################################################################################## +######################################################################### + # + # █▀▀▄ ▀ ▀▀█▀▀ ▀█ █ + # █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ ▄▀▀▄ ▄▀▀▄ █ █▀▀▄ ▄▀▀▄ █▄▀ + # █ █ █ ▀▄ █ █ █ █ █ █ █ █ █ █ █ ▄▄█ █ + # █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █ ▀▄▄▀ ▀▄▄▀ ▄█▄ █▄▄▀ ▀▄▄▀ █ + # + ######### Customizable developer toolbar for Symfony projects ######## + # + # @author Marcin Orlowski + # @copyright 2025-2026 Marcin Orlowski + # @license https://opensource.org/license/mit MIT + # @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony + # +######################################################################### + includes: - vendor/phpstan/phpstan-symfony/extension.neon diff --git a/src/DependencyInjection/DiscoDevBarExtension.php b/src/DependencyInjection/DiscoDevBarExtension.php deleted file mode 100644 index 8788683..0000000 --- a/src/DependencyInjection/DiscoDevBarExtension.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @copyright 2025 Marcin Orlowski - * @license https://opensource.org/license/mit MIT - * @link https://github.com/MarcinOrlowski/php-symfony-discodevbar - * - * ########################################################################## */ - -namespace MarcinOrlowski\DiscoDevBar\DependencyInjection; - -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Extension\Extension; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; - -/** - * DiscoDevBar Extension - * - * Loads bundle services configuration - */ -class DiscoDevBarExtension extends Extension -{ - public function load(array $configs, ContainerBuilder $container): void - { - $loader = new YamlFileLoader( - $container, - new FileLocator(\dirname(__DIR__) . '/../Resources/config') - ); - - $loader->load('services.yaml'); - } -} diff --git a/src/DependencyInjection/DiscoToolbarExtension.php b/src/DependencyInjection/DiscoToolbarExtension.php new file mode 100644 index 0000000..3ca958a --- /dev/null +++ b/src/DependencyInjection/DiscoToolbarExtension.php @@ -0,0 +1,44 @@ + + * @copyright 2025-2026 Marcin Orlowski + * @license https://opensource.org/license/mit MIT + * @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony + * + * ******************************************************************* */ + +namespace MarcinOrlowski\DiscoToolbar\DependencyInjection; + +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + +/** + * DiscoToolbar Extension + * + * Loads bundle services configuration + */ +class DiscoToolbarExtension extends Extension +{ + public function load(array $configs, ContainerBuilder $container): void + { + $loader = new YamlFileLoader( + $container, + new FileLocator(\dirname(__DIR__) . '/../Resources/config') + ); + + $loader->load('services.yaml'); + } +} diff --git a/src/DiscoDevBarBundle.php b/src/DiscoDevBarBundle.php deleted file mode 100644 index 202b33c..0000000 --- a/src/DiscoDevBarBundle.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @copyright 2025 Marcin Orlowski - * @license https://opensource.org/license/mit MIT - * @link https://github.com/MarcinOrlowski/php-symfony-discodevbar - * - * ########################################################################## */ - -namespace MarcinOrlowski\DiscoDevBar; - -use Symfony\Component\HttpKernel\Bundle\Bundle; - -/** - * DiscoDevBar Bundle - * - * Provides development toolbar/banner for worktree-based Symfony projects - */ -class DiscoDevBarBundle extends Bundle -{ - public function getPath(): string - { - return \dirname(__DIR__); - } -} diff --git a/src/DiscoToolbarBundle.php b/src/DiscoToolbarBundle.php new file mode 100644 index 0000000..5c99c3f --- /dev/null +++ b/src/DiscoToolbarBundle.php @@ -0,0 +1,36 @@ + + * @copyright 2025-2026 Marcin Orlowski + * @license https://opensource.org/license/mit MIT + * @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony + * + * ******************************************************************* */ + +namespace MarcinOrlowski\DiscoToolbar; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +/** + * DiscoToolbar Bundle + * + * Provides customizable toolbar for Symfony projects + */ +class DiscoToolbarBundle extends Bundle +{ + public function getPath(): string + { + return \dirname(__DIR__); + } +} diff --git a/src/Dto/DiscoDevBarData.php b/src/Dto/DiscoToolbarData.php similarity index 64% rename from src/Dto/DiscoDevBarData.php rename to src/Dto/DiscoToolbarData.php index 23dc177..f865808 100644 --- a/src/Dto/DiscoDevBarData.php +++ b/src/Dto/DiscoToolbarData.php @@ -2,25 +2,25 @@ declare(strict_types=1); -/* ############################################################################# +/* ********************************************************************** * - * █▀▀▄ ▀ █▀▀▄ █▀▀▄ - * █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ █ ▄▀▀▄ █ █ █▀▀▄ ▄▀▀▄ █▄▀ - * █ █ █ ▀▄ █ █ █ █ █ █▀▀ █ █ █ █ ▄▄█ █ - * █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █▄▄▀ ▀▄▄▀ ▀▄▀ █▄▄▀ ▀▄▄▀ █ + * █▀▀▄ ▀ ▀▀█▀▀ ▀█ █ + * █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ ▄▀▀▄ ▄▀▀▄ █ █▀▀▄ ▄▀▀▄ █▄▀ + * █ █ █ ▀▄ █ █ █ █ █ █ █ █ █ █ █ ▄▄█ █ + * █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █ ▀▄▄▀ ▀▄▄▀ ▄█▄ █▄▄▀ ▀▄▄▀ █ * - * Customizable developer toolbar for Symfony projects + * ******* Customizable developer toolbar for Symfony projects ******** * * @author Marcin Orlowski - * @copyright 2025 Marcin Orlowski + * @copyright 2025-2026 Marcin Orlowski * @license https://opensource.org/license/mit MIT - * @link https://github.com/MarcinOrlowski/php-symfony-discodevbar + * @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony * - * ########################################################################## */ + * ******************************************************************* */ -namespace MarcinOrlowski\DiscoDevBar\Dto; +namespace MarcinOrlowski\DiscoToolbar\Dto; -class DiscoDevBarData +class DiscoToolbarData { /** * @param array $left diff --git a/src/Dto/IconType.php b/src/Dto/IconType.php index bc7fc45..4048dd1 100644 --- a/src/Dto/IconType.php +++ b/src/Dto/IconType.php @@ -2,23 +2,23 @@ declare(strict_types=1); -/* ############################################################################# +/* ********************************************************************** * - * █▀▀▄ ▀ █▀▀▄ █▀▀▄ - * █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ █ ▄▀▀▄ █ █ █▀▀▄ ▄▀▀▄ █▄▀ - * █ █ █ ▀▄ █ █ █ █ █ █▀▀ █ █ █ █ ▄▄█ █ - * █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █▄▄▀ ▀▄▄▀ ▀▄▀ █▄▄▀ ▀▄▄▀ █ + * █▀▀▄ ▀ ▀▀█▀▀ ▀█ █ + * █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ ▄▀▀▄ ▄▀▀▄ █ █▀▀▄ ▄▀▀▄ █▄▀ + * █ █ █ ▀▄ █ █ █ █ █ █ █ █ █ █ █ ▄▄█ █ + * █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █ ▀▄▄▀ ▀▄▄▀ ▄█▄ █▄▄▀ ▀▄▄▀ █ * - * Customizable developer toolbar for Symfony projects + * ******* Customizable developer toolbar for Symfony projects ******** * * @author Marcin Orlowski - * @copyright 2025 Marcin Orlowski + * @copyright 2025-2026 Marcin Orlowski * @license https://opensource.org/license/mit MIT - * @link https://github.com/MarcinOrlowski/php-symfony-discodevbar + * @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony * - * ########################################################################## */ + * ******************************************************************* */ -namespace MarcinOrlowski\DiscoDevBar\Dto; +namespace MarcinOrlowski\DiscoToolbar\Dto; enum IconType: string { diff --git a/src/Dto/Widget.php b/src/Dto/Widget.php index 8172337..5dab8a1 100644 --- a/src/Dto/Widget.php +++ b/src/Dto/Widget.php @@ -2,23 +2,23 @@ declare(strict_types=1); -/* ############################################################################# +/* ********************************************************************** * - * █▀▀▄ ▀ █▀▀▄ █▀▀▄ - * █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ █ ▄▀▀▄ █ █ █▀▀▄ ▄▀▀▄ █▄▀ - * █ █ █ ▀▄ █ █ █ █ █ █▀▀ █ █ █ █ ▄▄█ █ - * █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █▄▄▀ ▀▄▄▀ ▀▄▀ █▄▄▀ ▀▄▄▀ █ + * █▀▀▄ ▀ ▀▀█▀▀ ▀█ █ + * █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ ▄▀▀▄ ▄▀▀▄ █ █▀▀▄ ▄▀▀▄ █▄▀ + * █ █ █ ▀▄ █ █ █ █ █ █ █ █ █ █ █ ▄▄█ █ + * █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █ ▀▄▄▀ ▀▄▄▀ ▄█▄ █▄▄▀ ▀▄▄▀ █ * - * Customizable developer toolbar for Symfony projects + * ******* Customizable developer toolbar for Symfony projects ******** * * @author Marcin Orlowski - * @copyright 2025 Marcin Orlowski + * @copyright 2025-2026 Marcin Orlowski * @license https://opensource.org/license/mit MIT - * @link https://github.com/MarcinOrlowski/php-symfony-discodevbar + * @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony * - * ########################################################################## */ + * ******************************************************************* */ -namespace MarcinOrlowski\DiscoDevBar\Dto; +namespace MarcinOrlowski\DiscoToolbar\Dto; class Widget { diff --git a/src/Listener/ExceptionListener.php b/src/Listener/ExceptionListener.php index 4086050..3dad171 100644 --- a/src/Listener/ExceptionListener.php +++ b/src/Listener/ExceptionListener.php @@ -2,7 +2,23 @@ declare(strict_types=1); -namespace MarcinOrlowski\DiscoDevBar\Listener; +/* ********************************************************************** + * + * █▀▀▄ ▀ ▀▀█▀▀ ▀█ █ + * █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ ▄▀▀▄ ▄▀▀▄ █ █▀▀▄ ▄▀▀▄ █▄▀ + * █ █ █ ▀▄ █ █ █ █ █ █ █ █ █ █ █ ▄▄█ █ + * █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █ ▀▄▄▀ ▀▄▄▀ ▄█▄ █▄▄▀ ▀▄▄▀ █ + * + * ******* Customizable developer toolbar for Symfony projects ******** + * + * @author Marcin Orlowski + * @copyright 2025-2026 Marcin Orlowski + * @license https://opensource.org/license/mit MIT + * @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony + * + * ******************************************************************* */ + +namespace MarcinOrlowski\DiscoToolbar\Listener; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; use Symfony\Component\HttpKernel\Event\ResponseEvent; @@ -11,10 +27,10 @@ use Twig\Environment; /** - * Injects DiscoDevBar into Symfony's exception debug pages in dev environment. + * Injects DiscoToolbar into Symfony's exception debug pages in dev environment. * * The exception debug pages are standalone HTML pages that don't use Twig templates, - * so we need to inject the devbar via response modification. + * so we need to inject the toolbar via response modification. */ #[AsEventListener(event: KernelEvents::RESPONSE, priority: -100)] class ExceptionListener @@ -51,31 +67,31 @@ public function onKernelResponse(ResponseEvent $event): void return; } - // Don't inject if devbar is already present (shouldn't happen, but be safe) - if (str_contains($content, 'disco-devbar')) { + // Don't inject if toolbar is already present (shouldn't happen, but be safe) + if (str_contains($content, 'disco-toolbar')) { return; } try { - $devbarHtml = $this->twig->render('@DiscoDevBar/devbar.html.twig'); + $toolbarHtml = $this->twig->render('@DiscoToolbar/toolbar.html.twig'); } catch (\Throwable) { // If rendering fails, don't break the exception page return; } // Extract tags and inject them into - preg_match_all('/]*>/i', $devbarHtml, $linkMatches); + preg_match_all('/]*>/i', $toolbarHtml, $linkMatches); $links = implode("\n", $linkMatches[0]); - $devbarDiv = preg_replace('/]*>\s*/i', '', $devbarHtml); + $toolbarDiv = preg_replace('/]*>\s*/i', '', $toolbarHtml); // Inject links and extra styling into $extraStyle = ''; $content = str_replace('', $links . $extraStyle . '', $content); - // Inject devbar div after tag + // Inject toolbar div after tag $content = preg_replace( '/(]*>)/i', - '$1' . $devbarDiv, + '$1' . $toolbarDiv, $content, 1 ); diff --git a/src/Service/DiscoDevBarService.php b/src/Service/DiscoToolbarService.php similarity index 79% rename from src/Service/DiscoDevBarService.php rename to src/Service/DiscoToolbarService.php index f0113d3..e96cef6 100644 --- a/src/Service/DiscoDevBarService.php +++ b/src/Service/DiscoToolbarService.php @@ -2,38 +2,37 @@ declare(strict_types=1); -/* ############################################################################# +/* ********************************************************************** * - * █▀▀▄ ▀ █▀▀▄ █▀▀▄ - * █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ █ ▄▀▀▄ █ █ █▀▀▄ ▄▀▀▄ █▄▀ - * █ █ █ ▀▄ █ █ █ █ █ █▀▀ █ █ █ █ ▄▄█ █ - * █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █▄▄▀ ▀▄▄▀ ▀▄▀ █▄▄▀ ▀▄▄▀ █ + * █▀▀▄ ▀ ▀▀█▀▀ ▀█ █ + * █ █ ▀█ ▄▀▀▄ ▄▀▀▄ ▄▀▀▄ █ ▄▀▀▄ ▄▀▀▄ █ █▀▀▄ ▄▀▀▄ █▄▀ + * █ █ █ ▀▄ █ █ █ █ █ █ █ █ █ █ █ ▄▄█ █ + * █▄▄▀ ▄█▄ ▀▄▄▀ ▀▄▄▀ ▀▄▄▀ █ ▀▄▄▀ ▀▄▄▀ ▄█▄ █▄▄▀ ▀▄▄▀ █ * - * Customizable developer toolbar for Symfony projects + * ******* Customizable developer toolbar for Symfony projects ******** * * @author Marcin Orlowski - * @copyright 2025 Marcin Orlowski + * @copyright 2025-2026 Marcin Orlowski * @license https://opensource.org/license/mit MIT - * @link https://github.com/MarcinOrlowski/php-symfony-discodevbar + * @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony * - * ########################################################################## */ + * ******************************************************************* */ -namespace MarcinOrlowski\DiscoDevBar\Service; +namespace MarcinOrlowski\DiscoToolbar\Service; use Composer\InstalledVersions; -use MarcinOrlowski\DiscoDevBar\Dto\DiscoDevBarData; -use MarcinOrlowski\DiscoDevBar\Dto\Widget; +use MarcinOrlowski\DiscoToolbar\Dto\DiscoToolbarData; +use MarcinOrlowski\DiscoToolbar\Dto\Widget; use Symfony\Component\Yaml\Yaml; -class DiscoDevBarService +class DiscoToolbarService { /** * List of supported config filenames (in order of preference) */ private const CONFIG_FILES = [ - '.disco-devbar.yaml', - '.disco-devbar.yml', - '.debug-banner.yaml', // Legacy, kept for backward compatibility + '.disco.yaml', + '.disco.yml', ]; /** @@ -52,7 +51,7 @@ public function __construct( ) { } - public function getDiscoDevBarData(): DiscoDevBarData + public function getDiscoToolbarData(): DiscoToolbarData { $configPath = $this->findConfigFile(); $version = $this->getVersion(); @@ -60,7 +59,7 @@ public function getDiscoDevBarData(): DiscoDevBarData // Default: show error message when no config found if ($configPath === null) { $errorMessage = 'Config file not found: ' . self::CONFIG_FILES[0]; - return new DiscoDevBarData( + return new DiscoToolbarData( left: [], right: [], leftExpand: false, @@ -110,7 +109,7 @@ public function getDiscoDevBarData(): DiscoDevBarData $bgColorLight = $config['bg_color_light'] ?? self::DEFAULT_BG_COLOR_LIGHT; $bgColorDark = $config['bg_color_dark'] ?? self::DEFAULT_BG_COLOR_DARK; - return new DiscoDevBarData( + return new DiscoToolbarData( left: $leftWidgets, right: $rightWidgets, leftExpand: $this->hasExpandingWidget($leftWidgets), @@ -182,11 +181,12 @@ function ($widgetData): Widget { */ private function getVersion(): string { + $version = null; try { - $version = InstalledVersions::getVersion('marcin-orlowski/symfony-discodevbar'); - return $version ?? 'dev'; - } catch (\Exception $e) { - return 'dev'; + $version = InstalledVersions::getVersion('marcin-orlowski/disco-toolbar-symfony'); + } catch (\Exception) { + // do nothing } + return $version ?? 'dev'; } } diff --git a/src/Twig/DiscoDevBarExtension.php b/src/Twig/DiscoDevBarExtension.php deleted file mode 100644 index 8389fd7..0000000 --- a/src/Twig/DiscoDevBarExtension.php +++ /dev/null @@ -1,59 +0,0 @@ - - * @copyright 2025 Marcin Orlowski - * @license https://opensource.org/license/mit MIT - * @link https://github.com/MarcinOrlowski/php-symfony-discodevbar - * - * ########################################################################## */ - -namespace MarcinOrlowski\DiscoDevBar\Twig; - -use MarcinOrlowski\DiscoDevBar\Service\DiscoDevBarService; -use Twig\Extension\AbstractExtension; -use Twig\TwigFunction; - -/** - * Twig extension that provides access to DiscoDevBar data - */ -class DiscoDevBarExtension extends AbstractExtension -{ - public function __construct( - private readonly DiscoDevBarService $discoDevBarService - ) { - } - - /** - * Returns list of functions provided by this extension. - * - * @return array List of functions - */ - public function getFunctions(): array - { - return [ - new TwigFunction('debug_banner_data', [ - $this, - 'getDiscoDevBarData', - ]), - ]; - } - - /** - * Returns DiscoDevBar data for template rendering - */ - public function getDiscoDevBarData(): \MarcinOrlowski\DiscoDevBar\Dto\DiscoDevBarData - { - return $this->discoDevBarService->getDiscoDevBarData(); - } -} diff --git a/src/Twig/DiscoToolbarExtension.php b/src/Twig/DiscoToolbarExtension.php new file mode 100644 index 0000000..f63a1a5 --- /dev/null +++ b/src/Twig/DiscoToolbarExtension.php @@ -0,0 +1,59 @@ + + * @copyright 2025-2026 Marcin Orlowski + * @license https://opensource.org/license/mit MIT + * @link https://github.com/MarcinOrlowski/php-discotoolbar-symfony + * + * ******************************************************************* */ + +namespace MarcinOrlowski\DiscoToolbar\Twig; + +use MarcinOrlowski\DiscoToolbar\Service\DiscoToolbarService; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; + +/** + * Twig extension that provides access to DiscoToolbar data + */ +class DiscoToolbarExtension extends AbstractExtension +{ + public function __construct( + private readonly DiscoToolbarService $discoToolbarService + ) { + } + + /** + * Returns list of functions provided by this extension. + * + * @return array List of functions + */ + public function getFunctions(): array + { + return [ + new TwigFunction('disco_toolbar_data', [ + $this, + 'getDiscoToolbarData', + ]), + ]; + } + + /** + * Returns DiscoToolbar data for template rendering + */ + public function getDiscoToolbarData(): \MarcinOrlowski\DiscoToolbar\Dto\DiscoToolbarData + { + return $this->discoToolbarService->getDiscoToolbarData(); + } +}