File: parse-mf2

package info (click to toggle)
php-mf2 0.3.0-0.2
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,896 kB
  • sloc: php: 2,584; xml: 8; makefile: 2
file content (37 lines) | stat: -rwxr-xr-x 770 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env php
<?php

$files = array(
  __DIR__ . '/../vendor/autoload.php',
  __DIR__ . '/../../../autoload.php',
  __DIR__ . '/../Mf2/Parser.php'
);

foreach ($files as $file) {
	if (file_exists($file)) {
		require $file;
		define('COMPOSER_INSTALL_LOCATION', $file);
		break;
	}
}

if (!defined('COMPOSER_INSTALL_LOCATION')) {
	die('A composer /vendor/autoload.php file could not be found. You need to install composer: https://getcomposer.org/download');
}

if (!empty($argv[1])) {
	$url = $argv[1];
	if (!preg_match('|https?://|', $url)) {
		$url = 'http://' . $url;
	}	
} else {
	$url = null;
}

$result = Mf2\parse(fgets(STDIN), $url);

if (defined('JSON_PRETTY_PRINT')) {
	echo json_encode($result, JSON_PRETTY_PRINT);
} else {
	echo json_encode($result);
}