Today I need to clear my cache via php on Symfony3, here is a very simple solution.
before, on Symfony2 my code to do this was :
$input = new StringInput(null);
$output = new NullOutput();
$command = new CacheClearCommand();
But when i upgrade to Symfony3 i had an error :
ServiceNotFoundException in Container.php line 266
So i took some minutes to search for a solution and the shortest way i found was :
$dir = $this->get('kernel')->getRootDir().'/..';
exec("php $dir.'/bin/console cache:clear");
But obviously it still posed problems for me, so the solution I propose:
$fs = new Filesystem();
If you have "cleaner" suggestions, do not hesitate to let a comment, I am here to learn.