How can I make Symfony2 run certain Commands every time the page loads when it is in the Dev environment?
We use TypeScript and I have build a command which will grab all of my TypeScript and compile it. The only problem is, I have to do this manually every time I upload some new code, which slows things down when debugging (I'm perfectly fine doing it this way for Production though).
I'd like it to call that Command every page load (if some of the files have changed since it last compiled... all logic I'll built out). I just need to know where I should hook in to.
Thanks.
If you are set on using Symfony to compile your TypeScript I would try using an event listener
You could try something like this (untested):
Add a service to the config_dev.yml file so that the listener only runs in the dev environment
# app/config/config_dev.yml
services:
compileTypeScript:
class: myApp\TypescriptBundle\Controller\TypescriptComiler
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 64 }
I'm not exactly sure how priority works, but 64 seemed to hit the sweet spot for me.
Create the class you referenced above and add in your code to compile the TypeScript.
//Class
class TypescriptCompiler extends controller
{
public function onKernelRequest(GetResponseEvent $event)
{
// compile your TypeScript here
}
}
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