Skip to content

Instantly share code, notes, and snippets.

@sebathomson
Last active October 8, 2015 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebathomson/7e95119257802e5e4c54 to your computer and use it in GitHub Desktop.
Save sebathomson/7e95119257802e5e4c54 to your computer and use it in GitHub Desktop.
Obtener 'container' desde cualquier clase [Symfony2]
<?php
/*
* @author Sebastián Thomson <seba.thomson@gmail.com>
* @description
* Esta función puede ser pegada en cualquier clase del proyecto
* Y podrás acceder al Inyector de Dependencias (container)
*
* @example
* <code>
* $container = $this->obtenerContainer();
* </code>
*/
function obtenerContainer()
{
global $kernel;
if ('AppCache' == get_class($kernel)) {
$kernel = $kernel->getKernel();
}
return $kernel->getContainer();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment