You are here

function drush_phpstorm_metadata in http:BL 8

Generate PhpStorm Metadata file.

See also

http://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Advanced+Metadata

File

drush/phpstorm.drush.inc, line 47
Generate PhpStorm metadata file.

Code

function drush_phpstorm_metadata() {
  $container = \Drupal::getContainer();
  $reflectedClass = new ReflectionClass($container);
  $map = array();

  // Map for all services of the container.
  // @see \Symfony\Component\DependencyInjection\Container::getServiceIds().
  foreach ($reflectedClass
    ->getMethods() as $method) {
    if (preg_match('/^get(.+)Service$/', $method->name, $match)) {
      $id = strtolower(preg_replace(array(
        '/([A-Z]+)([A-Z][a-z])/',
        '/([a-z\\d])([A-Z])/',
      ), array(
        '\\1_\\2',
        '\\1_\\2',
      ), strtr($match[1], '_', '.')));
      $service = \Drupal::service($id);
      if (is_object($service)) {
        $map["\\Drupal::service('')"][$id] = '\\' . get_class($service);
      }
    }
  }

  // Entity Manager - getStorage
  foreach (\Drupal::entityTypeManager()
    ->getDefinitions() as $type => $definition) {
    $class = Drupal::entityTypeManager()
      ->getStorage($type);
    $map["\\Drupal::entityManager()->getStorage('')"][$type] = '\\' . get_class($class);
    $map["\\Drupal::entityTypeManager()->getStorage('')"][$type] = '\\' . get_class($class);
  }
  $content = _drush_phpstorm_metadata_phpstorm_metadata_template($map);
  file_put_contents(DRUPAL_ROOT . '/.phpstorm.meta.php', $content);
}