本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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);
}
示例5: slice
/**
* {@inheritDoc}
*/
public function slice($offset, $length = null)
{
$this->initialize();
return $this->collection->slice($offset, $length);
}
示例6: findAll
/**
* {@inheritdoc}
*/
public function findAll($page = 1, $pageSize = null)
{
return array_values($this->taskExecutionCollection->slice(($page - 1) * $pageSize, $pageSize));
}
示例7: getItems
/**
* {@inheritDoc}
*/
public function getItems($offset, $itemCountPerPage)
{
return array_values($this->collection->slice($offset, $itemCountPerPage));
}
示例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];
}
示例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()];
}
示例10: slice
/**
* {@inheritdoc}
*/
public function slice($offset, $length = null)
{
return $this->inner->slice($offset, $length);
}
示例11: testSlice
/**
* @dataProvider provideCollection
*/
public function testSlice(Collection $coll, array $elements)
{
$this->assertSame(array_slice($elements, 0, -1, true), $coll->slice(0, -1));
}
示例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);
}
示例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;
}