efficience-it/microphonetest-bundle

麦克风测试

安装: 1

依赖: 0

建议者: 0

安全性: 0

星标: 1

关注者: 0

分支: 0

开放问题: 0

语言:JavaScript

类型:symfony-bundle

v1.0.0 2022-10-25 15:48 UTC

This package is auto-updated.

Last update: 2024-09-26 12:45:55 UTC


README

这个麦克风测试是一个基于Symfony的Bundle。

它由位于里尔的法国公司Efficience IT创建。

安装

步骤1:使用Composer安装Bundle

使用Composer需要efficience-it/microphonetest-bundle

$ composer require efficience-it/microphonetest-bundle

步骤2:配置项目中的麦克风测试

验证以下行是否在bundles.php文件中。如果没有,复制并粘贴。

EfficienceIt\MicrophoneTestBundle\MicrophoneTestBundle::class => ['all' => true]

步骤3:在您的网站上添加麦克风测试

在任何一个控制器中,您都可以调用MicrophoneTestService及其displayMicrophoneTest函数。

以下是一个控制器的示例,其中包含了一个包含Bundle的路由

class HomeController extends AbstractController
{    
    /**
     * @Route("/home", name="app_home")
     */
    public function index(MicrophoneTestService $microphoneTestService): Response
    {
        // Replace 'home/index.html.twig' with the name of your template
        return $this->render('home/index.html.twig', [
            'microphone' => $microphoneTestService->displayMicrophoneTest()
        ]);
    }
}
}

要将麦克风测试显示在页面上,只需在模板文件中包含以下内容

{% extends 'base.html.twig' %}

{% block title %}Hello HomeController!{% endblock %}

{% block body %}
    {% include microphone %}
{% endblock %}

访问您的路由(在这个例子中为localhost/home),麦克风测试应该会出现!

如何检索结果?

创建一个新的控制器(例如ResultsController),并复制/粘贴以下代码

/* DON'T ADD A @Route ANNOTATION */
class ResultsController extends AbstractController
{    
    /* DON'T CHANGE THIS ROUTE ! */
    /**
     * @Route("/microphone-results", name="microphone_results", methods={"POST"})
     */
    public function microphoneResults(Request $request): Response
    {
        if (!$request->isXmlHttpRequest()) {
            throw new AccessDeniedException();
        }

        $requestContent = json_decode($request->getContent(), true);
        dump($requestContent);

        return new JsonResponse($requestContent);
    }
}

使用这个路由(通过AJAX调用),您可以检索麦克风测试结果,并对其进行任何操作!