Class yii\mongodb\file\Cursor

Inheritanceyii\mongodb\file\Cursor » IteratorIterator
ImplementsCountable
Available since extension's version2.1
Source Code https://github.com/yiisoft/yii2-mongodb/blob/master/src/file/Cursor.php

Cursor is a wrapper around \MongoDB\Driver\Cursor, which allows returning of the record with yii\mongodb\file\Download instance attached.

Public Properties

Hide inherited properties

Property Type Description Defined By
$collection yii\mongodb\file\Collection Related GridFS collection instance. yii\mongodb\file\Cursor

Public Methods

Hide inherited methods

Method Description Defined By
__call() PHP magic method, which is invoked on attempt of invocation not existing method. yii\mongodb\file\Cursor
__construct() Constructor. yii\mongodb\file\Cursor
__get() PHP magic method, which is invoked on attempt of getting not existing property. yii\mongodb\file\Cursor
__isset() PHP magic method, which is invoked on attempt of checking if a property is set. yii\mongodb\file\Cursor
__set() PHP magic method, which is invoked on attempt of setting not existing property. yii\mongodb\file\Cursor
__unset() PHP magic method, which is invoked on attempt of unsetting of property. yii\mongodb\file\Cursor
count() Count elements of this cursor. yii\mongodb\file\Cursor
current() Return the current element This method is required by the interface Iterator. yii\mongodb\file\Cursor
getId() Returns the ID for this cursor. yii\mongodb\file\Cursor
getInnerIterator() yii\mongodb\file\Cursor
setTypeMap() Sets a type map to use for BSON unserialization. yii\mongodb\file\Cursor
toArray() Returns an array containing all results for this cursor yii\mongodb\file\Cursor

Property Details

Hide inherited properties

$collection public property

Related GridFS collection instance.

Method Details

Hide inherited methods

__call() public method

PHP magic method, which is invoked on attempt of invocation not existing method.

It redirects method call to inner iterator.

public __call( string $name, array $arguments ): mixed
$name string

Method name.

$arguments array

Method arguments

return mixed

Method result.

                public function __call($name, $arguments)
{
    return call_user_func_array([$this->getInnerIterator(), $name], $arguments);
}

            
__construct() public method

Constructor.

public __construct( yii\mongodb\file\Collection $collection, \MongoDB\Driver\Cursor $cursor ): mixed
$collection yii\mongodb\file\Collection
$cursor \MongoDB\Driver\Cursor

                public function __construct($collection, $cursor)
{
    $this->collection = $collection;
    parent::__construct($cursor);
}

            
__get() public method

PHP magic method, which is invoked on attempt of getting not existing property.

It returns value from the inner iterator.

public __get( string $name ): mixed
$name string

Field name.

return mixed

Field value.

                public function __get($name)
{
    return $this->getInnerIterator()->{$name};
}

            
__isset() public method

PHP magic method, which is invoked on attempt of checking if a property is set.

public __isset( string $name ): boolean
$name string

Field name.

return boolean

Whether field exists or not.

                public function __isset($name)
{
    $cursor = $this->getInnerIterator();
    return isset($cursor->$name);
}

            
__set() public method

PHP magic method, which is invoked on attempt of setting not existing property.

It passes value to the inner iterator.

public __set( string $name, mixed $value ): mixed
$name string

Field name.

$value mixed

Field value.

                public function __set($name, $value)
{
    $this->getInnerIterator()->{$name} = $value;
}

            
__unset() public method

PHP magic method, which is invoked on attempt of unsetting of property.

public __unset( string $name ): mixed
$name string

Field name.

                public function __unset($name)
{
    $cursor = $this->getInnerIterator();
    unset($cursor->$name);
}

            
count() public method

Count elements of this cursor.

This method is required by the interface Countable.

public count( ): integer
return integer

Elements count.

                #[\ReturnTypeWillChange]
public function count()
{
    return count($this->cursor);
}

            
current() public method

Return the current element This method is required by the interface Iterator.

public current( ): mixed
return mixed

Current row

                #[\ReturnTypeWillChange]
public function current()
{
    $value = parent::current();
    if (!isset($value['file'])) {
        $value['file'] = $this->collection->createDownload(array_intersect_key($value, ['_id' => true, 'filename' => true, 'length' => true, 'chunkSize' => true]));
    }
    return $value;
}

            
getId() public method

Returns the ID for this cursor.

public getId( ): \MongoDB\BSON\Int64
return \MongoDB\BSON\Int64

Cursor ID.

                public function getId()
{
    return $this->getInnerIterator()->getId();
}

            
getInnerIterator() public method

public getInnerIterator( ): \MongoDB\Driver\Cursor
return \MongoDB\Driver\Cursor
setTypeMap() public method

Sets a type map to use for BSON unserialization.

public setTypeMap( array $typemap ): mixed
$typemap array

Type map.

                public function setTypeMap($typemap)
{
    $this->getInnerIterator()->setTypeMap($typemap);
}

            
toArray() public method

Returns an array containing all results for this cursor

public toArray( ): array
return array

Containing all results for this cursor.

                public function toArray()
{
    $result = [];
    foreach ($this as $key => $value) {
        $result[$key] = $value;
    }
    return $result;
}