idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
59,700
function htmlMarkup ( $ realm , $ return_to = null , $ immediate = false , $ form_tag_attrs = null ) { $ form = $ this -> formMarkup ( $ realm , $ return_to , $ immediate , $ form_tag_attrs ) ; if ( Auth_OpenID :: isFailure ( $ form ) ) { return $ form ; } return Auth_OpenID :: autoSubmitHTML ( $ form ) ; }
Get a complete html document that will autosubmit the request to the IDP .
59,701
function extensionResponse ( $ namespace_uri , $ require_signed ) { if ( $ require_signed ) { return $ this -> getSignedNS ( $ namespace_uri ) ; } else { return $ this -> message -> getArgs ( $ namespace_uri ) ; } }
Extract signed extension data from the server s response .
59,702
static function discover ( $ uri , $ fetcher , $ extra_ns_map = null , $ timeout = 20 ) { $ result = new Auth_Yadis_DiscoveryResult ( $ uri ) ; $ headers = array ( "Accept: " . Auth_Yadis_CONTENT_TYPE . ', text/html; q=0.3, application/xhtml+xml; q=0.5' ) ; if ( $ fetcher === null ) { $ fetcher = Auth_Yadis_Yadis :: ge...
This should be called statically and will build a Yadis instance if the discovery process succeeds . This implements Yadis discovery as specified in the Yadis specification .
59,703
public function generateNonce ( RequestInterface $ request ) { return sha1 ( uniqid ( '' , true ) . $ request -> getUri ( ) -> getHost ( ) . $ request -> getUri ( ) -> getPath ( ) ) ; }
Returns a Nonce Based on the unique id and URL .
59,704
protected function createBaseString ( RequestInterface $ request , array $ params ) { $ url = $ request -> getUri ( ) -> withQuery ( '' ) ; $ query = http_build_query ( $ params , '' , '&' , PHP_QUERY_RFC3986 ) ; return strtoupper ( $ request -> getMethod ( ) ) . '&' . rawurlencode ( $ url ) . '&' . rawurlencode ( $ qu...
Creates the Signature Base String .
59,705
public static function create ( $ faultString , $ faultCode ) { if ( ! isset ( self :: $ exceptionMap [ $ faultCode ] ) ) { return new self ( $ faultString , $ faultCode ) ; } return new self :: $ exceptionMap [ $ faultCode ] ( $ faultString , $ faultCode ) ; }
Creates a new Fault .
59,706
public function faults ( ) { $ faultReflection = new \ ReflectionClass ( 'Supervisor\Exception\Fault' ) ; $ faults = array_flip ( $ faultReflection -> getConstants ( ) ) ; $ this -> taskCleanDir ( [ __DIR__ . '/src/Exception/Fault' ] ) -> run ( ) ; foreach ( $ faults as $ code => $ name ) { $ exName = $ this -> createE...
Generates fault exception classes
59,707
protected function createExceptionName ( $ faultString ) { $ parts = explode ( '_' , $ faultString ) ; $ parts = array_map ( function ( $ el ) { return ucfirst ( strtolower ( $ el ) ) ; } , $ parts ) ; return implode ( '' , $ parts ) ; }
Returns a CamelCased exception name from UNDER_SCORED fault string
59,708
public function getAllProcesses ( ) { $ processes = $ this -> getAllProcessInfo ( ) ; foreach ( $ processes as $ key => $ processInfo ) { $ processes [ $ key ] = new Process ( $ processInfo ) ; } return $ processes ; }
Returns all processes as Process objects .
59,709
public function addProvider ( BlacklistProviderInterface $ provider ) { if ( $ provider === $ this ) { throw new \ RuntimeException ( 'Unable to add ChainProvider to itself.' ) ; } $ this -> providers [ ] = $ provider ; return $ this ; }
Adds a new blacklist provider .
59,710
public function isBlacklisted ( $ password ) { foreach ( $ this -> providers as $ provider ) { if ( true === $ provider -> isBlacklisted ( $ password ) ) { return true ; } } return false ; }
Runs trough all the providers until one returns true .
59,711
public function findOne ( $ condition = [ ] , $ fields = [ ] , $ options = [ ] ) { $ options [ 'limit' ] = 1 ; $ cursor = $ this -> find ( $ condition , $ fields , $ options ) ; $ rows = $ cursor -> toArray ( ) ; return empty ( $ rows ) ? null : current ( $ rows ) ; }
Returns a single document .
59,712
public function insert ( $ data , $ options = [ ] ) { return $ this -> database -> createCommand ( ) -> insert ( $ this -> name , $ data , $ options ) ; }
Inserts new data into collection .
59,713
public function count ( $ condition = [ ] , $ options = [ ] ) { return $ this -> database -> createCommand ( ) -> count ( $ this -> name , $ condition , $ options ) ; }
Counts records in this collection .
59,714
public function group ( $ keys , $ initial , $ reduce , $ options = [ ] ) { return $ this -> database -> createCommand ( ) -> group ( $ this -> name , $ keys , $ initial , $ reduce , $ options ) ; }
Performs aggregation using Mongo group command .
59,715
public function getReadPreference ( ) { if ( ! is_object ( $ this -> _readPreference ) ) { if ( $ this -> _readPreference === null ) { $ this -> _readPreference = $ this -> db -> manager -> getReadPreference ( ) ; } elseif ( is_scalar ( $ this -> _readPreference ) ) { $ this -> _readPreference = new ReadPreference ( $ ...
Returns read preference for this command .
59,716
public function getWriteConcern ( ) { if ( $ this -> _writeConcern !== null ) { if ( is_scalar ( $ this -> _writeConcern ) ) { $ this -> _writeConcern = new WriteConcern ( $ this -> _writeConcern ) ; } } return $ this -> _writeConcern ; }
Returns write concern for this command .
59,717
public function getReadConcern ( ) { if ( $ this -> _readConcern !== null ) { if ( is_scalar ( $ this -> _readConcern ) ) { $ this -> _readConcern = new ReadConcern ( $ this -> _readConcern ) ; } } return $ this -> _readConcern ; }
Retuns read concern for this command .
59,718
public function query ( $ collectionName , $ options = [ ] ) { $ databaseName = $ this -> databaseName === null ? $ this -> db -> defaultDatabaseName : $ this -> databaseName ; $ token = $ this -> log ( 'find' , array_merge ( [ 'ns' => $ databaseName . '.' . $ collectionName , 'filter' => $ this -> document , ] , $ opt...
Executes this command as a mongo query
59,719
public function dropDatabase ( ) { $ this -> document = $ this -> db -> getQueryBuilder ( ) -> dropDatabase ( ) ; $ result = current ( $ this -> execute ( ) -> toArray ( ) ) ; return $ result [ 'ok' ] > 0 ; }
Drops database associated with this command .
59,720
public function createCollection ( $ collectionName , array $ options = [ ] ) { $ this -> document = $ this -> db -> getQueryBuilder ( ) -> createCollection ( $ collectionName , $ options ) ; $ result = current ( $ this -> execute ( ) -> toArray ( ) ) ; return $ result [ 'ok' ] > 0 ; }
Creates new collection in database associated with this command . s
59,721
public function dropCollection ( $ collectionName ) { $ this -> document = $ this -> db -> getQueryBuilder ( ) -> dropCollection ( $ collectionName ) ; $ result = current ( $ this -> execute ( ) -> toArray ( ) ) ; return $ result [ 'ok' ] > 0 ; }
Drops specified collection .
59,722
public function listIndexes ( $ collectionName , $ options = [ ] ) { $ this -> document = $ this -> db -> getQueryBuilder ( ) -> listIndexes ( $ collectionName , $ options ) ; try { $ cursor = $ this -> execute ( ) ; } catch ( Exception $ e ) { $ notFoundCodes = [ 26 , 60 ] ; if ( in_array ( $ e -> getCode ( ) , $ notF...
Returns information about current collection indexes .
59,723
public function count ( $ collectionName , $ condition = [ ] , $ options = [ ] ) { $ this -> document = $ this -> db -> getQueryBuilder ( ) -> count ( $ collectionName , $ condition , $ options ) ; $ result = current ( $ this -> execute ( ) -> toArray ( ) ) ; return $ result [ 'n' ] ; }
Counts records in specified collection .
59,724
public function addUpdate ( $ condition , $ document , $ options = [ ] ) { $ options = array_merge ( [ 'multi' => true , 'upsert' => false , ] , $ options ) ; if ( $ options [ 'multi' ] ) { $ keys = array_keys ( $ document ) ; if ( ! empty ( $ keys ) && strncmp ( '$' , $ keys [ 0 ] , 1 ) !== 0 ) { $ document = [ '$set'...
Adds the update operation to the batch command .
59,725
public function addDelete ( $ condition , $ options = [ ] ) { $ this -> document [ ] = [ 'type' => 'delete' , 'condition' => $ this -> db -> getQueryBuilder ( ) -> buildCondition ( $ condition ) , 'options' => $ options , ] ; return $ this ; }
Adds the delete operation to the batch command .
59,726
public function insert ( $ collectionName , $ document , $ options = [ ] ) { $ this -> document = [ ] ; $ this -> addInsert ( $ document ) ; $ result = $ this -> executeBatch ( $ collectionName , $ options ) ; if ( $ result [ 'result' ] -> getInsertedCount ( ) < 1 ) { return false ; } return reset ( $ result [ 'inserte...
Inserts new document into collection .
59,727
public function batchInsert ( $ collectionName , $ documents , $ options = [ ] ) { $ this -> document = [ ] ; foreach ( $ documents as $ key => $ document ) { $ this -> document [ $ key ] = [ 'type' => 'insert' , 'document' => $ document ] ; } $ result = $ this -> executeBatch ( $ collectionName , $ options ) ; if ( $ ...
Inserts batch of new documents into collection .
59,728
public function update ( $ collectionName , $ condition , $ document , $ options = [ ] ) { $ batchOptions = [ ] ; foreach ( [ 'bypassDocumentValidation' ] as $ name ) { if ( isset ( $ options [ $ name ] ) ) { $ batchOptions [ $ name ] = $ options [ $ name ] ; unset ( $ options [ $ name ] ) ; } } $ this -> document = [ ...
Update existing documents in the collection .
59,729
public function delete ( $ collectionName , $ condition , $ options = [ ] ) { $ batchOptions = [ ] ; foreach ( [ 'bypassDocumentValidation' ] as $ name ) { if ( isset ( $ options [ $ name ] ) ) { $ batchOptions [ $ name ] = $ options [ $ name ] ; unset ( $ options [ $ name ] ) ; } } $ this -> document = [ ] ; $ this ->...
Removes documents from the collection .
59,730
public function find ( $ collectionName , $ condition , $ options = [ ] ) { $ queryBuilder = $ this -> db -> getQueryBuilder ( ) ; $ this -> document = $ queryBuilder -> buildCondition ( $ condition ) ; if ( isset ( $ options [ 'projection' ] ) ) { $ options [ 'projection' ] = $ queryBuilder -> buildSelectFields ( $ op...
Performs find query .
59,731
public function group ( $ collectionName , $ keys , $ initial , $ reduce , $ options = [ ] ) { $ this -> document = $ this -> db -> getQueryBuilder ( ) -> group ( $ collectionName , $ keys , $ initial , $ reduce , $ options ) ; $ cursor = $ this -> execute ( ) ; $ result = current ( $ cursor -> toArray ( ) ) ; return $...
Performs aggregation using MongoDB group command .
59,732
public function explain ( $ collectionName , $ query ) { $ this -> document = $ this -> db -> getQueryBuilder ( ) -> explain ( $ collectionName , $ query ) ; $ cursor = $ this -> execute ( ) ; return current ( $ cursor -> toArray ( ) ) ; }
Return an explanation of the query often useful for optimization and debugging .
59,733
public function listDatabases ( $ condition = [ ] , $ options = [ ] ) { if ( $ this -> databaseName === null ) { $ this -> databaseName = 'admin' ; } $ this -> document = $ this -> db -> getQueryBuilder ( ) -> listDatabases ( $ condition , $ options ) ; $ cursor = $ this -> execute ( ) ; $ result = current ( $ cursor -...
Returns the list of available databases .
59,734
public function listCollections ( $ condition = [ ] , $ options = [ ] ) { $ this -> document = $ this -> db -> getQueryBuilder ( ) -> listCollections ( $ condition , $ options ) ; $ cursor = $ this -> execute ( ) ; return $ cursor -> toArray ( ) ; }
Returns the list of available collections .
59,735
protected function getValue ( $ key ) { $ query = new Query ; $ row = $ query -> select ( [ 'data' ] ) -> from ( $ this -> cacheCollection ) -> where ( [ 'id' => $ key , '$or' => [ [ 'expire' => 0 ] , [ 'expire' => [ '$gt' => time ( ) ] ] , ] , ] ) -> one ( $ this -> db ) ; if ( empty ( $ row ) ) { return false ; } ret...
Retrieves a value from cache with a specified key . This method should be implemented by child classes to retrieve the data from specific cache storage .
59,736
protected function setValue ( $ key , $ value , $ expire ) { $ result = $ this -> db -> getCollection ( $ this -> cacheCollection ) -> update ( [ 'id' => $ key ] , [ 'expire' => $ expire > 0 ? $ expire + time ( ) : 0 , 'data' => $ value , ] ) ; if ( $ result ) { $ this -> gc ( ) ; return true ; } return $ this -> addVa...
Stores a value identified by a key in cache . This method should be implemented by child classes to store the data in specific cache storage .
59,737
protected function addValue ( $ key , $ value , $ expire ) { $ this -> gc ( ) ; if ( $ expire > 0 ) { $ expire += time ( ) ; } else { $ expire = 0 ; } try { $ this -> db -> getCollection ( $ this -> cacheCollection ) -> insert ( [ 'id' => $ key , 'expire' => $ expire , 'data' => $ value , ] ) ; return true ; } catch ( ...
Stores a value identified by a key into cache if the cache does not contain this key . This method should be implemented by child classes to store the data in specific cache storage .
59,738
protected function deleteValue ( $ key ) { $ this -> db -> getCollection ( $ this -> cacheCollection ) -> remove ( [ 'id' => $ key ] ) ; return true ; }
Deletes a value with the specified key from cache This method should be implemented by child classes to delete the data from actual cache storage .
59,739
public static function register ( $ protocol = 'gridfs' , $ force = false ) { if ( in_array ( $ protocol , stream_get_wrappers ( ) ) ) { if ( ! $ force ) { return ; } stream_wrapper_unregister ( $ protocol ) ; } stream_wrapper_register ( $ protocol , get_called_class ( ) , STREAM_IS_URL ) ; }
Registers this steam wrapper .
59,740
private function parsePath ( $ path ) { $ pathInfo = parse_url ( $ path ) ; $ this -> _protocol = $ pathInfo [ 'scheme' ] ; $ this -> _namespace = $ pathInfo [ 'host' ] ; parse_str ( $ pathInfo [ 'query' ] , $ this -> _queryParams ) ; }
Parses stream open path initializes internal parameters .
59,741
private function fetchCollection ( ) { $ contextOptions = $ this -> getContextOptions ( ) ; if ( isset ( $ contextOptions [ $ this -> _protocol ] [ 'collection' ] ) ) { $ collection = $ contextOptions [ $ this -> _protocol ] [ 'collection' ] ; if ( $ collection instanceof Collection ) { throw new InvalidConfigException...
Fetches associated file collection from stream options .
59,742
protected function getCollectionName ( ) { if ( $ this -> collectionName ) { return $ this -> collectionName ; } $ modelClass = $ this -> modelClass ; return $ modelClass :: collectionName ( ) ; }
Returns collection name used by this fixture .
59,743
protected function loadMessagesFromDb ( $ category , $ language ) { $ fallbackLanguage = substr ( $ language , 0 , 2 ) ; $ fallbackSourceLanguage = substr ( $ this -> sourceLanguage , 0 , 2 ) ; $ languages = [ $ language , $ fallbackLanguage , $ fallbackSourceLanguage ] ; $ rows = ( new Query ( ) ) -> select ( [ 'langu...
Loads the messages from MongoDB . You may override this method to customize the message storage in the MongoDB .
59,744
public function addOptions ( $ options ) { if ( is_array ( $ this -> options ) ) { $ this -> options = array_merge ( $ this -> options , $ options ) ; } else { $ this -> options = $ options ; } return $ this ; }
Adds additional cursor options .
59,745
public function andFilterCompare ( $ name , $ value , $ defaultOperator = '=' ) { $ matches = [ ] ; if ( preg_match ( '/^(<>|>=|>|<=|<|=)/' , $ value , $ matches ) ) { $ op = $ matches [ 1 ] ; $ value = substr ( $ value , strlen ( $ op ) ) ; } else { $ op = $ defaultOperator ; } return $ this -> andFilterWhere ( [ $ op...
Helper method for easy querying on values containing some common operators .
59,746
public function buildCursor ( $ db = null ) { $ this -> prepare ( ) ; $ options = $ this -> options ; if ( ! empty ( $ this -> orderBy ) ) { $ options [ 'sort' ] = $ this -> orderBy ; } $ options [ 'limit' ] = $ this -> limit ; $ options [ 'skip' ] = $ this -> offset ; $ cursor = $ this -> getCollection ( $ db ) -> fin...
Builds the MongoDB cursor for this query .
59,747
protected function fetchRows ( $ cursor , $ all = true , $ indexBy = null ) { $ token = 'fetch cursor id = ' . $ cursor -> getId ( ) ; Yii :: info ( $ token , __METHOD__ ) ; try { Yii :: beginProfile ( $ token , __METHOD__ ) ; $ result = $ this -> fetchRowsInternal ( $ cursor , $ all ) ; Yii :: endProfile ( $ token , _...
Fetches rows from the given Mongo cursor .
59,748
public function modify ( $ update , $ options = [ ] , $ db = null ) { if ( ! empty ( $ this -> emulateExecution ) ) { return null ; } $ this -> prepare ( ) ; $ collection = $ this -> getCollection ( $ db ) ; if ( ! empty ( $ this -> orderBy ) ) { $ options [ 'sort' ] = $ this -> orderBy ; } $ options [ 'fields' ] = $ t...
Performs findAndModify query and returns a single row of result .
59,749
public function exists ( $ db = null ) { if ( ! empty ( $ this -> emulateExecution ) ) { return false ; } $ cursor = $ this -> buildCursor ( $ db ) ; foreach ( $ cursor as $ row ) { return true ; } return false ; }
Returns a value indicating whether the query result contains any row of data .
59,750
public function sum ( $ q , $ db = null ) { if ( ! empty ( $ this -> emulateExecution ) ) { return 0 ; } return $ this -> aggregate ( $ q , 'sum' , $ db ) ; }
Returns the sum of the specified column values .
59,751
public function average ( $ q , $ db = null ) { if ( ! empty ( $ this -> emulateExecution ) ) { return 0 ; } return $ this -> aggregate ( $ q , 'avg' , $ db ) ; }
Returns the average of the specified column values .
59,752
protected function aggregate ( $ column , $ operator , $ db ) { if ( ! empty ( $ this -> emulateExecution ) ) { return null ; } $ this -> prepare ( ) ; $ collection = $ this -> getCollection ( $ db ) ; $ pipelines = [ ] ; if ( $ this -> where !== null ) { $ pipelines [ ] = [ '$match' => $ this -> where ] ; } $ pipeline...
Performs the aggregation for the given column .
59,753
public function count ( $ collectionName , $ condition = [ ] , $ options = [ ] ) { $ document = [ 'count' => $ collectionName ] ; if ( ! empty ( $ condition ) ) { $ document [ 'query' ] = ( object ) $ this -> buildCondition ( $ condition ) ; } return array_merge ( $ document , $ options ) ; }
Generates count command
59,754
public function findAndModify ( $ collectionName , $ condition = [ ] , $ update = [ ] , $ options = [ ] ) { $ document = array_merge ( [ 'findAndModify' => $ collectionName ] , $ options ) ; if ( ! empty ( $ condition ) ) { $ options [ 'query' ] = $ this -> buildCondition ( $ condition ) ; } if ( ! empty ( $ update ) )...
Generates find and modify command .
59,755
public function distinct ( $ collectionName , $ fieldName , $ condition = [ ] , $ options = [ ] ) { $ document = array_merge ( [ 'distinct' => $ collectionName , 'key' => $ fieldName , ] , $ options ) ; if ( ! empty ( $ condition ) ) { $ document [ 'query' ] = $ this -> buildCondition ( $ condition ) ; } return $ docum...
Generates distinct command .
59,756
public function group ( $ collectionName , $ keys , $ initial , $ reduce , $ options = [ ] ) { if ( ! ( $ reduce instanceof Javascript ) ) { $ reduce = new Javascript ( ( string ) $ reduce ) ; } if ( isset ( $ options [ 'condition' ] ) ) { $ options [ 'cond' ] = $ this -> buildCondition ( $ options [ 'condition' ] ) ; ...
Generates group command .
59,757
public function aggregate ( $ collectionName , $ pipelines , $ options = [ ] ) { foreach ( $ pipelines as $ key => $ pipeline ) { if ( isset ( $ pipeline [ '$match' ] ) ) { $ pipelines [ $ key ] [ '$match' ] = $ this -> buildCondition ( $ pipeline [ '$match' ] ) ; } } $ document = array_merge ( [ 'aggregate' => $ colle...
Generates aggregate command .
59,758
public function explain ( $ collectionName , $ query ) { $ query = array_merge ( [ 'find' => $ collectionName ] , $ query ) ; if ( isset ( $ query [ 'filter' ] ) ) { $ query [ 'filter' ] = ( object ) $ this -> buildCondition ( $ query [ 'filter' ] ) ; } if ( isset ( $ query [ 'projection' ] ) ) { $ query [ 'projection'...
Generates explain command .
59,759
public function listDatabases ( $ condition = [ ] , $ options = [ ] ) { $ document = array_merge ( [ 'listDatabases' => 1 ] , $ options ) ; if ( ! empty ( $ condition ) ) { $ document [ 'filter' ] = ( object ) $ this -> buildCondition ( $ condition ) ; } return $ document ; }
Generates listDatabases command .
59,760
public function buildSelectFields ( $ fields ) { $ selectFields = [ ] ; foreach ( ( array ) $ fields as $ key => $ value ) { if ( is_int ( $ key ) ) { $ selectFields [ $ value ] = true ; } else { $ selectFields [ $ key ] = is_scalar ( $ value ) ? ( bool ) $ value : $ value ; } } return $ selectFields ; }
Normalizes fields list for the MongoDB select composition .
59,761
public function buildSortFields ( $ fields ) { $ sortFields = [ ] ; foreach ( ( array ) $ fields as $ key => $ value ) { if ( is_int ( $ key ) ) { $ sortFields [ $ value ] = + 1 ; } else { if ( $ value === SORT_ASC ) { $ value = + 1 ; } elseif ( $ value === SORT_DESC ) { $ value = - 1 ; } $ sortFields [ $ key ] = $ val...
Normalizes fields list for the MongoDB sort composition .
59,762
public function buildCondition ( $ condition ) { static $ builders = [ 'NOT' => 'buildNotCondition' , 'AND' => 'buildAndCondition' , 'OR' => 'buildOrCondition' , 'BETWEEN' => 'buildBetweenCondition' , 'NOT BETWEEN' => 'buildBetweenCondition' , 'IN' => 'buildInCondition' , 'NOT IN' => 'buildInCondition' , 'REGEX' => 'bu...
Parses the condition specification and generates the corresponding Mongo condition .
59,763
public function buildNotCondition ( $ operator , $ operands ) { if ( count ( $ operands ) !== 2 ) { throw new InvalidParamException ( "Operator '$operator' requires two operands." ) ; } list ( $ name , $ value ) = $ operands ; $ result = [ ] ; if ( is_array ( $ value ) ) { $ result [ $ name ] = [ '$not' => $ this -> bu...
Composes NOT condition .
59,764
public function buildAndCondition ( $ operator , $ operands ) { $ operator = $ this -> normalizeConditionKeyword ( $ operator ) ; $ parts = [ ] ; foreach ( $ operands as $ operand ) { $ parts [ ] = $ this -> buildCondition ( $ operand ) ; } return [ $ operator => $ parts ] ; }
Connects two or more conditions with the AND operator .
59,765
public function buildBetweenCondition ( $ operator , $ operands ) { if ( ! isset ( $ operands [ 0 ] , $ operands [ 1 ] , $ operands [ 2 ] ) ) { throw new InvalidParamException ( "Operator '$operator' requires three operands." ) ; } list ( $ column , $ value1 , $ value2 ) = $ operands ; if ( strncmp ( 'NOT' , $ operator...
Creates an Mongo condition which emulates the BETWEEN operator .
59,766
public function buildInCondition ( $ operator , $ operands ) { if ( ! isset ( $ operands [ 0 ] , $ operands [ 1 ] ) ) { throw new InvalidParamException ( "Operator '$operator' requires two operands." ) ; } list ( $ column , $ values ) = $ operands ; $ values = ( array ) $ values ; $ operator = $ this -> normalizeCondit...
Creates an Mongo condition with the IN operator .
59,767
public function buildRegexCondition ( $ operator , $ operands ) { if ( ! isset ( $ operands [ 0 ] , $ operands [ 1 ] ) ) { throw new InvalidParamException ( "Operator '$operator' requires two operands." ) ; } list ( $ column , $ value ) = $ operands ; if ( ! ( $ value instanceof Regex ) ) { if ( preg_match ( '~\/(.+)\/...
Creates a Mongo regular expression condition .
59,768
public function buildLikeCondition ( $ operator , $ operands ) { if ( ! isset ( $ operands [ 0 ] , $ operands [ 1 ] ) ) { throw new InvalidParamException ( "Operator '$operator' requires two operands." ) ; } list ( $ column , $ value ) = $ operands ; if ( ! ( $ value instanceof Regex ) ) { $ value = new Regex ( preg_qu...
Creates a Mongo condition which emulates the LIKE operator .
59,769
public function getCollection ( $ name , $ refresh = false ) { if ( $ refresh || ! array_key_exists ( $ name , $ this -> _collections ) ) { $ this -> _collections [ $ name ] = $ this -> selectCollection ( $ name ) ; } return $ this -> _collections [ $ name ] ; }
Returns the Mongo collection with the given name .
59,770
public function getFileCollection ( $ prefix = 'fs' , $ refresh = false ) { if ( $ refresh || ! array_key_exists ( $ prefix , $ this -> _fileCollections ) ) { $ this -> _fileCollections [ $ prefix ] = $ this -> selectFileCollection ( $ prefix ) ; } return $ this -> _fileCollections [ $ prefix ] ; }
Returns Mongo GridFS collection with given prefix .
59,771
public function init ( ) { parent :: init ( ) ; $ this -> db = Instance :: ensure ( $ this -> db , Connection :: className ( ) ) ; if ( $ this -> cache !== null ) { $ this -> cache = Instance :: ensure ( $ this -> cache , Cache :: className ( ) ) ; } }
Initializes the application component . This method overrides the parent implementation by establishing the MongoDB connection .
59,772
protected function populateItem ( $ row ) { $ class = $ row [ 'type' ] == Item :: TYPE_PERMISSION ? Permission :: className ( ) : Role :: className ( ) ; if ( ! isset ( $ row [ 'data' ] ) || ( $ data = @ unserialize ( $ row [ 'data' ] ) ) === false ) { $ data = null ; } return new $ class ( [ 'name' => $ row [ 'name' ]...
Populates an auth item with the data fetched from collection
59,773
public function loadFromCache ( ) { if ( $ this -> items !== null || ! $ this -> cache instanceof Cache ) { return ; } $ data = $ this -> cache -> get ( $ this -> cacheKey ) ; if ( is_array ( $ data ) && isset ( $ data [ 0 ] , $ data [ 1 ] ) ) { list ( $ this -> items , $ this -> rules ) = $ data ; return ; } $ query =...
Loads data from cache
59,774
private function instantiateDefaultRoles ( ) { $ result = [ ] ; foreach ( $ this -> defaultRoles as $ roleName ) { $ result [ $ roleName ] = $ this -> createRole ( $ roleName ) ; } return $ result ; }
Returns defaultRoles as array of Role objects
59,775
public function insert ( $ runValidation = true , $ attributes = null ) { if ( $ runValidation && ! $ this -> validate ( $ attributes ) ) { return false ; } $ result = $ this -> insertInternal ( $ attributes ) ; return $ result ; }
Inserts a row into the associated Mongo collection using the attribute values of this record .
59,776
public function delete ( ) { $ result = false ; if ( $ this -> beforeDelete ( ) ) { $ result = $ this -> deleteInternal ( ) ; $ this -> afterDelete ( ) ; } return $ result ; }
Deletes the document corresponding to this active record from the collection .
59,777
private function dumpBsonObject ( Type $ object ) { if ( $ object instanceof Binary ) { return $ object -> getData ( ) ; } if ( method_exists ( $ object , '__toString' ) ) { return $ object -> __toString ( ) ; } return ArrayHelper :: toArray ( $ object ) ; }
Converts MongoDB BSON object to readable value .
59,778
public function getChunkCollection ( $ refresh = false ) { if ( $ refresh || ! is_object ( $ this -> _chunkCollection ) ) { $ this -> _chunkCollection = Yii :: createObject ( [ 'class' => 'yii\mongodb\Collection' , 'database' => $ this -> database , 'name' => $ this -> getPrefix ( ) . '.chunks' ] ) ; } return $ this ->...
Returns the MongoDB collection for the file chunks .
59,779
public function getFileCollection ( $ refresh = false ) { if ( $ refresh || ! is_object ( $ this -> _fileCollection ) ) { $ this -> _fileCollection = Yii :: createObject ( [ 'class' => 'yii\mongodb\Collection' , 'database' => $ this -> database , 'name' => $ this -> name ] ) ; } return $ this -> _fileCollection ; }
Returns the MongoDB collection for the files .
59,780
public function get ( $ id ) { $ document = $ this -> getFileCollection ( ) -> findOne ( [ '_id' => $ id ] ) ; return empty ( $ document ) ? null : $ this -> createDownload ( $ document ) ; }
Retrieves the file with given _id .
59,781
private function ensureFileIndexes ( ) { $ indexKey = [ 'filename' => 1 , 'uploadDate' => 1 ] ; foreach ( $ this -> listIndexes ( ) as $ index ) { if ( $ index [ 'key' ] === $ indexKey ) { return ; } } $ this -> createIndex ( $ indexKey ) ; }
Ensures indexes at file collection .
59,782
private function ensureChunkIndexes ( ) { $ chunkCollection = $ this -> getChunkCollection ( ) ; $ indexKey = [ 'files_id' => 1 , 'n' => 1 ] ; foreach ( $ chunkCollection -> listIndexes ( ) as $ index ) { if ( ! empty ( $ index [ 'unique' ] ) && $ index [ 'key' ] === $ indexKey ) { return ; } } $ chunkCollection -> cre...
Ensures indexes at chunk collection .
59,783
public function getChunkCursor ( $ refresh = false ) { if ( $ refresh || $ this -> _chunkCursor === null ) { $ file = $ this -> getDocument ( ) ; $ this -> _chunkCursor = $ this -> collection -> getChunkCollection ( ) -> find ( [ 'files_id' => $ file [ '_id' ] ] , [ ] , [ 'sort' => [ 'n' => 1 ] ] ) ; } return $ this ->...
Returns file chunks read cursor .
59,784
public function getChunkIterator ( $ refresh = false ) { if ( $ refresh || $ this -> _chunkIterator === null ) { $ this -> _chunkIterator = new \ IteratorIterator ( $ this -> getChunkCursor ( $ refresh ) ) ; $ this -> _chunkIterator -> rewind ( ) ; } return $ this -> _chunkIterator ; }
Returns iterator for the file chunks cursor .
59,785
public function toStream ( $ stream ) { $ bytesWritten = 0 ; foreach ( $ this -> getChunkCursor ( ) as $ chunk ) { $ bytesWritten += fwrite ( $ stream , $ chunk [ 'data' ] -> getData ( ) ) ; } return $ bytesWritten ; }
Saves file into the given stream .
59,786
public function toFile ( $ filename ) { $ filename = Yii :: getAlias ( $ filename ) ; FileHelper :: createDirectory ( dirname ( $ filename ) ) ; return $ this -> toStream ( fopen ( $ filename , 'w+' ) ) ; }
Saves download to the physical file .
59,787
public function toString ( ) { $ result = '' ; foreach ( $ this -> getChunkCursor ( ) as $ chunk ) { $ result .= $ chunk [ 'data' ] -> getData ( ) ; } return $ result ; }
Returns a string of the bytes in the associated file .
59,788
public function substr ( $ start , $ length ) { $ document = $ this -> getDocument ( ) ; if ( $ start < 0 ) { $ start = max ( $ document [ 'length' ] + $ start , 0 ) ; } if ( $ start > $ document [ 'length' ] ) { return false ; } if ( $ length < 0 ) { $ length = $ document [ 'length' ] - $ start + $ length ; if ( $ len...
Return part of a file .
59,789
public function getResource ( ) { if ( $ this -> _resource === null ) { $ this -> _resource = $ this -> toResource ( ) ; } return $ this -> _resource ; }
Returns persistent stream resource which can be used to read file .
59,790
public function populate ( $ rows ) { if ( empty ( $ rows ) ) { return [ ] ; } $ indexBy = $ this -> indexBy ; $ this -> indexBy = null ; $ rows = parent :: populate ( $ rows ) ; $ this -> indexBy = $ indexBy ; $ models = $ this -> createModels ( $ rows ) ; if ( ! empty ( $ this -> with ) ) { $ this -> findWith ( $ thi...
Converts the raw query results into the format as specified by this query . This method is internally used to convert the data fetched from MongoDB into the format as required by this query .
59,791
public function toArray ( ) { $ result = [ ] ; foreach ( $ this as $ key => $ value ) { $ result [ $ key ] = $ value ; } return $ result ; }
Returns an array containing all results for this cursor
59,792
public function createCollection ( $ collection , $ options = [ ] ) { if ( is_array ( $ collection ) ) { list ( $ database , $ collectionName ) = $ collection ; } else { $ database = null ; $ collectionName = $ collection ; } $ this -> beginProfile ( $ token = " > create collection " . $ this -> composeCollectionLog...
Creates new collection with the specified options .
59,793
public function dropCollection ( $ collection ) { $ this -> beginProfile ( $ token = " > drop collection " . $ this -> composeCollectionLogName ( $ collection ) . " ..." ) ; $ this -> db -> getCollection ( $ collection ) -> drop ( ) ; $ this -> endProfile ( $ token ) ; }
Drops existing collection .
59,794
public function createIndexes ( $ collection , $ indexes ) { $ this -> beginProfile ( $ token = " > create indexes on " . $ this -> composeCollectionLogName ( $ collection ) . " (" . Json :: encode ( $ indexes ) . ") ..." ) ; $ this -> db -> getCollection ( $ collection ) -> createIndexes ( $ indexes ) ; $ this -> e...
Creates indexes in the collection .
59,795
public function createIndex ( $ collection , $ columns , $ options = [ ] ) { $ this -> beginProfile ( $ token = " > create index on " . $ this -> composeCollectionLogName ( $ collection ) . " (" . Json :: encode ( ( array ) $ columns ) . empty ( $ options ) ? "" : ", " . Json :: encode ( $ options ) . ") ..." ) ; $ ...
Creates an index on the collection and the specified fields .
59,796
public function dropAllIndexes ( $ collection ) { $ this -> beginProfile ( $ token = " > drop all indexes on " . $ this -> composeCollectionLogName ( $ collection ) . ") ..." ) ; $ this -> db -> getCollection ( $ collection ) -> dropAllIndexes ( ) ; $ this -> endProfile ( $ token ) ; }
Drops all indexes for specified collection .
59,797
protected function composeCollectionLogName ( $ collection ) { if ( is_array ( $ collection ) ) { list ( $ database , $ collection ) = $ collection ; return $ database . '.' . $ collection ; } return $ collection ; }
Composes string representing collection name .
59,798
public function generateLabels ( $ attributes ) { $ labels = [ ] ; foreach ( $ attributes as $ attribute ) { if ( ! strcasecmp ( $ attribute , '_id' ) ) { $ label = 'ID' ; } else { $ label = Inflector :: camel2words ( $ attribute ) ; if ( substr_compare ( $ label , ' id' , - 3 , 3 , true ) === 0 ) { $ label = substr ( ...
Generates the attribute labels for the specified attributes list .
59,799
public function generateRules ( $ attributes ) { $ rules = [ ] ; $ safeAttributes = [ ] ; foreach ( $ attributes as $ attribute ) { if ( $ attribute == '_id' ) { continue ; } $ safeAttributes [ ] = $ attribute ; } if ( ! empty ( $ safeAttributes ) ) { $ rules [ ] = "[['" . implode ( "', '" , $ safeAttributes ) . "'], '...
Generates validation rules for the specified collection .