If you are not in a controller or a module, you can retrieve it by using the
getContext method. The
Context class uses a singleton and this function will return the instance of the
$context = Context::getContext();
In a few words, if you don't know what a singleton is, it's a system that restricts the instantiation of a class to one object. Although this is not mandatory, it's a good idea for you to read some articles, such as the Wikipedia article about it at http://en.wikipedia.org/wiki/Singleton_pattern .