📜 ⬆️ ⬇️

Switch to web application source from browser in one click


When working with web applications, it is sometimes difficult only to determine by the URL which controller / module / script handles the request. This is especially true when a new employee appears in the development team, and he has to study the application architecture and routing configs.

In principle, this problem is solved if in a dev-environment some plug-in / module is connected to the application (for example, Profiler in Symfony) that displays the file name or controller class, or if some kind of debugger is used. But still, it is much more convenient to go to the source directly from the page in the browser. About how we implemented it in AdMe, read under the cut.

It all started with the fact that I, not finding ready-made solutions, decided to write a small Profiler plugin for ZendFramework 1 (it is used in our company's projects). In the dev environment, this plugin adds a fixed block at the bottom of the page containing some useful information, including the name of the controller and the action. For AJAX, this information is written in HTTP headers.

The idea was developed by my head PavelRadaev , proposing to use an interesting tool LinCastor , developed by a friend onflapp , for which he has a lot of respect. The tool allows you to define your own URL scheme (for example, znd-file: //) and specify the application that will process such requests, and also, importantly, allows you to remove the prefixes of this scheme when passing the URL to the application. The tool is written for Mac OS, but I think for other OS you can find (or develop) an analogue.
')
So, we defined the znd-file URL scheme, specified the application for processing Zend Studio, and set the prefix removal.
As a result, the URL of the form
znd-file:///Users/linar/Desktop/dev/test.php
converted to
file:///Users/linar/Desktop/dev/test.php
and transferred to Zend Studio, which, in turn, perfectly opens the files at this URL.



Now it remains to add the link to the controller file in the Profiler plugin so that the file opens normally for all developers in their local version. In our case, it turned out to be easy, because for all developers, local versions of all projects were in the same working folder in the subfolders with the project domain name. Thus, we all just created a symbolic link / phpdev to this working folder, and the links to the files began to look like
znd-file:///phpdev/project.domain/src/AdMe/Article/Controller/Index.php
and voila, navigating to the controller file from the browser works. It was pleasantly surprised that Zend Studio opens the files within the project, despite the fact that it opens through the URL and also through a symbolic link.

Also in the plugin links have been added to all used views. As it looks, can be seen in the picture above. It turned out to be so convenient that it was decided in the near future to write the processing of ajax request headers either using JavaScript / jQuery tools, or even through a browser plugin.

Of course, in one degree or another, a similar tool can be implemented for other IDE and other scripting programming languages ​​(and if you are perverted, then for the compiled ones, you just need to correctly configure the links to the sources).

Source: https://habr.com/ru/post/180637/


All Articles