本文整理汇总了PHP中any函数的典型用法代码示例。如果您正苦于以下问题:PHP any函数的具体用法?PHP any怎么用?PHP any使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了any函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/** Creates directory or throws exception on fail
* @param string $pathname
* @param int $mode Mode in octal
* @return bool
*/
public static function create($pathname, $mode = self::MOD_DEFAULT)
{
if (strpos($pathname, '/') !== false) {
$pathname = explode('/', $pathname);
}
if (is_array($pathname)) {
$current_dir = '';
$create = array();
do {
$current_dir = implode('/', $pathname);
if (is_dir($current_dir)) {
break;
}
$create[] = array_pop($pathname);
} while (any($pathname));
if (any($create)) {
$create = array_reverse($create);
$current_dir = implode('/', $pathname);
foreach ($create as $dir) {
$current_dir .= '/' . $dir;
if (!is_dir($current_dir)) {
if (!($action = @mkdir($current_dir, $mode))) {
throw new \System\Error\Permissions(sprintf('Failed to create directory on path "%s" in mode "%s". Please check your permissions.', $current_dir, base_convert($mode, 10, 8)));
}
}
}
}
} else {
if (!($action = @mkdir($pathname, $mode, true))) {
throw new \System\Error\Permissions(sprintf('Failed to create directory on path "%s" in mode "%s". Please check your permissions.', $pathname, base_convert($mode, 10, 8)));
}
}
return $action;
}
示例2: get_new
static function get_new()
{
try {
$old_items = static::get_all()->fetch();
} catch (\System\Error $e) {
$old_items = array();
}
$old = array();
foreach ($old_items as &$m) {
$old[] = $m->date->format('sql') . '-' . $m->seoname;
}
$items = self::checkout_folder($old);
if (any($items)) {
$sums = collect(array('attr', 'md5_sum'), $items, true);
try {
$old = static::get_all(array("t0.md5_sum IN ('" . implode("','", $sums) . "')"))->fetch();
} catch (\System\Error $e) {
$old = array();
}
}
foreach ($old as $mig) {
foreach ($items as $key => $nmig) {
if ($mig->get_checksum() == $nmig->get_checksum()) {
if ($mig->status == 'ok') {
unset($items[$key]);
} else {
$items[$key] = $mig;
}
}
}
}
uasort($items, array('self', 'sort'));
return $items;
}
示例3: controller_waypoints
function controller_waypoints($args, $output = "inline")
{
$location["tr"] = explode(",", $args["tr"]);
$location["bl"] = explode(",", $args["bl"]);
$location["tl"] = array($location["tr"][0], $location["bl"][1]);
$location["br"] = array($location["bl"][0], $location["tr"][1]);
$location["center"] = array($location["bl"][0] + ($location["tr"][0] - $location["bl"][0]) / 2, $location["bl"][1] + ($location["tr"][1] - $location["bl"][1]) / 2);
$zoom = any($args["zoom"], 1);
$yelp = new Yelp();
$wherestr = "WHERE {NavigationLocation.lat} <= " . mysql_escape_string($location["tr"][0]) . " AND {NavigationLocation.lat} >= " . mysql_escape_string($location["bl"][0]);
$wherestr .= " AND {NavigationLocation.lon} <= " . mysql_escape_string($location["tr"][1]) . " AND {NavigationLocation.lon} >= " . mysql_escape_string($location["bl"][1]);
$wherestr .= " AND {NavigationLocation.zoom_min} <= " . mysql_escape_string($zoom) . " AND {NavigationLocation.zoom_max} >= " . mysql_escape_string($zoom);
$wherestr .= " AND {NavigationLocation.name} != 'mapcenter'";
$locations_center = $this->conn->load("NavigationLocation", "mapcenter");
if (empty($locations_center)) {
$locations_center = new NavigationLocation();
$locations_center->locationid = "mapcenter";
$locations_center->name = "mapcenter";
$locations_center->type = "hidden";
}
$locations_center->lat = $location["center"][0];
$locations_center->lon = $location["center"][1];
$locations_center->zoom_min = $zoom;
$locations_center->zoom_max = $zoom;
$this->conn->save($locations_center);
$locations_db = $this->conn->select("NavigationLocation", $wherestr);
$locations_yelp = $yelp->getReviews($location);
if (is_array($locations_db) && is_array($locations_yelp)) {
$locations = array_merge($locations_yelp, $locations_db);
} else {
$locations = any($locations_db, $locations_yelp);
}
$ret = json_encode($locations);
return $ret;
}
示例4: lookup
public static function lookup($hostname)
{
self::init();
Profiler::StartTimer("DNSResolver::lookup()", 2);
$data = DataManager::singleton();
$records = $apc = NULL;
$cachekey = "dnsresolver.lookup.{$hostname}";
if (self::$cache && !empty($data->caches["apc"]) && $data->caches["apc"]["default"]->enabled) {
$apc = $data->caches["apc"]["default"];
$cached = $apc->get($cachekey);
if ($cached !== false) {
$records = unserialize($cached);
Logger::Info("DNSResolver: found '{$hostname}' in APC cache");
}
}
if ($records === NULL) {
Logger::Info("DNSResolver: Looking up '{$hostname}'");
foreach (self::$search as $suffix) {
$fqdn = $hostname . (!empty($suffix) ? "." . $suffix : "");
$records = dns_get_record($fqdn, DNS_A);
if (!empty($records)) {
break;
}
}
if (self::$cache && !empty($records) && $apc !== NULL && $apc->enabled) {
$ttl = any(self::$ttl, $records[0]["ttl"]);
$apc->set($cachekey, serialize($records), array("lifetime" => $ttl));
}
}
Profiler::StopTimer("DNSResolver::lookup()");
return $records;
}
示例5: _createMessageWithByteCount
private function _createMessageWithByteCount($bytes)
{
$this->_bytes = $bytes;
$msg = $this->_mock('Swift_Mime_Message');
$this->_checking(Expectations::create()->ignoring($msg)->toByteStream(any())->calls(array($this, '_write')));
return $msg;
}
示例6: controller_account
function controller_account($args)
{
if (!User::authorized("mail")) {
throw new Exception("not allowed");
}
$vars["account"] = any($args["account"], $args["item"]);
return $this->GetComponentResponse("./account.tpl", $vars);
}
示例7: __construct
function __construct($locations = NULL)
{
$dbdir = any($locations['tmp'], 'tmp');
if (class_exists("Outlet")) {
Outlet::init(array('connection' => array('type' => 'datamanager'), 'classes' => array()));
$this->outlet =& Outlet::getInstance();
}
}
示例8: test_any
public function test_any()
{
ensure(any(array(1, 2, 3), function ($v) {
return $v > 2;
}));
ensure(!any(array(1, 2, 3), function ($v) {
return $v > 4;
}));
}
示例9: controller_irc
public function controller_irc($args)
{
$vars = array();
$vars["host"] = any($args["host"], array_get($_SESSION, "irc.host"), "irc.freenode.net");
$vars["port"] = any($args["port"], array_get($_SESSION, "irc.port"), 6667);
$vars["nick"] = any($args["nick"], array_get($_SESSION, "irc.nickname"), sprintf("peon%04d", rand(0, 9999)));
array_set($_SESSION, "irc.nickname", $vars["nick"]);
return $this->GetComponentResponse("./irc.tpl", $vars);
}
示例10: shouldNotRelyOnArryIndexesWhenUnwrappingToASingleResolutionValue
/** @test */
public function shouldNotRelyOnArryIndexesWhenUnwrappingToASingleResolutionValue()
{
$mock = $this->createCallableMock();
$mock->expects($this->once())->method('__invoke')->with($this->identicalTo(2));
$d1 = new Deferred();
$d2 = new Deferred();
any(['abc' => $d1->promise(), 1 => $d2->promise()])->then($mock);
$d2->resolve(2);
$d1->resolve(1);
}
示例11: whenTokenIsExpired
/**
* @test
*/
public function whenTokenIsExpired()
{
require realpath(__DIR__ . '/../../../') . '/etc/app.php';
$db = $this->createMockDb();
$user = array_merge($this->createFixtureUser(), array('token_timestamp' => time() - TOKEN_VALID_TIME - 1));
$db->expects(any())->method('findUserByToken')->will(returnValue($user));
$checker = $this->createTokenChecker($db);
$request = $this->createValidRequest();
$this->assertErrorResponse(403, 'Token expired', $checker($request, $app));
}
示例12: testSettingCharsetClearsCache
public function testSettingCharsetClearsCache()
{
$headers = $this->_createHeaderSet(array(), false);
$this->_checking(Expectations::create()->ignoring($headers)->toString()->returns("Content-Type: text/plain; charset=utf-8\r\n")->ignoring($headers));
$cache = $this->_createCache(false);
$this->_checking(Expectations::create()->one($cache)->clearKey(any(), 'body')->ignoring($cache));
$entity = $this->_createEntity($headers, $this->_createEncoder(), $cache);
$entity->setBody("blah\r\nblah!");
$entity->toString();
$entity->setCharset('iso-2022');
}
示例13: controller_exists
public function controller_exists($args)
{
$vars["usertype"] = any($args["usertype"], "default");
$vars["userid"] = $args["userid"];
$user = false;
if (!empty($vars["userid"])) {
$user = User::get($vars["usertype"], $vars["userid"]);
}
$vars["success"] = !empty($user);
return $this->GetComponentResponse("./exists.tpl", $vars);
}
示例14: run_tasks
/** Run callbacks
* @param string $trigger Name of trigger to fier
* @param array $args Data to pass
* @return void
*/
public function run_tasks($trigger, array $args = array())
{
if (any($this::$callbacks[$trigger])) {
foreach ($this::$callbacks[$trigger] as $task) {
if (is_callable(array($this, $task))) {
$this->{$task}($args);
} else {
throw new \System\Error\Model(sprintf('Invalid callback "%s" for "%s"', $task, $trigger));
}
}
}
}
示例15: compile
private function compile(array $tokens)
{
$cg = (object) ['ts' => TokenStream::fromSlice($tokens), 'parsers' => []];
traverse(rtoken('/^(T_\\w+)·(\\w+)$/')->onCommit(function (Ast $result) use($cg) {
$token = $result->token();
$id = $this->lookupCapture($token);
$type = $this->lookupTokenType($token);
$cg->parsers[] = token($type)->as($id);
}), ($parser = chain(rtoken('/^·\\w+$/')->as('type'), token('('), optional(ls(either(future($parser)->as('parser'), chain(token(T_FUNCTION), parentheses()->as('args'), braces()->as('body'))->as('function'), string()->as('string'), rtoken('/^T_\\w+·\\w+$/')->as('token'), rtoken('/^T_\\w+$/')->as('constant'), rtoken('/^·this$/')->as('this'), label()->as('label'))->as('parser'), token(',')))->as('args'), commit(token(')')), optional(rtoken('/^·\\w+$/')->as('label'), null)))->onCommit(function (Ast $result) use($cg) {
$cg->parsers[] = $this->compileParser($result->type, $result->args, $result->label);
}), $this->layer('{', '}', braces(), $cg), $this->layer('[', ']', brackets(), $cg), $this->layer('(', ')', parentheses(), $cg), rtoken('/^···(\\w+)$/')->onCommit(function (Ast $result) use($cg) {
$id = $this->lookupCapture($result->token());
$cg->parsers[] = layer()->as($id);
}), token(T_STRING, '·')->onCommit(function (Ast $result) use($cg) {
$offset = \count($cg->parsers);
if (0 !== $this->dominance || 0 === $offset) {
$this->fail(self::E_BAD_DOMINANCE, $offset, $result->token()->line());
}
$this->dominance = $offset;
}), rtoken('/·/')->onCommit(function (Ast $result) {
$token = $result->token();
$this->fail(self::E_BAD_CAPTURE, $token, $token->line());
}), any()->onCommit(function (Ast $result) use($cg) {
$cg->parsers[] = token($result->token());
}))->parse($cg->ts);
// check if macro dominance '·' is last token
if ($this->dominance === \count($cg->parsers)) {
$this->fail(self::E_BAD_DOMINANCE, $this->dominance, $cg->ts->last()->line());
}
$this->specificity = \count($cg->parsers);
if ($this->specificity > 1) {
if (0 === $this->dominance) {
$pattern = chain(...$cg->parsers);
} else {
/*
dominat macros are partially wrapped in commit()s and dominance
is the offset used as the 'event horizon' point... once the entry
point is matched, there is no way back and a parser error arises
*/
$prefix = array_slice($cg->parsers, 0, $this->dominance);
$suffix = array_slice($cg->parsers, $this->dominance);
$pattern = chain(...array_merge($prefix, array_map(commit::class, $suffix)));
}
} else {
/*
micro optimization to save one function call for every token on the subject
token stream whenever the macro pattern consists of a single parser
*/
$pattern = $cg->parsers[0];
}
return $pattern;
}