Get route for OPTIONS requests

@param string  $service       service id
@param array   $serviceConfig service configuration
@param array   $parameters    service params
@param boolean $useIdPattern  generate route with id param

@return Route
967858
public static function getRouteOptions($service, $serviceConfig, array $parameters = [], $useIdPattern = false)
    {
        if ($useIdPattern) {
            $parameters['id'] = self::ID_PATTERN;
        }
        return self::getRoute($service, 'OPTIONS', 'optionsAction', $serviceConfig, $parameters);
    }
48602
public function map($methods, $pattern, $callable)
	{
		$methods = (array) $methods;
		if (!is_string($pattern)) {
			throw new InvalidArgumentException('Route pattern must be a string');
		}
		
		// Prepend parent group pattern(s)
		if ($this->routeGroups) {
			$pattern = $this->processGroups() . $pattern;
		}
		
		// According to RFC methods are defined in uppercase (See RFC 7231)
		$methods = array_map("strtoupper", $methods);
		
		// Add route
		$route = $this->createRoute($methods, $pattern, $callable);
		$this->routes[$route->getIdentifier()] = $route;
		$this->routeCounter++;
		
		return $route;
	}
1020191
public function getUrl($operationConfig, $operationMetadata, &$inputMap) {

        $queryParams = array();
        
        $action = $operationConfig->getAction();
        $resourcePath = $operationConfig->getResourcePath();
        $queryList = $operationConfig->getQueryParams();
        $resolvedHostUrl = $operationMetadata->getHost();

        //arizzini: we need to validate the host
        $this->validateHost($resolvedHostUrl);
        
        $url = "%s";
        
        //arizzini: we need to apply the environment variable.
        if (strpos($resourcePath, "#env") !== FALSE) {
            $environment = "";
            if (!empty($operationMetadata->getContext())) {
                 $environment = $operationMetadata->getContext();
            } 
            
            $resourcePath = str_replace("#env", $environment, $resourcePath);
            $resourcePath = str_replace("//", "/", $resourcePath);
        }
        
        $tmpUrl = Util::getReplacedPath($this->removeForwardSlashFromTail($resolvedHostUrl).$this->removeForwardSlashFromTail($resourcePath), $inputMap);
        array_push($queryParams, $tmpUrl);
        
        switch ($action) {
            case "read":
            case "delete":
            case "list":
            case "query":
                foreach ($inputMap as $key => $value) {
                    if(!is_array($value)) {
                        $url = $this->appendToQueryString($url, "%s=%s");
                        array_push($queryParams, Util::urlEncode(strval($key)));
                        array_push($queryParams, Util::urlEncode(strval($value)));
                    }
                }
                break;
            default:
                break;
        }
        
        // we need to remove any queryParameters specified in the inputMap and 
        // add them as quertParameters
        switch ($action) {
            case "create":
            case "update":
                $queryMap = Util::subMap($inputMap, $queryList);
                foreach ($queryMap as $key => $value) {
                    if(!is_array($value)) {
                        $url = $this->appendToQueryString($url, "%s=%s");
                        array_push($queryParams, Util::urlEncode(strval($key)));
                        array_push($queryParams, Util::urlEncode(strval($value)));
                    }
                }
                break;
            default:
                break;
        }

        if ($operationMetadata->isJsonNative() == false) {
            $url = $this->appendToQueryString($url, "Format=JSON");
        }
        $url = vsprintf($url, $queryParams);
        
        return $url;
    }
1191219
protected function _getEndpoint($config)
    {
        if (isset($config['service.EndPoint'])) {
            return $config['service.EndPoint'];
        } else if (isset($config['mode'])) {
            switch (strtoupper($config['mode'])) {
                case 'SANDBOX':
                    return BlockCypherConstants::REST_SANDBOX_ENDPOINT;
                    break;
                case 'LIVE':
                    return BlockCypherConstants::REST_LIVE_ENDPOINT;
                    break;
                default:
                    throw new BlockCypherConfigurationException('The mode config parameter must be set to either sandbox/live');
                    break;
            }
        } else {
            // Defaulting to Sandbox
            return BlockCypherConstants::REST_SANDBOX_ENDPOINT;
        }
    }
208920
protected function createControllerWithName(ServiceLocatorInterface $services, $requestedName)
    {
        $options = $this->getOptions($requestedName, $services);

        $controllerType = $options->getControllerType() ?: RestfulController::class;

        return new $controllerType(
            $services->get('DomainServiceManager')->get($requestedName),
            $options
        );
    }
461444
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $routeCollection = new RouteCollection();
        $requestContext  = $serviceLocator->get('RouterRequestContext');
        $routerOptions   = array();

        $logger = $serviceLocator->has('logger') ? $serviceLocator->get('Logger') : null;

        $router = new Router($requestContext, $routeCollection, $routerOptions, $logger);

        // @todo - consider making a base router class, and then have a ModuleRouterFactory to pull module routes
        // @todo - find a way to set routes on this after we instantiate this factory

        // @todo - let you add new routes on demand and call $router->setRouteCollection()
        return $router;
    }
82087
private function getConfig(ServiceLocatorInterface $serviceLocator)
    {
        /* @var $config array */
        $config = $serviceLocator->get('config');
        if (isset($config['phpdi-zf2'])) {
            $config = $config['phpdi-zf2'];
        } else {
            $config = [];
        }

        return $config;
    }
