Piwik\Plugin\MetadataLoader::getPathToLicenseFile PHP Méthode

getPathToLicenseFile() public méthode

public getPathToLicenseFile ( ) : null | string
Résultat null | string
    public function getPathToLicenseFile()
    {
        $prefixPath = $this->getPathToPluginFolder() . '/';
        $licenseFiles = array('LICENSE', 'LICENSE.md', 'LICENSE.txt');
        foreach ($licenseFiles as $licenseFile) {
            $pathToLicense = $prefixPath . $licenseFile;
            if (is_file($pathToLicense) && is_readable($pathToLicense)) {
                return $pathToLicense;
            }
        }
        return null;
    }

Usage Example

Exemple #1
0
 public function showLicense()
 {
     $pluginName = Common::getRequestVar('pluginName', null, 'string');
     $metadata = new Plugin\MetadataLoader($pluginName);
     $license_file = $metadata->getPathToLicenseFile();
     $license = 'No license file found for this plugin.';
     if (!empty($license_file)) {
         $license = file_get_contents($license_file);
         $license = nl2br($license);
     }
     $view = $this->configureView('@CorePluginsAdmin/license');
     $view->pluginName = $pluginName;
     $view->license = $license;
     return $view->render();
 }