src/AppBundle/Controller/Callback/EndpointController.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace AppBundle\Controller\Callback;

use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Controller\BaseController;
use Symfony\Component\HttpFoundation\JsonResponse;

class EndpointController extends BaseController
{
    private $pool = array();

    public function publishAction(Request $request, $type)
    {
        //为了兼容老的云搜索
        if ($type == 'cloud_search') {
            $callbacks = $this->get('extension.manager')->getCallbacks();
            $biz = $this->getBiz();
            $processerInstance = $biz[$callbacks[$type]];

            return $processerInstance->execute($request);
        } else {
            $ac = $request->query->get('ac');
            if (strpos($ac, '.') === false) {
                throw new \InvalidArgumentException('找不到合法的请求');
            }
            list($processer, $action) = explode('.', $ac);
            $instance = $this->getProcessInstance($type, $processer);

            $data = $instance->$action($request);

            return  new JsonResponse($data);
        }
    }

    private function getProcessInstanceClass($module, $processer)
    {
        $module = ucfirst($module);
        $className = ucfirst($processer);

        $class = __NAMESPACE__."\\{$module}\\{$className}";
        if (!class_exists($class)) {
            throw new \Exception("{$module}-{$className} is not exist!");
        }

        return $class;
    }

    public function getProcessInstance($module, $processer)
    {
        $key = $module.'_'.$processer;
        if (empty($this->pool[$key])) {
            $class = $this->getProcessInstanceClass($module, $processer);
            $instance = new $class($this);

            if ($instance instanceof ContainerAware) {
                $instance->setContainer($this->container);
            }

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。