{"id":24230746,"url":"https://github.com/feskol/php-navigation","last_synced_at":"2025-10-13T21:41:16.332Z","repository":{"id":272128255,"uuid":"915486000","full_name":"feskol/php-navigation","owner":"feskol","description":"A simple and effective Navigation to manage active states in navigation structures.","archived":false,"fork":false,"pushed_at":"2025-08-12T05:01:55.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-15T11:53:55.737Z","etag":null,"topics":["navigation","navigation-active-state","navigation-helper","php","php-library","php8","php83","php84"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/feskol/php-navigation","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/feskol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-12T00:49:45.000Z","updated_at":"2025-08-12T05:01:51.000Z","dependencies_parsed_at":"2025-01-12T11:28:35.539Z","dependency_job_id":"123ea55f-0bf5-4741-aef0-3bb0dbbd439b","html_url":"https://github.com/feskol/php-navigation","commit_stats":null,"previous_names":["feskol/php-navigation"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/feskol/php-navigation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feskol%2Fphp-navigation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feskol%2Fphp-navigation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feskol%2Fphp-navigation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feskol%2Fphp-navigation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feskol","download_url":"https://codeload.github.com/feskol/php-navigation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feskol%2Fphp-navigation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017051,"owners_count":26085951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["navigation","navigation-active-state","navigation-helper","php","php-library","php8","php83","php84"],"created_at":"2025-01-14T13:30:05.927Z","updated_at":"2025-10-13T21:41:16.316Z","avatar_url":"https://github.com/feskol.png","language":"PHP","funding_links":["https://buymeacoffee.com/feskol","https://paypal.me/feskol"],"categories":[],"sub_categories":[],"readme":"# PHP-Navigation\n\n[![GitHub Release][releases-badge]][releases-link]\n![GitHub License][license-badge]\n[![Packagist Downloads][packagist-badge]][packagist-link]\n[![codecov](https://codecov.io/gh/feskol/php-navigation/graph/badge.svg?token=ZJ6ZQ8AUGY)](https://codecov.io/gh/feskol/php-navigation)\n\n[releases-badge]: https://img.shields.io/github/v/release/feskol/php-navigation\n[releases-link]: https://github.com/feskol/php-navigation/releases\n[license-badge]: https://img.shields.io/github/license/feskol/php-navigation\n[packagist-badge]: https://img.shields.io/packagist/dt/feskol/php-navigation\n[packagist-link]: https://packagist.org/packages/feskol/php-navigation\n[support-buy-me-coffee]: https://buymeacoffee.com/feskol\n[support-badge-buy-me-coffee]: https://img.shields.io/badge/Buy%20Me%20a%20Coffee-ffdd00?\u0026logo=buy-me-a-coffee\u0026logoColor=black\n[support-paypal-me]: https://paypal.me/feskol\n[support-badge-paypal-me]: https://img.shields.io/badge/PayPal_Me-003087?logo=paypal\u0026logoColor=fff\n\n## Overview\n\nA simple and effective Navigation to manage active states in navigation structures.  \nFor Symfony integration, check out the [NavigationBundle](https://github.com/feskol/NavigationBundle).\n\n## Features\n\n- Automatically tracks a link's active status and makes it easy to check if a parent navigation item has active child\n  links.\n- Easy to set up and integrate into existing projects.\n- Flexible and extensible for complex navigation structures.\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require feskol/php-navigation\n```\n\n## Usage\n\n### Building Your Navigation Structure\n\n```php\nuse Feskol\\Navigation\\Link;\nuse Feskol\\Navigation\\Navigation;\n\n// create links\n$navLink = new Link();\n$navLink-\u003esetTitle('Company')\n    -\u003esetHref('/company');\n    \n$subNavLink = new Link();\n$subNavLink-\u003esetTitle('About us')\n    -\u003esetHref('/company/about-us')\n    -\u003esetIsActive(true);\n    \n// add the $subNavLink as $navLinks Child\n$navLink-\u003eaddChild($subNavLink);\n\n\n// To have all links in one place you can use the provided Navigation class:\n$navigation = new Navigation();\n$navigation-\u003esetTitle('MyNavigation');\n\n// add the created $navLink to the Navigation\n$navigation-\u003eaddLink($navLink);\n```\n\nIterating through Navigation links:\n\n```php\nforeach ($navigation-\u003egetLinks() as $link){\n    echo $link-\u003egetTitle(); // \"Company\"\n    echo $link-\u003ehasActiveChildren(); // \"true\" - because the child is active\n    \n    foreach($link-\u003egetChildren() as $subLink){\n        echo $link-\u003egetTitle(); // \"About us\"\n        echo $link-\u003eisActive(); // \"true\"\n    }\n}\n```\n\n### Common link data\n\nThe `Link` class provides setter and getter methods for the common attributes of an `\u003ca\u003e`-tag.  \nThe most commonly used ones are `href=\"\"` and `target=\"\"`:\n\n```php\nuse Feskol\\Navigation\\Link;\n\n$link = new Link();\n\n// href\n$link-\u003esetHref('/company/about-us');\n$link-\u003egetHref(); // \"/company/about-us\"\n\n// target\n$link-\u003esetTarget(Link::TARGET_BLANK);\n$link-\u003egetTarget(); // \"_blank\"\n```\n\nTo view all available methods for the common link data, check out the\n[`AbsctractHyperLink` class](https://github.com/feskol/php-navigation/blob/main/src/AbstractHyperLink.php).\n\n### Additional Data\n\nThere are often situations where you need additional data for your navigation, such as icons or images.  \nThe best approach is to create your own class (e.g. `MyCustomLink`) that extends the `Link` class:\n\n```php\nuse Feskol\\Navigation\\Link;\n\nclass MyCustomLink extends Link\n{\n    private ?string $icon = null;\n    \n    public function getIcon(): ?string {\n        return $this-\u003eicon;\n    }\n    \n    public function setIcon(?string $icon): static {\n        $this-\u003eicon = $icon;\n        return $this;\n    }\n}\n```\n\nThen use your `MyCustomLink` class instead of the `Link` class:\n\n```php\n$link = new MyCustomLink();\n$link-\u003esetTitle('Company')\n    -\u003esetHref('/company')\n    -\u003esetIcon('bi bi-user'); // For example, using Bootstrap-Icon classes\n```\n\n## Handling translations in your frontend\n\n### Symfony\n\nIn Symfony, you can use the `TranslatableMessage` class to hold translation infos which you can use in your frontend.  \nIn Twig, apply the `|trans` filter to translate the `TranslatableMessage`.\n\nBoth the `Navigation` and `Link` classes accept any object implementing the  `\\Stringable` interface in their\n`setTitle()` methods.\nThis allows you to pass objects like `TranslatableMessage` or custom classes with a `__toString()` method.\n\n#### Example in Symfony\n\n```php\nuse Feskol\\Navigation\\Link;\nuse Feskol\\Navigation\\Navigation;\nuse Symfony\\Component\\Translation\\TranslatableMessage;\n\n$navigation = new Navigation();\n$navigation-\u003esetTitle(new TranslatableMessage('MyNavigation', [], 'navigation'));\n\n$navLink = new Link();\n$navLink-\u003esetTitle(new TranslatableMessage(\n    'Nav-Item for %customerName%',\n    ['%customerName%' =\u003e $customer-\u003egetName()], // Dynamic translation parameters \n    'navigation' // Translation domain\n));\n\n$navigation-\u003eaddLink($navLink);\n```\n\nAnd then in your Twig template:\n\n````twig\n{# @var \\Feskol\\Navigation\\Navigation navigation #}  \n\nTranslated Navigation Title: {{ navigation.title|trans }}  \n\n{% for link in navigation.links %}  \n    Translated Link Title: {{ link.title|trans }}  \n{% endfor %}  \n````\n\n## Contribution Guidelines\n\nWe welcome contributions to this project! To ensure clarity and fairness for all contributors, we require that all\ncontributors sign our **Contributor License Agreement (CLA)**.\n\nBy signing the CLA, you confirm that:\n\n1. You grant us the perpetual, worldwide, non-exclusive, royalty-free, irrevocable right to use, modify, sublicense, and\n   distribute your contribution as part of this project or any other project.\n2. You retain ownership of your contribution, but grant us the rights necessary to use it without restriction.\n3. Your contribution does not violate the rights of any third party.\n\n### How to Sign the CLA\n\nBefore submitting a pull request, please sign the CLA using the following link:  \n[Sign the CLA](https://cla-assistant.io/feskol/php-navigation)\n\nContributions cannot be merged unless the CLA is signed.\n\nThank you for your contributions and for helping us build something great!\n\n## Testing\n\nWe're using phpunit.\n\nRun tests:\n\n```bash\nphp vendor/bin/phpunit\n```\n\n## ❤️ Support This Project\n\nIf you find this project helpful and would like to support my work:\n\n- 🌟 **Star the repository** to show your appreciation.\n- 💸 **Donate via**:\n    - Buy Me a Coffe: [![Buy Me A Coffee][support-badge-buy-me-coffee]][support-buy-me-coffee]\n    - PayPal: [![PayPal][support-badge-paypal-me]][support-paypal-me]\n\nThank you for your support!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeskol%2Fphp-navigation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeskol%2Fphp-navigation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeskol%2Fphp-navigation/lists"}