Download the PHP package fuko-php/open without Composer
On this page you can find all versions of the php package fuko-php/open. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fuko-php/open
More information about fuko-php/open
Files in fuko-php/open
Informations about the package open
Fuko\Open
Fuko\Open is a small PHP library that helps you to generate links for opening referenced files directly in your IDE or editor, or have it linked to an online repository.
Basic Use
At the heart of it is all is the \Fuko\Open\Link
class, which is really simple: it
takes a format to use in its constructor, and then using that format it creates a
formatted link to a code reference identified by its file and line:
The format is sprintf()
-based, with two placeholders: first one is %s
for
the file, and the second one is %d
for the line. That's it, it's pretty simple.
Translating Paths
There are occasions when leading portions of the filenames must be "translated" to something different, like when:
-
like when you get the real path to a file after some of its parent folders was a symlink that was resolved to its real source;
-
like when you've mounted a shared network volume with your web server machine, and you want to use the locally mounted names, and not the remote ones
- or like when you are using Docker and you want to translate the Docker-based filenames to your locally-accessible filenames.
For all of those cases, the \Fuko\Open\Link
objects have the ability to replace
leading filename prefixes. You can add a new prefix for translating a file path
like this:
You can add multiple prefixes, as usually there is more than one symlinked folder in most projects.
Editor Links
There are several IDEs and editors that support special URL format for local files with the purpose to allow them to open them directly. This feature will only work if you are running your code locally, so that your source code files are accessible to the editor.
To generate such URLs you must use the format associated with that editor:
Once you have created the \Fuko\Open\Link
object, you call its link()
method
to get the generated and formatted URL:
The \Fuko\Open\Link::link()
method is also called if you do \Fuko\Open\Link::__invoke()
, so
you can also just do this:
Editor Sniff
You can sniff what editor is installed locally by using \Fuko\Open\Sniff::detect()
. It
will either return the editor link format found, or if nothing is found it will return NULL
.
The sniffing is done using "sniffer" functions/methods. There are some that are built-in,
but you can add your own using \Fuko\Open\Sniff::addSniffer()
. The sniffers must
return either the format to use in the \Fuko\Open\Link
constructor, or an empty string if
there is no match.
Supported Editors
This is the list of the IDEs and editors supported by Fuko\Open
Editor | Format Const |
---|---|
Atom | \Fuko\Open\Editor::ATOM |
GNU Emacs | \Fuko\Open\Editor::EMACS |
Espresso | \Fuko\Open\Editor::ESPRESSO |
IntelliJ IDEA | \Fuko\Open\Editor::IDEA |
Mac Vim | \Fuko\Open\Editor::MACVIM |
Apache NetBeans | \Fuko\Open\Editor::NETBEANS |
Nova | \Fuko\Open\Editor::NOVA |
PhpStorm | \Fuko\Open\Editor::PHPSTORM |
Sublime Text | \Fuko\Open\Editor::SUBLIME |
TextMate | \Fuko\Open\Editor::TEXTMATE |
Visual Studio Code | \Fuko\Open\Editor::VSCODE |
VSCodium | \Fuko\Open\Editor::VSCODIUM |
Repo Links
There are situations in which you do not want to create links to local source code files,
but instead link to your code repository. Code repo source links usually contain not
just the workspace/account/project and the repo name, but also the branch/tag/commit at
which you reviewing the code. To create repo links use the Fuko\Open\Repo
class, which
will help you to get a new \Fuko\Open\Link
object with the repo link format setup inside:
There constants inside the Fuko\Open\Repo
class to help you with the formats for
the different source-code hosting websites:
Fuko\Open\Repo::BITBUCKET
is for Bitbucket CloudFuko\Open\Repo::GITHUB
is for GitHub