<commit_before><?php

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Zend\Validator\Barcode;

require_once __DIR__.'/../common/appcommon.php';

$app['controllers']
    ->assert('uuid', '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}')
;

$app->get('/barcode/{gtin}', function($gtin) use ($app) {
    $gtin = sprintf('%014d', $gtin);
    
    return $app->redirect('/barcode/'.$gtin);
})->assert('gtin', '[0-9]{8,13}');

$app->get('/barcode/{gtin}', function($gtin) use ($app) {
    $validator = new Barcode('GTIN14');
    if(!$validator->isValid($gtin)) {
        throw new NotFoundHttpException('Invalid barcode');
    }
    
    $sql = 'SELECT uuid FROM barcodes WHERE barcode = ?';
    $uuid = $app['db']->fetchColumn($sql, array($gtin));
    
    if(false === $uuid) {
        $app['db']
            ->executeUpdate('INSERT INTO barcodes (uuid, barcode) VALUES (?,?)', array(
                $uuid = trim(`uuidgen -r`),
                $gtin
            ))
        ;
    }

   return barcode_response($app, $uuid, $gtin);
})->assert('gtin', '[0-9]{14}');

$app->get('/barcode/{uuid}', function($uuid) use ($app) {
    $sql = 'SELECT barcode FROM barcodes WHERE uuid = ?';
    $gtin = $app['db']->fetchColumn($sql, array($uuid));
    
    if(false === $gtin) {
        throw new NotFoundHttpException('UUID not found');
    }
    
    return barcode_response($app, $uuid, $gtin);
});

$app['debug'] = in_array($_SERVER['REMOTE_ADDR'], array ('127.0.0.1'));
$app->run();
<commit_msg>Redirecting to UUID<commit_after><?php

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Zend\Validator\Barcode;

require_once __DIR__.'/../common/appcommon.php';

$app['controllers']
    ->assert('uuid', '[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}')
;

$app->get('/barcode/{gtin}', function($gtin) use ($app) {
    $gtin = sprintf('%014d', $gtin);
    $validator = new Barcode('GTIN14');
    if(!$validator->isValid($gtin)) {
        throw new NotFoundHttpException('Invalid barcode');
    }
    
    $sql = 'SELECT uuid FROM barcodes WHERE barcode = ?';
    $uuid = $app['db']->fetchColumn($sql, array($gtin));
    
    if(false === $uuid) {
        $app['db']
            ->executeUpdate('INSERT INTO barcodes (uuid, barcode) VALUES (?,?)', array(
                $uuid = trim(`uuidgen -r`),
                $gtin
            ))
        ;
    }
    
    return $app->redirect('/barcode/'.$uuid);
})->assert('gtin', '[0-9]{8,14}');

$app->get('/barcode/{uuid}', function($uuid) use ($app) {
    $sql = 'SELECT barcode FROM barcodes WHERE uuid = ?';
    $gtin = $app['db']->fetchColumn($sql, array($uuid));
    
    if(false === $gtin) {
        throw new NotFoundHttpException('UUID not found');
    }
    
    return barcode_response($app, $uuid, $gtin);
});

$app['debug'] = in_array($_SERVER['REMOTE_ADDR'], array ('127.0.0.1'));
$app->run();

{'fraction_non_alphanumeric': 0.22860089377793055, 'fraction_numerical': 0.023375730491577863, 'mean_word_length': 3.157142857142857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '445550', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1068, 'n_words': 178}