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";