本文整理汇总了PHP中assert_options函数的典型用法代码示例。如果您正苦于以下问题:PHP assert_options函数的具体用法?PHP assert_options怎么用?PHP assert_options使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_options函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* Register assertion handler in php
*
* @returns void
*/
public static function register()
{
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
assert_options(ASSERT_CALLBACK, array('libfajr\\Assert', 'myAssertHandler'));
}
示例2: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!Session::has('role')) {
return redirect('/login');
}
if (!isset($_COOKIE['login'])) {
$visitorCount = 1;
}
$setTime = time() + 3600;
if (isset($_COOKIE['login'])) {
$visitorCount = $_COOKIE['login'] + 1;
setCookie('login', $visitorCount, $setTime);
} else {
setCookie('login', $visitorCount, $setTime);
}
if (!Session::has('anchor')) {
session(['anchor' => '2']);
}
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
assert_options(ASSERT_CALLBACK, 'my_assert_handler');
$old_error_handler = set_error_handler("myErrorHandler");
return $next($request);
}
示例3: ERAssertInRange
function ERAssertInRange($expr, $min, $max, $description)
{
$expression = eval("return {$expr};");
assert_options(ASSERT_CALLBACK, create_function('$file, $line, $code', "echo \"{$description}; expected in range ({$min}),({$max}) but found ({$expression})\n" . '";'));
$success = assert("(({$expr}) >= ({$min})) && (({$expr}) <= ({$max}))");
assertion_increase($success);
}
示例4: assert_in_function
function assert_in_function()
{
assert_options(ASSERT_ACTIVE, true);
$value = '2';
var_dump(assert(is_string($value)));
var_dump(assert('is_string($value)'));
}
示例5: isModuleEnabled
/**
* Determine whether a module is enabled.
*
* Will return false if the given module doesn't exists.
*
* @param string $module Name of the module
*
* @return bool True if the given module is enabled, false otherwise.
*
* @throws Exception If module.enable is set and is not boolean.
*/
public static function isModuleEnabled($module)
{
$moduleDir = self::getModuleDir($module);
if (!is_dir($moduleDir)) {
return false;
}
$globalConfig = SimpleSAML_Configuration::getOptionalConfig();
$moduleEnable = $globalConfig->getArray('module.enable', array());
if (isset($moduleEnable[$module])) {
if (is_bool($moduleEnable[$module]) === true) {
return $moduleEnable[$module];
}
throw new Exception("Invalid module.enable value for for the module {$module}");
}
if (assert_options(ASSERT_ACTIVE) && !file_exists($moduleDir . '/default-enable') && !file_exists($moduleDir . '/default-disable')) {
SimpleSAML_Logger::error("Missing default-enable or default-disable file for the module {$module}");
}
if (file_exists($moduleDir . '/enable')) {
return true;
}
if (!file_exists($moduleDir . '/disable') && file_exists($moduleDir . '/default-enable')) {
return true;
}
return false;
}
示例6: installHandler
/**
* Install this assertion handler.
*
* This function will register this assertion handler. If will not enable assertions if they are
* disabled.
*/
public static function installHandler()
{
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_BAIL, 0);
assert_options(ASSERT_QUIET_EVAL, 0);
assert_options(ASSERT_CALLBACK, array('SimpleSAML_Error_Assertion', 'onAssertion'));
}
示例7: run
/**
* Runs tests and outputs report. This function will run all functions
* beginning with test_ found in all files provided as arguments. Invalid
* files are skipped.
*
* @param string|array $files Either a string or an array of test files
*
* @return bool True if all tests passes, false otherwise
*/
public static function run($files)
{
static $tokens = array();
$failures = array();
assert_options(ASSERT_ACTIVE, true);
assert_options(ASSERT_BAIL, false);
assert_options(ASSERT_WARNING, false);
assert_options(ASSERT_QUIET_EVAL, false);
assert_options(ASSERT_CALLBACK, function ($file, $line, $assert, $description = null) use(&$failures, &$tokens) {
$failures[] = array('file' => $file, 'line' => $line, 'assert' => $assert, 'description' => $description);
});
if (is_string($files)) {
$files = (array) $files;
}
$asserts = 0;
$tests = 0;
$t0 = microtime(true);
foreach ($files as $file) {
if (!(is_string($file) && is_readable($file))) {
continue;
}
$source = file_get_contents($file);
$asserts = preg_match_all('/assert\\(/im', $source, $_);
if (preg_match_all('/function (test_(?:[a-z_][a-z0-9_]*))\\(/im', $source, $matches)) {
$functions = $matches[1];
require_once $file;
foreach ($functions as $f) {
if (is_callable($f)) {
$tests += 1;
call_user_func($f);
}
}
}
}
$t = round(microtime(true) - $t0, 3);
ob_start();
if ($failures) {
print 'Failed ' . count($failures) . " of {$asserts} assert(s) in {$tests} test(s) - completed in {$t} seconds." . PHP_EOL;
print str_repeat('-', 79) . PHP_EOL;
foreach ($failures as $i => $failure) {
print $i + 1 . ". {$failure['file']}:{$failure['line']}" . PHP_EOL;
if (strlen($failure['assert'])) {
print "\t{$failure['assert']}" . PHP_EOL;
}
print str_repeat('-', 79) . PHP_EOL;
}
} else {
print "Passed {$asserts} assert(s) in {$tests} test(s) - completed in {$t} seconds." . PHP_EOL;
}
$report = ob_get_clean();
if (php_sapi_name() == 'cli') {
echo $report;
} else {
echo '<pre>' . PHP_EOL;
echo $report;
echo '</pre>' . PHP_EOL;
}
return empty($failures);
}
示例8: setup
static function setup()
{
set_error_handler(array("\\libraries\\ExceptionHandler", "error_handler"));
set_exception_handler(array("\\libraries\\ExceptionHandler", 'exception_handler'));
register_shutdown_function(array("\\libraries\\ExceptionHandler", "check_for_fatal"));
assert_options(ASSERT_ACTIVE, true);
assert_options(ASSERT_CALLBACK, array("\\libraries\\ExceptionHandler", '_assert_failure'));
}
示例9: main
function main($argv)
{
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('display_errors', 'on');
assert_options(ASSERT_CALLBACK, 'assert_cb');
$proc = new phpjs();
$proc->translate_file($argv[1]);
}
示例10: setAssertionsLevel1
public static function setAssertionsLevel1($enable)
{
assert('is_bool($enable)', vs(isset($this), get_defined_vars()));
assert_options(ASSERT_ACTIVE, $enable);
if (self::$ms_anyFailedAssertionIsFatal && $enable) {
assert_options(ASSERT_BAIL, true);
}
}
示例11: assertsInitialize
protected function assertsInitialize()
{
assert_options(ASSERT_ACTIVE, static::$ASSERT_ACTIVE);
assert_options(ASSERT_WARNING, static::$ASSERT_WARNING);
assert_options(ASSERT_BAIL, static::$ASSERT_BAIL);
assert_options(ASSERT_QUIET_EVAL, static::$ASSERT_QUIET_EVAL);
assert_options(ASSERT_CALLBACK, [$this, static::ASSERT_FAILED_METHOD]);
}
示例12: resetAssertOptions
/**
* Reset assert() options
*
* @return void
*/
public static function resetAssertOptions()
{
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 1);
assert_options(ASSERT_BAIL, 0);
assert_options(ASSERT_QUIET_EVAL, 0);
assert_options(ASSERT_CALLBACK, null);
}
示例13: refreshAssertBindings
/** @return void */
public function refreshAssertBindings()
{
assert_options(ASSERT_CALLBACK, array($this, 'assertCallback'));
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
assert_options(ASSERT_BAIL, 0);
}
示例14: setAssertHandling
/**
*
*/
protected function setAssertHandling()
{
// Active assert and make it quiet
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
// Set up the callback
assert_options(ASSERT_CALLBACK, array($this, 'assertHandler'));
}
示例15: register
public static function register()
{
self::$oldhandler = set_error_handler(array(__CLASS__, '__php_handleError'), E_ALL);
\set_exception_handler(array(__CLASS__, '__php_handleException'));
// Active assert and make it quiet
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
assert_options(ASSERT_CALLBACK, array(__CLASS__, '__php_handleAssert'));
}