Return the number of times members of a token class appear in the string.

@param string $class
Token class to count.
@return integer
Returns the number of times members of the token class appear in the
string.
485951
protected function _getClassCount($class)
    {
        $count = 0;
        if ($class == self::CLASS_LETTER) {
            $count = $this->_getClassCount(self::CLASS_LOWER)
                   + $this->_getClassCount(self::CLASS_UPPER);
        } else {
            if (isset ($this->_tokenCounts[$class])) {
                $count = $this->_tokenCounts[$class];
            }
        }

        return $count;
    }
710401
private function extractEntry($class)
    {
        if ($class != $this->baseClass && !is_subclass_of($class, $this->baseClass)) {
            return false;
        }

        if (!preg_match_all('~/?([a-zA-Z0-9]+)~', $class, $namespaces)) {
            throw new \Exception("Unexpected class {$class}.");
        }

        $prefix = $suffix = null;
        $parts = $namespaces[0];

        foreach ($parts as $index => $namespace) {
            if ($namespace == 'Component') {
                $prefix = strtolower($parts[$index + 1]);
                break;
            } elseif (preg_match('~([a-zA-Z0-9]+)Bundle~', $namespace, $matches)) {
                $prefix = strtolower($matches[1]);
                break;
            }
        }

        $suffix = strtolower(end($parts));

        if (empty($prefix) || empty($suffix)) {
            throw new \Exception(
                "Failed to extract discriminator value from class '{$class}'."
            );
        }

        $value = $prefix . '_' . $suffix;

        if (in_array($value, $this->map)) {
            throw new \Exception("Found duplicate discriminator map entry '{$value}' in {$class}");
        }

        $this->map[$class] = $value;

        return true;
    }
229904
public static function tableize($class)
    {
        $underscored = Strings::camelCaseToUnderscore($class);
        $parts = explode('_', $underscored);
        $suffix = Inflector::pluralize(array_pop($parts));
        $parts[] = $suffix;
        return implode('_', $parts);
    }
687307
public function count(string $column = '*'): int
    {
        $select = clone $this;

        //To be escaped in compiler
        $select->columns = ["COUNT({$column})"];
        $select->ordering = [];
        $select->grouping = [];

        $st = $select->run();
        try {
            return (int)$st->fetchColumn();
        } finally {
            $st->close();
        }
    }
904158
public function getClass(string $class){
        if(!class_exists($class)){
            throw new \InvalidArgumentException();
        }

        if(!array_key_exists($class, $this->classes)){
            $this->classes[$class]  = new \ReflectionClass($class);
        }

        return $this->classes[$class];
    }
203065
public function isSingleton(string $class): bool
	{
		$class = $this->resolveAlias($class);

		return isset($this->instances[$class]) || (isset($this->hints[$class]) && $this->hints[$class]['singleton'] === true);
	}
898882
public function resolve($class)
    {
        $result = false;
        $prefix = $class;

        while (false !== ($pos = strrpos($prefix, '\\'))) {
            $prefix = substr($class, 0, $pos + 1);

            if (isset($this->prefixes[$prefix])) {
                $result = $this->resolveFilename($prefix, str_replace('\\', '/', substr($class, $pos + 1)));

                if ($result !== false) {
                    break;
                }
            }

            $prefix = rtrim($prefix, '\\');
        }

        return $result;
    }
927032
public function getByType($class)
    {
        $class = array_map('strtolower', (array)$class);

        $out = array_filter($this->_items, function ($assoc) use ($class) {
            list(, $name) = namespaceSplit(get_class($assoc));

            return in_array(strtolower($name), $class, true);
        });

        return array_values($out);
    }
298186
public function getTraitsOfClass($class)
    {
        $definitions = [];

        // in case there is a hierarchy of classes
        $classes = $this->getSuperClasses($class);
        if (is_array($classes)) {
            foreach ($classes as $subClass) {
                if (isset($subClass['traits'])) {
                    foreach ($subClass['traits'] as $classTrait) {
                        foreach ($this->traits as $trait) {
                            if ($classTrait === $trait['trait']) {
                                $traitDefinition[$trait['trait']] = $trait;
                                $definitions = array_merge($definitions, $traitDefinition);
                            }
                        }
                    }
                }
            }
        }

        // trait used by the given class
        $classDefinition = isset($this->classes[$class]) ? $this->classes[$class] : null;
        if (!$classDefinition || empty($classDefinition['traits'])) {
            return $definitions;
        }
        $classTraits = $classDefinition['traits'];
        foreach ($this->traits as $trait) {
            foreach ($classTraits as $classTrait => $name) {
                if ($trait['trait'] === $name) {
                    $traitDefinition[$name] = $trait;
                    $definitions = array_merge($definitions, $traitDefinition);
                }
            }
        }

        return $definitions;
    }
1320873
private function getSender($class)
    {
        $sender = in_array($class, $this->summarys) ? new SummarySender() : new BillSender();
        $sender->setClient($this->wsClient);
        if ($this->codeProvider) {
            $sender->setCodeProvider($this->codeProvider);
        }

        return $sender;
    }
