<?php
declare(strict_types=1);
namespace Plesk\Wappspector\Matchers;
use League\Flysystem\Filesystem;
use Plesk\Wappspector\MatchResult\EmptyMatchResult;
use Plesk\Wappspector\MatchResult\MatchResultInterface;
use Plesk\Wappspector\MatchResult\Yii as MatchResult;
class Yii implements MatcherInterface
{
private const VERSIONS = [
[
'file' => 'yii',
'versionFile' => '/vendor/yiisoft/yii2/BaseYii.php',
'versionRegexp' => '/public static function getVersion\(\)\s*\{\s*return \'([^\']+)\';\s*}/',
],
[
'file' => 'framework/yiic',
'versionFile' => '/framework/YiiBase.php',
'versionRegexp' => '/public static function getVersion\(\)\s*\{\s*return \'([^\']+)\';\s*}/',
],
];
public function match(Filesystem $fs, string $path): MatchResultInterface
{
$path = rtrim($path, '/');
foreach (self::VERSIONS as $version) {
if (!$fs->fileExists($path . '/' . $version['file'])) {
continue;
}
return new MatchResult($path, $this->detectVersion($fs, $path, $version));
}
return new EmptyMatchResult();
}
private function detectVersion(Filesystem $fs, string $path, array $versionInfo): ?string
{
$version = null;
$yii2VersionFile = $path . $versionInfo['versionFile'];
if ($fs->fileExists($yii2VersionFile)) {
preg_match($versionInfo['versionRegexp'], $fs->read($yii2VersionFile), $matches);
if (isset($matches[1])) {
$version = $matches[1];
}
}
return $version;
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| CakePHP.php | File | 1.02 KB | 0644 |
|
| CodeIgniter.php | File | 1.14 KB | 0644 |
|
| Composer.php | File | 1.09 KB | 0644 |
|
| DotNet.php | File | 1.05 KB | 0644 |
|
| Drupal.php | File | 1.63 KB | 0644 |
|
| Duda.php | File | 1.72 KB | 0644 |
|
| Joomla.php | File | 3.79 KB | 0644 |
|
| Laravel.php | File | 1.9 KB | 0644 |
|
| MatcherInterface.php | File | 343 B | 0644 |
|
| NodeJs.php | File | 866 B | 0644 |
|
| Php.php | File | 1.07 KB | 0644 |
|
| Prestashop.php | File | 1.41 KB | 0644 |
|
| Python.php | File | 742 B | 0644 |
|
| Ruby.php | File | 713 B | 0644 |
|
| Sitejet.php | File | 976 B | 0644 |
|
| Siteplus.php | File | 1.79 KB | 0644 |
|
| Sitepro.php | File | 980 B | 0644 |
|
| Symfony.php | File | 905 B | 0644 |
|
| Typo3.php | File | 1.77 KB | 0644 |
|
| UpLevelMatcherTrait.php | File | 982 B | 0644 |
|
| WebPresenceBuilder.php | File | 1.97 KB | 0644 |
|
| Wordpress.php | File | 1.48 KB | 0644 |
|
| Yii.php | File | 1.64 KB | 0644 |
|