<commit_before><?php
require_once __DIR__.'/../vendor/autoload.php';

$app = new Silex\Application();
// Please set to false in a production environment
$app['debug'] = true;
$app->register(new Predis\Silex\ClientServiceProvider(), [
		'predis.parameters' => 'tcp://127.0.0.1:6379',
		'predis.options'    => [
		'prefix'  => 'msiof:',
		'profile' => '3.0',
		],
]);

$toys = array(
    '00001'=> array(
        'name' => 'Racing Car',
        'quantity' => '53',
        'description' => '...',
        'image' => 'racing_car.jpg',
    ),
    '00002' => array(
        'name' => 'Raspberry Pi',
        'quantity' => '13',
        'description' => '...',
        'image' => 'raspberry_pi.jpg',
    ),
);

$app['predis']->set('toys', json_encode($toys));

$app->get('/', function() use ($toys) {
    return $app['predis']->get('toys');
});

$app->get('/{stockcode}', function (Silex\Application $app, $stockcode) {
    $toys = json_decode($app['predis']->get('toys'), true);
    if (!isset($toys[$stockcode])) {
        $app->abort(404, "Stockcode {$stockcode} does not exist.");
    }
    return json_encode($toys[$stockcode]);
});

$app->run();
<commit_msg>Redis changes, new routes, header apikey<commit_after><?php
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

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

//apiKey to customerid mapping
$apiKeys = [
		'cheese' => 100
];

$serverKeys = [
		'ww1' => [
				'hostname' => 'ww1',
				'serverid' => 1
		]
];

$app = new Application();
// Please set to false in a production environment
//$app['debug'] = true;
$app->register(new Predis\Silex\ClientServiceProvider(), [
		'predis.parameters' => 'tcp://127.0.0.1:6379',
		'predis.options'    => [
		'prefix'  => 'msiof:',
		'profile' => '3.0',
		],
]);

$app->get('/', function(Application $app, Request $request) {
		$apiKey = $request->headers->get('X-Api-Key');
		if(empty($apiKey)) {
				return new Response(json_encode(['error' => 'Access Denied'], JSON_PRETTY_PRINT), 403);
		} else {
				$app['predis']->hmset('dannyisadouche', [
						'doucheLevel' => 9000,
						'hairLevel' => 1,
						'cheese' => 'Yes',
						'awesome' => 'No'
						]);
				return 'Your apiKey is: ' . $apiKey;
		}
		
		return $app['predis']->get('toys'). " ---- " . $nextServerId;
});

//Add server
$app->post('/server', function(Application $app, Request $request) {
		$nextServerId = $app['predis']->incr('next_server_id');
		return 'no';
});

$app->get('/{stockcode}', function (Application $app, $stockcode) {
    $toys = json_decode($app['predis']->get('toys'), true);
    if (!isset($toys[$stockcode])) {
        $app->abort(404, "Stockcode {$stockcode} does not exist.");
    }
    return json_encode($toys[$stockcode]);
});

$app->run();

{'fraction_non_alphanumeric': 0.22917411512334646, 'fraction_numerical': 0.020736503396496245, 'mean_word_length': 3.5495934959349595, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 50, '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': '861416', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1019, 'n_words': 186}