Get plugin types.

@param string $pattern
The plugin type search pattern.
@param string $plugin_path
The plugin path after the /src directory.

@return array
An array of plugin type class names, keyed by type identifier.
19214
protected function getPluginTypes($pattern, $plugin_path)
    {
        $types = [];
        $project_root = ProjectX::projectRoot();

        foreach ($this->getInstalledPluginNamespaces() as $name => $namespace) {
            $plugin_dir = "$project_root/vendor/$name";

            if (!file_exists($plugin_dir)) {
                continue;
            }
            $plugin_dir = "$plugin_dir/src";

            if (isset($plugin_path)) {
                $plugin_dir = "$plugin_dir/$plugin_path";
            }

            if (!file_exists($plugin_dir)) {
                continue;
            }

            $classes = (new PhpClassDiscovery)
                ->setSearchPattern($pattern)
                ->addSearchLocation($plugin_dir)
                ->discover();

            foreach ($classes as $classname) {
                if (!class_exists($classname)) {
                    continue;
                }

                $types[$classname::getTypeId()] = $classname;
            }
        }

        return $types;
    }
739249
public function getPluginNamespaces()
    {
        $classNames = [];

        foreach ($this->getVendorAndPluginNames() as $vendorName => $vendorList) {
            foreach ($vendorList as $pluginName => $pluginPath) {
                $namespace = '\\'.$vendorName.'\\'.$pluginName;
                $namespace = Str::normalizeClassName($namespace);
                $classNames[$namespace] = $pluginPath;
            }
        }

        return $classNames;
    }
955646
private static function pluginFolderPaths($plugins, $folder_path)
    {
        $paths = [];

        foreach ($plugins as $path) {
            $iterator = new \DirectoryIterator($path);

            /** @var \DirectoryIterator $directory */
            foreach ($iterator as $directory) {
                if (!$directory->isDir() || $directory->isDot()) {
                    continue;
                }

                // Path to the languages folder
                $lang_path = $directory->getPathName() . '/' . $folder_path;

                // If this folder exists, add it to the list of paths
                if (file_exists($lang_path)) {
                    $paths []= $lang_path;
                }
            }
        }
        return $paths;
    }
872335
public static Class<?> getPluginClass(final String pluginClass, final File pluginDir,
      final List<String> extLibClassPaths, ClassLoader parentClassLoader) {

    URLClassLoader urlClassLoader =
        getURLClassLoader(pluginDir, extLibClassPaths, parentClassLoader);

    return getPluginClass(pluginClass, urlClassLoader);
  }
161086
private static function findClasses($path)
    {
        $contents = file_get_contents($path);
        try {
        	//$nbResults = preg_match_all('{\b(?:class|interface|trait)\b}i', $contents);
        	//$nbResults = preg_match_all('{\b(?:class)\b}i', $contents, $results, PREG_OFFSET_CAPTURE);
        	
        	
        	/*$nbResults = preg_match_all('{\b(?:class)\b}i', $contents);
            if ($nbResults == 0) {
                return array();
            }*/
        	
            // Let's trim the content after the last "class" keyword line.
            $classKeywordPos = strrpos($contents, 'class');
            if ($classKeywordPos === false) {
            	return array();
            }
            //$classKeywordPos = $results[0][count($results[0])-1][1];
            
            // Jump 2 newlines after the last class keyword.
            if (strlen($contents) > $classKeywordPos+6) {
	            $newLinePos = strpos($contents, "\n", $classKeywordPos+6);
	            if ($newLinePos) {
		            $newLinePos = strpos($contents, "\n", $newLinePos+1);
		            if ($newLinePos) {
		            	$contents = substr($contents, 0, $newLinePos);
		            }
	            }
            }
            
            // Let's ignore any warning because we are cutting in the middle of a PHP file and we might cut in a 
            // comment.
            $currentErrorReporting = error_reporting(E_ALL & ~E_COMPILE_WARNING);
            $tokens = token_get_all($contents);
            error_reporting($currentErrorReporting);
        } catch (\Exception $e) {
            throw new \RuntimeException('Could not scan for classes inside '.$path.": \n".$e->getMessage(), 0, $e);
        }
        $T_TRAIT  = version_compare(PHP_VERSION, '5.4', '<') ? -1 : T_TRAIT;

        $classes = array();

        $namespace = '';
       	
        for ($i = 0, $max = count($tokens); $i < $max; $i++) {
            $token = $tokens[$i];

            if (is_string($token)) {
                continue;
            }

            $class = '';

            switch ($token[0]) {
                case T_NAMESPACE:
                    $namespace = '';
                    // If there is a namespace, extract it
                    while (($t = $tokens[++$i]) && is_array($t)) {
                        if (in_array($t[0], array(T_STRING, T_NS_SEPARATOR))) {
                            $namespace .= $t[1];
                        }
                    }
                    $namespace .= '\\';
                    break;
                case T_CLASS:
                //case T_INTERFACE:
                //case $T_TRAIT:
                    // Find the classname
            		
                    while (($t = $tokens[++$i]) && is_array($t)) {
                    	if (T_STRING === $t[0]) {
                            $class .= $t[1];
                        } elseif ($class !== '' && T_WHITESPACE == $t[0]) {
                            break;
                        }
                    }

                    $classes[] = ltrim($namespace . $class, '\\');
                    /*if ($nbResults == 1) {
                    	// Optim: if there is only one "class" keyword in the file, there is only one class, and we have it!
                    	return $classes;
                    }*/
                    break;
                default:
                    break;
            }
        }
        

        return $classes;
    }
