|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
|
|
|
|
|
|
|
|
|
use App\Services\UserCopy\UserCopyManifest;
|
|
|
|
|
|
|
|
|
|
$root = dirname(__DIR__);
|
|
|
|
|
$assert = static function (bool $condition, string $message): void {
|
|
|
|
|
if (!$condition) {
|
|
|
|
|
throw new RuntimeException($message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$manifest = UserCopyManifest::load();
|
|
|
|
|
$entries = [];
|
|
|
|
|
foreach ($manifest['entries'] as $entry) {
|
|
|
|
|
$entries[(string) $entry['key']] = $entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$files = [];
|
|
|
|
|
$templateRoot = $root . '/resources/views/venix';
|
|
|
|
|
$iterator = new RecursiveIteratorIterator(
|
|
|
|
|
new RecursiveDirectoryIterator(
|
|
|
|
|
$templateRoot,
|
|
|
|
|
FilesystemIterator::SKIP_DOTS
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
foreach ($iterator as $file) {
|
|
|
|
|
if ($file->isFile()
|
|
|
|
|
&& $file->getExtension() === 'tpl'
|
|
|
|
|
&& !str_starts_with(
|
|
|
|
|
$file->getPathname(),
|
|
|
|
|
$templateRoot . '/admin/'
|
|
|
|
|
)) {
|
|
|
|
|
$files[] = $file->getPathname();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sort($files, SORT_STRING);
|
|
|
|
|
|
|
|
|
|
$bindingCount = 0;
|
|
|
|
|
$boundGroups = [];
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
|
$source = file_get_contents($file);
|
|
|
|
|
$relative = substr($file, strlen($root) + 1);
|
|
|
|
|
$assert(is_string($source), 'Cannot read ' . $relative . '.');
|
|
|
|
|
preg_match_all(
|
|
|
|
|
'/\{user_copy_binding\b[^}]*\}/',
|
|
|
|
|
$source,
|
|
|
|
|
$calls,
|
|
|
|
|
PREG_OFFSET_CAPTURE
|
|
|
|
|
);
|
|
|
|
|
foreach ($calls[0] as [$call, $offset]) {
|
|
|
|
|
$bindingCount++;
|
|
|
|
|
$strict = preg_match(
|
|
|
|
|
'/\A\{user_copy_binding\s+key=([\'\"])([a-z0-9][a-z0-9._-]{1,190})\1\s*\}\z/D',
|
|
|
|
|
$call,
|
|
|
|
|
$match
|
|
|
|
|
);
|
|
|
|
|
$assert($strict === 1,
|
|
|
|
|
'Copy binding must use one literal key in ' . $relative . '.');
|
|
|
|
|
$key = (string) $match[2];
|
|
|
|
|
$assert(isset($entries[$key]),
|
|
|
|
|
'Copy binding references an unknown key in ' . $relative . ': ' . $key);
|
|
|
|
|
$surface = (string) $entries[$key]['editor_surface'];
|
|
|
|
|
$adminBindingAllowed = $surface === 'admin'
|
|
|
|
|
&& (str_starts_with((string) $entries[$key]['page'], 'auth.')
|
|
|
|
|
|| in_array($key, [
|
|
|
|
|
'public.shell.nav.login',
|
|
|
|
|
'public.shell.nav.register',
|
|
|
|
|
], true));
|
|
|
|
|
$assert(in_array($surface, ['page', 'shared'], true)
|
|
|
|
|
|| $adminBindingAllowed,
|
|
|
|
|
'Non-visible dynamic copy cannot be bound to a page element: '
|
|
|
|
|
. $key);
|
|
|
|
|
$boundGroups[(string) $entries[$key]['editor_group']] = true;
|
|
|
|
|
|
|
|
|
|
$tagStart = strrpos(substr($source, 0, (int) $offset), '<');
|
|
|
|
|
$assert($tagStart !== false,
|
|
|
|
|
'Copy binding is outside an HTML start tag in ' . $relative . '.');
|
|
|
|
|
$prefix = substr(
|
|
|
|
|
$source,
|
|
|
|
|
(int) $tagStart,
|
|
|
|
|
(int) $offset - (int) $tagStart
|
|
|
|
|
);
|
|
|
|
|
$assert(preg_match(
|
|
|
|
|
'/\A<(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)\b/i',
|
|
|
|
|
$prefix
|
|
|
|
|
) !== 1,
|
|
|
|
|
'Copy binding cannot target a void element in ' . $relative . '.');
|
|
|
|
|
$assert(!str_contains($prefix, '>')
|
|
|
|
|
&& substr_count($prefix, '"') % 2 === 0
|
|
|
|
|
&& substr_count($prefix, "'") % 2 === 0,
|
|
|
|
|
'Copy binding is inside an attribute value in ' . $relative . '.');
|
|
|
|
|
$after = substr($source, (int) $offset + strlen($call));
|
|
|
|
|
$assert(preg_match('/\A\s*\/?>/', $after) === 1,
|
|
|
|
|
'Copy binding must be the final start-tag attribute in '
|
|
|
|
|
. $relative . '.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ([
|
|
|
|
|
'auth.login',
|
|
|
|
|
'auth.password',
|
|
|
|
|
'auth.register',
|
|
|
|
|
'cloud.backups',
|
|
|
|
|
'cloud.deploy',
|
|
|
|
|
'cloud.detail',
|
|
|
|
|
'cloud.instances',
|
|
|
|
|
'cloud.invoice_detail',
|
|
|
|
|
'cloud.invoices',
|
|
|
|
|
'cloud.isos',
|
|
|
|
|
'cloud.keys',
|
|
|
|
|
'cloud.reinstall',
|
|
|
|
|
'cloud.snapshots',
|
|
|
|
|
'cloud.traffic',
|
|
|
|
|
'cloud.vpcs',
|
|
|
|
|
'common.shared',
|
|
|
|
|
'legal.privacy',
|
|
|
|
|
'legal.terms',
|
|
|
|
|
'public.error',
|
|
|
|
|
'public.home',
|
|
|
|
|
'shell.public',
|
|
|
|
|
'shell.user',
|
|
|
|
|
'user.account',
|
|
|
|
|
'user.invite',
|
|
|
|
|
'user.recharge',
|
|
|
|
|
'user.tickets',
|
|
|
|
|
] as $requiredGroup) {
|
|
|
|
|
$assert(isset($boundGroups[$requiredGroup]),
|
|
|
|
|
'Public/shared copy group lacks safe bindings: ' . $requiredGroup);
|
|
|
|
|
}
|
|
|
|
|
$assert($bindingCount >= 810,
|
|
|
|
|
'User-page copy binding coverage unexpectedly regressed.');
|
|
|
|
|
|
|
|
|
|
echo "User copy binding interface contracts passed.\n";
|