Поиск имени класса сущности

@param string $entityPostfix
@param array  $namespacesIndex
@param string $entityInterface

@return bool|string
177761
public function resolveEntityClassName($entityPostfix, array $namespacesIndex = [], $entityInterface)
    {
        $entityClassName = false;
        foreach ($namespacesIndex as $rootNamespace) {
            $currentEntityClassName = $rootNamespace . $entityPostfix;
            if (class_exists($currentEntityClassName)) {
                $r = new ReflectionClass($currentEntityClassName);
                if ($r->implementsInterface($entityInterface)) {
                    $entityClassName = $currentEntityClassName;
                    break;
                }
            }
        }

        return $entityClassName;
    }
595961
private function namespaceDefinitions(array $definitions, Endpoint $endpoint): array
    {
        $namespacedDefinitions = [];
        /** @var DefinitionInterface $definition */
        foreach ($definitions as $definition) {
            if (!$definition->hasMeta('namespace') || !$definition->getMeta('namespace')) {
                $namespacedDefinitions[$definition->getName()] = $definition;
                continue;
            }

            $root = null;
            $parent = null;
            $namespaceConfig = $definition->getMeta('namespace');
            $namespacePath = $namespaceConfig['namespace'] ?? null;
            if ($namespacePath) {
                $querySuffix = $this->globalConfig['nodes']['query_suffix'] ?? 'Query';
                $mutationSuffix = $this->globalConfig['nodes']['mutation_suffix'] ?? 'Mutation';
                $subscriptionSuffix = $this->globalConfig['nodes']['subscription_suffix'] ?? 'Subscription';
                $namespaces = explode('/', $namespacePath);
                foreach ($namespaces as $namespace) {
                    $name = lcfirst($namespace);
                    $suffix = $querySuffix;
                    if ($definition instanceof MutationDefinition) {
                        $suffix = $mutationSuffix;
                    }
                    if ($definition instanceof SubscriptionDefinition) {
                        $suffix = $subscriptionSuffix;
                    }
                    $typeName = ucfirst($name).$suffix;
                    if (!$root) {
                        if (isset($namespacedDefinitions[$name])) {
                            $root = $namespacedDefinitions[$name];
                        } else {
                            $root = $this->createRootNamespace($definition, $name, $typeName, $endpoint);
                        }
                        $parent = $endpoint->getType($root->getType());
                        $namespacedDefinitions[$root->getName()] = $root;
                    } else {
                        $parent = $this->createChildNamespace($parent, $name, $typeName, $endpoint);
                    }
                }
                if ($alias = $namespaceConfig['alias'] ?? null) {
                    $definition->setName($alias);
                }
                $this->addDefinitionToNamespace($parent, $definition, $definition->getName());
                continue;
            }

            if ($bundle = $namespaceConfig['bundle'] ?? null) {
                $bundleQuerySuffix = $this->globalConfig['bundle']['query_suffix'] ?? 'BundleQuery';
                $bundleMutationSuffix = $this->globalConfig['bundle']['mutation_suffix'] ?? 'BundleMutation';
                $bundleSubscriptionSuffix = $this->globalConfig['bundle']['subscription_suffix'] ?? 'BundleSubscription';
                $name = lcfirst($bundle);
                $suffix = $bundleQuerySuffix;
                if ($definition instanceof MutationDefinition) {
                    $suffix = $bundleMutationSuffix;
                }
                if ($definition instanceof SubscriptionDefinition) {
                    $suffix = $bundleSubscriptionSuffix;
                }
                $typeName = ucfirst($name).$suffix;
                $root = $this->createRootNamespace($definition, $name, $typeName, $endpoint);
                $parent = $endpoint->getType($root->getType());
            }

            if ($nodeName = $namespaceConfig['node'] ?? null) {
                if ($endpoint->hasTypeForClass($nodeName)) {
                    $nodeName = $endpoint->getTypeForClass($nodeName);
                }

                $name = Inflector::pluralize(lcfirst($nodeName));

                $querySuffix = $this->globalConfig['nodes']['query_suffix'] ?? 'Query';
                $mutationSuffix = $this->globalConfig['nodes']['mutation_suffix'] ?? 'Mutation';
                $subscriptionSuffix = $this->globalConfig['nodes']['subscription_suffix'] ?? 'Subscription';

                $suffix = $querySuffix;
                if ($definition instanceof MutationDefinition) {
                    $suffix = $mutationSuffix;
                }
                if ($definition instanceof SubscriptionDefinition) {
                    $suffix = $subscriptionSuffix;
                }

                $typeName = ucfirst($nodeName).$suffix;
                if (!$root) {
                    $root = $this->createRootNamespace($definition, $name, $typeName, $endpoint);
                    $parent = $endpoint->getType($root->getType());
                } elseif ($parent) {
                    $parent = $this->createChildNamespace($parent, $name, $typeName, $endpoint);
                }

                if ($alias = $namespaceConfig['alias'] ?? null) {
                    $originName = $definition->getName();
                    $definition->setName($alias);
                } else {
                    //remove node suffix on namespaced definitions
                    $originName = $definition->getName();
                    $definition->setName(preg_replace(sprintf("/(\w+)%s$/", $nodeName), '$1', $definition->getName()));
                    $definition->setName(preg_replace(sprintf("/(\w+)%s$/", Inflector::pluralize($nodeName)), '$1', $definition->getName()));
                }
            }

            if ($root && $parent) {
                $this->addDefinitionToNamespace($parent, $definition, $originName);
                $namespacedDefinitions[$root->getName()] = $root;
            } else {
                $namespacedDefinitions[$definition->getName()] = $definition;
            }
        }

        return $namespacedDefinitions;
    }