946705
private static function findClasses($path)
    {
        $contents = file_get_contents($path);
        $tokens = token_get_all($contents);
        $classes = [];
        $namespace = '';
        for ($i = 0; isset($tokens[$i]); ++$i) {
            $token = $tokens[$i];
            if (!isset($token[1])) {
                continue;
            }
            $class = '';
            switch ($token[0]) {
                case T_NAMESPACE:
                    $namespace = '';
                    // If there is a namespace, extract it
                    while (isset($tokens[++$i][1])) {
                        if (in_array($tokens[$i][0], array(T_STRING, T_NS_SEPARATOR))) {
                            $namespace .= $tokens[$i][1];
                        }
                    }
                    $namespace .= '\\';
                    break;
                case T_CLASS:
                case T_INTERFACE:
                case T_TRAIT:
                    // Skip usage of ::class constant
                    $isClassConstant = false;
                    for ($j = $i - 1; $j > 0; --$j) {
                        if (!isset($tokens[$j][1])) {
                            break;
                        }
                        if (T_DOUBLE_COLON === $tokens[$j][0]) {
                            $isClassConstant = true;
                            break;
                        } elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
                            break;
                        }
                    }
                    if ($isClassConstant) {
                        break;
                    }
                    // Find the classname
                    while (isset($tokens[++$i][1])) {
                        $t = $tokens[$i];
                        if (T_STRING === $t[0]) {
                            $class .= $t[1];
                        } elseif ('' !== $class && T_WHITESPACE === $t[0]) {
                            break;
                        }
                    }
                $classes[] = ltrim($namespace . $class, '\\');
                    break;
                default:
                    break;
            }
        }

        return $classes;
    }
956014
public static function get_plugin_list($plugintype) {
        self::init();

        if (!isset(self::$plugins[$plugintype])) {
            return array();
        }
        return self::$plugins[$plugintype];
    }
247135
def GetPlugins(cls):
    
    for plugin_name, plugin_class in iter(cls._plugin_classes.items()):
      yield plugin_name, plugin_class
676956
def discover_plugin(module_path)
        plugin = plugin_classes.find {|c| c.send(:valid_module_dir?, module_path) }
        raise NoSuitablePluginFoundException unless plugin
        plugin
     end
1055729
private function getPluginClassForPath(Codebase $codebase, $path, $must_extend)
    {
        $file_storage = $codebase->createFileStorageForPath($path);
        $file_to_scan = new FileScanner($path, $this->shortenFileName($path), true);
        $file_to_scan->scan(
            $codebase,
            $file_storage
        );

        $declared_classes = ClassLikeAnalyzer::getClassesForFile($codebase, $path);

        if (!count($declared_classes)) {
            throw new \InvalidArgumentException(
                'Plugins must have at least one class in the file - ' . $path . ' has ' .
                    count($declared_classes)
            );
        }

        $fq_class_name = reset($declared_classes);

        if (!$codebase->classlikes->classExtends(
            $fq_class_name,
            $must_extend
        )
        ) {
            throw new \InvalidArgumentException(
                'This plugin must extend ' . $must_extend . ' - ' . $path . ' does not'
            );
        }

        /**
         * @var class-string<T>
         */
        return $fq_class_name;
    }
