parse-mf2 769 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env php
  2. <?php
  3. $files = array(
  4. __DIR__ . '/../vendor/autoload.php',
  5. __DIR__ . '/../../../autoload.php',
  6. __DIR__ . '/../Mf2/Parser.php'
  7. );
  8. foreach ($files as $file) {
  9. if (file_exists($file)) {
  10. require $file;
  11. define('COMPOSER_INSTALL_LOCATION', $file);
  12. break;
  13. }
  14. }
  15. if (!defined('COMPOSER_INSTALL_LOCATION')) {
  16. die('A composer /vendor/autoload.php file could not be found. You need to install composer: https://getcomposer.org/download');
  17. }
  18. if (!empty($argv[1])) {
  19. $url = $argv[1];
  20. if (!preg_match('|https?://|', $url)) {
  21. $url = 'http://' . $url;
  22. }
  23. } else {
  24. $url = null;
  25. }
  26. $result = Mf2\parse(fgets(STDIN), $url);
  27. if (defined('JSON_PRETTY_PRINT')) {
  28. echo json_encode($result, JSON_PRETTY_PRINT);
  29. } else {
  30. echo json_encode($result);
  31. }