function QueryBase::getNamespaces

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::getNamespaces()
  2. 8.9.x core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::getNamespaces()
  3. 11.x core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::getNamespaces()

Gets a list of namespaces of the ancestors of a class.

Returns a list of namespaces that includes the namespace of the class, as well as the namespaces of its parent class and ancestors. This is useful for locating classes in a hierarchy of namespaces, such as when searching for the appropriate query class for an entity type.

Parameters

$object: An object within a namespace.

Return value

array A list containing the namespace of the class, the namespace of the parent of the class and so on and so on.

4 calls to QueryBase::getNamespaces()
QueryFactory::__construct in core/modules/workspaces/src/EntityQuery/QueryFactory.php
Constructs a QueryFactory object.
QueryFactory::__construct in core/lib/Drupal/Core/Config/Entity/Query/QueryFactory.php
Constructs a QueryFactory object.
QueryFactory::__construct in core/lib/Drupal/Core/Entity/Query/Sql/QueryFactory.php
Constructs a QueryFactory object.
QueryFactory::__construct in core/lib/Drupal/Core/Entity/Query/Null/QueryFactory.php
Constructs a QueryFactory object.

File

core/lib/Drupal/Core/Entity/Query/QueryBase.php, line 483

Class

QueryBase
The base entity query class.

Namespace

Drupal\Core\Entity\Query

Code

public static function getNamespaces($object) {
    $namespaces = [];
    for ($class = get_class($object); $class; $class = get_parent_class($class)) {
        $namespaces[] = substr($class, 0, strrpos($class, '\\'));
    }
    return $namespaces;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.