本文整理汇总了PHP中Collection::clear方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::clear方法的具体用法?PHP Collection::clear怎么用?PHP Collection::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection::clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reverseTransform
/**
* @param array $ids
* @param Collection $collection
*/
public function reverseTransform($ids, $collection)
{
if (count($ids) == 0) {
// don't check for collection count, a straight clear doesnt initialize the collection
$collection->clear();
return $collection;
}
$em = $this->getOption('em');
$metadata = $em->getClassMetadata($this->getOption('className'));
$reflField = $metadata->getReflectionProperty($metadata->identifier[0]);
foreach ($collection as $object) {
$key = array_search($reflField->getValue($object), $ids);
if (false === $key) {
$collection->removeElement($object);
} else {
unset($ids[$key]);
}
}
// @todo: This can be greatly optimized into a single SELECT .. WHERE id IN () query.
foreach ($ids as $id) {
$entity = $em->find($this->getOption('className'), $id);
if (!$entity) {
throw new TransformationFailedException("Selected entity of type '" . $this->getOption('className') . "' by id '" . $id . "' which is not present in the database.");
}
$collection->add($entity);
}
return $collection;
}
示例2: clear
/**
* {@inheritdoc}
*/
public function clear()
{
if ($this->initialized && $this->isEmpty()) {
return;
}
if ($this->mapping !== null && isset($this->mapping['embedded'])) {
foreach ($this->coll as $element) {
$this->dm->getUnitOfWork()->scheduleOrphanRemoval($element);
}
}
$this->coll->clear();
$this->changed();
$this->dm->getUnitOfWork()->scheduleCollectionDeletion($this);
$this->takeSnapshot();
}
示例3: clear
/**
* {@inheritdoc}
*/
public function clear()
{
if ($this->initialized && $this->isEmpty()) {
return;
}
if ($this->mapping !== null && isset($this->mapping['embedded'])) {
foreach ($this->coll as $element) {
$this->uow->scheduleOrphanRemoval($element);
}
}
$this->mongoData = array();
$this->coll->clear();
if ($this->mapping['isOwningSide']) {
$this->changed();
$this->uow->scheduleCollectionDeletion($this);
$this->takeSnapshot();
}
}
示例4: testIsEmptyClear
public function testIsEmptyClear()
{
$this->assertEquals(false, $this->collection->isEmpty());
$this->collection->clear();
$this->assertEquals(true, $this->collection->isEmpty());
}
示例5: clear
/**
* Removes all of the elements from this collection.
* @return void
* @throws NotSupportedException
*/
public function clear()
{
parent::clear();
$this->loaded = false;
}
示例6: clear
/**
* {@inheritdoc}
*/
public function clear()
{
$this->_initialize();
$result = $this->_coll->clear();
if ($this->_association->isOwningSide) {
$this->_changed();
$this->_em->getUnitOfWork()->scheduleCollectionDeletion($this);
}
return $result;
}