idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
12,300
public function buildImporterQueue ( ) { $ queue = [ ] ; foreach ( Yii :: $ app -> getApplicationModules ( ) as $ id => $ module ) { $ response = $ module -> import ( $ this ) ; if ( is_array ( $ response ) ) { foreach ( $ response as $ class ) { $ object = Yii :: createObject ( $ class , [ $ this , $ module ] ) ; $ position = $ object -> queueListPosition ; while ( true ) { if ( ! array_key_exists ( $ position , $ queue ) ) { break ; } ++ $ position ; } $ queue [ $ position ] = $ object ; } } } ksort ( $ queue ) ; return $ queue ; }
Get all importer objects with the assigned queue position .
12,301
public function actionIndex ( ) { $ queue = $ this -> buildImporterQueue ( ) ; foreach ( $ queue as $ pos => $ object ) { $ this -> verbosePrint ( "Run importer object '{$object->className()}' on position '{$pos}'." , __METHOD__ ) ; $ this -> verbosePrint ( 'Module context id: ' . $ object -> module -> id ) ; $ object -> run ( ) ; } if ( Yii :: $ app -> hasModule ( 'admin' ) ) { Config :: set ( Config :: CONFIG_LAST_IMPORT_TIMESTAMP , time ( ) ) ; Config :: set ( Config :: CONFIG_INSTALLER_VENDOR_TIMESTAMP , Yii :: $ app -> packageInstaller -> timestamp ) ; Yii :: $ app -> db -> createCommand ( ) -> update ( 'admin_user' , [ 'force_reload' => 1 ] ) -> execute ( ) ; } $ this -> output ( 'LUYA import command (based on LUYA ' . Boot :: VERSION . ')' ) ; foreach ( $ this -> getLog ( ) as $ section => $ value ) { $ this -> outputInfo ( PHP_EOL . $ section . ":" ) ; $ this -> logValueToTable ( $ value ) ; } return $ this -> outputSuccess ( "Importer run successful." ) ; }
Run the import process .
12,302
private function logValueToTable ( array $ logs ) { $ table = new Table ( ) ; $ table -> setHeaders ( [ 'Key' , 'Value' ] ) ; $ rows = [ ] ; foreach ( $ logs as $ key => $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ kk => $ kv ) { $ rows [ ] = [ $ kk , $ kv ] ; } } else { $ rows [ ] = [ $ key , $ value ] ; } } $ table -> setRows ( $ rows ) ; echo $ table -> run ( ) ; }
Print the log values as a table .
12,303
protected function output ( $ message , $ color = null ) { $ format = [ ] ; if ( ! $ this -> isMuted ( ) ) { if ( $ color !== null ) { $ format [ ] = $ color ; } echo Console :: ansiFormat ( "\r" . $ message . "\n" , $ format ) ; } }
Helper method for writting console application output include before and after wrappers .
12,304
public static function getInstantiatedTagObjects ( ) { $ context = self :: getInstance ( ) ; foreach ( $ context -> tags as $ key => $ config ) { $ context -> instantiatTag ( $ key ) ; } return $ context -> tags ; }
Generate the instance for all registered tags .
12,305
private function parseTag ( $ tag , $ context ) { $ this -> instantiatTag ( $ tag ) ; $ value = isset ( $ context [ 'value' ] ) ? $ context [ 'value' ] : false ; $ sub = isset ( $ context [ 'sub' ] ) ? $ context [ 'sub' ] : false ; if ( $ sub ) { $ sub = str_replace ( [ '\)' , '\(' ] , [ ')' , '(' ] , $ sub ) ; } return $ this -> tags [ $ tag ] -> parse ( $ value , $ sub ) ; }
Parse the given tag with context informations .
12,306
private function processText ( $ text ) { if ( ! is_string ( $ text ) || empty ( $ text ) ) { return $ text ; } preg_match_all ( static :: REGEX , $ text , $ results , PREG_SET_ORDER ) ; foreach ( $ results as $ row ) { if ( empty ( $ row [ 'value' ] ) ) { continue ; } $ tag = $ row [ 'function' ] ; if ( $ this -> hasTag ( $ tag ) ) { $ replace = $ this -> parseTag ( $ tag , $ row ) ; $ text = preg_replace ( '/' . preg_quote ( $ row [ 0 ] , '/' ) . '/mi' , $ replace , $ text , 1 ) ; } } return $ text ; }
Process a given text .
12,307
public function isCachable ( ) { if ( $ this -> _cachable === null ) { $ this -> _cachable = Yii :: $ app -> has ( 'cache' ) ? true : false ; } return $ this -> _cachable ; }
Check if the current configuration of the application and the property allows a caching of the language container data .
12,308
public function setHasCache ( $ key , $ value , $ dependency = null , $ cacheExpiration = null ) { if ( $ this -> isCachable ( ) ) { if ( is_array ( $ dependency ) ) { $ dependency = Yii :: createObject ( $ dependency ) ; } return Yii :: $ app -> cache -> set ( $ key , $ value , is_null ( $ cacheExpiration ) ? $ this -> _cacheExpiration : $ cacheExpiration , $ dependency ) ; } return false ; }
Store cache data for a specific key if caching is enabled in this application .
12,309
public function deleteHasCache ( $ key ) { if ( $ this -> isCachable ( ) ) { return Yii :: $ app -> cache -> delete ( $ key ) ; } return false ; }
Remove a value from the cache if caching is enabled .
12,310
public function getHasCache ( $ key ) { if ( $ this -> isCachable ( ) ) { $ data = Yii :: $ app -> cache -> get ( $ key ) ; $ enumKey = ( is_array ( $ key ) ) ? implode ( "," , $ key ) : $ key ; if ( $ data ) { Yii :: debug ( "Cacheable trait key '$enumKey' successfully loaded from cache." , __METHOD__ ) ; return $ data ; } Yii :: debug ( "Cacheable trait key '$enumKey' has not been found in cache." , __METHOD__ ) ; } return false ; }
Get the caching data if caching is allowed and there is any data stored for this key .
12,311
public function getMailer ( ) { if ( $ this -> _mailer === null ) { $ this -> _mailer = new PHPMailer ( ) ; $ this -> _mailer -> CharSet = 'UTF-8' ; $ this -> _mailer -> From = $ this -> from ; $ this -> _mailer -> FromName = $ this -> fromName ; $ this -> _mailer -> isHTML ( true ) ; $ this -> _mailer -> XMailer = ' ' ; if ( $ this -> isSMTP ) { if ( $ this -> debug ) { $ this -> _mailer -> SMTPDebug = 2 ; } $ this -> _mailer -> isSMTP ( ) ; $ this -> _mailer -> SMTPSecure = $ this -> smtpSecure ; $ this -> _mailer -> Host = $ this -> host ; $ this -> _mailer -> SMTPAuth = $ this -> smtpAuth ; $ this -> _mailer -> Username = $ this -> username ; $ this -> _mailer -> Password = $ this -> password ; $ this -> _mailer -> Port = $ this -> port ; $ this -> _mailer -> SMTPOptions = [ 'ssl' => [ 'verify_peer' => false , 'verify_peer_name' => false , 'allow_self_signed' => true ] , ] ; } } return $ this -> _mailer ; }
Getter for the mailer object
12,312
public function compose ( $ subject = null , $ body = null ) { $ this -> cleanup ( ) ; if ( $ subject !== null ) { $ this -> subject ( $ subject ) ; } if ( $ body !== null ) { $ this -> body ( $ body ) ; } return $ this ; }
Compose a new mail message .
12,313
public function body ( $ body ) { $ message = $ this -> wrapLayout ( $ body ) ; $ this -> getMailer ( ) -> Body = $ message ; $ alt = empty ( $ this -> altBody ) ? $ this -> convertMessageToAltBody ( $ message ) : $ this -> altBody ; $ this -> getMailer ( ) -> AltBody = $ alt ; return $ this ; }
Set the HTML body for the mailer message if a layout is defined the layout will automatically wrapped about the html body .
12,314
public function convertMessageToAltBody ( $ message ) { $ message = preg_replace ( '/<head>(.*?)<\/head>/s' , '' , $ message ) ; $ tags = [ '</p>' , '<br />' , '<br>' , '<hr />' , '<hr>' , '</h1>' , '</h2>' , '</h3>' , '</h4>' , '</h5>' , '</h6>' ] ; return trim ( strip_tags ( str_replace ( $ tags , PHP_EOL , $ message ) ) ) ; }
Try to convert the message into an alt body tag .
12,315
public function render ( $ viewFile , array $ params = [ ] ) { $ this -> body ( Yii :: $ app -> view -> render ( $ viewFile , $ params ) ) ; return $ this ; }
Render a view file for the given Controller context .
12,316
public function addresses ( array $ emails ) { foreach ( $ emails as $ name => $ mail ) { if ( is_int ( $ name ) ) { $ this -> address ( $ mail ) ; } else { $ this -> address ( $ mail , $ name ) ; } } return $ this ; }
Add multiple addresses into the mailer object .
12,317
public function address ( $ email , $ name = null ) { $ this -> getMailer ( ) -> addAddress ( $ email , ( empty ( $ name ) ) ? $ email : $ name ) ; return $ this ; }
Add a single address with optional name
12,318
public function ccAddresses ( array $ emails ) { foreach ( $ emails as $ name => $ mail ) { if ( is_int ( $ name ) ) { $ this -> ccAddress ( $ mail ) ; } else { $ this -> ccAddress ( $ mail , $ name ) ; } } return $ this ; }
Add multiple CC addresses into the mailer object .
12,319
public function ccAddress ( $ email , $ name = null ) { $ this -> getMailer ( ) -> addCC ( $ email , ( empty ( $ name ) ) ? $ email : $ name ) ; return $ this ; }
Add a single CC address with optional name
12,320
public function bccAddresses ( array $ emails ) { foreach ( $ emails as $ name => $ mail ) { if ( is_int ( $ name ) ) { $ this -> bccAddress ( $ mail ) ; } else { $ this -> bccAddress ( $ mail , $ name ) ; } } return $ this ; }
Add multiple BCC addresses into the mailer object .
12,321
public function bccAddress ( $ email , $ name = null ) { $ this -> getMailer ( ) -> addBCC ( $ email , ( empty ( $ name ) ) ? $ email : $ name ) ; return $ this ; }
Add a single BCC address with optional name
12,322
public function addAttachment ( $ filePath , $ name = null ) { $ this -> getMailer ( ) -> addAttachment ( $ filePath , empty ( $ name ) ? pathinfo ( $ filePath , PATHINFO_BASENAME ) : $ name ) ; return $ this ; }
Add attachment .
12,323
public function addReplyTo ( $ email , $ name = null ) { $ this -> getMailer ( ) -> addReplyTo ( $ email , empty ( $ name ) ? $ email : $ name ) ; return $ this ; }
Add ReplyTo Address .
12,324
public function send ( ) { if ( empty ( $ this -> mailer -> Subject ) || empty ( $ this -> mailer -> Body ) ) { throw new Exception ( "Mail subject() and body() can not be empty in order to send mail." ) ; } if ( ! $ this -> getMailer ( ) -> send ( ) ) { Yii :: error ( $ this -> getError ( ) , __METHOD__ ) ; return false ; } return true ; }
Trigger the send event of the mailer
12,325
private function getUserAuthClass ( ) { if ( $ this instanceof UserBehaviorInterface ) { $ class = $ this -> userAuthClass ( ) ; if ( ! $ class ) { return false ; } if ( ! is_object ( $ class ) ) { return Yii :: createObject ( $ class ) ; } return $ class ; } return false ; }
Whether the rest controller is protected or not .
12,326
public function sendModelError ( Model $ model ) { if ( ! $ model -> hasErrors ( ) ) { throw new InvalidParamException ( 'The model as thrown an uknown Error.' ) ; } Yii :: $ app -> response -> setStatusCode ( 422 , 'Data Validation Failed.' ) ; $ result = [ ] ; foreach ( $ model -> getFirstErrors ( ) as $ name => $ message ) { $ result [ ] = [ 'field' => $ name , 'message' => $ message , ] ; } return $ result ; }
Send Model errors with correct headers .
12,327
public function sendArrayError ( array $ errors ) { Yii :: $ app -> response -> setStatusCode ( 422 , 'Data Validation Failed.' ) ; $ result = [ ] ; foreach ( $ errors as $ key => $ value ) { $ messages = ( array ) $ value ; foreach ( $ messages as $ msg ) { $ result [ ] = [ 'field' => $ key , 'message' => $ msg ] ; } } return $ result ; }
Send Array validation error .
12,328
public function parse ( $ value , $ sub ) { $ label = $ sub ? : $ value ; if ( $ this -> obfuscate ) { if ( ! $ sub ) { $ label = $ this -> obfuscate ( $ label ) ; } return '<a href="' . $ this -> obfuscate ( "mailto:{$value}" ) . '" rel="nofollow">' . $ label . '</a>' ; } return Html :: mailto ( $ label , $ value , [ 'rel' => 'nofollow' , ] ) ; }
Generate the Mail Tag .
12,329
public function obfuscate ( $ email ) { $ output = null ; for ( $ i = 0 ; $ i < strlen ( $ email ) ; $ i ++ ) { $ output .= '&#' . ord ( $ email [ $ i ] ) . ';' ; } return $ output ; }
Obfucscate email adresse
12,330
public function autoFormat ( $ value ) { if ( ( new EmailValidator ( ) ) -> validate ( $ value ) ) { return $ this -> asEmail ( $ value ) ; } if ( ( new UrlValidator ( ) ) -> validate ( $ value ) ) { return $ this -> asUrl ( $ value ) ; } if ( is_bool ( $ value ) ) { return $ this -> asBoolean ( $ value ) ; } return $ value ; }
Auto format the value to a given format like url email .
12,331
public static function csv ( $ input , array $ keys = [ ] , $ header = true ) { $ delimiter = "," ; $ input = self :: transformInput ( $ input ) ; $ array = self :: generateContentArray ( $ input , $ keys , $ header ) ; return self :: generateOutputString ( $ array , $ delimiter ) ; }
Export an Array or ActiveQuery instance into a CSV formated string .
12,332
public static function xlsx ( $ input , array $ keys = [ ] , $ header = true ) { $ input = self :: transformInput ( $ input ) ; $ array = self :: generateContentArray ( $ input , $ keys , $ header ) ; $ writer = new XLSXWriter ( ) ; $ writer -> writeSheet ( $ array ) ; return $ writer -> writeToString ( ) ; }
Export an Array or ActiveQuery instance into a Excel formatted string .
12,333
protected static function generateContentArray ( $ contentRows , $ keys , $ generateHeader = true ) { if ( is_scalar ( $ contentRows ) ) { throw new Exception ( "Content must be either an array, object or traversable" ) ; } $ attributeKeys = $ keys ; $ header = [ ] ; $ rows = [ ] ; $ i = 0 ; foreach ( $ contentRows as $ content ) { if ( ! empty ( $ keys ) && is_array ( $ content ) ) { foreach ( $ content as $ k => $ v ) { if ( ! in_array ( $ k , $ keys ) ) { unset ( $ content [ $ k ] ) ; } } } elseif ( ! empty ( $ keys ) && is_object ( $ content ) ) { $ attributeKeys [ get_class ( $ content ) ] = $ keys ; } $ rows [ $ i ] = ArrayHelper :: toArray ( $ content , $ attributeKeys , false ) ; if ( $ i == 0 && $ generateHeader ) { if ( $ content instanceof ActiveRecordInterface ) { foreach ( $ content as $ k => $ v ) { if ( empty ( $ keys ) ) { $ header [ ] = $ content -> getAttributeLabel ( $ k ) ; } elseif ( in_array ( $ k , $ keys ) ) { $ header [ ] = $ content -> getAttributeLabel ( $ k ) ; } } } else { $ header = array_keys ( $ rows [ 0 ] ) ; } } $ i ++ ; } if ( $ generateHeader ) { return ArrayHelper :: merge ( [ $ header ] , $ rows ) ; } return $ rows ; }
Generate content by rows .
12,334
protected static function generateRow ( array $ row , $ delimiter , $ enclose ) { array_walk ( $ row , function ( & $ item ) use ( $ enclose ) { if ( is_bool ( $ item ) ) { $ item = ( int ) $ item ; } elseif ( is_null ( $ item ) ) { $ item = '' ; } elseif ( ! is_scalar ( $ item ) ) { $ item = "[array]" ; } $ item = $ enclose . Html :: encode ( $ item ) . $ enclose ; } ) ; return implode ( $ delimiter , $ row ) . PHP_EOL ; }
Generate a row by its items .
12,335
public function setTelephone ( $ telephone ) { $ telephone = ltrim ( $ telephone , '\\' ) ; $ validator = new RegularExpressionValidator ( [ 'pattern' => '#^(?:0|\+[0-9]{2})[\d\- ()]+$#' ] ) ; if ( $ validator -> validate ( $ telephone , $ error ) ) { $ this -> _telephone = $ telephone ; } else { $ this -> _telephone = false ; } }
Setter method for telephone number .
12,336
public function transferMessage ( $ message , $ file = __FILE__ , $ line = __LINE__ ) { return $ this -> apiServerSendData ( $ this -> getExceptionArray ( [ 'message' => $ message , 'file' => $ file , 'line' => $ line , ] ) ) ; }
Send a custom message to the api server event its not related to an exception .
12,337
private function apiServerSendData ( array $ data ) { if ( $ this -> transferException ) { $ curl = new Curl ( ) ; $ curl -> setOpt ( CURLOPT_CONNECTTIMEOUT , 2 ) ; $ curl -> setOpt ( CURLOPT_TIMEOUT , 2 ) ; $ curl -> post ( Url :: ensureHttp ( rtrim ( $ this -> api , '/' ) ) . '/create' , [ 'error_json' => Json :: encode ( $ data ) , ] ) ; $ this -> lastTransferCall = $ curl ; return $ curl -> isSuccess ( ) ; } return null ; }
Send the array data to the api server .
12,338
public function getExceptionArray ( $ exception ) { $ _message = 'Uknonwn exception object, not instance of \Exception.' ; $ _file = 'unknown' ; $ _line = 0 ; $ _trace = [ ] ; $ _previousException = [ ] ; if ( is_object ( $ exception ) ) { $ prev = $ exception -> getPrevious ( ) ; if ( ! empty ( $ prev ) ) { $ _previousException = [ 'message' => $ prev -> getMessage ( ) , 'file' => $ prev -> getFile ( ) , 'line' => $ prev -> getLine ( ) , 'trace' => $ this -> buildTrace ( $ prev ) , ] ; } $ _trace = $ this -> buildTrace ( $ exception ) ; $ _message = $ exception -> getMessage ( ) ; $ _file = $ exception -> getFile ( ) ; $ _line = $ exception -> getLine ( ) ; } elseif ( is_string ( $ exception ) ) { $ _message = 'exception string: ' . $ exception ; } elseif ( is_array ( $ exception ) ) { $ _message = isset ( $ exception [ 'message' ] ) ? $ exception [ 'message' ] : 'exception array dump: ' . print_r ( $ exception , true ) ; $ _file = isset ( $ exception [ 'file' ] ) ? $ exception [ 'file' ] : __FILE__ ; $ _line = isset ( $ exception [ 'line' ] ) ? $ exception [ 'line' ] : __LINE__ ; } return [ 'message' => $ _message , 'file' => $ _file , 'line' => $ _line , 'requestUri' => isset ( $ _SERVER [ 'REQUEST_URI' ] ) ? $ _SERVER [ 'REQUEST_URI' ] : null , 'serverName' => isset ( $ _SERVER [ 'SERVER_NAME' ] ) ? $ _SERVER [ 'SERVER_NAME' ] : null , 'date' => date ( 'd.m.Y H:i' ) , 'trace' => $ _trace , 'previousException' => $ _previousException , 'ip' => isset ( $ _SERVER [ 'REMOTE_ADDR' ] ) ? $ _SERVER [ 'REMOTE_ADDR' ] : null , 'get' => isset ( $ _GET ) ? ArrayHelper :: coverSensitiveValues ( $ _GET , $ this -> sensitiveKeys ) : [ ] , 'post' => isset ( $ _POST ) ? ArrayHelper :: coverSensitiveValues ( $ _POST , $ this -> sensitiveKeys ) : [ ] , 'bodyParams' => Yii :: $ app instanceof Application ? ArrayHelper :: coverSensitiveValues ( Yii :: $ app -> request -> bodyParams ) : [ ] , 'session' => isset ( $ _SESSION ) ? ArrayHelper :: coverSensitiveValues ( $ _SESSION , $ this -> sensitiveKeys ) : [ ] , 'server' => isset ( $ _SERVER ) ? ArrayHelper :: coverSensitiveValues ( $ _SERVER , $ this -> sensitiveKeys ) : [ ] , 'profiling' => Yii :: getLogger ( ) -> profiling , 'logger' => Yii :: getLogger ( ) -> messages , ] ; }
Get an readable array to transfer from an exception
12,339
private function buildTrace ( $ exception ) { $ _trace = [ ] ; foreach ( $ exception -> getTrace ( ) as $ key => $ item ) { $ _trace [ $ key ] = [ 'file' => isset ( $ item [ 'file' ] ) ? $ item [ 'file' ] : null , 'line' => isset ( $ item [ 'line' ] ) ? $ item [ 'line' ] : null , 'function' => isset ( $ item [ 'function' ] ) ? $ item [ 'function' ] : null , 'class' => isset ( $ item [ 'class' ] ) ? $ item [ 'class' ] : null , ] ; } return $ _trace ; }
Build trace array from exception .
12,340
public function getIsAdmin ( ) { if ( $ this -> _isAdmin === null ) { if ( $ this -> getIsConsoleRequest ( ) && ! $ this -> forceWebRequest && ! Yii :: $ app -> hasModule ( 'admin' ) ) { $ this -> _isAdmin = false ; } else { if ( Yii :: $ app -> defaultRoute == 'admin' && empty ( $ this -> pathInfo ) ) { $ this -> _isAdmin = true ; } else { $ resolver = Yii :: $ app -> composition -> getResolvedPathInfo ( $ this ) ; $ parts = explode ( '/' , $ resolver -> resolvedPath ) ; $ first = reset ( $ parts ) ; if ( preg_match ( '/admin/i' , $ first , $ results ) ) { $ this -> _isAdmin = true ; } else { $ this -> _isAdmin = false ; } } } } return $ this -> _isAdmin ; }
Getter method resolves the current url request and check if admin context .
12,341
public function verbosePrint ( $ message , $ section = null ) { if ( $ this -> verbose ) { $ this -> output ( ( ! empty ( $ section ) ) ? $ section . ': ' . $ message : $ message ) ; } }
Method to print informations directly when verbose is enabled .
12,342
public function selectModule ( array $ options = [ ] ) { $ modules = [ ] ; foreach ( Yii :: $ app -> getModules ( ) as $ id => $ object ) { if ( ! $ object instanceof \ luya \ base \ Module ) { continue ; } if ( isset ( $ options [ 'onlyAdmin' ] ) && $ options [ 'onlyAdmin' ] ) { if ( ! $ object instanceof AdminModuleInterface ) { continue ; } } if ( isset ( $ options [ 'hideCore' ] ) && $ options [ 'hideCore' ] ) { if ( $ object instanceof CoreModuleInterface ) { continue ; } } $ modules [ $ id ] = $ id ; } $ text = ( isset ( $ options [ 'text' ] ) ) ? $ options [ 'text' ] : 'Please select a module:' ; return $ this -> select ( $ text , $ modules ) ; }
Get selection list for console commands with defined options .
12,343
public function createClassName ( $ string , $ suffix = false ) { $ name = Inflector :: camelize ( $ string ) ; if ( $ suffix !== false && StringHelper :: endsWith ( $ name , $ suffix , false ) ) { $ name = substr ( $ name , 0 , - ( strlen ( $ suffix ) ) ) ; } return $ name . $ suffix ; }
Generates a class name with camelcase style and specific suffix if not already provided
12,344
public function getSqlTablesArray ( ) { $ names = Yii :: $ app -> db -> schema -> tableNames ; return array_combine ( $ names , $ names ) ; }
Get the sql tables from the current database connection
12,345
protected function isColumnAutoIncremental ( $ table , $ columns ) { foreach ( $ columns as $ column ) { if ( isset ( $ table -> columns [ $ column ] ) && $ table -> columns [ $ column ] -> autoIncrement ) { return true ; } } return false ; }
Checks if any of the specified columns is auto incremental .
12,346
public function autoEncodeAttributes ( ) { foreach ( $ this -> attributes as $ name ) { if ( ! isset ( $ this -> owner -> getDirtyAttributes ( ) [ $ name ] ) ) { continue ; } $ value = $ this -> owner -> { $ name } ; if ( is_array ( $ value ) ) { $ this -> owner -> { $ name } = $ this -> jsonEncode ( $ name ) ; } } }
Encode attributes .
12,347
public static function coverSensitiveValues ( array $ data , array $ keys = [ ] ) { if ( empty ( $ keys ) ) { $ keys = self :: $ sensitiveDefaultKeys ; } $ clean = [ ] ; foreach ( $ keys as $ key ) { $ kw = strtolower ( $ key ) ; foreach ( $ data as $ k => $ v ) { if ( is_array ( $ v ) ) { $ clean [ $ k ] = static :: coverSensitiveValues ( $ v , $ keys ) ; } elseif ( is_scalar ( $ v ) && ( $ kw == strtolower ( $ k ) || StringHelper :: startsWith ( strtolower ( $ k ) , $ kw ) ) ) { $ v = str_repeat ( "*" , strlen ( $ v ) ) ; $ clean [ $ k ] = $ v ; } } } return array_replace ( $ data , $ clean ) ; }
Cover senstive values from a given list of keys .
12,348
public static function arrayUnshiftAssoc ( & $ arr , $ key , $ val ) { $ arr = array_reverse ( $ arr , true ) ; $ arr [ $ key ] = $ val ; return array_reverse ( $ arr , true ) ; }
Prepend an assoc array item as first entry for a given array .
12,349
public static function typeCast ( array $ array ) { $ return = [ ] ; foreach ( $ array as $ k => $ v ) { if ( is_numeric ( $ v ) ) { $ return [ $ k ] = StringHelper :: typeCastNumeric ( $ v ) ; } elseif ( is_array ( $ v ) ) { $ return [ $ k ] = self :: typeCast ( $ v ) ; } else { $ return [ $ k ] = $ v ; } } return $ return ; }
TypeCast values from a mixed array source . numeric values will be casted as integer .
12,350
public static function search ( array $ array , $ searchText , $ sensitive = false ) { $ function = ( $ sensitive ) ? 'strpos' : 'stripos' ; return array_filter ( $ array , function ( $ item ) use ( $ searchText , $ function ) { $ response = false ; foreach ( $ item as $ key => $ value ) { if ( $ response ) { continue ; } if ( $ function ( $ value , "$searchText" ) !== false ) { $ response = true ; } } return $ response ; } ) ; }
Search trough all keys inside of an array any occurence will return the rest of the array .
12,351
public static function searchColumn ( array $ array , $ column , $ search ) { $ array = array_values ( $ array ) ; $ columns = array_column ( $ array , $ column ) ; $ key = array_search ( $ search , $ columns ) ; return ( $ key !== false ) ? $ array [ $ key ] : false ; }
Search for a Column Value inside a Multidimension array and return the array with the found key .
12,352
public static function searchColumns ( array $ array , $ column , $ search ) { $ keys = array_filter ( $ array , function ( $ var ) use ( $ column , $ search ) { return strcasecmp ( $ search , $ var [ $ column ] ) == 0 ? true : false ; } ) ; return $ keys ; }
Search for columns with the given search value returns the full array with all valid items .
12,353
public static function generateRange ( $ from , $ to , $ text = null ) { $ range = range ( $ from , $ to ) ; $ array = array_combine ( $ range , $ range ) ; if ( $ text ) { array_walk ( $ array , function ( & $ item , $ key ) use ( $ text ) { if ( is_array ( $ text ) ) { list ( $ singular , $ plural ) = $ text ; if ( $ key == 1 ) { $ item = "{$key} {$singular}" ; } else { $ item = "{$key} {$plural}" ; } } else { $ item = "{$key} {$text}" ; } } ) ; } return $ array ; }
Generate an Array from a Rang with an appending optional Text .
12,354
public static function classInfo ( $ file ) { if ( is_file ( $ file ) ) { $ phpCode = file_get_contents ( $ file ) ; } else { $ phpCode = $ file ; } $ namespace = false ; if ( preg_match ( '/^namespace\s+(.+?);(\s+|\r\n)?$/sm' , $ phpCode , $ results ) ) { $ namespace = $ results [ 1 ] ; } $ classes = self :: classNameByTokens ( $ phpCode ) ; return [ 'namespace' => $ namespace , 'class' => end ( $ classes ) ] ; }
Provide class informations from a file path or file content .
12,355
private static function classNameByTokens ( $ phpCode ) { $ classes = [ ] ; $ tokens = token_get_all ( $ phpCode ) ; $ count = count ( $ tokens ) ; for ( $ i = 2 ; $ i < $ count ; $ i ++ ) { if ( $ tokens [ $ i - 2 ] [ 0 ] == T_CLASS && $ tokens [ $ i - 1 ] [ 0 ] == T_WHITESPACE && $ tokens [ $ i ] [ 0 ] == T_STRING ) { $ classes [ ] = $ tokens [ $ i ] [ 1 ] ; } } return $ classes ; }
Tokenize the php code from a given class in in order to determine the class name .
12,356
public static function unlink ( $ file ) { try { if ( parent :: unlink ( $ file ) ) { return true ; } } catch ( \ Exception $ e ) { } if ( is_link ( $ file ) ) { $ sym = @ readlink ( $ file ) ; if ( $ sym ) { if ( @ unlink ( $ file ) ) { return true ; } } } if ( realpath ( $ file ) && realpath ( $ file ) !== $ file ) { if ( @ unlink ( realpath ( $ file ) ) ) { return true ; } } return false ; }
Unlink a file which handles symlinks .
12,357
public function routeHasLanguageCompositionPrefix ( $ route , $ language ) { $ parts = explode ( "/" , $ route ) ; if ( isset ( $ parts [ 0 ] ) && $ parts [ 0 ] == $ language ) { return true ; } return false ; }
Ensure whether a route starts with a language short key or not .
12,358
public function getMenu ( ) { if ( $ this -> _menu === null ) { $ menu = Yii :: $ app -> get ( 'menu' , false ) ; if ( $ menu ) { $ this -> _menu = $ menu ; } else { $ this -> _menu = false ; } } return $ this -> _menu ; }
Get the menu component if its registered in the current applications .
12,359
public function getComposition ( ) { if ( $ this -> _composition === null ) { $ this -> _composition = Yii :: $ app -> get ( 'composition' ) ; } return $ this -> _composition ; }
Get the composition component
12,360
public function createUrl ( $ params ) { $ response = $ this -> internalCreateUrl ( $ params ) ; if ( $ this -> contextNavItemId ) { return $ this -> urlReplaceModule ( $ response , $ this -> contextNavItemId , $ this -> getComposition ( ) ) ; } return $ response ; }
Extend createUrl method by verify its context implementation to add cms urls prepand to the requested createurl params .
12,361
public function createMenuItemUrl ( $ params , $ navItemId , $ composition = null ) { $ composition = empty ( $ composition ) ? $ this -> getComposition ( ) : $ composition ; $ url = $ this -> internalCreateUrl ( $ params , $ composition ) ; if ( ! $ this -> menu ) { return $ url ; } return $ this -> urlReplaceModule ( $ url , $ navItemId , $ composition ) ; }
Create an url for a menu item .
12,362
public function internalCreateUrl ( $ params , $ composition = null ) { $ params = ( array ) $ params ; $ composition = empty ( $ composition ) ? $ this -> getComposition ( ) : $ composition ; $ originalParams = $ params ; $ params [ 0 ] = $ composition -> prependTo ( $ params [ 0 ] , $ composition -> createRoute ( ) ) ; $ response = parent :: createUrl ( $ params ) ; if ( strpos ( $ response , rtrim ( $ params [ 0 ] , '/' ) ) !== false ) { $ response = parent :: createUrl ( $ originalParams ) ; } $ response = $ this -> removeBaseUrl ( $ response ) ; $ response = $ composition -> prependTo ( $ response ) ; return $ this -> prependBaseUrl ( $ response ) ; }
Yii2 createUrl base implementation extends the prepand of the comosition
12,363
public function internalCreateAbsoluteUrl ( $ params , $ scheme = null ) { $ params = ( array ) $ params ; $ url = $ this -> internalCreateUrl ( $ params ) ; if ( strpos ( $ url , '://' ) === false ) { $ url = $ this -> getHostInfo ( ) . $ url ; } if ( is_string ( $ scheme ) && ( $ pos = strpos ( $ url , '://' ) ) !== false ) { $ url = $ scheme . substr ( $ url , $ pos ) ; } return $ url ; }
Create absolute url from the given route params .
12,364
private function findModuleInRoute ( $ route ) { $ route = parse_url ( $ route , PHP_URL_PATH ) ; $ parts = array_values ( array_filter ( explode ( '/' , $ route ) ) ) ; if ( isset ( $ parts [ 0 ] ) && array_key_exists ( $ parts [ 0 ] , Yii :: $ app -> getApplicationModules ( ) ) ) { return $ parts [ 0 ] ; } return false ; }
See if the module of a provided route exists in the luya application list .
12,365
private function urlReplaceModule ( $ url , $ navItemId , Composition $ composition ) { $ route = $ composition -> removeFrom ( $ this -> removeBaseUrl ( $ url ) ) ; $ moduleName = $ this -> findModuleInRoute ( $ route ) ; if ( $ moduleName === false || $ this -> menu === false ) { return $ url ; } $ item = $ this -> menu -> find ( ) -> where ( [ 'id' => $ navItemId ] ) -> with ( 'hidden' ) -> lang ( $ composition [ 'langShortCode' ] ) -> one ( ) ; if ( ! $ item ) { throw new BadRequestHttpException ( "Unable to find nav_item_id '$navItemId' to generate the module link for url '$url'." ) ; } $ isOutgoingModulePage = $ item -> type == 2 && $ moduleName !== $ item -> moduleName ; if ( $ isOutgoingModulePage || $ item -> isHome ) { return $ url ; } if ( $ isOutgoingModulePage && $ moduleName !== Yii :: $ app -> controller -> module -> id ) { return $ url ; } return preg_replace ( "/$moduleName/" , rtrim ( $ item -> link , '/' ) , ltrim ( $ route , '/' ) , 1 ) ; }
Replace the url with the current module context .
12,366
public function setAreaServed ( $ areaServed ) { ObjectHelper :: isInstanceOf ( $ areaServed , [ Place :: class , TextValue :: class ] ) ; $ this -> _areaServed = $ areaServed ; return $ this ; }
Set Area Served .
12,367
public function inGroup ( $ alias ) { if ( $ this -> isGuest ) { return false ; } $ identity = $ this -> identity ; if ( ! $ identity instanceof GroupUserIdentityInterface ) { throw new InvalidConfigException ( 'The $identityClass must be instance of luya\web\GroupUserIdentityInterface.' ) ; } $ groups = ( array ) $ alias ; foreach ( $ groups as $ groupAlias ) { if ( in_array ( $ groupAlias , $ identity -> authGroups ( ) ) ) { return true ; } } return false ; }
Checks whether a user exists for the provided group based on the GroupUserIdentityInterface implementation
12,368
public static function isTraitInstanceOf ( $ object , $ haystack ) { $ traits = static :: traitsList ( $ object ) ; if ( is_object ( $ haystack ) ) { $ haystack = static :: traitsList ( $ haystack ) ; } foreach ( ( array ) $ haystack as $ stack ) { if ( in_array ( $ stack , $ traits ) ) { return true ; } } return false ; }
Check whether a given object contains a trait .
12,369
public static function traitsList ( $ object , $ autoload = true ) { $ traits = [ ] ; do { $ traits = array_merge ( class_uses ( $ object , $ autoload ) , $ traits ) ; } while ( $ object = get_parent_class ( $ object ) ) ; $ traitsToSearch = $ traits ; while ( ! empty ( $ traitsToSearch ) ) { $ newTraits = class_uses ( array_pop ( $ traitsToSearch ) , $ autoload ) ; $ traits = array_merge ( $ newTraits , $ traits ) ; $ traitsToSearch = array_merge ( $ newTraits , $ traitsToSearch ) ; } ; foreach ( $ traits as $ trait => $ same ) { $ traits = array_merge ( class_uses ( $ trait , $ autoload ) , $ traits ) ; } return $ traits ; }
Get an array with all traits for a given object
12,370
public static function callMethodSanitizeArguments ( $ object , $ method , array $ argumentsList = [ ] ) { $ reflection = new ReflectionMethod ( $ object , $ method ) ; $ methodArgs = [ ] ; foreach ( $ reflection -> getParameters ( ) as $ param ) { if ( array_key_exists ( $ param -> name , $ argumentsList ) ) { $ methodArgs [ ] = $ argumentsList [ $ param -> name ] ; } if ( ! $ param -> isOptional ( ) && ! array_key_exists ( $ param -> name , $ argumentsList ) ) { throw new Exception ( sprintf ( "The argument '%s' is required for method '%s' in class '%s'." , $ param -> name , $ method , get_class ( $ object ) ) ) ; } } return call_user_func_array ( [ $ object , $ method ] , $ methodArgs ) ; }
Call a method and ensure arguments .
12,371
public function resolveRoute ( $ route ) { $ routeParts = explode ( '/' , $ route ) ; foreach ( $ routeParts as $ k => $ v ) { if ( ( $ k == 0 && $ v == $ this -> id ) || ( empty ( $ v ) ) ) { unset ( $ routeParts [ $ k ] ) ; } } if ( count ( $ routeParts ) == 0 ) { return $ this -> defaultRoute ; } return implode ( '/' , $ routeParts ) ; }
Extract the current module from the route and return the new resolved route .
12,372
public static function registerTranslation ( $ prefix , $ basePath , array $ fileMap ) { if ( ! isset ( Yii :: $ app -> i18n -> translations [ $ prefix ] ) ) { Yii :: $ app -> i18n -> translations [ $ prefix ] = [ 'class' => 'yii\i18n\PhpMessageSource' , 'basePath' => $ basePath , 'fileMap' => $ fileMap , ] ; } }
Register a Translation to the i18n component .
12,373
public static function baseT ( $ category , $ message , array $ params = [ ] , $ language = null ) { static :: onLoad ( ) ; return Yii :: t ( $ category , $ message , $ params , $ language ) ; }
Base translation method which invokes the onLoad function .
12,374
public function setSuffix ( $ suffix ) { $ this -> _suffix = $ suffix ; $ this -> request -> setPathInfo ( implode ( '/' , [ $ this -> module -> id , $ suffix ] ) ) ; }
Setter for the suffix property .
12,375
public function getRequestRoute ( ) { if ( $ this -> _requestRoute !== null ) { return $ this -> _requestRoute ; } if ( $ this -> _defaultRoute !== null && empty ( $ this -> getSuffix ( ) ) ) { $ array = $ this -> _defaultRoute ; } else { $ route = $ this -> urlManager -> parseRequest ( $ this -> request ) ; $ array = [ 'route' => $ route [ 0 ] , 'args' => $ route [ 1 ] , 'originalArgs' => $ route [ 1 ] , ] ; } $ array [ 'route' ] = $ this -> module -> resolveRoute ( $ array [ 'route' ] ) ; if ( empty ( $ array [ 'args' ] ) ) { $ array [ 'args' ] = $ this -> request -> get ( ) ; } if ( $ this -> _defaultRoute !== null ) { $ array [ 'args' ] = array_merge ( $ this -> _defaultRoute [ 'args' ] , $ array [ 'args' ] ) ; } $ this -> _requestRoute = $ array ; return $ array ; }
Determine the default route based on current defaultRoutes or parsedRequested by the UrlManager .
12,376
public function defaultRoute ( $ controller , $ action = null , array $ args = [ ] ) { $ this -> _defaultRoute = [ 'route' => implode ( '/' , [ $ this -> module -> id , $ controller , ( empty ( $ action ) ) ? 'index' : $ action ] ) , 'args' => $ args , 'originalArgs' => $ args , ] ; }
Inject a defaultRoute .
12,377
public function getUrlRule ( ) { $ request = $ this -> getRequestRoute ( ) ; return [ 'module' => $ this -> module -> id , 'route' => $ this -> module -> id . '/' . $ request [ 'route' ] , 'params' => $ request [ 'originalArgs' ] , ] ; }
Returns the url rule parameters which are taken from the requested route .
12,378
public function run ( ) { $ requestRoute = $ this -> getRequestRoute ( ) ; $ controller = $ this -> module -> createController ( $ requestRoute [ 'route' ] ) ; if ( ! isset ( $ controller [ 0 ] ) && ! is_object ( $ controller [ 0 ] ) ) { throw new NotFoundHttpException ( sprintf ( "Unable to create controller '%s' for module '%s'." , $ requestRoute [ 'route' ] , $ this -> module -> id ) ) ; } Yii :: debug ( 'LUYA module run module "' . $ this -> module -> id . '" route ' . $ requestRoute [ 'route' ] , __METHOD__ ) ; $ this -> controller = $ controller [ 0 ] ; $ originalController = Yii :: $ app -> controller ; $ this -> controller -> on ( Controller :: EVENT_BEFORE_ACTION , function ( $ event ) { Yii :: $ app -> controller = $ this -> controller ; } ) ; $ this -> controller -> on ( Controller :: EVENT_AFTER_ACTION , function ( $ event ) use ( $ originalController ) { Yii :: $ app -> controller = $ originalController ; } ) ; return $ this -> controller -> runAction ( $ controller [ 1 ] , $ requestRoute [ 'args' ] ) ; }
Run the route based on the values .
12,379
public function getResolvedKeyValue ( $ key ) { $ keys = $ this -> resolvedValues ; return isset ( $ keys [ $ key ] ) ? $ keys [ $ key ] : false ; }
Get a value for a given resolved pattern key .
12,380
protected function getInternalResolverArray ( ) { if ( $ this -> _resolved === null ) { $ requestPathInfo = $ this -> trailingPathInfo ( ) ; $ newRegex = $ this -> buildRegexPattern ( ) ; preg_match_all ( static :: VAR_MATCH_REGEX , $ this -> composition -> pattern , $ patternDefinitions , PREG_SET_ORDER ) ; foreach ( $ patternDefinitions as $ definition ) { $ newRegex = str_replace ( $ definition [ 0 ] , '(' . rtrim ( ltrim ( $ definition [ 2 ] , '(' ) , ')' ) . ')' , $ newRegex ) ; } preg_match_all ( $ newRegex , $ requestPathInfo , $ matches , PREG_SET_ORDER ) ; if ( isset ( $ matches [ 0 ] ) && ! empty ( $ matches [ 0 ] ) ) { $ keys = [ ] ; $ matches = $ matches [ 0 ] ; $ compositionPrefix = $ matches [ 0 ] ; unset ( $ matches [ 0 ] ) ; $ matches = array_values ( $ matches ) ; foreach ( $ matches as $ k => $ v ) { $ keys [ $ patternDefinitions [ $ k ] [ 1 ] ] = $ v ; } $ route = StringHelper :: replaceFirst ( $ compositionPrefix , '' , $ requestPathInfo ) ; } else { $ matches = [ ] ; $ keys = $ this -> composition -> default ; $ route = $ requestPathInfo ; } if ( $ this -> composition -> expectedValues ) { foreach ( $ keys as $ k => $ v ) { $ possibleValues = $ this -> composition -> expectedValues [ $ k ] ; if ( ! in_array ( $ v , $ possibleValues ) ) { throw new NotFoundHttpException ( "The requested composition key \"{$k}\" with value \"{$v}\" is not in the possible values list." ) ; } } } $ this -> _resolved = [ 'route' => rtrim ( $ route , '/' ) , 'values' => $ keys , ] ; } return $ this -> _resolved ; }
Resolve the current data .
12,381
public function setAuthor ( $ author ) { ObjectHelper :: isInstanceOf ( $ author , [ Organization :: class , PersonInterface :: class ] ) ; $ this -> _author = $ author ; return $ this ; }
The author of this content or rating . Please note that author is special in that HTML 5 provides a special mechanism for indicating authorship via the rel tag . That is equivalent to this and may be used interchangeably .
12,382
public function setCopyrightHolder ( $ copyrightHolder ) { ObjectHelper :: isInstanceOf ( $ copyrightHolder , [ Organization :: class , PersonInterface :: class ] ) ; $ this -> _copyrightHolder = $ copyrightHolder ; return $ this ; }
The party holding the legal copyright to the CreativeWork .
12,383
public function setPublisher ( $ publisher ) { ObjectHelper :: isInstanceOf ( $ publisher , [ Organization :: class , Person :: class ] ) ; $ this -> _publisher = $ publisher ; return $ this ; }
The publisher of the creative work .
12,384
public function setAutoGenerateProxyClasses ( int $ mode ) : void { $ this -> autoGenerateProxyClasses = $ mode ; $ proxyManagerConfig = $ this -> getProxyManagerConfiguration ( ) ; switch ( $ mode ) { case self :: AUTOGENERATE_FILE_NOT_EXISTS : $ proxyManagerConfig -> setGeneratorStrategy ( new FileWriterGeneratorStrategy ( new FileLocator ( $ proxyManagerConfig -> getProxiesTargetDir ( ) ) ) ) ; break ; case self :: AUTOGENERATE_EVAL : $ proxyManagerConfig -> setGeneratorStrategy ( new EvaluatingGeneratorStrategy ( ) ) ; break ; default : throw new InvalidArgumentException ( 'Invalid proxy generation strategy given - only AUTOGENERATE_FILE_NOT_EXISTS and AUTOGENERATE_EVAL are supported.' ) ; } }
Sets an int flag that indicates whether proxy classes should always be regenerated during each script execution .
12,385
public function addFilter ( string $ name , string $ className , array $ parameters = [ ] ) : void { $ this -> attributes [ 'filters' ] [ $ name ] = [ 'class' => $ className , 'parameters' => $ parameters , ] ; }
Add a filter to the list of possible filters .
12,386
public function geoNear ( $ x , $ y = null ) : Stage \ GeoNear { return $ this -> builder -> geoNear ( $ x , $ y ) ; }
Outputs documents in order of nearest to farthest from a specified point . You can only use this as the first stage of a pipeline .
12,387
public function generateHydratorClasses ( array $ classes , ? string $ toDir = null ) : void { $ hydratorDir = $ toDir ? : $ this -> hydratorDir ; $ hydratorDir = rtrim ( $ hydratorDir , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; foreach ( $ classes as $ class ) { $ hydratorClassName = str_replace ( '\\' , '' , $ class -> name ) . 'Hydrator' ; $ hydratorFileName = $ hydratorDir . $ hydratorClassName . '.php' ; $ this -> generateHydratorClass ( $ class , $ hydratorClassName , $ hydratorFileName ) ; } }
Generates hydrator classes for all given classes .
12,388
public static function isAtomic ( string $ strategy ) : bool { return $ strategy === ClassMetadata :: STORAGE_STRATEGY_ATOMIC_SET || $ strategy === ClassMetadata :: STORAGE_STRATEGY_ATOMIC_SET_ARRAY ; }
Returns whether update query must be included in query updating owning document .
12,389
public static function isHash ( string $ strategy ) : bool { return $ strategy === ClassMetadata :: STORAGE_STRATEGY_SET || $ strategy === ClassMetadata :: STORAGE_STRATEGY_ATOMIC_SET ; }
Returns whether Collection hold associative array .
12,390
public static function isList ( ? string $ strategy ) : bool { return $ strategy !== ClassMetadata :: STORAGE_STRATEGY_SET && $ strategy !== ClassMetadata :: STORAGE_STRATEGY_ATOMIC_SET ; }
Returns whether Collection hold array indexed by consecutive numbers .
12,391
public function showLatencyStats ( bool $ histograms = false ) : self { $ this -> latencyStats = $ histograms ? self :: LATENCY_STATS_HISTOGRAMS : self :: LATENCY_STATS_SIMPLE ; return $ this ; }
Adds latency statistics to the return document .
12,392
private function wrapCursor ( Cursor $ baseCursor ) : Iterator { return new CachingIterator ( new HydratingIterator ( $ baseCursor , $ this -> dm -> getUnitOfWork ( ) , $ this -> class ) ) ; }
Wraps the supplied base cursor in the corresponding ODM class .
12,393
private function createDocument ( array $ result , ? object $ document = null , array $ hints = [ ] ) : ? object { if ( $ document !== null ) { $ hints [ Query :: HINT_REFRESH ] = true ; $ id = $ this -> class -> getPHPIdentifierValue ( $ result [ '_id' ] ) ; $ this -> uow -> registerManaged ( $ document , $ id , $ result ) ; } return $ this -> uow -> getOrCreateDocument ( $ this -> class -> name , $ result , $ hints , $ document ) ; }
Creates or fills a single document object from an query result .
12,394
public function prepareProjection ( array $ fields ) : array { $ preparedFields = [ ] ; foreach ( $ fields as $ key => $ value ) { $ preparedFields [ $ this -> prepareFieldName ( $ key ) ] = $ value ; } return $ preparedFields ; }
Prepare a projection array by converting keys which are PHP property names to MongoDB field names .
12,395
public function prepareSort ( array $ fields ) : array { $ sortFields = [ ] ; foreach ( $ fields as $ key => $ value ) { if ( is_array ( $ value ) ) { $ sortFields [ $ this -> prepareFieldName ( $ key ) ] = $ value ; } else { $ sortFields [ $ this -> prepareFieldName ( $ key ) ] = $ this -> getSortDirection ( $ value ) ; } } return $ sortFields ; }
Prepare a sort specification array by converting keys to MongoDB field names and changing direction strings to int .
12,396
private function hasDBRefFields ( $ value ) : bool { if ( ! is_array ( $ value ) && ! is_object ( $ value ) ) { return false ; } if ( is_object ( $ value ) ) { $ value = get_object_vars ( $ value ) ; } foreach ( $ value as $ key => $ _ ) { if ( $ key === '$ref' || $ key === '$id' || $ key === '$db' ) { return true ; } } return false ; }
Checks whether the value has DBRef fields .
12,397
private function hasQueryOperators ( $ value ) : bool { if ( ! is_array ( $ value ) && ! is_object ( $ value ) ) { return false ; } if ( is_object ( $ value ) ) { $ value = get_object_vars ( $ value ) ; } foreach ( $ value as $ key => $ _ ) { if ( isset ( $ key [ 0 ] ) && $ key [ 0 ] === '$' ) { return true ; } } return false ; }
Checks whether the value has query operators .
12,398
private function getClassDiscriminatorValues ( ClassMetadata $ metadata ) : array { $ discriminatorValues = [ ] ; if ( $ metadata -> discriminatorValue !== null ) { $ discriminatorValues [ ] = $ metadata -> discriminatorValue ; } foreach ( $ metadata -> subClasses as $ className ) { $ key = array_search ( $ className , $ metadata -> discriminatorMap ) ; if ( ! $ key ) { continue ; } $ discriminatorValues [ ] = $ key ; } if ( $ metadata -> defaultDiscriminatorValue && in_array ( $ metadata -> defaultDiscriminatorValue , $ discriminatorValues ) ) { $ discriminatorValues [ ] = null ; } return $ discriminatorValues ; }
Returns the list of discriminator values for the given ClassMetadata
12,399
private function getQueryForDocument ( object $ document ) : array { $ id = $ this -> uow -> getDocumentIdentifier ( $ document ) ; $ id = $ this -> class -> getDatabaseIdentifierValue ( $ id ) ; $ shardKeyQueryPart = $ this -> getShardKeyQuery ( $ document ) ; return array_merge ( [ '_id' => $ id ] , $ shardKeyQueryPart ) ; }
Get shard key aware query for single document .