Doctrine Common
  1. Doctrine Common
  2. DCOM-17

Add Collection::slice($offset, $length)

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-BETA4
    • Fix Version/s: 2.0.0-RC1
    • Component/s: Collections
    • Labels:
      None

      Description

      Since we are still at a point were bc breaks are potentially not so harming:

      We need a slice() method on the Collection for forward compatibility, the support for large and very large collections using FETCH_EXTRA would heavily benefit from a method like this.

      /**
       * 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.
       * 
       * @param int $offset
       * @param int $length
       * @return array
       */
      public function slice($offset, $length = null);
      

      The ArrayCollection implement would be:

      public function slice($offset, $length = null);
      {
          return array_slice($this->_elements, $offset, $length, true); // preserve keys
      }
      

        Activity

        Benjamin Eberlei created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Description Since we are still at a point were bc breaks are potentially not so harming:

        We need a slice() method on the Collection for forward compatibility, the support for large and very large collections using FETCH_EXTRA would heavily benefit from a method like this.

        {code}
        /**
         * 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 are not guaranteed to be preserved, numerical keys are re-indexed in their
         * order of appearance.
         *
         * @param int $offset
         * @param int $length
         * @return array
         */
        public function slice($offset, $length = null);
        {code}

        The ArrayCollection implement would be:

        {code}
        public function slice($offset, $length = null);
        {
            return array_slice($this->_elements, $offset, $length);
        }
        {code}
        Since we are still at a point were bc breaks are potentially not so harming:

        We need a slice() method on the Collection for forward compatibility, the support for large and very large collections using FETCH_EXTRA would heavily benefit from a method like this.

        {code}
        /**
         * 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.
         *
         * @param int $offset
         * @param int $length
         * @return array
         */
        public function slice($offset, $length = null);
        {code}

        The ArrayCollection implement would be:

        {code}
        public function slice($offset, $length = null);
        {
            return array_slice($this->_elements, $offset, $length);
        }
        {code}
        Benjamin Eberlei made changes -
        Description Since we are still at a point were bc breaks are potentially not so harming:

        We need a slice() method on the Collection for forward compatibility, the support for large and very large collections using FETCH_EXTRA would heavily benefit from a method like this.

        {code}
        /**
         * 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.
         *
         * @param int $offset
         * @param int $length
         * @return array
         */
        public function slice($offset, $length = null);
        {code}

        The ArrayCollection implement would be:

        {code}
        public function slice($offset, $length = null);
        {
            return array_slice($this->_elements, $offset, $length);
        }
        {code}
        Since we are still at a point were bc breaks are potentially not so harming:

        We need a slice() method on the Collection for forward compatibility, the support for large and very large collections using FETCH_EXTRA would heavily benefit from a method like this.

        {code}
        /**
         * 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.
         *
         * @param int $offset
         * @param int $length
         * @return array
         */
        public function slice($offset, $length = null);
        {code}

        The ArrayCollection implement would be:

        {code}
        public function slice($offset, $length = null);
        {
            return array_slice($this->_elements, $offset, $length, true); // preserve keys
        }
        {code}
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Assignee Roman S. Borschel [ romanb ] Benjamin Eberlei [ beberlei ]
        Benjamin Eberlei made changes -
        Workflow jira [ 11739 ] jira-feedback2 [ 17873 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17873 ] jira-feedback3 [ 19836 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Benjamin Eberlei
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: