Exemplo n.º 1
0
#!/usr/bin/env php
<?php 
use Interlink\Parser;
use Interlink\Handler;
use Interlink\Renderer\HyperlinkRenderer;
use Interlink\LabelResolver\BugzillaLabelResolver;
use GuzzleHttp\Client as GuzzleClient;
require_once __DIR__ . '/../vendor/autoload.php';
$parser = new Parser();
// Register the 'mozilla-bugzilla' handler, with advanced LabelResolver
$guzzle = new GuzzleClient();
$resolver = new BugzillaLabelResolver($guzzle, 'https://bugzilla.mozilla.org/');
$renderer = new HyperlinkRenderer();
$handler = new Handler("https://bugzilla.mozilla.org/show_bug.cgi?id={{reference}}", $renderer, $resolver);
$parser->registerHandler("mozilla-bugzilla", $handler);
$text = file_get_contents(__DIR__ . '/bugzilla.md');
echo $parser->parse($text);
Exemplo n.º 2
0
#!/usr/bin/env php
<?php 
use Interlink\Parser;
use Interlink\Handler;
use Interlink\Renderer\HyperlinkRenderer;
use Interlink\Renderer\ImageRenderer;
use Interlink\Renderer\TemplateRenderer;
use Interlink\LabelResolver\UppercaseLabelResolver;
require_once __DIR__ . '/../vendor/autoload.php';
$text = file_get_contents(__DIR__ . '/simple.md');
$parser = new Parser();
// Register the 'google' handler, a simple hyperlink
$renderer = new HyperlinkRenderer();
$handler = new Handler("http://www.google.com/?q={{reference}}", $renderer);
$parser->registerHandler("google", $handler);
// Register a custom template renderer example
$renderer = new TemplateRenderer('<a href="{{url}}" class="{{classname}}">{{label}}</a>');
$renderer->setData("classname", "example");
$handler = new Handler("http://www.bing.com/search?q={{reference}}", $renderer);
$parser->registerHandler("bing", $handler);
// Registering the 'wikipedia' handler, with example labelresolver
$renderer = new HyperlinkRenderer();
$resolver = new UppercaseLabelResolver();
// This will uppercase the reference
$handler = new Handler("http://www.wikipedia.com/?q={{reference}}", $renderer);
$parser->registerHandler("wikipedia", $handler, $resolver);
// Registering the 'snag.gy' image handler, adding an <img /> tag
$renderer = new ImageRenderer();
$handler = new Handler("http://i.snag.gy/{{reference}}.jpg", $renderer);
$parser->registerHandler("snag.gy", $handler);
echo $parser->parse($text);
Exemplo n.º 3
0
#!/usr/bin/env php
<?php 
use Interlink\Parser;
use Interlink\Handler;
use Interlink\Renderer\HyperlinkRenderer;
use Interlink\LabelResolver\PdoLookupLabelResolver;
use PDO;
require_once __DIR__ . '/../vendor/autoload.php';
$parser = new Parser();
// Creating a PDO connection
$pdo = new PDO('mysql:host=127.0.0.1;dbname=exampledb', 'username', 'password');
// Register the 'acme-faq' handler, with advanced LabelResolver
$renderer = new HyperlinkRenderer();
// This resolver will lookup the faq record where `id`=reference, and return the value in the `title` column
$resolver = new PdoLookupLabelResolver($pdo, 'faq', 'id', 'title');
$handler = new Handler("http://www.acme.web/faq/{{reference}}", $renderer, $resolver);
$parser->registerHandler("acme-faq", $handler);
// Register the 'acme-wiki' handler, with advanced LabelResolver
$renderer = new HyperlinkRenderer();
$resolver = new PdoLookupLabelResolver($pdo, 'wikipage', 'code', 'title');
$handler = new Handler("http://www.acme.web/wiki/{{reference}}", $renderer, $resolver);
$parser->registerHandler("acme-wiki", $handler);
$text = file_get_contents(__DIR__ . '/pdolookup.md');
echo $parser->parse($text);