PHPackages                             nord-ua/vocabulary-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. nord-ua/vocabulary-bundle

ActiveSymfony-bundle

nord-ua/vocabulary-bundle
=========================

Manage vocabulary data like countries and cities easy.

148PHP

Since Mar 26Pushed 12y ago2 watchersCompare

[ Source](https://github.com/ryabenko-pro/VocabularyBundle)[ Packagist](https://packagist.org/packages/nord-ua/vocabulary-bundle)[ RSS](/packages/nord-ua-vocabulary-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

VocabularyBundle
================

[](#vocabularybundle)

This bundle lets you manage and use lists of data like countries, cities, subway station or categories in your project. Also it can be used for i18n. This bundle is using MongoDB as storage and released under MIT license.

All you need to do is simply to create file with vocabulary data. Lets say you want create categories for items in online shop.

Installation
------------

[](#installation)

Composer:

```
"nord-ua/vocabulary-bundle": "2.0.*@dev"

```

How does it works
-----------------

[](#how-does-it-works)

Each value in dictionary consist of 4 field: type, language, search key (somehow it called *slug*) and, actually, value we will looking for. In items you must store slugs of vocabulary values. Later `VocabularyService` will give you actual values for them.

Populate vocabulary
-------------------

[](#populate-vocabulary)

1. Create file @BundleName/Resources/vocabulary/**category**.**en**.txt. Here 'category' is type, 'en' is language. You have create separate file for each type.
2. Fill the file with categories, just one category name per line
3. Run `vocabulary:load` task to populate database

Retrieving all the values
-------------------------

[](#retrieving-all-the-values)

```
$container->get('vocabulary.service')->getRoots('category');

```

Retrieving specific values
--------------------------

[](#retrieving-specific-values)

When you need output human readable values of categories:

```
$container->get('vocabulary.service')->vocabularyValues([/* slugs */], 'category');

```

In template
-----------

[](#in-template)

Use `vocabularyValues` or `vocabularyValue` filters:

```
{% for category in item.categories|vocabularyValues('category') %}
  {{ category }}
{% endfor %}

```

File syntax
===========

[](#file-syntax)

In simple cases file can just contain values for categories, one on a row. Slug will be generated when vocabulary loading. Important feature is that slugs must be and will be equal on all servers (devs and prods). But if you wish set slugs manually, you can put them on beginning of string and separate with colon from value:

```
cat1: Category 1
cat2: category 2
...

```

Params
======

[](#params)

Every vocabulary value can have custom params. E.g. Moscow subway have many stations with same name, but located on different branches ([example](http://metro.yandex.ru/moscow/)). Params are useful to store important data:

```
culture-red: Culture park [branch=red]
culture-ring: Culture park [branch=ring]
cmsm-red: Comsomolskaya [branch=red]
cmsm-ring: Comsomolskaya [branch=ring]

```

Or, to not to repeat same branch param, you can group lines by same params:

```
[branch=red]
culture-red: Culture park
cmsm-red: Comsomolskaya
----

lbrr: Lenin Library

[branch=ring]
culture-ring: Culture park
cmsm-ring: Comsomolskaya

```

Pay attention to line `---` - it clear common params, so **Lenin Library** station will not have any *branch* param.

Trees
=====

[](#trees)

Trees are special case for params: you can group you items by parent, just set `parent` param. E.g. to create categories tree:

// category.en.txt

```
cat1: Category 1
cat2: Category 2

[parent=cat1]
subcat11: Category 1 Subcategory 1
subcat12: Category 1 Subcategory 2
subcat13: Category 1 Subcategory 3
---

[parent=cat1]
subcat11: Category 2 Subcategory 1
subcat22: Category 2 Subcategory 2
subcat33: Category 2 Subcategory 3
---

```

Once again, do not forget `---` line! To retrieve subcategories, simply call

```
$container->get('vocabulary.service')->preloadTree('category');
$container->get('vocabulary.service')->vocabularyValue('cat1', 'category')->getChildren();

```

Precache
========

[](#precache)

By default values are loaded in moment of need. In case of categories you know before you need most of them. So you can precache values by calling `preload` or `preloadTree`. In twig template you can call `{{ vocabulary.preload('country') }}`.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d86caa722d4bd82646318f54f28c7109ecfc447b85d64f53a89b4a2bc0586168?d=identicon)[ryabenko-pro](/maintainers/ryabenko-pro)

---

Top Contributors

[![ryabenko-pro](https://avatars.githubusercontent.com/u/572611?v=4)](https://github.com/ryabenko-pro "ryabenko-pro (20 commits)")

### Embed Badge

![Health badge](/badges/nord-ua-vocabulary-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/nord-ua-vocabulary-bundle/health.svg)](https://phpackages.com/packages/nord-ua-vocabulary-bundle)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
