dongsheng8664 2016-08-30 11:16
浏览 74
已采纳

触发Symfony缓存,资产,样式刷新HTTP

I am working on a Symfony 2 WebApp. The WebApp has been online for about two years, now I would like to update the design. This work should be outsourced to a 3rd party designer.

The designer should be able to work an a live version of the WebApp (= actually running on my server instead of just plain files) so that design changes become visible instantly when refreshing the browser. Thus the designer needs to be able to change/add files directly on the server and to refresh the cache, assets and styles (using SASS + Compass) when ever needed.

At the same time, the designer should not have general access to neither the WebApp code nor the server itself.

Giving access to the design files only is already solved: I have moved all necessary files/folders from the Symfony installation to a separate folder that is accessible by FTP by the designer. Within the Symfony installation the files/folders have been replaced by symlinks (see my question here).

This works great. Only problem is, currently cache/asset/style refresh can currently only be triggered by direct access via SSH:

$ php app/console cache:clear --env=prod --no-debug
$ php app/console assetic:dump --env=prod --no-debug
$ compass compile --output-style compressed --force

Is it somehow possible to expose these commands via HTTP(S)? Of course the designer will be working on a dedicated Symfony installation. Thus changes will not have any effect on the live version.

Problem is, that app/console... is outside the domain root of the WebApp. Of course I could set another domain to point to app/console... But this way all other files and folders below this dir would be accessible as well.

Additionally I am not sure, if compass compile... can be run from HTTP at all. How can this be done?

I am aware, that refreshing cache and assets is not absolutely necessary when using the dev front controller (.../app_dev.php/...) but without able to refresh / re-compile the Compass and SASS files, style changes will not become visible.

So: Can this be done by HTTP? Maybe using some proxy-script that is called by PHP?

  • 写回答

3条回答 默认 最新

  • douhao3562 2016-08-30 12:39
    关注

    To expose these commands via HTTP(S), you can add for your designer a route calling an action in a controller to run the PHP commands, as explained in the doc:

    // src/AppBundle/Controller/CommandController.php
    namespace AppBundle\Controller;
    
    use Symfony\Bundle\FrameworkBundle\Console\Application;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\Console\Input\ArrayInput;
    use Symfony\Component\Console\Output\NullOutput;
    use Symfony\Component\HttpFoundation\Response;
    
    class CommandController extends Controller
    {
        public function refreshAction()
        {
            $kernel = $this->get('kernel');
            $application = new Application($kernel);
            $application->setAutoExit(false);
    
            $input = new ArrayInput(
                array(
                    'command' => 'cache:clear',
                    '--env' => 'prod',
                ),
                array(
                    'command' => 'assetic:dump',
                    '--env' => 'prod',
                ),
            );
    
            // You don't need the output
            $output = new NullOutput();
            $application->run($input, $output);
    
            $content = "Refreshed";
    
            return new Response($content);
        }
    }
    

    For the compass command, you can use assetic:watch as mentioned in giorgio comment.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题