455709
protected function useRelationInterfaceInEntityInterface(string $classPath, string $interfacePath): void
    {
        $entityFqn           = PhpClass::fromFile($classPath)->getQualifiedName();
        $entityInterfaceFqn  = $this->namespaceHelper->getEntityInterfaceFromEntityFqn($entityFqn);
        $entityInterfacePath = (new \ts\Reflection\ReflectionClass($entityInterfaceFqn))->getFileName();
        $entityInterface     = PhpInterface::fromFile($entityInterfacePath);
        $relationInterface   = PhpInterface::fromFile($interfacePath);
        $entityInterface->addInterface($relationInterface);
        $this->codeHelper->generate($entityInterface, $entityInterfacePath);
    }
533128
public function lookupPrefix( $namespace )
	{
		foreach ( $this->namespaces as $prefix => $value )
		{
			if ( strcasecmp( $namespace, $value ) === 0 ) return $prefix;
		}

		return false;
	}
739827
private function resolveChildIndex($nodeOrIndex)
    {
        if (is_int($nodeOrIndex)) {
            return $nodeOrIndex;
        } elseif ($nodeOrIndex instanceof SVGNode) {
            return array_search($nodeOrIndex, $this->children, true);
        }

        return false;
    }
1019073
public function invoke($node, NodeInterface $parent): void
    {
        if (! $node instanceof Node\Stmt\Namespace_ || ! $parent instanceof PhpFileModelInterface) {
            throw new Exception('NamespaceNodeParser is made to parse a namespace node');
        }

        if ($node->name instanceof Node\Name) {
            $parent->setNamespace($node->name->parts);
        }

        $this->preParseUses($node->stmts, $parent);

        $this->parseSubNodes($node->stmts, $parent);
    }
1019017
protected static function _namespaceIsset($namespace, $name = null)
    {
        if (self::$_readable === false) {
            /**
             * @see Zend_Session_Exception
             */
            require_once 'Zend/Session/Exception.php';
            throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG);
        }

        if ($name === null) {
            return ( isset($_SESSION[$namespace]) || isset(self::$_expiringData[$namespace]) );
        } else {
            return ( isset($_SESSION[$namespace][$name]) || isset(self::$_expiringData[$namespace][$name]) );
        }
    }
291787
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
    {
        $intersection_types = $this->getNamespacedIntersectionTypes(
            $namespace,
            $aliased_classes,
            $this_class,
            $use_phpdoc_format
        );

        if ($this->value === 'static') {
            return 'static';
        }

        if ($this->value === $this_class) {
            return 'self' . $intersection_types;
        }

        if ($namespace && stripos($this->value, $namespace . '\\') === 0) {
            return preg_replace(
                '/^' . preg_quote($namespace . '\\') . '/i',
                '',
                $this->value
            ) . $intersection_types;
        }

        if (!$namespace && stripos($this->value, '\\') === false) {
            return $this->value . $intersection_types;
        }

        if (isset($aliased_classes[strtolower($this->value)])) {
            return $aliased_classes[strtolower($this->value)] . $intersection_types;
        }

        return '\\' . $this->value . $intersection_types;
    }
1237618
public function getNamespacedName(string $entityName, array $subDirectories): string
    {
        $noEntitiesDirectory = \array_slice($subDirectories, 2);
        $namespacedName      = \array_merge($noEntitiesDirectory, [$entityName]);

        return \ucfirst(\implode('', $namespacedName));
    }
