You are here

protected function AppCredentialEventSubscriber::getAppByName in Apigee Edge 8

Helper to load an app by name.

Parameters

string $name: The name of the app.

string $owner_id: The developer or team.

string $app_type: The type of the app.

Return value

\Drupal\apigee_edge\Entity\AppInterface|null The app with the provided name or null.

1 call to AppCredentialEventSubscriber::getAppByName()
AppCredentialEventSubscriber::dispatchRulesEvent in modules/apigee_edge_actions/src/EventSubscriber/AppCredentialEventSubscriber.php
Helper to dispatch a corresponding rules event for an api credential event.

File

modules/apigee_edge_actions/src/EventSubscriber/AppCredentialEventSubscriber.php, line 179

Class

AppCredentialEventSubscriber
Events for an API Product being added to an app already exist.

Namespace

Drupal\apigee_edge_actions\EventSubscriber

Code

protected function getAppByName(string $name, string $owner_id, string $app_type) : ?AppInterface {

  /* @var \Drupal\apigee_edge\Entity\AppInterface $appClass */
  $appClass = $this->entityTypeManger
    ->getStorage("{$app_type}_app")
    ->getEntityType()
    ->getClass();
  try {
    if ($app_type == 'developer') {

      /* @var \Drupal\apigee_edge\Entity\Controller\DeveloperAppControllerFactoryInterface $controller */
      $controller = \Drupal::service('apigee_edge.controller.developer_app_controller_factory');
      $edge_app = $controller
        ->developerAppController($owner_id)
        ->load($name);
    }
    else {

      /* @var \Drupal\apigee_edge_teams\Entity\Controller\TeamAppControllerFactory $controller */
      $controller = \Drupal::service('apigee_edge_teams.controller.team_app_controller_factory');
      $edge_app = $controller
        ->teamAppController($owner_id)
        ->load($name);
    }
    $app = $appClass::createFrom($edge_app);
    return $app;
  } catch (PluginException $exception) {
    $this->logger
      ->error($exception);
  }
  return NULL;
}