@param string $service
@param string $version

@return Model
@throws \RuntimeException
196503
private function loadModel($service, $version)
    {
        $path = __DIR__ . "/models/{$service}-{$version}.resources.php";
        if (!is_readable($path)) {
            throw new \RuntimeException(
                "The resources model file \"{$path}\" was not found."
            );
        }

        return new Model($service, include $path);
    }
859485
public function setApplication(string $name, string $version = '')
    {
        $this->application = $name.($version ? '/'.$version : '');

        // Reset the cached value
        $this->cachedUserAgent = null;

        return $this;
    }
1056484
public function handle(string $renderer, string $namespace, int $version, string $service, string $method)
    {
        $service = $this->initService($renderer, $namespace, $version, $service, $method);

        return $service->call($method);
    }
498408
public static function toComponents(Version $version)
    {
        return array(
            Parser::MAJOR => $version->getMajor(),
            Parser::MINOR => $version->getMinor(),
            Parser::PATCH => $version->getPatch(),
            Parser::PRE_RELEASE => $version->getPreRelease(),
            Parser::BUILD => $version->getBuild()
        );
    }
778561
public function index($version = null)
    {
        try {
            $request = new ServiceRequest();
            if (!empty($version)) {
                $request->setApiVersion($version);
            }

            Log::info('[REQUEST]', [
                'API Version' => $request->getApiVersion(),
                'Method'      => $request->getMethod(),
                'Service'     => null,
                'Resource'    => null
            ]);

            Log::debug('[REQUEST]', [
                'Parameters' => json_encode($request->getParameters(), JSON_UNESCAPED_SLASHES),
                'API Key'    => $request->getHeader('X_DREAMFACTORY_API_KEY'),
                'JWT'        => $request->getHeader('X_DREAMFACTORY_SESSION_TOKEN')
            ]);

            $limitedFields = ['id', 'name', 'label', 'description', 'type'];
            $fields = \Request::query(ApiOptions::FIELDS);
            if (!empty($fields) && !is_array($fields)) {
                $fields = array_map('trim', explode(',', trim($fields, ',')));
            } elseif (empty($fields)) {
                $fields = $limitedFields;
            }
            $fields = array_intersect($fields, $limitedFields);

            $group = \Request::query('group');
            $type = \Request::query('type');
            if (!empty($group)) {
                $results = ServiceManager::getServiceListByGroup($group, $fields, true);
            } elseif (!empty($type)) {
                $results = ServiceManager::getServiceListByType($type, $fields, true);
            } else {
                $results = ServiceManager::getServiceList($fields, true);
            }
            $services = [];
            foreach ($results as $info) {
                // only allowed services by role here
                if (Session::allowsServiceAccess(array_get($info, 'name'))) {
                    $services[] = $info;
                }
            }

            if (!empty($group)) {
                $results = ServiceManager::getServiceTypes($group);
            } elseif (!empty($type)) {
                $results = [ServiceManager::getServiceType($type)];
            } else {
                $results = ServiceManager::getServiceTypes();
            }
            $types = [];
            foreach ($results as $type) {
                $types[] = [
                    'name'        => $type->getName(),
                    'label'       => $type->getLabel(),
                    'group'       => $type->getGroup(),
                    'description' => $type->getDescription()
                ];
            }
            $response = ResponseFactory::create(['services' => $services, 'service_types' => $types]);
            Log::info('[RESPONSE]', ['Status Code' => $response->getStatusCode(), 'Content-Type' => $response->getContentType()]);

            return ResponseFactory::sendResponse($response, $request);
        } catch (\Exception $e) {
            return ResponseFactory::sendException($e, (isset($request) ? $request : null));
        }
    }
