/
var
/
www
/
html
/
sugardemo
/
src
/
Security
/
ModuleScanner
/
Upload File
HOME
<?php declare(strict_types=1); /* * Your installation or use of this SugarCRM file is subject to the applicable * terms available at * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/. * If you do not agree to all of the applicable terms or do not have the * authority to bind the entity as an authorized representative, then do not * install or use this SugarCRM file. * * Copyright (C) SugarCRM Inc. All rights reserved. */ namespace Sugarcrm\Sugarcrm\Security\ModuleScanner; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; use PhpParser\ParserFactory; use PhpParser\PrettyPrinter\Standard; final class SweetTranslator { public static function translate(string $code): ?string { $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); $traverser = new NodeTraverser(); $traverser->addVisitor(new NameResolver(null, ['replaceNodes' => false])); $traverser->addVisitor(new TranslateVisitor()); try { $stmts = $parser->parse($code); } catch (\Throwable $error) { return null; } $stmts = $traverser->traverse($stmts); $prettyPrinter = new Standard(); return $prettyPrinter->prettyPrintFile($stmts); } public static function patch(string $code): ?string { $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); $traverser = new NodeTraverser(); $traverser->addVisitor(new NameResolver(null, ['replaceNodes' => false])); $traverser->addVisitor(new PatchVisitor()); try { $stmts = $parser->parse($code); } catch (\Throwable $error) { return null; } $stmts = $traverser->traverse($stmts); $prettyPrinter = new Standard(); return $prettyPrinter->prettyPrintFile($stmts); } }