本文整理汇总了PHP中Doctrine\Common\Collections\Collection类的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: intersectUnion
/**
* This function performs a kind of "intersection union" operation, and is useful especially when dealing
* with dynamic forms. For instance, if a collection contains existing elements and a form remove one of those
* elements, this function will return a Collection that contains all the elements from $collection1, minus ones
* that are not present in $collection2. This is used internally in the DoctrineModule hydrator, so that the
* work is done for you automatically
*
* @param Collection $collection1
* @param Collection $collection2
* @return Collection
*/
public static function intersectUnion(Collection $collection1, Collection $collection2)
{
// Don't make the work both
if ($collection1 === $collection2) {
return $collection1;
}
$toRemove = array();
foreach ($collection1 as $key1 => $value1) {
$elementFound = false;
foreach ($collection2 as $key2 => $value2) {
if ($value1 === $value2) {
$elementFound = true;
unset($collection2[$key2]);
break;
}
}
if (!$elementFound) {
$toRemove[] = $key1;
}
}
// Remove elements that are in $collection1 but not in $collection2
foreach ($toRemove as $key) {
$collection1->remove($key);
}
// Add elements that are in $collection2 but not in $collection1
foreach ($collection2 as $value) {
$collection1->add($value);
}
return $collection1;
}
示例2: setRoles
/**
* Set the list of roles
* @param Collection $roles
*/
public function setRoles(Collection $roles)
{
$this->roles->clear();
foreach ($roles as $role) {
$this->roles[] = $role;
}
}
示例3: addError
/**
* @param mixed $context
* @param Collection|null $errors
*/
protected function addError($context, Collection $errors = null)
{
if ($errors && $this->getMessage()) {
$messageParameters = $this->getMessageParameters($context);
$errors->add(array('message' => $this->getMessage(), 'parameters' => $messageParameters));
}
}
示例4: let
function let(LoaderInterface $loader, Collection $resourcesToThemes, ThemeInterface $theme)
{
$theme->getLogicalName()->willReturn("sylius/sample-theme");
$resourcesToThemes->get(realpath($this->getThemeTranslationResourcePath()))->willReturn($theme);
$resourcesToThemes->get(realpath($this->getVanillaTranslationResourcePath()))->willReturn(null);
$this->beConstructedWith($loader, $resourcesToThemes);
}
示例5:
function it_applies_choice_filter_on_datasource_for_collection_value(FilterDatasourceAdapterInterface $datasource, Collection $collection, $utility)
{
$collection->count()->willReturn(2);
$collection->getValues()->willReturn(['foo', 'bar']);
$utility->applyFilter($datasource, 'data_name_key', 'IN', ['foo', 'bar'])->shouldBeCalled();
$this->apply($datasource, ['value' => $collection, 'type' => AjaxChoiceFilterType::TYPE_CONTAINS]);
}
示例6: filterDeleted
/**
* @param Collection $collection
*
* @return ArrayCollection
*/
private function filterDeleted(Collection $collection) : ArrayCollection
{
// getValues => reset keys
return new ArrayCollection($collection->filter(function ($entity) {
return !$entity instanceof SoftDeletableInterface || $entity->isDeleted() === false;
})->getValues());
}
示例7: addCategoryParent
private function addCategoryParent(CategoryInterface $category = null, Collection $collection)
{
if (null !== $category) {
$collection->add($category);
$this->addCategoryParent($category->getParent(), $collection);
}
}
示例8: setDomains
/**
* Twitter requires domains without scheme
*
* @param Doctrine\Common\Collections\Collection
*/
public function setDomains(Collection $domains)
{
$remap = $domains->map(function ($item) {
return str_replace(array("https://", "http://"), '', $item);
}, $domains);
$this->domains = $remap;
}
示例9: processConfiguration
/**
* {@inheritdoc}
*/
public function processConfiguration(Collection $collection)
{
$config = [];
$collection->map(function (PaymentMethodConfigurationInterface $configuration) use(&$config) {
$config[$configuration->getName()] = $configuration->getValue();
});
return $config;
}
示例10: clearPreviousCollection
/**
* Resets previous photo collection
*
* @param Collection $collection
*/
protected function clearPreviousCollection(Collection $collection)
{
if ($collection->count()) {
foreach ($collection as $item) {
$collection->removeElement($item);
}
}
}
示例11: removeEmpresa
/**
* @param Empresa $empresa
*/
public function removeEmpresa($empresa)
{
if ($this->empresas->contains($empresa)) {
$empresa->setDirector(null);
$this->empresas->removeElement($empresa);
}
}
示例12: removeItem
/**
* Remove item.
*
* @param \SWP\Component\Bridge\Model\Item $item
*/
public function removeItem(\SWP\Component\Bridge\Model\Item $item)
{
if ($this->items->contains($item)) {
$this->items->removeElement($item);
$item->setPackage(null);
}
}
示例13: addPost
/**
* Adds a post top the User's authored Posts.
*
* Post Author needs to be updated manually.
*
* @param Post $addPost
* @return User
*/
public function addPost(Post $addPost)
{
if (!$this->getAuthoredPosts()->contains($addPost)) {
$this->authoredPosts->add($addPost);
}
return $this;
}
示例14: addParent
/**
* @param Role $parent
*/
public function addParent(Role $parent)
{
if ($this->parents->contains($parent)) {
throw new LogicException(sprintf("Parent role '%s' already assigned.", $parent->getId()));
}
$this->parents->add($parent);
}
示例15: removeImage
/**
* {@inheritdoc}
*/
public function removeImage(TaxonImageInterface $image)
{
if ($this->hasImage($image)) {
$image->setTaxon(null);
$this->images->removeElement($image);
}
}