Get an API context object

@param string        $apiContext API context (leads, forms, etc)
@param AuthInterface $auth       API Auth object
@param string        $baseUrl    Base URL for API endpoints

@return Api\Api
@throws ContextNotFoundException
499087
public function newApi($apiContext, AuthInterface $auth, $baseUrl = '')
    {
        $apiContext = ucfirst($apiContext);

        $class = 'Mautic\\Api\\'.$apiContext;

        if (!class_exists($class)) {
            throw new ContextNotFoundException("A context of '$apiContext' was not found.");
        }

        return new $class($auth, $baseUrl);
    }
1167795
protected function _actionGet(AnCommandContext $context)
    {
        $this->setView('searches');

        if ($this->actor) {
            $this->getToolbar('actorbar')->setTitle($this->actor->name);
            $this->getService()->set('com:search.owner', $this->actor);
        }

        $this->_state
             ->insert('term')
             ->insert('scope')
             ->insert('search_comments')
             ->insert('search_nearby')
             ->insert('search_range')
             ->insert('search_leaders');

        $this->getService('anahita:language')->load('com_actors');

        $this->keywords = array_filter(explode(' ', $this->term));

        $this->scopes = $this->getService('com:components.domain.entityset.scope');

        $this->current_scope = $this->scopes->find($this->scope);

        $query = $this->getService('com:search.domain.query.node')
                      ->searchTerm($this->term)
                      ->limit($this->limit, $this->start);

        if ($this->actor) {
           $query->ownerContext($this->actor);
        }

        if ($this->search_comments) {
            $query->searchComments($this->search_comments);
        }

        if ($this->search_nearby && ($lnglat = $this->_geocoder->geocode($this->search_nearby))) {
            $query->searchNearby($lnglat);
            $query->searchRange($this->search_range);
        }

        if ($this->current_scope) {
            $query->scope($this->current_scope);
        }

        if ($this->sort == 'recent') {
            $query->order('node.created_on', 'DESC');
        } elseif ($this->search_nearby && $this->sort == 'distance' ) {
            $query->order('distance', 'ASC');
        } else {
            $query->orderByRelevance();
        }

        //print str_replace('#_', 'jos', $query);

        $entities = $query->toEntitySet();

        $this->_state->setList($entities);

        parent::_actionGet($context);
    }
135857
public function getAnnouncementFromID($mid, $apiServiceFilterContext = null)
    {
        foreach ($this->getRootAssociationIDs() as $key => $rootAssociationID) {
            try {
                $result = $this->getAnnouncementFromAssociation($rootAssociationID, $mid, $apiServiceFilterContext);
                if (isset($result)) {
                    return $result;
                }
            } catch (ContextException $e) {
                if ($key === count($this->getRootAssociationIDs()) - 1) {
                    throw $e;
                }
            }
        }

        return null;
    }
737102
public function fetchRequester(AnCommandContext $context)
    {
        $data = $context->data;

        if ($this->getItem()) {
            $this->getState()
                 ->requester = $this->getItem()
                                    ->requesters
                                    ->fetch($data->requester);
        }
    }
547273
def _authn_context_decl(decl, authn_auth=None):
    
    return factory(saml.AuthnContext,
                   authn_context_decl=decl,
                   authenticating_authority=factory(
                       saml.AuthenticatingAuthority, text=authn_auth))
283104
private function prepareApiResponse(
        ResponseContextAbstract $responseContext,
        string $apiClassMethod
    ): ApiResponseInterface {
        $prepareApiResponse = sprintf("prepare%sResponse", ucfirst($apiClassMethod));

        $this->assertMethodExists($prepareApiResponse);

        $apiResponse = $this->{$prepareApiResponse}($responseContext);

        return $apiResponse;
    }
712582
protected function getFromStreamContext($url, $context)
    {

        $level = error_reporting(0);
        $body = file_get_contents($url, 0, $context);

        error_reporting($level);

        if ($body === false) {
            $error = error_get_last();
            $message = isset($error['message']) && $error['message'] ? $error['message'] : "Cannot read from $url.";
            throw new RuntimeException($message);
        }



        if (isset($http_response_header)) {
            $header = implode("\r\n", $http_response_header);
            return "$header\r\n\r\n$body";
        }

        return $body;
    }
934287
public static function create(
        AuthInterface $authentication,
        bool $throwsExceptions = false,
        string $baseUrl = 'https://api.idos.io/1.0/'
    ) : self {
        return new static(
            $authentication,
            new Client(),
            $throwsExceptions,
            $baseUrl
        );
    }
971540
public function getAnnouncementsFromRootAssociations($apiServiceFilterContext = null)
    {
        $result = [];

        foreach ($this->getRootAssociationIDs() as $key => $rootAssociationID) {
            try {
                $result[] = $this->getAnnouncementsFromAssociation($rootAssociationID, $apiServiceFilterContext);
            } catch (ContextException $e) {
                if ($key === count($this->getRootAssociationIDs()) - 1) {
                    throw $e;
                }
            }
        }

        return $result;
    }
134988
public function getContext(ModelContextInterface $context = null)
    {
        $context = new ModelContext($context);
        $context->setState($this->getState());
        $context->setIdentityKey($this->_identity_key);

        return $context;
    }
553978
public static function getUserClient($organization = null, $apiKey = null, $options = [])
    {
        $baseUrl = BaseClient::DEFAULT_API_BASE_URL;

        //bc compability, when first param was $options
        if (\is_array($organization)) {
            $options = $organization;
            $organization = null;
            $apiKey = null;
        }
        if (isset($options[self::API_BASE_URL])) {
            $baseUrl = $options[self::API_BASE_URL];
        }

        $client = self::getGuzzleClient($baseUrl, $options);

        return new UserClient($client, $organization, $apiKey);
    }
545399
public static PredictionEndpoint authenticate(String baseUrl, final String apiKey) {
        ServiceClientCredentials serviceClientCredentials = new ServiceClientCredentials() {
            @Override
            public void applyCredentialsFilter(OkHttpClient.Builder builder) {
            }
        };
        return authenticate(baseUrl, serviceClientCredentials, apiKey);
    }
118944
public function matchContext($contextUid, MatchContextParameters $params = null)
    {
        $endpoint = vsprintf('contexts/%s/match/async', $contextUid);
        $requestData = $this->getDefaultRequestData('json', is_null($params) ? [] : $params->exportToArray());

        return $this->sendRequest($endpoint, $requestData, self::HTTP_METHOD_POST);
    }
538834
public static function GetBaseUriWithProvider( $context, $provider )
	{
		return ExtFuncs::GetBaseUri( $context, CoreFuncs::NodeValue( CoreFuncs::ContextNode( $provider ) ) );
	}
571223
private function getApiResponseContext(RequestContext $requestContext): ResponseContextAbstract
    {
        $responseContext = $this->httpClient->sendRequest(
            $requestContext
        );

        $this->processApiResponseContextErrors($responseContext);

        return $responseContext;
    }
1290746
public function getToken(TokenContext $context)
    {
        $getTokenCallback = $this->callbackFunc;
        $jwtString = $getTokenCallback($context);

        return Jwt::fromString($jwtString);
    }
1003135
public static function absoluteBaseURLWithAuth(HTTPRequest $request = null)
    {
        // Detect basic auth
        $user = $request->getHeader('PHP_AUTH_USER');
        if ($user) {
            $password = $request->getHeader('PHP_AUTH_PW');
            $login = sprintf("%s:%s@", $user, $password) ;
        } else {
            $login = '';
        }

        return Director::protocol($request) . $login . static::host($request) . Director::baseURL();
    }