src/ApiBundle/Api/Resource/ResourceManager.php

(开头部分) 1KB

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

<?php

namespace ApiBundle\Api\Resource;

use ApiBundle\Api\PathMeta;
use Biz\Common\CommonException;
use Symfony\Component\DependencyInjection\ContainerInterface;

class ResourceManager
{
    private $container;

    private $customApiNamespaces = array();

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function create(PathMeta $meta)
    {
        $className = $this->getClassName($meta);
        if (!class_exists($className)) {
            throw CommonException::NOTFOUND_API();
        }

        return new ResourceProxy($this->container->get('api.field.filter.factory'), new $className($this->container, $this->container->get('biz')));
    }

    /**
     * 复写的API优先查找
     *
     * @param PathMeta $meta
     *
     * @return string
     */
    private function getClassName(PathMeta $meta)
    {
        $overrideFindInCustom = $meta->fallbackToCustomApi($this->customApiNamespaces);

        if ($overrideFindInCustom['isFind']) {
            return $overrideFindInCustom['className'];
        } else {
            return $meta->getResourceClassName();
        }
    }

    public function registerApi($namespace)
    {
        $this->customApiNamespaces[] = $namespace;
    }
}

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

AI 解读 AI

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

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