1226134
public function findAnnotationClass(string $class): ?string
    {
        $annotationClass = "";

        // Handle exact class name matches, including aliases classes...
        if(array_key_exists($class, $this->uses))
            $annotationClass = $this->uses[$class];

        // Handle fully qualified class names...
        if($annotationClass === "" && in_array($class, $this->uses))
        {
            $key = array_search($class, $this->uses);
            $annotationClass = $this->uses[$key];
        }

        // Determine the current classes namespace...
        $namespaceParts = explode("\\", $this->class);
        array_pop($namespaceParts);
        $namespace = implode("\\", $namespaceParts)."\\";

        // Handle class names living in the same namespace...
        if($annotationClass === "" && class_exists($namespace.$class))
            $annotationClass = $namespace.$class;

        // Make certain the class exists before continuing...
        if ($annotationClass !== "" && class_exists($annotationClass))
        {
            // TODO: Handle the situation where '@var ClassName' is not meant to be an Annotation class...

            /*
            // Also make certain the class extends 'Annotation'...
            if (!is_subclass_of($annotationClass, Annotation::class, true)) {
                throw new \Exception("[MVQN\Annotations\AnnotationReader] The annotation class '$annotationClass' ".
                    "must extend '".Annotation::class."'!");
            }
            */
            // Return the fully qualified class, if nothing went wrong!
            return $annotationClass;
        }

        // If nothing else matched, then throw an exception!
        throw new \Exception("[MVQN\Annotations\AnnotationReader] The annotation class '$class' must exist and ".
            "extend '".Annotation::class . "'!");
        //return null;
    }
535443
public function hasClass($class = null)
    {
        if ($class !== null) {
            $classes = explode(' ', $this->getClass());
            return in_array($class, $classes);
        } else {
            return $this->hasAttribute('class');
        }
    }
549148
public function findFile($class)
    {
        $class = Normalizer::ns($class, false);
        if (isset($this->classMap[$class])) {
            return $this->classMap[$class];
        }
        $index = substr($class, 0, 4);
        if (isset($this->indexes[$index])) {
            $namespace = $class;
            while (false !== $pos = strrpos($namespace, '\\')) {
                $namespace = substr($class, 0, $pos + 1);
                if (! isset($this->paths[$namespace])) {
                    $namespace = rtrim($namespace, '\\');
                    continue;
                }
                $subclass = substr($class, $pos + 1);
                $subpath  = Normalizer::path($subclass, false) . '.php';
                foreach ($this->paths[$namespace] as $dir) {
                    $path = $dir . $subpath;
                    if (is_readable($path)) {
                        if ($this->classRegistration) {
                            $this->classMap[$class] = $path;
                        }

                        return $path;
                    }
                }
                $namespace = rtrim($namespace, '\\');
            }
        }

        if ($this->classRegistration) {
            $this->classMap[$class] = false;
        }

        return false;
    }
721344
final public static function getInstance($calledClass = null)
    {
        $calledClass = $calledClass ?: get_called_class();

        if (!isset(self::$instances[ $calledClass ])) {
            self::$instances[ $calledClass ] = new $calledClass();
        }

        return self::$instances[ $calledClass ];
    }
232710
public function getApplicationIdByClass(string $class): string
    {
        foreach ($this->applications as $appId => $appConfig) {
            if ($appConfig['class'] === $class) {
                return $appId;
            }
        }
        throw new \RuntimeException('Application id not found.', Saw::ERROR_APPLICATION_CLASS_NOT_EXISTS);
    }
824072
public function addUseStatementIfNecessary(string $class): string
    {
        $shortClassName = Str::getShortClassName($class);
        if ($this->isInSameNamespace($class)) {
            return $shortClassName;
        }

        $namespaceNode = $this->getNamespaceNode();

        $targetIndex = null;
        $addLineBreak = false;
        $lastUseStmtIndex = null;
        foreach ($namespaceNode->stmts as $index => $stmt) {
            if ($stmt instanceof Node\Stmt\Use_) {
                // I believe this is an array to account for use statements with {}
                foreach ($stmt->uses as $use) {
                    $alias = $use->alias ? $use->alias->name : $use->name->getLast();

                    // the use statement already exists? Don't add it again
                    if ($class === (string) $use->name) {
                        return $alias;
                    }

                    if ($alias === $shortClassName) {
                        // we have a conflicting alias!
                        // to be safe, use the fully-qualified class name
                        // everywhere and do not add another use statement
                        return '\\'.$class;
                    }
                }

                // if $class is alphabetically before this use statement, place it before
                // only set $targetIndex the first time you find it
                if (null === $targetIndex && Str::areClassesAlphabetical($class, (string) $stmt->uses[0]->name)) {
                    $targetIndex = $index;
                }

                $lastUseStmtIndex = $index;
            } elseif ($stmt instanceof Node\Stmt\Class_) {
                if (null !== $targetIndex) {
                    // we already found where to place the use statement

                    break;
                }

                // we hit the class! If there were any use statements,
                // then put this at the bottom of the use statement list
                if (null !== $lastUseStmtIndex) {
                    $targetIndex = $lastUseStmtIndex + 1;
                } else {
                    $targetIndex = $index;
                    $addLineBreak = true;
                }

                break;
            }
        }

        if (null === $targetIndex) {
            throw new \Exception('Could not find a class!');
        }

        $newUseNode = (new Builder\Use_($class, Node\Stmt\Use_::TYPE_NORMAL))->getNode();
        array_splice(
            $namespaceNode->stmts,
            $targetIndex,
            0,
            $addLineBreak ? [$newUseNode, $this->createBlankLineNode(self::CONTEXT_OUTSIDE_CLASS)] : [$newUseNode]
        );

        $this->updateSourceCodeFromNewStmts();

        return $shortClassName;
    }
197585
public function getClass($class)
    {
        $cacheKey = self::CACHE_KEY_CLASSES . strtolower($class);

        if (! $reflectionClass = $this->cache->fetch($cacheKey)) {
            $reflectionClass = new ReflectionClass($class);
            $this->cache->store($cacheKey, $reflectionClass);
        }

        return $reflectionClass;
    }