You are here

public static function Base::getMethods in DRD Agent 4.0.x

Same name in this branch
  1. 4.0.x src/Crypt/Base.php \Drupal\drd_agent\Crypt\Base::getMethods()
  2. 4.0.x src/Agent/Auth/Base.php \Drupal\drd_agent\Agent\Auth\Base::getMethods()
Same name and namespace in other branches
  1. 8.3 src/Crypt/Base.php \Drupal\drd_agent\Crypt\Base::getMethods()

Get a list of crypt methods, either just their ids or instances of each.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container:

bool $instances: Whether to receive ids (FALSE) or instances (TRUE).

Return value

array List of crypt methods.

Overrides BaseInterface::getMethods

1 call to Base::getMethods()
Agent::getCryptMethods in src/Controller/Agent.php
Route callback to retrieve a list of available crypt methods.

File

src/Crypt/Base.php, line 25

Class

Base
Provides base encryption functionality.

Namespace

Drupal\drd_agent\Crypt

Code

public static function getMethods(ContainerInterface $container, $instances = FALSE) : array {
  $methods = [];
  foreach ([
    'MCrypt',
    'OpenSSL',
    'TLS',
  ] as $item) {
    $classname = "\\Drupal\\drd_agent\\Crypt\\Method\\{$item}";

    /* @var BaseMethodInterface $method */
    $method = new $classname($container);
    if ($method instanceof BaseMethodInterface && $method
      ->isAvailable()) {
      if ($instances) {
        $methods[$method
          ->getLabel()] = $method;
      }
      else {
        $methods[$method
          ->getLabel()] = [
          'classname' => $classname,
          'cipher' => $method
            ->getCipherMethods(),
        ];
      }
    }
  }
  return $methods;
}