當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。