1314022
public function uses(string $service, ?string $version = null): Contracts\Request
    {
        if (\is_null($version) || ! \array_key_exists($version, $this->supportedVersions)) {
            $version = $this->defaultVersion;
        }

        $name = \str_replace('.', '\\', $service);
        $class = \sprintf('%s\%s\%s', $this->getResourceNamespace(), $this->supportedVersions[$version], $name);

        if (! \class_exists($class)) {
            throw new InvalidArgumentException("Resource [{$service}] for version [{$version}] is not available.");
        }

        return $this->via(new $class($this));
    }
1278880
public function version($version = null)
    {
        if (func_num_args() === 0) {
            return $this->_version;
        }
        $this->_version = $version;
        return $this;
    }
1160366
public static function factory($name)
    {
        if (!isset(self::$services[$name])) {
            throw new \RuntimeException("The service [$name] don't register.");
        }

        $service = self::$services[$name];

        if (\is_object($service) && method_exists($service, '__invoke')) {
            return $service();
        }

        return $service;
    }
148377
private function getServiceKey(string $interfaceClass, string $version, string $method): string
    {
        return \sprintf('%s_%s_%s', $interfaceClass, $version, $method);
    }
267835
public function deserialize(string $json): WrapperInterface
    {
        try {
            /** @var WrapperInterface $wrapper */
            $wrapper = $this->jms()->deserialize(
                $json,
                $this->wrapperClass(),
                'json'
            );
        } catch (\Exception $e) {
            throw new \RuntimeException('Error while deserialize "' . $json . '"', 0, $e);
        }

        return $wrapper;
    }
380195
public function put(string $body, string $version = HttpVersion::HTTP_1_1): HttpResponse
    {
        return HttpRequest::create($this->httpUri, $this->headers)
                ->put($body, $this->timeout, $version);
    }
644355
private function getService(string $service)
    {
        if ($this->container instanceof ContainerInterface && $this->container->has($service)) {
            return $this->container->get($service);
        }

        return new $service();
    }
1047805
public function define(string $resource, $versionOrClosure, $closureOrDescription = null, string $description = null)
    {
        $version = $this->version;
        $closure = $closureOrDescription;

        if ($versionOrClosure instanceof \Closure) {
            $version = $this->version;
            $closure = $versionOrClosure;
            $description = $closureOrDescription;
        }

        if (is_numeric($versionOrClosure)) {
            $version = intval($versionOrClosure);
        }

        $this->definitions->push(new ResourceDefinition($version, $resource, $description));

        $resourceDefinition = $this->definition($resource, $version);
        call_user_func_array($closure, [$resourceDefinition]);

        return $this;
    }
616872
public function getImageVersionHash($model, $version) {
		if (empty($this->_imageVersionHashes[$model][$version])) {
			throw new RuntimeException(sprintf('Version "%s" for identifier "%s" does not exist!', $version, $model));
		}

		return $this->_imageVersionHashes[$model][$version];
	}
1256303
public function setRuntimeServices($runtimeServices)
    {
        if (!in_array(gettype($runtimeServices), ['array', 'object'])) {
            throw new \InvalidArgumentException("The service provider list must be an array or an object, given " . gettype($runtimeServices));
        }

        $this->runtimeServices = array_merge($this->runtimeServices, (new Model($runtimeServices))->toArray());
    }
266739
public static function take(AggregateIdInterface $aggregateId, AggregateRootInterface $aggregate, $version)
    {
        $dateTime = \DateTimeImmutable::createFromFormat('U.u', sprintf('%.6F', microtime(true)));

        return new static($aggregateId, $aggregate, $version, $dateTime);
    }
346188
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $service = new RevisionService();

        /** @var RevisionRepositoryInterface $revisionRepository */
        $revisionRepository = $serviceLocator->get('RevisionRepository');
        $service->setRevisionRepository($revisionRepository);

        /** @var DateTimeFactoryInterface $dateTimeFactory */
        $dateTimeFactory = $serviceLocator->get('dateTimeFactory');
        $service->setDateTimeFactory($dateTimeFactory);

        return $service;
    }