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条)

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证