309090
protected function getInterfaceNamespace(File $phpCsFile, int $stackPointer): string
    {
        $namespacePosition = $phpCsFile->findPrevious(T_NAMESPACE, $stackPointer);
        $endOfNamespacePosition = $phpCsFile->findEndOfStatement($namespacePosition);

        $tokens = $phpCsFile->getTokens();
        $namespaceTokens = array_splice($tokens, $namespacePosition + 2, $endOfNamespacePosition - $namespacePosition - 2);

        $namespace = '';
        foreach ($namespaceTokens as $token) {
            $namespace .= $token['content'];
        }

        return $namespace;
    }
1060900
private function entityClassStub($name, Collection $interfaces, Collection $traits)
    {
        $useString       = new Collection();
        $traitString     = new Collection();
        $interfaceString = $interfaces->count() ? ' implements ' . $interfaces->pluck('alias')->implode(', ') : '';

        foreach ($interfaces as $int) {
            $useString[] = "use {$int['class']}" . (isset($int['alias']) ? ' as ' . $int['alias'] : '') . ';';
        }
        foreach ($traits as $trait) {
            $ref = new \ReflectionClass($trait);
            $useString[]   = "use {$trait};";
            $traitString[] = "    use {$ref->getShortName()};";
        }

        $useString   = $this->collectionToString($useString, "\n", "\n", "\n");
        $traitString = $this->collectionToString($traitString, "\n", null, "\n");

        return <<<CLASS
<?php

namespace $this->entityNamespace;
$useString
/**
 * Class $name
 *
 * @package    $this->entityNamespace
 * @subpackage $this->entityNamespace\\{$name}
 */
class $name$interfaceString
{

$traitString
}

CLASS;

    }
1071254
public function create($namespace, $recipient, $expireIn = 300, $length = 6, $type = 'numeric')
    {
        $validCode = new ValidCode();
        $validCode->setNamespace($namespace);
        $validCode->setRecipient($recipient);
        $now = new \DateTime();
        $expiredAt = $now->add(new \DateInterval('PT' . $expireIn . 'S'));
        $validCode->setExpiredAt($expiredAt);
        $code = Str::random($length, $type);
        $validCode->setCode($code);
        $cacheKey = $this->getCacheKey($namespace, $recipient);
        $this->cache->save($cacheKey, $validCode, $expireIn);
        return $code;
    }
246155
protected function checkRaw( $namespace, PermissibleEntity $entity = null )
	{
		if ( $namespace == null || strlen( $namespace ) == 0 || $namespace == "everybody" || $namespace == "-1" )
			$namespace = Permission::EVERYBODY;
		if ( $namespace == "op" || $namespace == "0" )
			$namespace = Permission::OP;
		if ( $namespace == "admin" )
			$namespace = Permission::ADMIN;
		if ( $namespace == "banned" )
			$namespace = Permission::BANNED;
		if ( $namespace == "whitelisted" )
			$namespace = Permission::WHITELISTED;

		$namespace = static::getAlias( $namespace );

		if ( !preg_match( "/[a-z0-9_.]*/", $namespace ) )
			throw new PermissionException( "The permission namespace [$namespace] can only contain the characters 'a-z0-9_.'." );

		$permission_defaults = PermissionDefaults::find( $namespace );

		if ( $entity === null )
		{
			if ( !Acct::check() )
			{
				$result = $this->checkWalker( $namespace, [] );
				if ( $result == PermissionValues::UNSET )
					$result = $permission_defaults->value_default;

				return $result;
			}
			$entity = Acct::acct();
		}

		$group_state = PermissionValues::UNSET;

		/*
		 * Check group permissible state
		 */
		foreach ( $entity->groups() as $group )
		{
			$group_state = $this->checkRaw( $namespace, $group );
			if ( $group_state == PermissionValues::ALWAYS || $group_state == PermissionValues::NEVER )
				break;
		}

		/*
		 * Check user permissible state
		 */
		$user_state = $this->checkWalker( $namespace, $entity->permissions() );

		if ( $group_state == PermissionValues::ALWAYS || $group_state == PermissionValues::NEVER )
		{
			if ( $user_state == PermissionValues::ALWAYS )
				return true;
			else if ( $user_state == PermissionValues::NEVER )
				return false;
			else
				return $group_state;
		}
		else if ( $group_state == PermissionValues::UNSET && $user_state == PermissionValues::UNSET )
			return $permission_defaults->value_default;
		else if ( $user_state == PermissionValues::UNSET )
			return $group_state;
		else // if ( $group_state == PermissionValues::UNSET )
			return $user_state;
	}