547288
private function getService(string $name, array $params = []): ?IService
    {
        if (array_key_exists($name, $this->servicesInstances)) {
            return $this->servicesInstances[$name];
        }

        $serviceConfig = $this->getServiceConfig($name);
        if ($serviceConfig === null) {
            return null;
        }

        $class = $serviceConfig['class'];
        unset($serviceConfig['class']);
        $serviceConfig = array_merge($serviceConfig, isset($params[0]) && \is_array($params[0]) ? $params[0] : []);

        if (!class_exists($class)) {
            throw new InvalidConfigException(sprintf('Class %s does not exists', $class));
        }

        if (\is_subclass_of($class, BaseModelService::class)
            || \is_subclass_of($class, BaseControllerService::class)
        ) {
            $service = new $class($this, $serviceConfig);
        } else {
            $service = new $class($serviceConfig);
        }

        if (!($service instanceof IService)) {
            throw new InvalidConfigException('Service class must implement `' . IService::class . '`.');
        }

        return $this->servicesInstances[$name] = $service;
    }
350363
public function setRoute(array $methods, string $regexp, $callable): RouteInterface
    {
        return $this
            ->setMethods($methods)
            ->setRegexp($regexp)
            ->setCallback($callable);
    }
1128600
public function get($name, array $params = array())
    {
        if (null === $this->serviceLocator) {
            throw new DomainException('No ServiceLocator defined, use `createServiceWithName` instead of `get`');
        }

        if (self::USE_SL_BEFORE_DI === $this->useServiceLocator && $this->serviceLocator->has($name)) {
            return $this->serviceLocator->get($name);
        }

        try {
            return parent::get($name, $params);
        } catch (ClassNotFoundException $e) {
            if (self::USE_SL_AFTER_DI === $this->useServiceLocator && $this->serviceLocator->has($name)) {
                return $this->serviceLocator->get($name);
            }

            throw new Exception\ServiceNotFoundException(
                sprintf('Service %s was not found in this DI instance', $name),
                null,
                $e
            );
        }
    }
1057965
public function login($service, $config = array())
    {
        $config = new AnConfig($config);

        $config->append(array(
            'html' => $this->icon($service),
            'url' => $this->url($service),
            'attributes' => array(),
        ));

        $html = $this->getService('com:base.template.helper.html');

        $link = $html->link($config->html, $config->url, $config->attributes)
                     ->class('btn btn-'.$service)
                     ->dataTrigger('PostLink')
                     ->title($service);

        return $link;
    }
200897
public function make($alias, $use_singletons=false)
	{
		$alias = strtolower($alias);

		if (! array_key_exists($alias, $this->services))
		{
			throw new \InvalidArgumentException('No Service is registered for alias: '. $alias);
		}

		// The provider could be either a string (namespaced class)
		// or a Closure that returns an instance of the desired class.
		$service = $this->services[$alias];

		if (is_string($service))
		{
			if (! class_exists($service, true))
			{
				throw new \RuntimeException('Unable to locate the Service Provider: '. $this->services[$alias] );
			}

			return $this->inject($service, $use_singletons);
		}

		else if (is_callable($service))
		{
			return $service( $this );
		}

		return null;
	}
1314454
public static function service(string $service)
    {
        if (!array_key_exists($service, self::$available_services)) {
            throw (new ServiceNotFoundException(sprintf(
                '"%s" is not registered as a service.',
                $service
            )))->setServiceName($service);
        }

        $service_class = static::$available_services[$service];

        $config = static::$config['services'][$service] ?? null;

        if (is_null($config)) {
            throw (new ServiceConfigurationNotFoundException(sprintf(
                '"%s" configuration not found.',
                $service
            )))->setServiceName($service);
        }

        return $service_class::configure($config);
    }
225823
public function amOnRoute($routeName, array $params = [])
    {
        if (!$this->di->has('url')) {
            $this->fail('Unable to resolve "url" service.');
        }

        /** @var Url $url */
        $url = $this->di->getShared('url');

        $urlParams = ['for' => $routeName];

        if ($params) {
            $urlParams += $params;
        }

        $this->amOnPage($url->get($urlParams, null, true));
    }
448953
public function getServiceConfiguration($pretty = true)
    {
        ValidationUtility::ensureBoolean('$pretty', $pretty);

        $queryParams = array('pretty' => $pretty);

        return $this->callServiceGetApi(
            null, self::$SERVICE_CONFIGURATION_API_PATH, $queryParams);
    }
1133982
public function createServiceBusService($connectionString)
    {
        $settings = ServiceBusSettings::createFromConnectionString(
            $connectionString
        );

        $httpClient = $this->httpClient();
        $serializer = $this->serializer();
        $serviceBusWrapper = new ServiceBusRestProxy(
            $httpClient,
            $settings->getServiceBusEndpointUri(),
            $serializer
        );

        // Adding headers filter
        $headers = [];

        $headersFilter = new HeadersFilter($headers);
        $serviceBusWrapper = $serviceBusWrapper->withFilter($headersFilter);

        $filter = $settings->getFilter();

        return $serviceBusWrapper->withFilter($filter);
    }
925009
protected function getUrl($route, array $parameters = [], $useRequest = false)
    {
        $router = $this->getContext()->getComponent()->getRouter();

        if ($useRequest) {
            $request = $this->getContext()->getRequest();

            $parameters += $request->getParams(IComponentRequest::ROUTE)->toArray();
        }

        return $router->assemble($route, $parameters) ?: '/';
    }