apigee_edge-8.x-1.17/modules/apigee_edge_teams/src/CliService.php

modules/apigee_edge_teams/src/CliService.php
<?php

/**
 * Copyright 2022 Google Inc.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
 * License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

namespace Drupal\apigee_edge_teams;

use Drupal\apigee_edge\Command\Util\ApigeeEdgeManagementCliServiceInterface;
use Drupal\apigee_edge_teams\Controller\TeamMemberSyncController;
use Symfony\Component\Console\Style\StyleInterface;

/**
 * A CLI service which defines all the commands logic and delegates the methods.
 */
class CliService implements CliServiceInterface {

  /**
   * The service that makes calls to the Apigee API.
   *
   * @var \Drupal\apigee_edge\Command\Util\ApigeeEdgeManagementCliServiceInterface
   */
  private $apigeeEdgeManagementCliService;

  /**
   * CliService constructor.
   *
   * @param \Drupal\apigee_edge\Command\Util\ApigeeEdgeManagementCliServiceInterface $apigeeEdgeManagementCliService
   *   The ApigeeEdgeManagementCliService to make calls to Apigee Edge.
   */
  public function __construct(ApigeeEdgeManagementCliServiceInterface $apigeeEdgeManagementCliService) {
    $this->apigeeEdgeManagementCliService = $apigeeEdgeManagementCliService;
  }

  /**
   * {@inheritdoc}
   */
  public function sync(StyleInterface $io, callable $t) {
    $io->title($t('Team Member synchronization'));
    $batch = TeamMemberSyncController::getBatch();
    $last_message = '';

    foreach ($batch['operations'] as $operation) {
      $context = [
        'finished' => 0,
      ];

      while ($context['finished'] < 1) {
        call_user_func_array($operation[0], array_merge($operation[1], [&$context]));
        if (isset($context['message']) && $context['message'] !== $last_message) {
          $io->text($t($context['message']));
        }
        $last_message = $context['message'];

        gc_collect_cycles();
      }
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc