Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EP-Klassen berücksichtigen #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 51 additions & 37 deletions lib/ExtensionPoint/ExtensionPointParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@

use Cheatsheet\ParserAbstract;
use Cheatsheet\Str;
use SplFileInfo;
use rex_file;
use rex_path;

use function count;
use function strlen;

use const DIRECTORY_SEPARATOR;
use const PREG_OFFSET_CAPTURE;
use const PREG_SET_ORDER;

class ExtensionPointParser extends ParserAbstract
{
const PATTERN = '
public const PATTERN = '
@
(?<complete>
\s*
rex_extension::registerPoint\(
\s*
new\s*\\\?rex_extension_point\(
new\s*\\\?rex_extension_point(_(?<class>[a-z0-9_]+))?\(
(?<params>.*?)
\)
\s*
Expand All @@ -33,57 +41,63 @@ class ExtensionPointParser extends ParserAbstract
)
@isx';


public function parse()
{
$results = [];

/** @var SplFileInfo $file */
/** @var \SplFileInfo $file */
foreach ($this->iterator as $file) {
$filepath = $file->getPathname();
$content = \rex_file::get($filepath);
$content = rex_file::get($filepath);

$path = explode(DIRECTORY_SEPARATOR, str_replace(\rex_path::src(), '', $filepath));
$path = explode(DIRECTORY_SEPARATOR, str_replace(rex_path::src(), '', $filepath));
$cacheFilename = 'core.cache';
if(isset($path[0]) && $path[0] === 'addons' && isset($path[2]) && $path[2] === 'plugins') {
if (isset($path[0]) && 'addons' == $path[0] && isset($path[2]) && 'plugins' == $path[2]) {
$cacheFilename = $path[1] . '.' . $path[3] . '.cache';
} elseif(isset($path[0]) && $path[0] === 'addons' && isset($path[1]) && $path[1] !== '') {
} elseif (isset($path[0]) && 'addons' == $path[0] && isset($path[1]) && '' != $path[1]) {
$cacheFilename = $path[1] . '.cache';
}

preg_match_all(self::PATTERN, $content, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
foreach ($matches as $match) {
$paramsAsString = $match['params'][0];
$paramsAsArray = Str::parseAsArray($paramsAsString);

list($before) = str_split($content, $match['complete'][1]);
$lineNumber = strlen($before) - strlen(str_replace("\n", '', $before)) + 1;

$complete = trim($match['complete'][0], "\t\n\r\0\x0B");
$spaces = strspn($complete, " ");
if ($spaces <= 3) {
$complete = trim($complete);
} else {
$complete = implode("\n", array_map(function($line) use ($spaces) {
return substr($line, $spaces);
}, explode("\n", $complete)));
}
if (count($matches)) {
// dump($matches);
foreach ($matches as $match) {
$paramsAsString = $match['params'][0];
$paramsAsArray = Str::parseAsArray($paramsAsString);

$results[] = [
'internal::cacheFilename' => $cacheFilename,
'point' => $complete,
'name' => trim($paramsAsArray[0], "'"),
'subject' => ($paramsAsArray[1] ?? ''),
'params' => ($paramsAsArray[2] ?? ''),
'readonly' => (!isset($paramsAsArray[3]) || (($paramsAsArray[3] === 'false' || $paramsAsArray[3] === '0')) ? 'false' : $paramsAsArray[3]),
'filepath' => $filepath,
'filename' => $file->getFilename(),
'ln' => $lineNumber,
];
if (-1 < $match['class'][1]) {
array_unshift($paramsAsArray, strtoupper($match['class'][0]));
}

[$before] = str_split($content, $match['complete'][1]);
$lineNumber = strlen($before) - strlen(str_replace("\n", '', $before)) + 1;

$complete = trim($match['complete'][0], "\t\n\r\0\x0B");
$spaces = strspn($complete, ' ');
if ($spaces <= 3) {
$complete = trim($complete);
} else {
$complete = implode("\n", array_map(static function ($line) use ($spaces) {
return substr($line, $spaces);
}, explode("\n", $complete)));
}

$results[] = [
'internal::cacheFilename' => $cacheFilename,
'point' => $complete,
'name' => trim($paramsAsArray[0], "'"),
'subject' => ($paramsAsArray[1] ?? ''),
'params' => ($paramsAsArray[2] ?? ''),
'readonly' => (!isset($paramsAsArray[3]) || (isset($paramsAsArray[3]) && ('false' == $paramsAsArray[3] || '0' == $paramsAsArray[3])) ? 'false' : $paramsAsArray[3]),
'filepath' => $filepath,
'filename' => $file->getFilename(),
'ln' => $lineNumber,
];
}
}
}

if (count($results) > 0) {
if (count($results)) {
usort($results, '\Cheatsheet\Arr::sortByName');
}

Expand Down
Loading