- create a route for accepting reqeust to open
- create a controller and call
launchEditor()
from out there - fix link in twig/html
- it requires working server to accept requests, so launch the server.
note
It uses ??
-operator so it's PHP7.0+
<?php | |
/** | |
* launchEditor | |
* @see the reference is - https://github.com/yyx990803/launch-editor | |
* @param null $filename | |
* @param null $lineNumber | |
* @return string|null | |
*/ | |
function launchEditor($filename = null, $lineNumber = null){ | |
/** @see https://github.com/yyx990803/launch-editor for more */ | |
function runPowerShellCommand($cmd){ | |
return shell_exec('powershell -Command "' . $cmd . '"'); | |
} | |
function guessEditor(){ | |
$COMMON_EDITORS_WIN = [ | |
'Brackets.exe', | |
'Code.exe', | |
'atom.exe', | |
'sublime_text.exe', | |
'notepad++.exe', | |
'clion.exe', | |
'clion64.exe', | |
'idea.exe', | |
'idea64.exe', | |
'phpstorm.exe', | |
'phpstorm64.exe', | |
'pycharm.exe', | |
'pycharm64.exe', | |
'rubymine.exe', | |
'rubymine64.exe', | |
'webstorm.exe', | |
'webstorm64.exe' | |
]; | |
# getting list of processes, i.e. "exporer.exe \nchrome.exe \nphpstorm.exe \n" | |
$output = runPowerShellCommand('Get-WmiObject Win32_Process | select path'); | |
$runningProcesses = explode("\n", $output); | |
foreach ($runningProcesses as $fullPath) { | |
$fullPath = trim($fullPath, " \r"); # in case if we have \r\n line separators | |
if (!$fullPath) | |
continue; # sometimes line's empty | |
$baseName = basename($fullPath); | |
# if file's in list of editors - return full executable path. | |
if (in_array($baseName, $COMMON_EDITORS_WIN)) { | |
return $fullPath; | |
} | |
} | |
return ''; | |
} | |
$editor = guessEditor(); | |
$filename = $filename ?? $_GET['filename'] ?? ''; | |
$lineNumber = $lineNumber ?? $_GET['line'] ?? 1; | |
if (!($editor && $filename)) | |
return null; | |
// $commandLine = sprintf('cmd.exe /C "%s" --line %s "%s"', | |
$commandLine = sprintf('"%s" --line %s "%s"', | |
$editor, | |
$lineNumber, | |
$filename | |
); | |
system($commandLine); | |
return $commandLine; | |
} | |
public function openEditorAction(Application $app) { | |
# launching only in dev environment | |
if (PHP_OS !== "WINNT") | |
throw new NotFoundHttpException("No such Page ;)"); | |
$launched = launchEditor(); | |
return "Launched $launched."; | |
} |
<abbr title="{{ exception.class_fqn|default('unknown') }}">{{ exception.class_name|default('unknown') }}</abbr> | |
</code> in <code> | |
{# simply calling javascript with ajax request #} | |
<abbr title="{{ exception.file_path|default('unknown') }}" onclick="url=('//SITE/_open-editor?filename={{ exception.file_path|default('unknown')|url_encode }}&line={{ exception.object.line|default(1) }}'); var xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.send(null); return false;"> |