Skip to content

Add compatibility with Doctrine Collection interface #51

Description

@strider2038

Is your feature request related to a problem? Please describe.

On our projects we use strictly typed collections for Doctrine. I think it will be nice if AbstractCollection class can implement methods from Doctrine Collection interface.

Describe the solution you'd like

I suggest to add methods to AbstractCollection and/or AbstractArray that will be compatible with Collection

  • public function removeElement($element)
  • public function containsKey($key)
  • public function get($key)
  • public function getKeys()
  • public function getValues()
  • public function set($key, $value)
  • public function key()
  • public function current()
  • public function next()
  • public function exists(Closure $p)
  • public function forAll(Closure $p)
  • public function partition(Closure $p)
  • public function indexOf($element)
  • public function slice($offset, $length = null)

Then user of the library can do something like this.

class ConcreteClassCollection extends Ramsey\Collection\AbstractCollection implements Doctrine\Common\Collections\Collection {
    public function getType(): string
    {
        return ConcreteClass::class;
    }
}

Describe alternatives you've considered

Maybe better approach is to add a trait?

class ConcreteClassCollection extends Ramsey\Collection\AbstractCollection implements Doctrine\Common\Collections\Collection {
    use DoctrineCollectionTrait;

    public function getType(): string
    {
        return ConcreteClass::class;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions