PHP code example of fuko-php / open

1. Go to this page and download the library: Download fuko-php/open library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fuko-php / open example snippets



use \Fuko\Open\Link;

$link = new Link('source-code://%s:%d');
$href = $link->link(__FILE__, __LINE__);


use \Fuko\Open\Link;

$link = new Link('source-code://%s#%05d');
$link->addPrefix(getcwd() . '/', '/upside/down/');
$href = $link->link(__FILE__, __LINE__);
// source-code://%2Fupside%2Fdown%2Fdemo.php#00023


use \Fuko\Open\{Link, Editor};

$href = (new Link(Editor::ATOM))
	->addPrefix(getcwd() . '/', '/upside/down/')
	->addPrefix('/private/tmp', 'tmp')
	->link(__FILE__, __LINE__);


use \Fuko\Open\Editor;
use \Fuko\Open\Link;

/* I have Atom installed locally, so this is what I want to use */
$editor = new Link(Editor::ATOM);

echo $editor->link('/var/www/html/index.html', 2);
// atom://core/open/file?filename=%2Fvar%2Fwww%2Fhtml%2Findex.html&line=2

echo $editor('/var/www/html/index.html', 2);


use \Fuko\Open\{Link, Sniff};

/* I have Atom installed locally, so this is how you can detect it */
$format = (new Sniff)->detect();
if ($format)
{
	echo (new Link($format))->link('/var/www/html/index.html', 2);
	// atom://core/open/file?filename=%2Fvar%2Fwww%2Fhtml%2Findex.html&line=2
}

$sniff->addSniffer(function()
{
	return getenv('EDITOR') === 'subl -w'
		? \Fuko\Open\Editor::SUBLIME
		: '';
});


use \Fuko\Open\Repo;

$repo = new Repo(Repo::GITHUB,
	getcwd() . '/',	// cloned repo root folder which must be stripped from the link
	'fuko-php',	// workspace (aka project or account)
	'open',		// name of the repository
	'master'	// branch, tag or commit
	);

echo $repo->getLink()->link(__FILE__, 42);
// https://github.com/fuko-php/open/blob/master/tests%2FRepoTest.php#L42