本文整理汇总了PHP中Configurator::stripComments方法的典型用法代码示例。如果您正苦于以下问题:PHP Configurator::stripComments方法的具体用法?PHP Configurator::stripComments怎么用?PHP Configurator::stripComments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Configurator
的用法示例。
在下文中一共展示了Configurator::stripComments方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ErrorController
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();
示例2: json_decode
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;
}
}
}