Ejemplo n.º 1
0
require_once APPPATH . "auth/Auth.php";
require_once APPPATH . "auth/BasicAuth.php";
$c = new ErrorController();
// Keep cores as the last item
$config_files = array("general", "routes", "db", "cores", "auth");
$config_validator = new Validator();
// Check if all config files are present and validate them
foreach ($config_files as $file) {
    $filename = APPPATH . "config/" . $file . ".json";
    $schema = APPPATH . "config/schema/" . $file . "-schema.json";
    if (!file_exists($filename)) {
        echo "The file {$file} doesn't exist. Please check whether you have copied " . APPPATH . "config/{$file}.example.json to " . $filename;
        exit;
    } elseif (file_exists($schema)) {
        // Validate config file if schema exists
        $config_validator->check(json_decode(Configurator::stripComments(file_get_contents($filename))), json_decode(file_get_contents($schema)));
        if (!$config_validator->isValid()) {
            echo "JSON ({$file}.json) does not validate. Violations:\n";
            foreach ($config_validator->getErrors() as $error) {
                echo sprintf("[%s] %s\n", $error['property'], $error['message']);
            }
            exit;
        }
    }
}
// Start loading config files
try {
    $config = Configurator::load($config_files);
} catch (Exception $e) {
    // TODO: show nice error page
    echo $e->getMessage();
Ejemplo n.º 2
0
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\FormError;
use Symfony\Component\Validator\Constraints as Assert;
// Allows to strip the comments from a json file
require_once STARTPATH . 'app/core/configurator.php';
// Used to write json to file, formatted to be read by humans
require_once __DIR__ . '/../src/nicejson-php/nicejson.php';
// Load users from file
// Fetch users from the auth.json file
$filename = STARTPATH . "app/config/auth.json";
// This object will be used by user management and route management, so don't delete it
$userObject = json_decode(file_get_contents($filename));
$users = get_object_vars($userObject);
// Fetch routes from file
$routeFile = STARTPATH . "app/config/cores.json";
$routeObject = json_decode(Configurator::stripComments(file_get_contents($routeFile)));
$routes = get_object_vars($routeObject);
// Save the routes used per user
$userroutes = array();
foreach ($routes as $namespace => $core) {
    foreach ($core->routes as $index => $route) {
        foreach ($route->users as $user) {
            $numberofroutes = 0;
            if (isset($userroutes[$user]->routes)) {
                $numberofroutes = count($userroutes[$user]->routes);
            }
            $userroutes[$user]->routes[$numberofroutes]->namespace = $namespace;
            $userroutes[$user]->routes[$numberofroutes]->index = $index;
        }
    }
}