<commit_before><?php

require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';

use UoMCS\OpenBadges\Frontend\Client;

use Symfony\Component\HttpFoundation\Response;

$app = new Silex\Application();

$app->get('/assertions/{uid}', function($uid) use ($app) {
  $client = new Client();
  $response = $client->get("/assertions/$uid");

  if (!$response->isOk())
  {
    $app->abort($response->getStatusCode());
  }

  $badge = $client->getBodyArray();

  $loader = new Twig_Loader_Filesystem(TWIG_TEMPLATES_DIR);
  $twig = new Twig_Environment($loader);

  return $twig->render('assertions/show.html', array('badge' => $badge));
})
->assert('uid', '[0-9a-zA-Z]+');

$app->get('/assertions/{email}', function($email) use($app) {
  $client = new Client();
  $response = $client->get("/assertions/$email");

  if (!$response->isOk())
  {
    $app->abort($response->getStatusCode());
  }

  $badges = $client->getBodyArray();

  $loader = new Twig_Loader_Filesystem(TWIG_TEMPLATES_DIR);
  $twig = new Twig_Environment($loader);

  return $twig->render('assertions/list.html', array('badges' => $badges));
});

$app->get('/badges/images/{id}', function($id) use ($app) {
  $client = new Client();
  $client_response = $client->get("/badges/images/$id");

  if (!$client_response->isOk())
  {
    $app->abort($client_response->getStatusCode());
  }

  $response = new Response();
  $response->setContent($client_response->getBody());
  $response->headers->set('Content-Type', 'image/png');

  return $response;
})
->assert('id', '[1-9][0-9]*');

$app->get('/badges/{id}', function($id) use ($app) {
  $client = new Client();
  $response = $client->get("/badges/$id");

  if (!$response->isOk())
  {
    $app->abort($response->getStatusCode());
  }

  $badge = $client->getBodyArray();

  $loader = new Twig_Loader_Filesystem(TWIG_TEMPLATES_DIR);
  $twig = new Twig_Environment($loader);

  return $twig->render('badges/show.html', array('badge' => $badge));
})
->assert('id', '[1-9][0-9]*');
<commit_msg>Replace web service backend URL with frontend URL for images<commit_after><?php

require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../autoload.php';
require_once __DIR__ . '/../vendor/autoload.php';

use UoMCS\OpenBadges\Frontend\Client;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$app = new Silex\Application();

$app->get('/assertions/{uid}', function($uid) use ($app) {
  $client = new Client();
  $response = $client->get("/assertions/$uid");

  if (!$response->isOk())
  {
    $app->abort($response->getStatusCode());
  }

  $badge = $client->getBodyArray();

  $loader = new Twig_Loader_Filesystem(TWIG_TEMPLATES_DIR);
  $twig = new Twig_Environment($loader);

  return $twig->render('assertions/show.html', array('badge' => $badge));
})
->assert('uid', '[0-9a-zA-Z]+');

$app->get('/assertions/{email}', function($email) use($app) {
  $client = new Client();
  $response = $client->get("/assertions/$email");

  if (!$response->isOk())
  {
    $app->abort($response->getStatusCode());
  }

  $badges = $client->getBodyArray();

  $loader = new Twig_Loader_Filesystem(TWIG_TEMPLATES_DIR);
  $twig = new Twig_Environment($loader);

  return $twig->render('assertions/list.html', array('badges' => $badges));
});

$app->get('/badges/images/{id}', function($id) use ($app) {
  $client = new Client();
  $client_response = $client->get("/badges/images/$id");

  if (!$client_response->isOk())
  {
    $app->abort($client_response->getStatusCode());
  }

  $response = new Response();
  $response->setContent($client_response->getBody());
  $response->headers->set('Content-Type', 'image/png');

  return $response;
})
->assert('id', '[1-9][0-9]*');

$app->get('/badges/{id}', function(Request $request, $id) use ($app) {
  $client = new Client();
  $response = $client->get("/badges/$id");

  if (!$response->isOk())
  {
    $app->abort($response->getStatusCode());
  }

  $badge = $client->getBodyArray();

  $badge['image'] = str_replace(OPEN_BADGES_BACKEND_URL, $request->getSchemeAndHttpHost(), $badge['image']);

  $loader = new Twig_Loader_Filesystem(TWIG_TEMPLATES_DIR);
  $twig = new Twig_Environment($loader);

  return $twig->render('badges/show.html', array('badge' => $badge));
})
->assert('id', '[1-9][0-9]*');

{'fraction_non_alphanumeric': 0.22601328142889857, 'fraction_numerical': 0.004579803068468056, 'mean_word_length': 4.886792452830188, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2931248', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1554, 'n_words': 245}