本文整理汇总了PHP中Illuminate\Support\Collection::search方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::search方法的具体用法?PHP Collection::search怎么用?PHP Collection::search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Collection
的用法示例。
在下文中一共展示了Collection::search方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: crawlUrl
/**
* Crawl and process a single URL.
* @param $url string
* @return mixed|null
*/
protected function crawlUrl($url, $parentUrl = null)
{
if (!$url || $this->crawled->search($url) !== false || Str::startsWith($url, "#")) {
return null;
}
$this->log("Crawling URL: " . $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response = curl_exec($ch);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = $this->parseHeader(substr($response, 0, $headerSize));
$body = substr($response, $headerSize);
curl_close($ch);
$this->crawled->push($url);
if (!$this->validate($header, $body, $url, $parentUrl)) {
return null;
}
$processed = $this->processHtml($url, HtmlDomParser::str_get_html($body));
$this->add($processed);
// Recursively crawl other URLs that were found.
foreach ($processed['urls'] as $href) {
$this->crawlUrl($href, $url);
}
}
示例2: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$IP = new Collection(['172.16.80.25', '::1']);
if ($IP->search($request->ip()) === false) {
return redirect('/login');
}
return $next($request);
}
示例3: findByGroupAndName
/**
* @param $group
* @param $name
* @return string
*/
private function findByGroupAndName($group, $name)
{
if (!$this->values) {
return (object) ['value' => "{$group}::{$name}"];
}
$value = $this->values->search(function ($item) use($group, $name) {
return $item->group == $group && $item->group_name == $name;
});
if ($value === false) {
return (object) ['value' => "{$group}::{$name}"];
}
return $this->values[$value];
}
示例4: pushCriteria
/**
* @param \Bosnadev\Repositories\Contracts\CriteriaInterface $criteria
*
* @return $this
*/
public function pushCriteria(CriteriaInterface $criteria)
{
if ($this->preventCriteriaOverwriting) {
// Find existing criteria
$key = $this->criteria->search(function ($item) use($criteria) {
return is_object($item) and get_class($item) == get_class($criteria);
});
// Remove old criteria
if (is_int($key)) {
$this->criteria->offsetUnset($key);
}
}
$this->criteria->push($criteria);
return $this;
}
示例5: regenerate
/**
* regenerate duplicated code
* @return string
*/
private function regenerate($code)
{
/**
* Get Codes ID
*/
$id = $this->codes->search($code);
/**
* Regenerate Code
*/
$this->codes[$id] = $this->generateCode();
/**
* Check DB Again for duplication
*/
$this->checkDatabase();
}
示例6: is
/**
* Return true if user has all roles
*
* @param string|array $role
* @param bool $any
* @return bool
*/
public function is($role, $any = false)
{
if (is_null($this->slugRoles)) {
$this->loadRoles();
$this->slugRoles = $this->roles->lists('slug');
}
if ($role instanceof Model) {
$role = $role->slug;
}
if (is_array($role)) {
foreach ($role as $item) {
if ($this->slugRoles->search($item) === false) {
return false;
} elseif ($any === true) {
return true;
}
}
return true;
}
return $this->slugRoles->search($role) !== false;
}
示例7: testSearchReturnsFalseWhenItemIsNotFound
public function testSearchReturnsFalseWhenItemIsNotFound()
{
$c = new Collection([1, 2, 3, 4, 5, 'foo' => 'bar']);
$this->assertFalse($c->search(6));
$this->assertFalse($c->search('foo'));
$this->assertFalse($c->search(function ($value) {
return $value < 1 && is_numeric($value);
}));
$this->assertFalse($c->search(function ($value) {
return $value == 'nope';
}));
}
示例8: triggerDeviceError
/**
* @param string $token
*/
protected function triggerDeviceError(Collection $devices, $token)
{
$device = $devices->search(function ($device) use($token) {
return $device->token == $token;
});
if (!empty($device)) {
$this->errors[] = $device;
}
}
示例9: generateSuffix
/**
* Generate a unique suffix for the given slug (and list of existing, "similar" slugs.
*
* @param string $slug
* @param string $separator
* @param \Illuminate\Support\Collection $list
* @return string
*/
protected function generateSuffix($slug, $separator, Collection $list)
{
$len = strlen($slug . $separator);
// If the slug already exists, but belongs to
// our model, return the current suffix.
if ($list->search($slug) === $this->model->getKey()) {
$suffix = explode($separator, $slug);
return end($suffix);
}
$list->transform(function ($value, $key) use($len) {
return intval(substr($value, $len));
});
// find the highest value and return one greater.
return $list->max() + 1;
}
示例10: getContentOffset
/**
* Get the offset of a specified piece of content within this element.
*
* @param FluentHtmlElement|string|mixed $content to look for
* @return mixed key for matching content, or false if not found
*/
protected function getContentOffset($content)
{
return $this->html_contents->search($content);
}