You are here

class YamlFormReflectionHelper in YAML Form 8

Helper class for reflection methods.

Hierarchy

Expanded class hierarchy of YamlFormReflectionHelper

2 files declare their use of YamlFormReflectionHelper
YamlFormElementBase.php in src/YamlFormElementBase.php
YamlFormPluginElementController.php in src/Controller/YamlFormPluginElementController.php

File

src/Utility/YamlFormReflectionHelper.php, line 8

Namespace

Drupal\yamlform\Utility
View source
class YamlFormReflectionHelper {

  /**
   * Get this element's class hierarchy.
   *
   * @return array
   *   An array containing this elements class hierarchy.
   */
  public static function getParentClasses($object, $base_class_name = '') {
    $class = get_class($object);
    $parent_classes = [
      self::getClassName($class),
    ];
    do {
      $parent_class = get_parent_class($class);
      $parent_class_name = self::getClassName($parent_class);
      $parent_classes[] = $parent_class_name;
      $class = $parent_class;
    } while ($parent_class_name != $base_class_name && $class);
    return array_reverse($parent_classes);
  }

  /**
   * Get a class's name without its namespace.
   *
   * @param string $class
   *   A class.
   *
   * @return string
   *   The class's name without its namespace.
   */
  protected static function getClassName($class) {
    $parts = preg_split('#\\\\#', $class);
    return end($parts);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
YamlFormReflectionHelper::getClassName protected static function Get a class's name without its namespace.
YamlFormReflectionHelper::getParentClasses public static function Get this element's class hierarchy.