<?php /** * @author Patrick van Bergen */ use earley\reader\ConfigReader; use earley\storage\FileSystemStorage; require_once __DIR__ . '/autoloader.php'; error_reporting(E_ALL); ini_set('display_errors', 1); // sanitize input $configName = isset($_POST['conf']) ? $_POST['conf'] : ''; // create a clean config array from $_POST $configReader = new ConfigReader(); $config = $configReader->readConfig($_POST); #todo: move to config file $configurationBaseDirectory = __DIR__ . '/../../earley-interface-data'; $storage = new FileSystemStorage($configurationBaseDirectory); if ($configName == '') { // create version 1 of a new configuration $configName = $storage->createConfiguration(); } // store a new version $newVersion = $storage->storeConfiguration($configName, $config); header('Content-type: application/json'); echo json_encode(['configName' => $configName, 'version' => $newVersion]);
<?php use earley\storage\FileSystemStorage; error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/php/autoloader.php'; // Create path variable to the root of this project // If URL ends in a slash followed by one or more digits (e.g. http://domain.com/abcde/1), returns a cleaned version of the URL, e.g. http://domain.com/ $path = preg_replace("/\\w+\\/\\d+\\/?\$/", '', $_SERVER['REQUEST_URI']); #todo: move to config file $configurationBaseDirectory = __DIR__ . '/../earley-interface-data'; $conf = isset($_GET['conf']) ? $_GET['conf'] : ''; $version = isset($_GET['v']) ? $_GET['v'] : 1; $storage = new FileSystemStorage($configurationBaseDirectory); $config = $storage->getConfiguration($conf, $version); $sentence = isset($config['sentence']) ? $config['sentence'] : 'i like the bananas'; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="robots" content="noindex"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>Earley interface + Early build</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous"> <link href="<?php echo $path; ?>