本文整理汇总了PHP中allow函数的典型用法代码示例。如果您正苦于以下问题:PHP allow函数的具体用法?PHP allow怎么用?PHP allow使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了allow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHelperAllow
public function testHelperAllow()
{
$app = $this->app;
$app['acl']::setPermission('sample.view', 'value', 'allow');
$status = allow('sample.view');
$this->assertTrue($status);
}
示例2: session_start
<?php
session_start();
function allow()
{
if (!$_SESSION['uid']) {
//display and error message
header('Location: login.php');
}
}
allow();
function getFiles()
{
require './settings.php';
$con = mysql_connect($host, $user, $password) or die(mysql_error());
$db = mysql_select_db($database, $con) or die(mysql_error());
$user = $_SESSION['uid'];
//echo $user;
$blah = mysql_query("SELECT * FROM `files` WHERE `user` = 1");
//mysql_fetch_assoc()
while ($file = $blah) {
// $string = mysql_fetch_assoc($file);
// echo $string['user'];
echo 'string';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="reset.css" />
示例3: templates
if ($user->AsPostfixAdministrator == false) {
$tpl = new templates();
echo "alert('" . $tpl->javascript_parse_text("{ERROR_NO_PRIVS}") . "');";
die;
exit;
}
if (isset($_GET["popup"])) {
popup();
exit;
}
if (isset($_GET["allow"])) {
allow();
exit;
}
if (isset($_GET["deny"])) {
allow(1);
exit;
}
if (isset($_POST["value-del"])) {
item_delete();
exit;
}
if (isset($_POST["value-add"])) {
item_add();
exit;
}
if (isset($_GET["help"])) {
help_page();
exit;
}
js();
示例4: dbconnect
}
$db = dbconnect();
if ($_POST && array_key_exists('tid', $_POST) && array_key_exists('fid', $_POST)) {
$newThread = false;
$tid = $_POST['tid'];
$uid = $_SESSION['user']->uid;
$title = strip_tags($_POST['title']);
require_once "bbcode.php";
$content = parse_bbcode_html(strip_tags($_POST['content'], '<br>'));
$approved = !isModerated($_POST['fid']) || allow('mod_approve') ? 1 : 0;
$date = time();
if (array_key_exists('pid', $_POST)) {
$pid = $_POST['pid'];
$res = dbquery("SELECT uid FROM posts WHERE pid=:pid", array('pid' => $pid));
$uid = $res->fetchColumn();
if (!(allow("mod_edit") || allow("forum_posting") && $_SESSION['user']->uid == $uid)) {
echo '<script>window.location="/";</script>';
die;
}
$pid = $_POST['pid'];
$res = dbquery("UPDATE posts SET title=:title, content=:content, approved=:approved\n WHERE pid=:pid;", array('title' => $title, 'content' => $content, 'pid' => $pid, 'approved' => $approved));
if ($res) {
$tid = getThread($pid);
echo "<script>window.location='/?page=thread&tid={$tid}#p{$pid}';</script>";
} else {
echo "Something went wrong";
}
} else {
$res = dbquery("INSERT INTO posts (uid, title, content, date, tid, approved)\n VALUES (:uid, :title, :content, FROM_UNIXTIME(:date), :tid, :approved)", array("uid" => $uid, "title" => $title, "content" => $content, "date" => $date, "tid" => $tid, "approved" => $approved));
$pid = $db->lastInsertId();
if ($res && $tid == "") {
示例5: expect
Connection: Close
User-Agent: Mozilla/5.0
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded
19
name1=value1&name2=value2
0
EOD;
expect($request->toMessage())->toBe($expected);
});
it("throws an exception when Content-Length is required but not be determined", function () {
$closure = function () {
$stream = Double::instance(['extends' => 'Lead\\Storage\\Stream\\Stream']);
allow($stream)->toReceive('length')->andReturn(null);
$request = new Request(['method' => 'POST', 'type' => 'application/x-www-form-urlencoded', 'body' => $stream]);
$request->toMessage();
};
expect($closure)->toThrow(new NetException('A Content-Length header is required but the request stream has a `null` length.'));
});
});
describe("->export()", function () {
it("exports default values", function () {
$request = new Request();
expect($request->export())->toEqual(['method' => 'GET', 'scheme' => 'http', 'version' => '1.1', 'host' => 'localhost', 'port' => 80, 'path' => '/', 'query' => '', 'fragment' => '', 'username' => null, 'password' => null, 'url' => 'http://localhost/', 'stream' => $request->stream()]);
});
it("exports a request", function () {
$request = new Request(['scheme' => 'http', 'host' => 'www.domain.com', 'port' => 80, 'username' => 'username', 'password' => 'password', 'path' => 'index.php']);
expect($request->export())->toEqual(['method' => 'GET', 'scheme' => 'http', 'version' => '1.1', 'host' => 'www.domain.com', 'port' => 80, 'path' => '/index.php', 'query' => '', 'fragment' => '', 'username' => 'username', 'password' => 'password', 'url' => 'http://www.domain.com/index.php', 'stream' => $request->stream()]);
});
示例6: expect
expect($backtrace)->toBeA('string');
$backtrace = explode("\n", $backtrace);
expect(empty($backtrace))->toBe(false);
});
it("returns a trace from eval'd code", function () {
$trace = debug_backtrace();
$trace[1]['file'] = "eval()'d code";
$backtrace = Debugger::trace(['trace' => $trace]);
expect($backtrace)->toBeA('string');
$trace = current(explode("\n", $backtrace));
expect($trace)->toMatch('~src[/|\\\\]Specification.php~');
});
describe("::_line()", function () {
beforeEach(function () {
$this->debugger = Double::classname(['extends' => 'Kahlan\\Analysis\\Debugger', 'methods' => ['::line']]);
allow($this->debugger)->toReceive('::line')->andRun(function ($trace) {
return static::_line($trace);
});
});
it("returns `null` with non-existing files", function () {
$debugger = $this->debugger;
$trace = ['file' => DS . 'some' . DS . 'none' . DS . 'existant' . DS . 'path' . DS . 'file.php', 'line' => null];
expect($debugger::line($trace))->toBe(null);
});
it("returns `null` when a line can't be found", function () {
$debugger = $this->debugger;
$nbline = count(file('spec' . DS . 'Suite' . DS . 'Analysis' . DS . 'Debugger.spec.php')) + 1;
$trace = ['file' => 'spec' . DS . 'Suite' . DS . 'Analysis' . DS . 'Debugger.spec.php', 'line' => $nbline + 1];
expect($debugger::line($trace))->toBe(null);
});
});
示例7: describe
<?php
namespace Kahlan\Spec\Suite\Filter\Behavior;
use Kahlan\Plugin\Double;
use Kahlan\Filter\MethodFilters;
describe('Filterable', function () {
beforeEach(function () {
$this->mock = Double::instance(['uses' => ['Kahlan\\Filter\\Behavior\\Filterable']]);
allow($this->mock)->toReceive('filterable')->andRun(function () {
return Filter::on($this, 'filterable', func_get_args(), function ($chain, $message) {
return "Hello {$message}";
});
});
});
describe("methodFilters", function () {
it("gets the `MethodFilters` instance", function () {
expect($this->mock->methodFilters())->toBeAnInstanceOf('Kahlan\\Filter\\MethodFilters');
});
it("sets a new `MethodFilters` instance", function () {
$methodFilters = new MethodFilters();
expect($this->mock->methodFilters($methodFilters))->toBeAnInstanceOf('Kahlan\\Filter\\MethodFilters');
expect($this->mock->methodFilters())->toBe($methodFilters);
});
});
});
示例8: it
it("merges two collection", function () {
$collection = new Collection(['data' => [['name' => "5"], ['name' => "6"]]]);
$this->through->merge($collection);
expect($this->through->data())->toBe([['name' => "0"], ['name' => "1"], ['name' => "2"], ['name' => "3"], ['name' => "4"], ['name' => "5"], ['name' => "6"]]);
});
it("merges two collection with key preservation", function () {
$collection = new Collection(['data' => [['name' => "5"], ['name' => "6"]]]);
$this->through->merge($collection, true);
expect($this->through->data())->toBe([['name' => "5"], ['name' => "6"], ['name' => "2"], ['name' => "3"], ['name' => "4"]]);
});
});
describe("->embed()", function () {
it("delegates the call up to the schema instance", function () {
$model = $this->tagModel;
$schema = $model::definition();
allow($schema)->toReceive('embed');
expect($schema)->toReceive('embed')->with($this->through, ['relation1.relation2']);
$this->through->embed(['relation1.relation2']);
});
});
describe("->data()", function () {
it("calls `to()`", function () {
expect($this->through)->toReceive('to')->with('array', []);
$this->through->data([]);
});
});
describe("->validates()", function () {
it("returns `true` when no validation error occur", function () {
$image = Image::create();
$image->tags[] = Tag::create();
$image->tags[] = Tag::create();
示例9: allow
$this->loader = Double::instance();
$this->class = Double::classname();
$this->file = 'some/path/file.php';
$this->stub1 = Double::instance();
$this->patchers->add('patcher1', $this->stub1);
$this->stub2 = Double::instance();
$this->patchers->add('patcher2', $this->stub2);
$file = $this->file;
allow($this->stub1)->toReceive('findFile')->andRun(function () use($file) {
return $file;
});
allow($this->stub2)->toReceive('findFile')->andRun(function () use($file) {
return $file;
});
});
it("runs findFile() on all patchers", function () {
expect($this->stub1)->toReceive('findFile')->with($this->loader, $this->class, $this->file);
expect($this->stub2)->toReceive('findFile')->with($this->loader, $this->class, $this->file);
$actual = $this->patchers->findFile($this->loader, $this->class, $this->file);
expect($actual)->toBe('some/path/file.php');
});
it("returns patchers overriding if available", function () {
$path = 'new/path/file.php';
allow($this->stub2)->toReceive('findFile')->andRun(function () use($path) {
return $path;
});
$actual = $this->patchers->findFile($this->loader, $this->class, $this->file);
expect($actual)->toBe($path);
});
});
});
示例10: expect
expect(http_response_code())->toEqual(404);
});
it('should redirect to 500 status page for exception', function () {
allow(Routeur::class)->toReceive('::stopExecution')->andRun(function () {
});
Routeur::set('bad', 'bad', function () {
throw new \Exception();
});
$closure = function () {
Routeur::dispatch('bad');
};
expect($closure)->toEcho('Erreur serveur ...');
expect(http_response_code())->toEqual(500);
});
it('should redirect to specific page with 500 status for exception', function () {
allow(Routeur::class)->toReceive('::stopExecution')->andRun(function () {
});
Routeur::set('bad', 'bad', function () {
throw new \Exception();
});
Routeur::set('500', '500', function () {
echo "erreur serveur";
});
$closure = function () {
Routeur::dispatch('bad');
};
expect($closure)->toEcho('erreur serveur');
expect(http_response_code())->toEqual(500);
});
});
describe('url', function () {
示例11: elseif
require 'dbconfig.php';
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 'creation';
}
if (!is_file('admin/' . $page . '.php') || !is_readable('admin/' . $page . '.php')) {
$page = '../404';
} elseif ($page == 'management') {
echo " <link rel='stylesheet' type='text/css' href='../styles/main.css'>";
} elseif ($page == 'moderation') {
echo " <link rel='stylesheet' type='text/css' href='../styles/thread.css'>";
}
?>
</head>
<body>
<?php
require "header.php";
if (allow('acp_view')) {
echo '<div id="main">';
require 'admin/header.php';
require 'admin/' . $page . '.php';
echo '<br /></div>';
} else {
echo "You are not allowed to view this page";
}
require "footer.php";
?>
</body>
</html>
示例12: dbquery
$desc = $row['description'];
$posts = $row['posts'];
$threads = $row['threads'];
echo "\n <a href='?page=forum&fid={$sfid}'>\n <div class='forum'>\n <div class='forum-data'>\n <h3>{$title}</h3>\n <p>{$desc}</p>\n </div>\n <div class='forum-activity'>\n <p>Posts: {$posts}</p>\n <p>Topics: {$threads}</p>\n </div>\n </div>\n </a>\n ";
}
echo "</div>";
}
echo "<div class='threads'><h2>Threads</h2>";
if (allow('forum_posting') && $locked == 0) {
echo "<a href='/?page=discussion&fid={$fid}'><div class='thread newthread'><div class='thread-data'><h3>+ New Thread</h3></div></div></a>";
}
$res = dbquery("SELECT COUNT(*) FROM threads \n WHERE fid=:fid \n ORDER BY lastpost_date;", array('fid' => $fid));
if ($res->fetchColumn() == 0) {
echo "<div class='error'><h3>No threads in this forum yet!</h3></div>";
}
if (allow('mod_approve')) {
$res = dbquery("SELECT * FROM threads \n WHERE fid=:fid \n ORDER BY lastpost_date DESC;", array('fid' => $fid));
} else {
$res = dbquery("SELECT * FROM threads \n WHERE fid=:fid AND approved=1\n ORDER BY lastpost_date DESC;", array('fid' => $fid));
}
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$title = $row['title'];
$tid = $row['tid'];
$uid = $row['uid'];
$date = date("D, d M Y H:i", strtotime($row['date']));
$posts = $row['posts'];
$lastpost_uid = $row['lastpost_uid'];
$lastpost_date = date("D, d M Y H:i", strtotime($row['lastpost_date']));
$user = getUsername($uid);
$lastpost_user = getUsername($lastpost_uid);
echo "\n <a href='?page=thread&tid={$tid}'>\n <div class='thread'>\n <div class='thread-data'>\n <h3>{$title}</h3>\n <span>By: <a href='?page=profile&uid={$uid}'>{$user}</a> on {$date}</span>\n </div>\n <div class='thread-activity'>\n <p>Posts: {$posts}</p>\n <span>Last post by: <a href='?page=profile&uid={$lastpost_uid}'>{$lastpost_user}</a></span>\n <p>{$lastpost_date}</p>\n </div>\n </div>\n </a>\n ";
示例13: expect
expect($this->database->convert('cast', '_default_', 123))->toBe(123);
expect($this->database->convert('cast', '_undefined_', 123))->toBe(123);
});
it("formats `null` values", function () {
expect($this->database->convert('datasource', 'id', null))->toBe('NULL');
expect($this->database->convert('datasource', 'serial', null))->toBe('NULL');
expect($this->database->convert('datasource', 'integer', null))->toBe('NULL');
expect($this->database->convert('datasource', 'float', null))->toBe('NULL');
expect($this->database->convert('datasource', 'decimal', null))->toBe('NULL');
expect($this->database->convert('datasource', 'date', null))->toBe('NULL');
expect($this->database->convert('datasource', 'datetime', null))->toBe('NULL');
expect($this->database->convert('datasource', 'boolean', null))->toBe('NULL');
expect($this->database->convert('datasource', 'null', null))->toBe('NULL');
expect($this->database->convert('datasource', 'string', null))->toBe('NULL');
expect($this->database->convert('datasource', '_default_', null))->toBe('NULL');
expect($this->database->convert('datasource', '_undefined_', null))->toBe('NULL');
});
});
describe("->errorMsg()", function () {
it("retuns the last error", function () {
allow($this->client)->toReceive('errorInfo')->andRun(function () {
return ['0000', null, null];
});
expect($this->database->errorMsg())->toBe('');
allow($this->client)->toReceive('errorInfo')->andRun(function () {
return ['42S02', -204, "Error"];
});
expect($this->database->errorMsg())->toBe('42S02 (-204):Error');
});
});
});
示例14: expect
expect($mon->time())->toBe(456);
});
it("expects stubbed method to be stubbed only when the with constraint is respected", function () {
$mon = new Mon();
allow('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\rand')->toBeCalled()->with(10, 20)->andReturn(40);
expect($mon->rand(0, 10))->toBe(5);
expect($mon->rand(10, 20))->toBe(40);
});
it('makes built-in PHP function to work', function () {
allow('file_get_contents')->toBeOK();
$mon = new Mon();
expect($mon->loadFile())->toBe(null);
});
it("throws an exception when trying to call `toReceive()`", function () {
expect(function () {
allow('time')->toReceive('something')->andReturn(123, 456);
})->toThrow(new Exception("Error `toReceive()` are only available on classes/instances not functions."));
});
});
it("throws an exception when trying to call `andReturn()` right away", function () {
expect(function () {
allow('time')->andReturn(123);
})->toThrow(new Exception("You must to call `toReceive()/toBeCalled()` before defining a return value."));
});
it("throws an exception when trying to call `andReturn()` right away", function () {
expect(function () {
allow('time')->andRun(function () {
});
})->toThrow(new Exception("You must to call `toReceive()/toBeCalled()` before defining a return value."));
});
});
示例15: skipIf
skipIf(!$box->has('source.database.sqlite'));
});
beforeEach(function () {
$box = box('chaos.spec');
$this->adapter = $box->get('source.database.sqlite');
});
describe("::enabled()", function () {
it("returns `true` for enabled features, false otherwise.", function () {
expect(Sqlite::enabled())->toEqual(['arrays' => false, 'transactions' => false, 'booleans' => true, 'default' => false]);
expect(Sqlite::enabled('arrays'))->toBe(false);
expect(Sqlite::enabled('transactions'))->toBe(false);
expect(Sqlite::enabled('booleans'))->toBe(true);
expect(Sqlite::enabled('default'))->toBe(false);
});
it("throws an exception if the extension is not loaded.", function () {
allow('extension_loaded')->toBeCalled()->andReturn(false);
expect(function () {
Sqlite::enabled();
})->toThrow(new DatabaseException("The PDO SQLite extension is not installed."));
});
});
describe("->connect()", function () {
it("throws an exception if no database name is set", function () {
$closure = function () {
new Sqlite(['database' => null]);
};
expect($closure)->toThrow(new DatabaseException('Error, no database name has been configured.'));
});
});
describe("->sources()", function () {
it("shows sources", function () {