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


PHP Iterator::count方法代码示例

本文整理汇总了PHP中Iterator::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Iterator::count方法的具体用法?PHP Iterator::count怎么用?PHP Iterator::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Iterator的用法示例。


在下文中一共展示了Iterator::count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: count

 /**
  * Count elements of an object
  *
  * Rewinding version of count 
  *
  * @return int
  */
 public function count()
 {
     if ($this->_iterator instanceof \Countable) {
         return $this->_iterator->count();
     }
     $count = iterator_count($this->_iterator);
     $this->_iterator->rewind();
     return $count;
 }
开发者ID:GemsTracker,项目名称:MUtil,代码行数:16,代码来源:ItemCallbackIterator.php

示例2: getPayments

 /**
  * lista wplat, uzywana takze do symulacji
  * 
  * @param Iterator $iterator
  * @return Payments
  */
 public function getPayments(Iterator $iterator)
 {
     $payments = new Payments();
     $amount = $this->transaction->getAmount();
     $overpayment = function ($amount) use($payments) {
         $payments->append(new Payment(array('amount' => $amount, 'type' => Payment::TYPE_OVERPAYMENT)));
     };
     if ($iterator->count() == 0) {
         /* jezeli brak dokumentow jedna wplata z nadp³at¹ */
         $overpayment($amount);
         return $payments;
     }
     /* rozlicza kwote transakcji na dokumenty ksiegowe */
     foreach ($iterator as $document) {
         /* @var $document SettlementInterface */
         if ($document instanceof Wrapper) {
             $due = $document->getPaymentAmount();
             /* kwota edytowana */
             $document = $document->getDocument();
             /* ograniczenia dla recznego rozliczenia */
             if ($due == 0 || $due > $document->getDocumentAmount()) {
                 $due = $document->getDocumentAmount();
             }
         } else {
             $due = $document->getDocumentAmount();
             /* kwota z dokumentu Do_zaplaty/kwota_raty... */
         }
         if ($amount == 0) {
             break;
         }
         $money = 0;
         if ($amount > floatval($due)) {
             $money = round(floatval($due), 2);
             $amount -= $money;
             $amount = round($amount, 2);
         } else {
             $money = $amount;
             $amount = 0;
         }
         $payments->append((new Payment(array('amount' => $amount, 'type' => Payment::TYPE_TRANSFER)))->setSettlementDocument($document));
     }
     if ($amount > 0) {
         /* jezeli jeszcze zostalo cos kasy (suma kwot faktur jest mniejsza niz kwota transakcji) to wstawia nadplate */
         $overpayment($amount);
     }
     return $payments;
 }
开发者ID:krozner,项目名称:BankStatement,代码行数:53,代码来源:Settlement.php

示例3: testCount

 /**
  * @param \Iterator $it
  * @param mixed $first
  * @param mixed $last
  * @param int $count
  * @param callable $predicate
  *
  * @dataProvider dataProvider
  */
 public function testCount(\Iterator $it, $first, $last, $count, callable $predicate = null)
 {
     $this->assertEquals($count, $it->count($predicate));
 }
开发者ID:hunts,项目名称:stream-php,代码行数:13,代码来源:IteratorExtensionTest.php

示例4: search

 /**
  * The main method for calling the search method in the spotify web API.
  * @param string $query
  * @param array $options
  * @link https://developer.spotify.com/technologies/web-api/search/
  * 
  */
 function search($query, $options)
 {
     if ($query == '') {
         throw new \Exception();
     }
     if (!isset($options['type'])) {
         $options['type'] = 'track';
     }
     if (!array_key_exists($options['type'], self::$_SPOTIFY_SEARCH_METHODS)) {
         // TODO: error
     }
     // TODO ex:
     $this->base_uri = self::$_SPOTIFY_SEARCH_ENDPOINT . strtolower($options['type']) . '.json';
     // if page is set, add that as an additional parameter
     $this->query_string = '?q=' . json_encode($query) . (isset($options['page']) ? '&page=' . Constants::PAGER_MAX_PAGES * $options['page'] : '');
     $response = $this->_call_spotify_api();
     $data = new \cecilia\model\SpotifyResult($response);
     if ($data->cursor->has_next) {
         $threshold = $data->cursor->total < CECILIA_PAGER_MAX_ITEMS ? $data->cursor->total : CECILIA_PAGER_MAX_ITEMS;
         $offset = Constants::SPOTIFY_RESULTS_PER_PAGE;
         $i = 0;
         $tmp_array = array();
         while ($offset < $threshold) {
             if ($i == 0) {
                 $p = $data->cursor->page + 1;
                 $this->query_string = '?q=' . json_encode($query) . '&page=' . $p;
                 $offset = $offset * 2;
                 $p++;
             } else {
                 if ($offset < $threshold) {
                     $this->query_string = '?q=' . json_encode($query) . '&page=' . $p;
                     $offset = $p * Constants::SPOTIFY_RESULTS_PER_PAGE;
                     $p++;
                 }
             }
             $tmp = new \cecilia\model\SpotifyResult($this->_call_spotify_api());
             $tmp_data = $tmp->data;
             $tmp_array = array_merge($tmp_data, $tmp_array);
             $i++;
             if ($i > 4) {
                 die(var_dump($tmp_array));
             }
         }
         $pager = new Pager($tmp);
     } else {
         $pager = new Pager($data);
     }
     if (isset($tmp_array)) {
         $data->data = array_merge($data->data, $tmp_array);
     }
     // now, we have the first page of results.  from this we can move forward with putting together the aggregated result set for caching.
     $parsed = array();
     $class_name = '\\cecilia\\model\\' . ucfirst($data->type);
     foreach ($data->data as $k => $v) {
         try {
             $parsed[] = new $class_name($v);
         } catch (\Exception $e) {
         }
     }
     $it = new Iterator($parsed);
     // if the filter option is set, filter the result.
     $filtered = new Filter($it);
     return $it->count() > 0 ? new Response(1, $parsed, $pager) : new Response(0, $parsed, $pager);
 }
开发者ID:blanc0,项目名称:cecilia,代码行数:71,代码来源:Cecilia.php

示例5: count

 /**
  * {@inheritdoc}
  */
 public function count()
 {
     $this->initialize();
     return $this->documents->count();
 }
开发者ID:hason,项目名称:sulu-document-manager,代码行数:8,代码来源:AbstractLazyCollection.php


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