865929
public function findTemplates(string $path, string $pattern = null, string $format = 'twig')
    {
        // Use glob() if possible
        if (false === strpos($path, '/**/') && (\defined('GLOB_BRACE') || false === strpos($path, '{'))) {
            $templates = glob(rtrim($path, '/').'/*.{'.$format.'}', \defined('GLOB_BRACE') ? GLOB_BRACE : 0);

            return null === $pattern ? $templates : preg_grep('$'.$pattern.'$', $templates);
        }

        $pattern = rtrim($path, '/').(null === $pattern ? '' : $pattern).'/*.{'.$format.'}';

        $finder = new Finder();
        $regex = Glob::toRegex($pattern);

        // All files in the given template folder
        $filesIterator = $finder->files()->followLinks()->sortByName()->in(\dirname($pattern));

        // Match the actual regex and filter the files
        $filesIterator = $filesIterator->filter(
            function (\SplFileInfo $info) use ($regex) {
                $path = $info->getPathname();

                return preg_match($regex, $path) && $info->isFile();
            }
        );

        $files = iterator_to_array($filesIterator);

        return array_keys($files);
    }
320366
final public function get_whitelists(string $plugindir) : array {
        $filters = [];

        if (!empty($plugindir)) {
            $plugindir .= "/";
        }

        foreach ($this->whitelistfolders as $folder) {
            $filters[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
        }

        foreach ($this->whitelistfiles as $file) {
            $filters[] = html_writer::tag('file', "{$plugindir}{$file}");
        }

        return $filters;
    }
257667
public function getPlugin($plugin_name, $plugin_type)
    {
        $function = null;
        if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
            if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) {
                $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
            } else if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) {
                $this->template->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type];
                $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
            }
        } else {
            if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) {
                $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
            } else if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) {
                $this->template->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type];
                $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
            }
        }
        if (isset($function)) {
            if ($plugin_type == 'modifier') {
                $this->modifier_plugins[$plugin_name] = true;
            }
            return $function;
        }
        // loop through plugin dirs and find the plugin
        $function = 'smarty_' . $plugin_type . '_' . $plugin_name;
        $file = $this->smarty->loadPlugin($function, false);

        if (is_string($file)) {
            if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
                $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file;
                $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function;
            } else {
                $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file;
                $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function;
            }
            if ($plugin_type == 'modifier') {
                $this->modifier_plugins[$plugin_name] = true;
            }
            return $function;
        }
        if (is_callable($function)) {
            // plugin function is defined in the script
            return $function;
        }
        return false;
    }
374849
def get_plugin_class(self, plugin_type, plugin_name):
        """"""
        plugin = self._get_plugin_type(plugin_type)
        return plugin.get_plugin_class(plugin_name)
997367
protected function _paths($plugin = null, $cached = true)
    {
        if ($cached === true) {
            if ($plugin === null && !empty($this->_paths)) {
                return $this->_paths;
            }
            if ($plugin !== null && isset($this->_pathsForPlugin[$plugin])) {
                return $this->_pathsForPlugin[$plugin];
            }
        }
        $templatePaths = App::path(static::NAME_TEMPLATE);
        $pluginPaths = $themePaths = [];
        if (!empty($plugin)) {
            for ($i = 0, $count = count($templatePaths); $i < $count; $i++) {
                $pluginPaths[] = $templatePaths[$i] . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR;
            }
            $pluginPaths = array_merge($pluginPaths, App::path(static::NAME_TEMPLATE, $plugin));
        }

        if (!empty($this->theme)) {
            $themePaths = App::path(static::NAME_TEMPLATE, Inflector::camelize($this->theme));

            if ($plugin) {
                for ($i = 0, $count = count($themePaths); $i < $count; $i++) {
                    array_unshift($themePaths, $themePaths[$i] . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR);
                }
            }
        }

        $paths = array_merge(
            $themePaths,
            $pluginPaths,
            $templatePaths,
            [dirname(__DIR__) . DIRECTORY_SEPARATOR . static::NAME_TEMPLATE . DIRECTORY_SEPARATOR]
        );

        if ($plugin !== null) {
            return $this->_pathsForPlugin[$plugin] = $paths;
        }

        return $this->_paths = $paths;
    }
445720
protected <T> Class<T> getType(String typeName) throws PluginRepositoryException {
        try {
            return (Class<T>) classLoader.loadClass(typeName.trim());
        } catch (ClassNotFoundException | LinkageError e) {
            // Catching class loader related errors for logging a message which plugin class
            // actually caused the problem.
            throw new PluginRepositoryException("Cannot find or load class " + typeName, e);
        }
    }
704138
protected function getPluginClasses($refresh = false)
    {
        if ($refresh || !$this->pluginClasses) {
            $this->pluginClasses = [];
            $files = $this->globByDirs($this->dirs, '/Plugin.php');
            foreach ($files as $file) {
                $class = $this->guessClassName($file);

                $name = explode('\\', $class)[1];
                $name = $this->dash($name);

                $this->pluginClasses[$name] = $class;
            }
            ksort($this->pluginClasses);
        }

        return $this->pluginClasses;
    }