I've found a decent answer regarding what is a bag in the context of java: What is meant by the term "bag"?
I did a google search and found that Symfony provides a lot of different "bag" interfaces like this one:
http://api.symfony.com/2.3/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.html
In symfony, is the term bag meant to be interpreted as the same way? Also, how is this different from a "container" or "collection".
A bag (the object's name is ParameterBag
) contains variables or parameters.
A collection contains a list of elements (think of it as an oriented-object version of array
with a lot of useful methods to manipulate the values). The object comes from the Doctrine framework. Symfony also has a concept of Collection and it is explained in its documentation.
A Container contains all kind of objects, it has its own ParameterBag object with its parameters loaded from anything within the parameters
key of your config file.
A Request object ($this->container->get('request')
) also has its own ParameterBag.
Code-wise, the Container's parameter bag and the Request's parameter bag are different and could have different methods but their goals are identical.
A bag
is short for ParameterBag
. A bag is a datatype used to help store data, similar to a collection in java. A bag specifically can access values via key/value as Dagon pointed out, but also has other operations that are useful.
The public operations of a bag are: clear
, add
, all
, get
, set
, has
, remove
, resolve
, resolveValue
, resolveString
, isResolved
, escapeValue
, and unescapedValue
.
If you'd like to see the operations of a bag in detail, you can do so here: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With