获取插件路径和类名
返回值为一个数组
第一项为插件路径,第二项为类名

@access public
@param string $pluginName 插件名
@param string $path 插件目录
@return array
@throws \Exception
11423
public static function portal($pluginName, $path) {
        $className = ucfirst($pluginName);
        switch (true) {
            case file_exists($pluginFileName = $path  . $pluginName . '/'.$className.'.php'):  //file_exists($pluginFileName = $path . '/' . $pluginName . '/Plugin.php'):
                $className = $className;
                break;
            case file_exists($pluginFileName = $path  . $pluginName . '.php')://file_exists($pluginFileName = $path . '/' . $pluginName . '.php'):
                $className = $className;
                break;
            default:
                throw new \Exception('Missing Plugin ' . $pluginName, 404);
        }

        return [$pluginFileName, $className];
    }
40521
public static function ls($path): array
    {
        $list = [];

        try {
            /*** class create new DirectoryIterator Object ***/
            foreach (new DirectoryIterator($path) as $item) {
                $list[] = $item;
            }
            /*** if an exception is thrown, catch it here ***/
        } catch (\Exception $e) {
            throw new FileNotFoundException($path . ' 没有任何内容');
        }

        return $list;
    }
140774
private function get_plugin_files( $path ) {
		$folder = dirname( $this->get_absolute_path( $path ) );

		// Return single file plugins immediately, to avoid iterating over the
		// entire plugins folder.
		if ( WP_PLUGIN_DIR === $folder ) {
			return (array) $path;
		}

		return $this->get_files( trailingslashit( $folder ) );
	}
664897
public function getFileName($path, $filename)
	{
		if (file_exists("$path/$filename")) {
			$filename = Nette\Utils\Random::generate() . '_' . $filename;
			$filename = $this->getFileName($path, $filename);
		} else {
			$filename;
		}

		return $filename;
	}
464228
protected function get_plugin_name() {
		$path = $this->get_path();
		$array = explode('/', $path);
		unset($array[count($array) - 1]);
		unset($array[count($array) - 1]);
		return end($array) . '/' . DIRECTORY_APP_NAME;
	}
894381
public function loadPlugin($namespace, $path)
    {
        $className = $namespace.'\Plugin';
        $classPath = $path.'/Plugin.php';

        try {
            // Autoloader failed?
            if (!class_exists($className)) {
                include_once $classPath;
            }

            // Not a valid plugin!
            if (!class_exists($className)) {
                return;
            }

            $classObj = new $className($this->app);
        } catch (\Throwable $e) {
            Log::error('Plugin ' . $className . ' could not be instantiated.', [
                'message' => $e->getMessage(),
                'file' => $e->getFile(),
                'line' => $e->getLine(),
                'trace' => $e->getTraceAsString()
            ]);
            return;
        }

        $classId = $this->getIdentifier($classObj);

        /*
         * Check for disabled plugins
         */
        if ($this->isDisabled($classId)) {
            $classObj->disabled = true;
        }

        $this->plugins[$classId] = $classObj;
        $this->pathMap[$classId] = $path;

        return $classObj;
    }
906622
private function getValidPath($path)
    {
        // If `$path` is array
        if (is_array($path)) {
            return $this->getPathFromArray($path);
        }

        // If `$path` is a directory
        if (is_dir($path)) {
            $paths = glob($path . '/*.*');
            if (empty($paths)) {
                throw new EmptyDirectoryException("Configuration directory: [$path] is empty");
            }
            return $paths;
        }

        // If `$path` is not a file, throw an exception
        if (!file_exists($path)) {
            throw new FileNotFoundException("Configuration file: [$path] cannot be found");
        }
        return array($path);
    }
191949
private function getPluginDefinition(string $handle, array $pluginInfo): array
    {
        $settings = null;
        $plugin = Craft::$app->plugins->getPlugin($handle);
        if ($plugin) {
            $settings = $plugin->getSettings();
        }

        return [
          'isEnabled' => $pluginInfo['isEnabled'],
          'isInstalled' => $pluginInfo['isInstalled'],
          'settings' => $settings ? $settings->attributes : [],
        ];
    }
993211
public static function setAlias(string $alias, string $path = null)
    {
        if ($alias[0] !== '@') {
            $alias = '@' . $alias;
        }

        // Delete alias
        if (!$path) {
            unset(self::$aliases[$alias]);

            return;
        }

        // $path 不是别名，直接设置
        if ($path[0] !== '@') {
            self::$aliases[$alias] = $path;

            return;
        }

        // $path是一个别名
        if (isset(self::$aliases[$path])) {
            self::$aliases[$alias] = self::$aliases[$path];

            return;
        }

        list($root) = explode('/', $path);
        if (!isset(self::$aliases[$root])) {
            throw new \InvalidArgumentException('The set root alias does not exist，alias=' . $root);
        }

        $rootPath  = self::$aliases[$root];
        $aliasPath = str_replace($root, '', $path);

        self::$aliases[$alias] = $rootPath . $aliasPath;
    }
