当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::search方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:breachofmind,项目名称:birdmin,代码行数:32,代码来源:SitemapGenerator.php

示例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);
 }
开发者ID:gerardoGomr,项目名称:sise,代码行数:15,代码来源:DirGeneralRestriccionIp.php

示例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];
 }
开发者ID:rhincodon,项目名称:laravel-db-language,代码行数:18,代码来源:DbLanguage.php

示例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;
 }
开发者ID:scolib,项目名称:repositories,代码行数:20,代码来源:Repository.php

示例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();
 }
开发者ID:SkysoulDesign,项目名称:mirage.dev,代码行数:19,代码来源:GenerateCodesCommand.php

示例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;
 }
开发者ID:thinhbuzz,项目名称:laravel-advanced-authorization,代码行数:28,代码来源:UserAuthorizationTrait.php

示例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';
     }));
 }
开发者ID:sa7bi,项目名称:euro16,代码行数:12,代码来源:SupportCollectionTest.php

示例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;
     }
 }
开发者ID:bnbwebexpertise,项目名称:laravel-push-notifications,代码行数:12,代码来源:ApnsService.php

示例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;
 }
开发者ID:cviebrock,项目名称:eloquent-sluggable,代码行数:23,代码来源:SlugService.php

示例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);
 }
开发者ID:fewagency,项目名称:fluent-html,代码行数:10,代码来源:FluentHtmlElement.php


注:本文中的Illuminate\Support\Collection::search方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。