986491
public function getPrefixForDocumentNamespace( $namespace )
	{
		if ( is_null( $this->cacheDocumentNamespaces ) )
		{
			$this->cacheDocumentNamespaces = array_flip( $this->instance_xml->getDocNamespaces() );
			// If the default namespace is one of the standards ones then the prefix may be missing
			$standardNamespaces = array_flip( XBRL_Constants::$standardPrefixes );
			$docNamespace = array_search( '', $this->cacheDocumentNamespaces );
			if ( $docNamespace )
			{
				if ( isset( $standardNamespaces[ $docNamespace ] ) )
				{
					$this->cacheDocumentNamespaces[ $docNamespace ] = $standardNamespaces[ $docNamespace ];
				}
				else
				{
					// Get the namespace for the respective namespace
					$taxonomy = $this->getInstanceTaxonomy()->getTaxonomyForNamespace( $docNamespace );
					if ( $taxonomy )
					{
						$this->cacheDocumentNamespaces[ $docNamespace ] = $taxonomy->getPrefix();
					}
				}
			}
		}

		return isset( $this->cacheDocumentNamespaces[ $namespace ] )
			? $this->cacheDocumentNamespaces[ $namespace ]
			: false;
	}
1059146
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
    {
        $base_value = $this instanceof TNamedObject
            ? parent::toNamespacedString($namespace, $aliased_classes, $this_class, $use_phpdoc_format)
            : $this->value;

        if ($base_value === 'non-empty-array') {
            $base_value = 'array';
        }

        if ($use_phpdoc_format) {
            if ($this instanceof TNamedObject || $this instanceof TIterable) {
                return $base_value;
            }

            $value_type = $this->type_params[1];

            if ($value_type->isMixed()) {
                return $base_value;
            }

            $value_type_string = $value_type->toNamespacedString($namespace, $aliased_classes, $this_class, true);

            if (!$value_type->isSingle()) {
                return '(' . $value_type_string . ')[]';
            }

            return $value_type_string . '[]';
        }

        $extra_types = '';

        if ($this instanceof TNamedObject && $this->extra_types) {
            $extra_types = '&' . implode(
                '&',
                array_map(
                    /**
                     * @return string
                     */
                    function (Atomic $extra_type) use ($namespace, $aliased_classes, $this_class) {
                        return $extra_type->toNamespacedString($namespace, $aliased_classes, $this_class, false);
                    },
                    $this->extra_types
                )
            );
        }

        return $base_value .
                '<' .
                implode(
                    ', ',
                    array_map(
                        /**
                         * @return string
                         */
                        function (Union $type_param) use ($namespace, $aliased_classes, $this_class) {
                            return $type_param->toNamespacedString($namespace, $aliased_classes, $this_class, false);
                        },
                        $this->type_params
                    )
                ) .
                '>' . $extra_types;
    }
1277200
private function getPrimaryNamespace(PackageInterface $package)
    {
        $primaryNs = null;

        foreach ($package->getAutoload() as $type => $pathMap) {
            if ($type !== 'psr-4') {
                continue;
            }

            if (count($pathMap) === 1) {
                $primaryNs = key($pathMap);
                break;
            }

            $matches = preg_grep('#^(\./)?src/?$#', $pathMap);
            if ($matches) {
                $primaryNs = key($matches);
                break;
            }

            if (false !== ($key = array_search('', $pathMap, true))
                || false !== ($key = array_search('.', $pathMap, true))
            ) {
                $primaryNs = $key;
            }

            break;
        }

        if (!$primaryNs) {
            throw new RuntimeException(sprintf("Unable to get primary namespace for package %s.", $package->getName()));
        }

        return $primaryNs;
    }
1328591
public function buildListEntityInterfaces(array $entityClassNames = [])
    {
        $listEntityInterfaces = [];

        $moduleOptionsManager = $this->getModuleOptionsPluginManager();
        $allowedModules = $this->getAllowedModules($entityClassNames);

        foreach ($entityClassNames as $entityClassName) {
            $r = new ReflectionClass($entityClassName);
            $useInterfaces = $r->getInterfaceNames();
            foreach ($useInterfaces as $currentInterface) {
                if ($moduleOptionsManager->hasModuleNameByClassName($currentInterface)) {
                    $moduleNameByInterface = $moduleOptionsManager->getModuleNameByClassName($currentInterface);
                    if (array_key_exists($moduleNameByInterface, $allowedModules)) {
                        $listEntityInterfaces[$currentInterface] = $currentInterface;
                    }
                }
            }
        }

        return $listEntityInterfaces;
    }