1261758
protected function getPluginParser($pluginName)
	{
		// Cache a new instance of this plugin's parser if there isn't one already
		if (!isset($this->pluginParsers[$pluginName]))
		{
			$pluginConfig = $this->pluginsConfig[$pluginName];
			$className = (isset($pluginConfig['className']))
			           ? $pluginConfig['className']
			           : 's9e\\TextFormatter\\Plugins\\' . $pluginName . '\\Parser';

			// Register the parser as a callback
			$this->pluginParsers[$pluginName] = [new $className($this, $pluginConfig), 'parse'];
		}

		return $this->pluginParsers[$pluginName];
	}
1048736
protected function _getNamespace($className, $pluginPath = null, $prefixPath = null)
    {
        $namespace = preg_replace('/(.*)Controller\//', '', $className);
        $namespace = preg_replace('/\//', '\\', $namespace);
        $namespace = preg_replace('/\.php/', '', $namespace);
        $prefixPath = preg_replace('/\//', '\\', Inflector::camelize($prefixPath));
        if (!$pluginPath) {
            $rootNamespace = Configure::read('App.namespace');
        } else {
            $rootNamespace = preg_replace('/\//', '\\', $pluginPath);
        }
        $namespace = [
            $rootNamespace,
            'Controller',
            $prefixPath,
            $namespace
        ];

        return implode('\\', Hash::filter($namespace));
    }
516063
public function load($pluginName, array $overrideProps = [])
	{
		// Validate the plugin name / class
		$pluginName = $this->normalizeKey($pluginName);
		$className  = 's9e\\TextFormatter\\Plugins\\' . $pluginName . '\\Configurator';

		if (!class_exists($className))
		{
			throw new RuntimeException("Class '" . $className . "' does not exist");
		}

		// Create the plugin
		$plugin = new $className($this->configurator, $overrideProps);

		// Save it
		$this->set($pluginName, $plugin);

		// Return it
		return $plugin;
	}
560997
public function _doFQLTableName($path, $token = null, $escape = false)
    {

        if (null === $token) {
            $token = $this->dotToken;
        }

        return self::__doFQLTableNameStatic($path, $token, $escape);
    }
874489
public function getDefaultInstanceConfig($pluginName)
    {
        $blockConfig = $this->blockConfigRepository->findById($pluginName);

        if (empty($blockConfig)) {
            throw new \Exception('Block config not found for ' . $pluginName); //@TODO throw custom exception class
        }

        return $blockConfig->getDefaultConfig();
    }
982824
private static function get_language_plugin_list( $path ) {
		$languages = [];

		// Try to open the given directory.
		$handle = \opendir( $path );
		if ( false === $handle ) {
			// Abort.
			return $languages; // @codeCoverageIgnore
		}

		// Read all files in directory.
		$file = \readdir( $handle );
		while ( $file ) {
			// We only want the JSON files.
			if ( '.json' === \substr( $file, -5 ) ) {
				$file_content = \file_get_contents( $path . $file );
				if ( \preg_match( '/"language"\s*:\s*((".+")|(\'.+\'))\s*,/', $file_content, $matches ) ) {
					$language_name = \substr( $matches[1], 1, -1 );
					$language_code = \substr( $file, 0, -5 );

					$languages[ $language_code ] = $language_name;
				}
			}

			// Read next file.
			$file = \readdir( $handle );
		}
		\closedir( $handle );

		// Sort translated language names according to current locale.
		\asort( $languages );

		return $languages;
	}
716633
protected function replaceNamedParameters($path, &$parameters)
    {
        $this->ensureTenancyInParameters($path, $parameters);

        return preg_replace_callback('/\{(.*?)\??\}/', function ($m) use (&$parameters) {
            if (isset($parameters[$m[1]])) {
                return Arr::pull($parameters, $m[1]);
            } elseif (isset($this->defaultParameters[$m[1]])) {
                return $this->defaultParameters[$m[1]];
            } else {
                return $m[0];
            }
        }, $path);
    }
44086
protected function _getPlgAssetUrl($path)
    {
        $isPlugin = false;
        $plgPaths = Configure::read('App.paths.plugins');
        foreach ($plgPaths as $plgPath) {
            $plgPath = ltrim(FS::clean($plgPath, '/'), '/');
            if (preg_match('(' . quotemeta($plgPath) . ')', $path)) {
                $path = str_replace($plgPath, '', $path);
                return [true, $path];
            }
        }

        foreach (Configure::read('plugins') as $name => $plgPath) {
            $plgPath = FS::clean($plgPath, '/');
            if (preg_match('(' . quotemeta($plgPath) . ')', $path)) {
                $path = Str::low($name) . '/' . str_replace($plgPath, '', $path);
                return [true, $path];
            }
        }

        return [$isPlugin, $path];
    }