當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::slice方法代碼示例

本文整理匯總了PHP中Doctrine\Common\Collections\Collection::slice方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::slice方法的具體用法?PHP Collection::slice怎麽用?PHP Collection::slice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\Common\Collections\Collection的用法示例。


在下文中一共展示了Collection::slice方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: slice

 /**
  * {@inheritDoc}
  */
 public function slice($offset, $length = null)
 {
     $array = [];
     foreach ($this->collection->slice($offset, $length) as $element) {
         $array[$this->getKey($element)] = $element;
     }
     return $array;
 }
開發者ID:cross-solution,項目名稱:yawik,代碼行數:11,代碼來源:IdentityWrapper.php

示例2: testSlice

 public function testSlice()
 {
     $this->_coll[] = 'one';
     $this->_coll[] = 'two';
     $this->_coll[] = 'three';
     $slice = $this->_coll->slice(0, 1);
     $this->assertInternalType('array', $slice);
     $this->assertEquals(array('one'), $slice);
     $slice = $this->_coll->slice(1);
     $this->assertEquals(array(1 => 'two', 2 => 'three'), $slice);
     $slice = $this->_coll->slice(1, 1);
     $this->assertEquals(array(1 => 'two'), $slice);
 }
開發者ID:TuxCoffeeCorner,項目名稱:tcc,代碼行數:13,代碼來源:CollectionTest.php

示例3: normalizeWarnings

 /**
  * Normalizes the warnings
  *
  * @param Collection $warnings
  * @param array      $context
  *
  * @return array
  */
 protected function normalizeWarnings(Collection $warnings, array $context = [])
 {
     $result = [];
     $selectedWarnings = [];
     if (isset($context['limit_warnings']) && $context['limit_warnings'] > 0) {
         $selectedWarnings = $warnings->slice(0, $context['limit_warnings']);
     } else {
         $selectedWarnings = $warnings;
     }
     foreach ($selectedWarnings as $warning) {
         $result[] = ['label' => $this->translator->trans($warning->getName()), 'reason' => $this->translator->trans($warning->getReason(), $warning->getReasonParameters()), 'item' => $warning->getItem()];
     }
     return $result;
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:22,代碼來源:StepExecutionNormalizer.php

示例4: slice

 /**
  * Extract a slice of $length elements starting at position $offset from the Collection.
  *
  * If $length is null it returns all elements from $offset to the end of the Collection.
  * Keys have to be preserved by this method. Calling this method will only return the
  * selected slice and NOT change the elements contained in the collection slice is called on.
  *
  * @param int $offset
  * @param int $length
  * @return array
  */
 public function slice($offset, $length = null)
 {
     if (!$this->initialized && !$this->isDirty && $this->association['fetch'] == Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) {
         return $this->em->getUnitOfWork()->getCollectionPersister($this->association)->slice($this, $offset, $length);
     }
     $this->initialize();
     return $this->coll->slice($offset, $length);
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:19,代碼來源:PersistentCollection.php

示例5: slice

 /**
  * {@inheritDoc}
  */
 public function slice($offset, $length = null)
 {
     $this->initialize();
     return $this->collection->slice($offset, $length);
 }
開發者ID:BozzaCoon,項目名稱:SPHERE-Framework,代碼行數:8,代碼來源:AbstractLazyCollection.php

示例6: findAll

 /**
  * {@inheritdoc}
  */
 public function findAll($page = 1, $pageSize = null)
 {
     return array_values($this->taskExecutionCollection->slice(($page - 1) * $pageSize, $pageSize));
 }
開發者ID:php-task,項目名稱:php-task,代碼行數:7,代碼來源:ArrayTaskExecutionRepository.php

示例7: getItems

 /**
  * {@inheritDoc}
  */
 public function getItems($offset, $itemCountPerPage)
 {
     return array_values($this->collection->slice($offset, $itemCountPerPage));
 }
開發者ID:KBO-Techo-Dev,項目名稱:MagazinePro-zf25,代碼行數:7,代碼來源:Collection.php

示例8: extractCommentsPage

 public static function extractCommentsPage(Collection $comments, $from)
 {
     return ['from' => $from, 'entities' => $comments->slice($from, AbstractCommentRepository::COMMENTS_PER_PAGE), 'total_count' => $comments->count(), 'entities_per_page' => self::COMMENTS_PER_PAGE];
 }
開發者ID:kipelovets,項目名稱:kipelovets,代碼行數:4,代碼來源:AbstractCommentRepository.php

示例9: extractPage

 public static function extractPage(Collection $collection, $from)
 {
     return ['from' => $from, 'entities' => $collection->slice($from, self::getEntitiesPerPage()), 'total_count' => $collection->count(), 'entities_per_page' => self::getEntitiesPerPage()];
 }
開發者ID:kipelovets,項目名稱:kipelovets,代碼行數:4,代碼來源:ArticleRepository.php

示例10: slice

 /**
  * {@inheritdoc}
  */
 public function slice($offset, $length = null)
 {
     return $this->inner->slice($offset, $length);
 }
開發者ID:peterkrejci,項目名稱:music-collection,代碼行數:7,代碼來源:ReadOnlyCollectionWrapper.php

示例11: testSlice

 /**
  * @dataProvider provideCollection
  */
 public function testSlice(Collection $coll, array $elements)
 {
     $this->assertSame(array_slice($elements, 0, -1, true), $coll->slice(0, -1));
 }
開發者ID:malarzm,項目名稱:collections,代碼行數:7,代碼來源:BaseTest.php

示例12: getScores

 /**
  * Get all historical scores indexed by date
  *
  * @param integer $limit
  *
  * @return array
  */
 public function getScores($limit = null)
 {
     if (null === $limit) {
         return $this->scores;
     }
     return $this->scores->slice(0, $limit);
 }
開發者ID:KnpLabs,項目名稱:KnpBundles,代碼行數:14,代碼來源:Bundle.php

示例13: slice

 /**
  * Slices a doctrine collection from an array of filters
  * @param  Collection                $storeNewsCollection
  * @param  array                     $filters
  * @throws \InvalidArgumentException
  * @return array
  * @author Yohann Marillet
  */
 public function slice(Collection $collection, array $filters)
 {
     if (!isset($filters['offset'])) {
         throw new \InvalidArgumentException('Filter key "offset" must be specified');
     }
     if (!isset($filters['limit'])) {
         $filters['limit'] = null;
     } else {
         $filters['limit'] = (int) $filters['limit'];
     }
     $return = $collection->slice((int) $filters['offset'], $filters['limit']);
     return $return;
 }
開發者ID:ymarillet,項目名稱:sknife,代碼行數:21,代碼來源:AbstractRepository.php


注:本文中的Doctrine\Common\Collections\Collection::slice方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。