コード例 #1
0
ファイル: MapIterator.php プロジェクト: jyxo/php
 /**
  * Seeks to defined position. Does NOT throw {@link \OutOfBoundsException}.
  *
  * @param integer $position New position
  */
 public function seek($position)
 {
     if ($this->iterator instanceof \SeekableIterator) {
         try {
             $this->iterator->seek($position);
         } catch (\OutOfBoundsException $e) {
             // Skipped on purpose, I don't think it's necessary
             // If you'd like to have this exception throw, remove this try-catch and add to 'else' block
             // If (!$this->valid()) { throw new \OutOfBoundsException('Invalid seek position'); };
         }
     } else {
         $this->rewind();
         for ($i = 0; $i < $position; $i++) {
             $this->next();
         }
     }
 }
コード例 #2
0
ファイル: Counter.php プロジェクト: CupOfTea696/Counter
 /**
  * Seeks to a position.
  *
  * @param  int  $position
  * @return void
  * @throws \InvalidArgumentException when $position is not an integer.
  * @throws \OutOfBoundsException when the seek $position exeeds the traversable's length.
  */
 public function seek($position)
 {
     if (!$this->isInt($position)) {
         throw new InvalidArgumentException('Seek position must be an integer.');
     }
     $position = max(0, (int) $position);
     if ($this->length !== null && $this->length < $position) {
         throw new OutOfBoundsException('Invalid seek position (' . $position . ').');
     }
     if ($this->traversable()) {
         if ($this->traversable instanceof SeekableIterator) {
             $this->traversable->seek($position);
         } else {
             $this->traversable->rewind();
             for ($i = 0; $i < $position; $i++) {
                 $this->traversable->next();
             }
         }
     }
     $this->i = $position;
 }
コード例 #3
0
ファイル: ActionController.php プロジェクト: reith2004/frapi
    /**
     * Prototype getErrors
     *
     * This method is not used. It is currently a prototype, a holder
     * for reverse engineering the actions and finding the errors
     * in each of the actions and creating them in the database associating
     * them with actions.
     *
     * @param  Iterator $it  The iterator to fetch the parameters from
     * @param  string   $methodName The original method name to parse.
     * @return mixed    Either an array of error or false.
     */
    private function getErrors($it, $methodName)
    {
        $error  = array();
        $i = 0;
        while ($it->valid()) {
            $it->next();
            $mainKey = $key = $it->key();
            $current = $it->current();

            if ((double)$current[0] == T_CONSTANT_ENCAPSED_STRING) {

                $error[$methodName][$key][$i] = array();
                $error[$methodName][$key][$i]['name'] = $current[1];

                while ($it->valid()) {
                    $it->next();
                    $current = $it->current();

                    if ((double)$current[0] == T_CONSTANT_ENCAPSED_STRING) {
                        $error[$methodName][$key]['message'] = $current[1];

                        while ($it->valid()) {

                            $it->next();
                            $current = $it->current();
                            if ((double)$current[0] == T_LNUMBER) {
                                $error[$methodName][$key]['code'] = $current[1];

                            }
                        }
                    } else {
                        if ($it->offsetExists($mainKey)) {
                            $it->seek($mainKey);
                        }
                    }
                }

                ++$i;
            } else {

            }
        }

        return !empty($error) ? $error : false;
    }