本文整理汇总了PHP中Illuminate\Support\Arr::where方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::where方法的具体用法?PHP Arr::where怎么用?PHP Arr::where使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Arr
的用法示例。
在下文中一共展示了Arr::where方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$referer = $request->server->get('referer');
// Referer is not provided, we continue
if (is_null($referer) or env('APP_ENV', 'production') !== 'production') {
return $next($request);
}
// Handle the dictionnary.
// @todo Refactor that
$dir = realpath(dirname(__FILE__) . '/../../../../../') . '/';
$path = $dir . 'spammers.json';
$file = file_get_contents($path);
// Dictionnary is not readable, abort.
if (empty($file)) {
abort(500, 'Unable to read spammers.json');
}
$dictionary = json_decode($file);
// Parse the referer
$url = new Parser(new PublicSuffixList([]));
$host = $url->parseHost($referer)->host;
// Compare dictionary against the referer...
$search = Arr::where($dictionary, function ($key, $value) use($host) {
return mb_stripos($host, $value) !== false;
});
// ...and check for results
if (count($search) > 0) {
abort(500, 'Spammers protection');
}
// No spam, we can continue :)
return $next($request);
}
示例2: has
/**
* Determine if a user exists in the repository.
*
* @param string $identification
* @param string $type Must be one of properties defined in User class
* @return bool
*/
public function has($identification, $type = 'uid')
{
if ($type == "uid") {
return Arr::has($this->items, $identification);
} else {
return Arr::where((array) $this->items, function ($key, $value) use($identification, $type) {
if (property_exists($value, $type)) {
return false;
}
return $value->{$type} == $identification;
});
}
}
示例3: FilterOutUserSettings
/**
* Iterate through the flattened array of settings and removes
* all user settings. A new array is build and returned.
*
* User settings are found to start with the 'User" key followed by a number,
* both parts are separated by a dot ('.').
*
* @param $allSettings
* @return array
*/
public static function FilterOutUserSettings($allSettings)
{
$allNonUserSetting = Arr::where($allSettings, function ($k) {
if ("User." === substr($k, 0, 5)) {
$kparts = explode('.', $k);
$user = User::ofUsername($kparts[1])->first();
if ($user instanceof User) {
return false;
}
}
return true;
});
return $allNonUserSetting;
}
示例4: getTransactionsAttribute
public function getTransactionsAttribute()
{
return Cache::remember('transactions-on-currency-' . $this->id, Cache::get('altwallets.transactions.ttl'), function () {
$transactions = $this->client->listtransactions();
$filtered = array_reverse(Arr::where($transactions, function ($key, $transaction) {
if (in_array($transaction->category, ['send', 'receive', 'move'])) {
return true;
}
return false;
}));
return array_map(function ($transaction) {
return new Transaction((array) $transaction);
}, $filtered);
});
}
示例5:
/**
* Filter the array using the given callback.
*
* @param array $array
* @param callable $callback
* @return array
*/
function array_where($array, callable $callback)
{
return Arr::where($array, $callback);
}
示例6: validateDistinct
/**
* Validate an attribute is unique among other values.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return bool
*/
protected function validateDistinct($attribute, $value, $parameters)
{
$attributeName = $this->getPrimaryAttribute($attribute);
$explicitPath = $this->getLeadingExplicitAttributePath($attributeName);
$attributeData = $this->extractDataFromPath($explicitPath);
$data = Arr::where(Arr::dot($attributeData), function ($key) use($attribute, $attributeName) {
return $key != $attribute && Str::is($attributeName, $key);
});
return !in_array($value, array_values($data));
}
示例7: getNumericParameters
/**
* Get the numeric parameters from a given list.
*
* @param array $parameters
* @return array
*/
protected function getNumericParameters(array $parameters)
{
return Arr::where($parameters, function ($k, $v) {
return is_numeric($k);
});
}
示例8: rememberManyForever
/**
* Get an array of items from the cache, or store the default value forever.
*
* @param array $keys
* @param \Closure $callback
* @return mixed
*/
public function rememberManyForever(array $keys, Closure $callback)
{
$values = $this->getMany($keys);
$items = Arr::where($values, function ($key, $value) {
return is_null($value);
});
if (!empty($items)) {
$items = array_combine(array_keys($items), $callback(array_keys($items)));
$this->foreverMany($items);
$values = array_replace($values, $items);
}
return $values;
}
示例9:
/**
* Filter the array using the given Closure.
*
* @param array $array
* @param \Closure $callback
* @return array
*/
function array_where($array, Closure $callback)
{
return Arr::where($array, $callback);
}
示例10: filter
/**
* Run a filter over each of the items.
*
* @param callable|null $callback
* @return static
*/
public function filter(callable $callback = null)
{
if ($callback) {
return new static(Arr::where($this->items, $callback));
}
return new static(array_filter($this->items));
}
示例11: prepareDataToJson
private function prepareDataToJson($admin = false)
{
// apply admin filter
return Arr::where($this->getData(), function ($key, $value) use($admin) {
$meta = Arr::get($this->metas, $key);
return $admin === false && $meta['admin'] === true ? false : true;
});
}
示例12: validateDistinct
/**
* Validate an attribute is unique among other values.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @return bool
*/
protected function validateDistinct($attribute, $value, $parameters)
{
$attributeName = $this->getPrimaryAttribute($attribute);
$data = Arr::where(Arr::dot($this->data), function ($key) use($attribute, $attributeName) {
return $key != $attribute && Str::is($attributeName, $key);
});
return !in_array($value, array_values($data));
}
示例13: fetchDescendant
/**
* search descendants getter
*
* @param string $siteKey site key
* @param string $name the name
* @return array
*/
public function fetchDescendant($siteKey, $name)
{
$data = $this->getData($siteKey, $this->getHead($name));
return Arr::where($data, function ($idx, $item) use($name) {
return Str::startsWith($item->name, $name) && $name !== $item->name;
});
}