idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
30,500
protected function getLocales ( ) { return \ localizer \ locales ( ) -> reduce ( function ( $ ids , $ locale ) { $ ids [ ] = $ locale -> id ( ) ; return $ ids ; } , [ ] ) ; }
Get list of all available locales
30,501
public function scopeTranslated ( Builder $ query ) { $ mainTable = $ this -> getTable ( ) ; $ keyName = $ this -> getKeyName ( ) ; $ relKeyName = $ this -> getRelationKey ( ) ; $ localeKey = $ this -> getLocaleKey ( ) ; $ joinTable = $ this -> getTranslationModel ( ) -> getTable ( ) ; $ langId = \ localizer \ locale ( ) -> id ( ) ; $ alias = "tt" ; if ( $ this -> isQueryWithoutColumns ( $ query ) ) { $ this -> fillQueryWithTranslatedColumns ( $ query , $ mainTable , $ keyName , $ alias ) ; } $ query -> leftJoin ( "{$joinTable} AS {$alias}" , function ( $ join ) use ( $ mainTable , $ keyName , $ relKeyName , $ localeKey , $ alias , $ langId ) { $ join -> on ( "{$mainTable}.{$keyName}" , '=' , "{$alias}.{$relKeyName}" ) -> where ( $ localeKey , '=' , ( int ) $ langId ) ; } ) ; return $ query ; }
Allows fetching Translatable items with translations
30,502
public function toArray ( $ withTranslations = true ) { $ attributes = parent :: toArray ( ) ; if ( $ withTranslations && $ this -> hasTranslatedAttributes ( ) ) { foreach ( $ this -> getTranslatedAttributes ( ) as $ field ) { if ( $ translations = $ this -> getTranslation ( ) ) { $ attributes [ $ field ] = $ translations -> $ field ; } } } return $ attributes ; }
Cast model to array
30,503
protected function modelToNorm ( $ value ) { try { foreach ( $ this -> config -> getModelTransformers ( ) as $ transformer ) { $ value = $ transformer -> transform ( $ value ) ; } } catch ( TransformationFailedException $ exception ) { throw new TransformationFailedException ( 'Unable to transform value for property path "' . $ this -> getPropertyPath ( ) . '": ' . $ exception -> getMessage ( ) , $ exception -> getCode ( ) , $ exception ) ; } return $ value ; }
Normalizes the value if a normalization transformer is set .
30,504
protected function processSomeAttachments ( $ models , $ attachments ) { foreach ( $ models as $ model ) { foreach ( $ model -> getAttachedFiles ( ) as $ attachedFile ) { if ( in_array ( $ attachedFile -> name , $ attachments ) ) { $ attachedFile -> reprocess ( ) ; } } } }
Process a only a specified subset of laraclip attachments .
30,505
protected function processAllAttachments ( $ models ) { foreach ( $ models as $ model ) { foreach ( $ model -> getAttachedFiles ( ) as $ attachedFile ) { $ attachedFile -> reprocess ( ) ; } } }
Process all laraclip attachments defined on a class .
30,506
public function updateConfiguration ( ) { $ this -> getEventDispatcher ( ) -> dispatch ( UpdateConfigurationEvent :: NAME , new UpdateConfigurationEvent ( $ this -> getWebserviceId ( ) , $ this -> getConfiguration ( ) ) ) ; }
Ask for Update of Server Configuration in Memory .
30,507
public function identify ( string $ webserviceId ) { $ event = $ this -> getEventDispatcher ( ) -> dispatch ( IdentifyServerEvent :: NAME , new IdentifyServerEvent ( $ this , $ webserviceId ) ) ; if ( $ event -> isRejected ( ) ) { return null ; } return $ event -> isIdentified ( ) ; }
Ask for Identifcation of Server in Memory .
30,508
public function commit ( string $ objectType , $ objectsIds , string $ action , string $ userName = 'Unknown User' , string $ comment = '' ) { $ event = new ObjectsCommitEvent ( $ this -> getWebserviceId ( ) , $ objectType , $ objectsIds , $ action , $ userName , $ comment ) ; $ this -> getEventDispatcher ( ) -> dispatch ( ObjectsCommitEvent :: NAME , $ event ) ; }
Commit an Object Change to Splash Server
30,509
public function file ( string $ path , string $ md5 ) { $ event = new ObjectFileEvent ( $ this -> getWebserviceId ( ) , $ path , $ md5 ) ; $ response = $ this -> getEventDispatcher ( ) -> dispatch ( ObjectFileEvent :: NAME , $ event ) ; return $ response -> getContents ( ) ; }
Get an Object File from Splash Server
30,510
public function objectIdChanged ( string $ objectType , string $ oldObjectId , string $ newObjectId ) { $ event = new ObjectsIdChangedEvent ( $ this -> getWebserviceId ( ) , $ objectType , $ oldObjectId , $ newObjectId ) ; $ this -> getEventDispatcher ( ) -> dispatch ( ObjectsIdChangedEvent :: NAME , $ event ) ; return true ; }
Tell Splash Object manager that Object Id Changed on Remote Server
30,511
public static function sendNoCacheHeaders ( ) { if ( false === headers_sent ( ) ) { header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ) ; header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ) ; header ( 'Cache-Control: no-store, no-cache, must-revalidate' ) ; header ( 'Cache-Control: post-check=0, pre-check=0' , false ) ; header ( 'Pragma: no-cache' ) ; return true ; } return false ; }
Sends no cache headers to ensure that a response wont get cached on its way to the client .
30,512
public static function getUrl ( ) { static $ uri = null ; if ( null === $ uri ) { $ uri = ( true === isset ( $ _SERVER [ 'SERVER_NAME' ] ) ) ? $ _SERVER [ 'SERVER_NAME' ] : '' ; if ( strlen ( $ uri ) > 0 ) { $ uri = ( ( true === is_ssl ( ) ) ? 'https://' : 'http://' ) . $ uri ; } if ( true === isset ( $ _SERVER [ 'SERVER_PORT' ] ) ) { if ( $ _SERVER [ 'SERVER_PORT' ] !== '80' && $ _SERVER [ 'SERVER_PORT' ] !== '443' ) { $ uri .= ':' . $ _SERVER [ 'SERVER_PORT' ] ; } } $ uri .= $ _SERVER [ 'REQUEST_URI' ] ; } return $ uri ; }
Returns the current URL used for request .
30,513
public function findByUser ( $ user , array $ options = array ( ) ) { if ( ! $ user instanceof User ) { $ user = $ this -> api ( 'subbly.user' ) -> find ( $ user ) ; } $ query = $ this -> newCollectionQuery ( $ options ) ; $ query -> with ( array ( 'user' => function ( $ query ) use ( $ user ) { $ query -> where ( 'uid' , '=' , $ user -> uid ) ; } ) ) ; return new Collection ( $ query ) ; }
Find a UserAddress by User .
30,514
public function setKey ( $ key ) { $ this -> nk = strlen ( $ key ) / 4 ; $ this -> rounds = $ this -> nk + self :: $ nb + 2 ; if ( $ this -> nk != 4 && $ this -> nk != 6 && $ this -> nk != 8 ) { throw new Doozr_Crypt_Service_Exception ( sprintf ( 'Key is %s bits long. *not* 128, 192, or 256.' , ( $ this -> nk * 32 ) ) ) ; } $ this -> rounds = $ this -> nk + self :: $ nb + 2 ; $ this -> word = [ ] ; $ this -> state = [ [ ] ] ; $ this -> KeyExpansion ( $ key ) ; }
Setter for key .
30,515
public function encrypt ( $ x ) { $ t = '' ; $ y = '' ; $ xsize = strlen ( $ x ) ; for ( $ i = 0 ; $ i < $ xsize ; $ i += 16 ) { for ( $ j = 0 ; $ j < 16 ; ++ $ j ) { if ( ( $ i + $ j ) < $ xsize ) { $ t [ $ j ] = $ x [ $ i + $ j ] ; } else { $ t [ $ j ] = chr ( 0 ) ; } } $ y .= $ this -> encryptBlock ( $ t ) ; } return $ y ; }
Encrypts an aribtrary length String .
30,516
public function toJson ( ) { $ response = new Doozr_Base_Response_Rest ( ) ; $ response -> status ( Doozr_Base_Response_Rest :: STATUS_ERROR ) -> message ( $ this -> getMessage ( ) ) -> data ( array ( 'error' => $ this -> getError ( ) ) ) ; $ data = $ response -> getData ( ) ; if ( $ this -> getToken ( ) !== null ) { $ data [ 'security' ] = array ( 'token' => $ this -> getToken ( ) ) ; } if ( true === DOOZR_DEBUGGING ) { $ data [ 'meta' ] = array ( 'message' => $ this -> getMessage ( ) , 'code' => $ this -> getCode ( ) , 'file' => $ this -> getFile ( ) , 'line' => $ this -> getLine ( ) , ) ; } $ response -> setData ( $ data ) ; return $ response -> toJson ( ) ; }
Exports current state as json for API responses .
30,517
protected function fetchAssets ( $ templateContents , $ section ) { $ pattern = sprintf ( '/BEGIN-%1$s[^\w\s]*[\r\n](.*?)[\r\n][^\w]*END-%1$s/s' , $ section ) ; preg_match ( $ pattern , $ templateContents , $ matches ) ; return ( ! empty ( $ matches ) ) ? explode ( "\n" , $ matches [ 1 ] ) : array ( ) ; }
Fetches the assets attributes indentified by a section
30,518
public function addChild ( self $ node ) { $ index = count ( $ this -> node_children ) ; $ this -> insertChildAt ( $ index , $ node ) ; }
Add the given node at the end .
30,519
public function insertChildAt ( $ index , self $ node ) { if ( $ node -> getParent ( ) != null ) { $ msg = sprintf ( 'Cannot add %s to %s because it already is a child of %s' , $ node , $ this , $ node -> getParent ( ) ) ; throw new LogicException ( $ msg ) ; } if ( $ index < 0 ) { throw new OutOfRangeException ( ) ; } if ( $ index > count ( $ this -> node_children ) ) { throw new OutOfRangeException ( ) ; } $ node -> node_parent = $ this ; $ node -> node_childIndex = $ index ; array_splice ( $ this -> node_children , $ index , 0 , [ $ node ] ) ; for ( $ i = $ index ; $ i < count ( $ this -> node_children ) ; $ i ++ ) { $ this -> node_children [ $ i ] -> childIndex = $ i ; } return $ this ; }
Add the given node at the specified index moving all children after this index back .
30,520
public function removeChild ( self $ node ) { if ( $ node -> getParent ( ) !== $ this ) { $ msg = sprintf ( 'Cannot remove %s from %s because it is not a child.' , $ node , $ this ) ; throw new InvalidArgumentException ( $ msg ) ; } $ this -> removeChildAt ( $ node -> getChildIndex ( ) ) ; return $ this ; }
Remove the given child node .
30,521
public function remove ( ) { $ p = $ this -> getParent ( ) ; if ( null == $ p ) { throw new LogicException ( ) ; } $ p -> removeChildAt ( $ this -> getChildIndex ( ) ) ; return $ this ; }
Remove this node from its parent .
30,522
public function removeChildAt ( $ index ) { $ node = $ this -> getChildAt ( $ index ) ; $ node -> node_parent = null ; $ node -> node_childIndex = null ; array_splice ( $ this -> node_children , $ index , 1 ) ; for ( $ i = $ index ; $ i < count ( $ this -> node_children ) ; $ i ++ ) { $ this -> node_children [ $ i ] -> node_childIndex = $ i ; } return $ node ; }
Remove the child node at the specified index .
30,523
public function getChildAt ( $ index ) { if ( $ index < 0 ) { throw new OutOfRangeException ( ) ; } if ( $ index >= count ( $ this -> node_children ) ) { throw new OutOfRangeException ( ) ; } return $ this -> node_children [ $ index ] ; }
Get the child at the specified index .
30,524
public static function delete ( $ request , $ match ) { $ group = Pluf_Shortcuts_GetObjectOr404 ( 'User_Group' , $ match [ 'group_id' ] ) ; $ user = Pluf_Shortcuts_GetObjectOr404 ( 'User_Account' , $ match [ 'user_id' ] ) ; $ group -> delAssoc ( $ user ) ; return $ user ; }
Deletes a user from a group . Id of deleted user should be specified in the match .
30,525
public function init ( $ config ) { $ this -> _initiated = true ; if ( $ this -> isNewRecord ( ) ) { $ this -> _tableName = static :: getTableName ( ) ; $ this -> _db = $ this -> _db ? $ this -> _db : static :: getDb ( ) ; $ this -> _columns = static :: getDb ( ) -> getTableColumns ( $ this -> _tableName ) ; $ this -> _pk = static :: getDb ( ) -> getTablePk ( $ this -> _tableName ) ; } else { if ( is_array ( $ this -> _pk ) ) { $ this -> _originalPk = [ ] ; foreach ( $ this -> _pk as $ k ) { $ this -> _originalPk [ $ k ] = $ this -> _attributes [ $ k ] ; } } else { $ this -> _originalPk = $ this -> _attributes [ $ this -> _pk ] ; } $ this -> afterLoad ( ) ; } $ this -> applyRelationsAttributes ( ) ; return parent :: init ( $ config ) ; }
It will check if it s a new record and set required attributes . Also if it s not a new record will record originalPk to be later used for updates .
30,526
private function getRelationFromDb ( $ name ) { if ( ! $ this -> relationsParser ) { $ this -> relationsParser = RelationsParser :: parse ( get_class ( $ this ) , new ModelCondition ( [ 'model' => get_class ( $ this ) ] ) , '*' ) ; } return $ this -> relationsParser -> getForSingleModel ( $ this , $ name ) ; }
Reads all relations for current model .
30,527
private function getSearchRelationsForPath ( $ path ) { $ matched = [ ] ; foreach ( $ this -> _searchedRelations as $ relation ) { if ( 0 === strpos ( $ relation , $ path . '.' ) ) { $ matched [ substr ( $ relation , strlen ( $ path . '.' ) ) ] = substr ( $ relation , strlen ( $ path . '.' ) ) ; } } $ this -> debug ( $ path . ': ' . implode ( "|||" , $ matched ) ) ; return $ matched ; }
Extracts only searched relations for specified path .
30,528
public function save ( $ validate = true ) { if ( $ validate ) { if ( ! $ this -> validate ( ) ) { return false ; } } if ( ! $ this -> beforeSave ( ) ) { return false ; } if ( $ this -> _isNewRecord ) { $ r = $ this -> _db -> table ( $ this -> _tableName ) -> insert ( $ this -> _updatedAttributes ) ; if ( is_string ( $ this -> _pk ) ) { $ this -> { $ this -> _pk } = $ r ; $ this -> _originalPk = $ this -> { $ this -> _pk } ; } else { foreach ( $ this -> _pk as $ k ) { $ this -> _originalPk [ $ k ] = $ this -> $ k ; } } $ this -> _isNewRecord = false ; $ this -> reload ( ) ; $ this -> afterSave ( ) ; if ( is_string ( $ this -> _pk ) && ! $ this -> { $ this -> _pk } ) { return false ; } elseif ( ! is_string ( $ this -> _pk ) && ! $ r ) { return false ; } } if ( ! $ this -> _updatedAttributes ) { $ this -> afterSave ( ) ; return true ; } if ( is_array ( $ this -> _pk ) ) { $ c = $ p = [ ] ; foreach ( $ this -> _originalPk as $ k => $ v ) { $ c [ ] = "`$k` = :pk_$k" ; $ p [ ":pk_$k" ] = $ v ; } $ r = ( bool ) $ this -> _db -> table ( $ this -> _tableName ) -> where ( implode ( " AND " , $ c ) , $ p ) -> update ( $ this -> _updatedAttributes ) ; } else { $ r = ( bool ) $ this -> _db -> table ( $ this -> _tableName ) -> where ( "`{$this->_pk}` = :__pk" ) -> setParam ( ':__pk' , $ this -> _originalPk ) -> update ( $ this -> _updatedAttributes ) ; } if ( $ r ) { $ this -> _updatedAttributes = [ ] ; if ( is_array ( $ this -> _pk ) ) { foreach ( $ this -> _pk as $ k ) { $ this -> _originalPk [ $ k ] = $ this -> $ k ; } } else { $ this -> _originalPk = $ this -> { $ this -> _pk } ; } } $ this -> afterSave ( ) ; return $ r ? : true ; }
Save the updates or if it s a new record it will insert it .
30,529
public function validate ( ) { if ( ! $ this -> getValidator ( ) -> validate ( $ this , $ this -> _action ) ) { $ this -> _errors = $ this -> getValidator ( ) -> getErrors ( ) ; return false ; } return true ; }
Validate current data
30,530
public function saveAsNew ( $ validate = true ) { if ( $ validate && ( ! $ this -> validate ( ) ) ) { return false ; } if ( ! is_string ( $ this -> _pk ) ) { $ this -> error ( "Can't duplicate rows in tables with multiple primary keys!" ) ; return false ; } $ originalBackup = $ this -> _originalPk ; unset ( $ this -> _attributes [ $ this -> _pk ] ) ; $ this -> _originalPk = $ this -> _db -> table ( $ this -> _tableName ) -> insert ( $ this -> _attributes ) ; if ( ! $ this -> _originalPk ) { $ this -> _originalPk = $ originalBackup ; return false ; } $ this -> reload ( ) ; return $ this -> _db -> lastInsertId ( ) ; }
It will create a copy of the current element in DB . This Object will be the new copy just inserted .
30,531
public function delete ( ) { if ( $ this -> beforeDelete ( ) ) { if ( is_array ( $ this -> _pk ) ) { $ c = $ p = [ ] ; foreach ( $ this -> _originalPk as $ k => $ v ) { $ c [ ] = "`$k` = :pk_$k" ; $ p [ ":pk_$k" ] = $ v ; } $ r = ( bool ) $ this -> _db -> table ( $ this -> _tableName ) -> where ( implode ( " AND " , $ c ) , $ p ) -> delete ( ) ; } else { $ r = ( bool ) $ this -> _db -> table ( $ this -> _tableName ) -> where ( "`{$this->_pk}` = :__pk" ) -> setParam ( ':__pk' , $ this -> _originalPk ) -> delete ( ) ; } if ( $ r ) { return $ this -> afterDelete ( ) ; } } }
Delete current row from table .
30,532
public function reload ( ) { $ this -> _relations = array ( ) ; if ( is_array ( $ this -> _pk ) ) { $ c = $ p = [ ] ; foreach ( $ this -> _originalPk as $ k => $ v ) { $ c [ ] = "`$k` = :pk_$k" ; $ p [ ":pk_$k" ] = $ v ; } $ this -> _attributes = $ this -> _db -> table ( $ this -> _tableName ) -> where ( implode ( " AND " , $ c ) , $ p ) -> first ( ) ; } else { $ this -> _attributes = $ this -> _db -> table ( $ this -> _tableName ) -> where ( "`{$this->_pk}` = :__pk" ) -> setParam ( ':__pk' , $ this -> _originalPk ) -> first ( ) ; } $ this -> _updatedAttributes = [ ] ; $ this -> afterLoad ( ) ; }
Reload info from DB for current object . Will also call afterLoad method in case updates are needed .
30,533
public function setError ( $ attribute , $ errorMessage ) { if ( ! isset ( $ this -> _errors [ $ attribute ] ) ) { $ this -> _errors [ $ attribute ] = array ( ) ; } $ this -> _errors [ $ attribute ] [ ] = $ errorMessage ; return $ this ; }
Add error messages for an attribute
30,534
public function hasErrors ( $ attribute = null ) { if ( ! count ( $ this -> _errors ) ) { return false ; } if ( $ attribute && isset ( $ this -> _errors [ $ attribute ] ) && count ( $ this -> _errors [ $ attribute ] ) ) { return true ; } elseif ( $ attribute ) { return false ; } return true ; }
Check if the entire model has errors or a specific attribute
30,535
public function setAttributes ( $ attributes ) { if ( count ( $ safe = static :: getSafeAttributes ( $ this -> _action ) ) ) { foreach ( $ safe as $ attribute ) { if ( isset ( $ attributes [ $ attribute ] ) ) { $ this -> $ attribute = $ attributes [ $ attribute ] ; } } return $ this ; } foreach ( $ attributes as $ name => $ value ) { $ this -> $ name = $ value ; } return $ this ; }
Set attributes in a safe way . it will check rules for safe attributes and it will ignore those that are not safe . To be used on search insert update from web form to make sure that the user doesn t add extra fields to the form .
30,536
public static function deleteAll ( $ condition , $ params = array ( ) ) { if ( ! is_a ( $ condition , '\\mpf\\datasources\\sql\\ModelCondition' ) ) { $ condition = ModelCondition :: getFrom ( $ condition , get_called_class ( ) ) ; } $ condition -> setParams ( $ params ) ; return static :: getDb ( ) -> execQuery ( $ condition -> forDelete ( ) , $ condition -> getParams ( ) ) ; }
Delete all models that match condition .
30,537
public static function deleteAllByAttributes ( $ attributes , $ condition = null , $ params = array ( ) ) { if ( ! is_a ( $ condition , '\\mpf\\datasources\\sql\\ModelCondition' ) ) { $ condition = ModelCondition :: getFrom ( $ condition , get_called_class ( ) ) ; } foreach ( $ attributes as $ k => $ v ) { $ condition -> compareColumn ( $ k , $ v ) ; } return static :: deleteAll ( $ condition , $ params ) ; }
Delete all by attributes
30,538
public static function deleteByPk ( $ pk , $ condition = null , $ params = array ( ) ) { if ( ! is_a ( $ condition , '\\mpf\\datasources\\sql\\ModelCondition' ) ) { $ condition = ModelCondition :: getFrom ( $ condition , get_called_class ( ) ) ; } $ condition -> compareColumn ( static :: getDb ( ) -> getTablePk ( static :: getTableName ( ) ) , $ pk ) ; return static :: deleteAll ( $ condition , $ params ) ; }
Delete models by primary key
30,539
public static function findAllByAttributes ( $ attributes , $ condition = null , $ params = [ ] ) { $ class = get_called_class ( ) ; $ condition = ModelCondition :: getFrom ( $ condition , $ class ) ; foreach ( $ attributes as $ name => $ value ) { $ condition -> compareColumn ( $ name , $ value ) ; } return self :: findAll ( $ condition , $ params ) ; }
Return all models that have the selected attributes .
30,540
public static function findAllByPk ( $ pk , $ condition = null , $ params = [ ] ) { $ class = get_called_class ( ) ; $ condition = ModelCondition :: getFrom ( $ condition , $ class ) ; $ condition -> compareColumn ( $ class :: getDb ( ) -> getTablePk ( $ class :: getTableName ( ) ) , $ pk ) ; return self :: findAll ( $ condition , $ params ) ; }
Return all models that have the selected primary keys .
30,541
public static function findByAttributes ( $ attributes , $ condition = null , $ params = [ ] ) { if ( ! is_a ( $ condition , '\\mpf\\datasources\\sql\\ModelCondition' ) ) $ condition = ModelCondition :: getFrom ( $ condition , get_called_class ( ) ) ; $ oldLimit = $ condition -> limit ; $ condition -> limit = 1 ; $ models = static :: findAllByAttributes ( $ attributes , $ condition , $ params ) ; $ condition -> limit = $ oldLimit ; return isset ( $ models [ 0 ] ) ? $ models [ 0 ] : null ; }
Return a model searched by the selected attributes and optional condition ;
30,542
public static function findByPk ( $ pk , $ condition = null ) { if ( ! is_a ( $ condition , '\\mpf\\datasources\\sql\\ModelCondition' ) ) $ condition = ModelCondition :: getFrom ( $ condition , get_called_class ( ) ) ; $ oldLimit = $ condition -> limit ; $ condition -> limit = 1 ; $ models = static :: findAllByPk ( $ pk , $ condition ) ; $ condition -> limit = $ oldLimit ; return isset ( $ models [ 0 ] ) ? $ models [ 0 ] : null ; }
Return single row model ;
30,543
public static function find ( $ condition , $ params = array ( ) ) { if ( ! is_a ( $ condition , '\\mpf\\datasources\\sql\\ModelCondition' ) ) $ condition = ModelCondition :: getFrom ( $ condition , get_called_class ( ) ) ; $ oldLimit = $ condition -> limit ; $ condition -> limit = 1 ; $ models = static :: findAll ( $ condition , $ params ) ; $ condition -> limit = $ oldLimit ; return isset ( $ models [ 0 ] ) ? $ models [ 0 ] : null ; }
Return a single class for a single row ;
30,544
public static function findAll ( $ condition = '1=1' , $ params = array ( ) ) { if ( ! is_a ( $ condition , '\\mpf\\datasources\\sql\\ModelCondition' ) ) { $ condition = ModelCondition :: getFrom ( $ condition , get_called_class ( ) ) ; } else { $ condition -> model = $ condition -> model ? $ condition -> model : get_called_class ( ) ; } $ condition -> setParams ( $ params ) ; $ searchedRelations = [ ] ; if ( is_array ( $ condition -> with ) ) { foreach ( $ condition -> with as $ k ) { $ searchedRelations [ $ k ] = $ k ; } } $ models = static :: getDb ( ) -> queryClass ( $ condition , get_called_class ( ) , $ condition -> getParams ( ) , [ [ '_columns' => static :: getDb ( ) -> getTableColumns ( static :: getTableName ( ) ) , '_pk' => static :: getDb ( ) -> getTablePk ( static :: getTableName ( ) ) , '_isNewRecord' => false , '_action' => 'update' , '_tableName' => static :: getTableName ( ) , '_db' => static :: getDb ( ) , '_searchedRelations' => $ searchedRelations ] ] ) ; if ( ! $ models ) { return [ ] ; } $ condition -> getExtraRelations ( $ models ) ; return $ models ; }
Return all models that match the given condition .
30,545
public static function update ( $ pk , $ fields ) { return static :: getDb ( ) -> table ( static :: getTableName ( ) ) -> where ( static :: getDb ( ) -> getTablePk ( static :: getTableName ( ) ) . ' = :pk' ) -> setParam ( ':pk' , $ pk ) -> update ( $ fields ) ; }
Return number of affected rows ;
30,546
protected function validateFilesystemOptions ( $ options ) { if ( preg_match ( "/:id\b/" , $ options [ 'url' ] ) !== 1 && preg_match ( "/:id_partition\b/" , $ options [ 'url' ] ) !== 1 && preg_match ( "/:hash\b/" , $ options [ 'url' ] ) !== 1 ) { throw new Exceptions \ InvalidUrlOptionException ( 'Invalid Url: an id, id_partition, or hash interpolation is required.' , 1 ) ; } }
Validate the attachment optioins for an attachment type when the storage driver is set to filesystem .
30,547
public function multi_run_executable ( $ recipe_name_or_right_script_href , array $ options = array ( ) ) { $ params = array ( 'id' => $ this -> id ) ; if ( preg_match ( '/^\/api/' , $ recipe_name_or_right_script_href ) ) { $ params [ 'right_script_href' ] = $ recipe_name_or_right_script_href ; } else { $ params [ 'recipe_name' ] = $ recipe_name_or_right_script_href ; } if ( count ( $ options ) > 0 ) { $ params = array_merge ( $ params , $ options ) ; } $ this -> executeCommand ( $ this -> _path_for_regex . '_multi_run_executable' , $ params ) ; }
Run an executable on all instances of this array .
30,548
public function launch ( array $ inputs = array ( ) ) { $ params = array ( 'id' => $ this -> id ) ; if ( count ( $ inputs ) > 0 ) { $ params [ 'inputs' ] = $ inputs ; } $ this -> executeCommand ( $ this -> _path_for_regex . '_launch' , $ params ) ; }
Launches a new instance in the server array with the configuration defined in the next_instance .
30,549
protected function output ( ) { $ flags = LOG_PID ; putenv ( 'TZ=UTC' ) ; openlog ( $ _SERVER [ 'REQUEST_URI' ] , $ flags , LOG_DAEMON ) ; $ content = $ this -> getContentRaw ( ) ; foreach ( $ content as $ logEntry ) { $ type = $ this -> typeToSystemType ( $ logEntry [ 'type' ] ) ; syslog ( $ type , $ logEntry [ 'message' ] ) ; } $ this -> clearContent ( ) ; closelog ( ) ; }
Writes the log - content to systems log .
30,550
public function update ( SplSubject $ subject , $ event = null ) { switch ( $ event ) { case 'log' : $ logs = $ subject -> getCollectionRaw ( ) ; foreach ( $ logs as $ log ) { $ this -> log ( $ log [ 'type' ] , $ log [ 'message' ] , unserialize ( $ log [ 'context' ] ) , $ log [ 'time' ] , $ log [ 'fingerprint' ] , $ log [ 'separator' ] ) ; } break ; } }
Update of SplObserver
30,551
protected function typeToSystemType ( $ type ) { switch ( $ type ) { case 'emergency' : $ type = LOG_EMERG ; break ; case 'alert' : $ type = LOG_ALERT ; break ; case 'critical' : $ type = LOG_CRIT ; break ; case 'error' : $ type = LOG_ERR ; break ; case 'warning' : $ type = LOG_WARNING ; break ; case 'notice' : $ type = LOG_NOTICE ; break ; case 'info' : $ type = LOG_INFO ; break ; default : case 'debug' : $ type = LOG_DEBUG ; break ; } return $ type ; }
Converts the passed type to systems log type and returns this type .
30,552
protected function purge ( array $ scopes = [ self :: SCOPE_EVERYTHING ] , array $ argumentBag = [ ] ) { $ result = 0 ; foreach ( $ scopes as $ scope ) { if ( false === in_array ( $ scope , $ this -> validScopes ) ) { throw new Doozr_Exception ( sprintf ( 'Scope %s not allowed!' , $ scope ) ) ; } if ( self :: SCOPE_EVERYTHING === $ scope ) { $ scope = $ this -> validScopes ; array_shift ( $ scope ) ; } else { $ scope = [ $ scope ] ; } $ app = Doozr_Kernel_App :: boot ( DOOZR_APP_ENVIRONMENT , DOOZR_RUNTIME_ENVIRONMENT , DOOZR_UNIX , DOOZR_DEBUGGING , DOOZR_CACHING , DOOZR_CACHING_CONTAINER , DOOZR_LOGGING , DOOZR_PROFILING , DOOZR_APP_ROOT , DOOZR_APP_NAMESPACE , DOOZR_DIRECTORY_TEMP , DOOZR_DOCUMENT_ROOT , DOOZR_NAMESPACE , DOOZR_NAMESPACE_FLAT ) ; foreach ( $ scope as $ singleScope ) { $ cache = Doozr_Loader_Serviceloader :: load ( 'cache' , DOOZR_CACHING_CONTAINER , $ singleScope , [ ] , DOOZR_UNIX , DOOZR_CACHING ) ; try { $ result += $ cache -> garbageCollection ( $ singleScope , - 1 , true ) ; } catch ( Exception $ exception ) { break ; } } } return $ result ; }
Purges content from cache .
30,553
public function send ( $ send_to , $ body , $ title = null ) { $ sender = static :: getSender ( ) ; $ tos = StringHelper :: toArray ( $ send_to ) ; foreach ( $ tos as $ email ) { $ sender -> addTo ( $ email ) ; } $ subject = $ title ; if ( $ title ) { if ( strlen ( $ title ) > strlen ( $ body ) ) { $ subject = $ body ; $ body = $ title ; } } else { $ subject = StringHelper :: str_cut ( $ body , 15 ) ; } $ res = $ sender -> setSubject ( $ subject ) -> setBody ( $ body , true ) -> send ( ) ; if ( ! $ res ) { return ErrorInfo :: error ( 'mail send error, check error log' ) ; } return ErrorInfo :: success ( 'mail send success' ) ; }
send one or more
30,554
private static function FilterByType ( $ dir , $ file , FileSystemEntryType $ type = null ) { if ( $ file == '.' || $ file == '..' ) return false ; if ( ! $ type ) return true ; $ path = Path :: Combine ( $ dir , $ file ) ; switch ( $ type ) { case FileSystemEntryType :: File ( ) : return is_file ( $ path ) ; case FileSystemEntryType :: Folder ( ) : return is_dir ( $ path ) ; case FileSystemEntryType :: Link ( ) : return is_link ( $ path ) ; } return false ; }
Returns true if the file sytem entry matches the given type
30,555
static function CreateIfNotExists ( $ dir , $ mode = 0777 ) { if ( ! self :: Exists ( $ dir ) ) { self :: Create ( $ dir , $ mode ) ; } }
Creates a folder if not exists
30,556
static function Delete ( $ dir ) { $ files = self :: GetFileSystemEntries ( $ dir ) ; foreach ( $ files as $ file ) { $ path = Path :: Combine ( $ dir , $ file ) ; switch ( self :: GetFileSystemEntryType ( $ path ) ) { case FileSystemEntryType :: File ( ) : case FileSystemEntryType :: Link ( ) : unlink ( $ path ) ; break ; case FileSystemEntryType :: Folder ( ) : self :: Delete ( $ path ) ; break ; } } rmdir ( $ dir ) ; }
Deletes a folder and all of its contents
30,557
public static function setCredentials ( $ acct_num , $ email , $ password ) { ClientFactory :: $ _acct_num = $ acct_num ; ClientFactory :: $ _email = $ email ; ClientFactory :: $ _password = $ password ; }
Sets the credentials to use for any client produced from this factory
30,558
public static function getClient ( $ version = "1.0" ) { $ acceptable_versions = array ( '1.0' , '1.5' ) ; if ( ! in_array ( $ version , $ acceptable_versions ) ) { throw new InvalidArgumentException ( "API Version $version is not supported, please try 1.0 or 1.5" ) ; } $ version = str_ireplace ( '.' , '_' , $ version ) ; return ClientFactory :: getBuilder ( ) -> get ( "guzzle-rs-$version" ) ; }
Returns a persistent instance of the Guzzle RightScaleClient .
30,559
public static function Init ( ) { add_filter ( 'template_include' , function ( $ t ) { return get_template_directory ( ) . '/index.php' ; } ) ; add_filter ( 'theme_templates' , array ( 'Balise\AnchorFramework\Anchor' , 'loadThemeTemplates' ) , 10 , 4 ) ; $ types = array ( 'index' , '404' , 'archive' , 'author' , 'category' , 'tag' , 'taxonomy' , 'date' , 'embed' , 'home' , 'frontpage' , 'page' , 'paged' , 'search' , 'single' , 'singular' , 'attachment' ) ; foreach ( $ types as $ type ) { add_filter ( "{$type}_template" , array ( 'Balise\AnchorFramework\Anchor' , 'getThemeTemplate' ) , 10 , 3 ) ; } if ( ! self :: $ renderer ) { $ paths = new \ SplPriorityQueue ; $ paths -> insert ( get_template_directory ( ) . '/app/views' , 200 ) ; $ paths -> insert ( dirname ( __DIR__ ) . '/views' , 100 ) ; self :: $ renderer = new BladeRenderer ( $ paths , array ( 'cache_path' => get_template_directory ( ) . '/public/views/' ) ) ; self :: $ renderer -> addCustomCompiler ( 'wp_head' , function ( $ expression ) { return '<?php wp_head(); ?>' ; } ) ; self :: $ renderer -> addCustomCompiler ( 'doquery' , function ( $ expression ) { return '<?php if (!isset($__posts)) { $posts = array(); } $__posts[] = $posts; $args = ' . $ expression . '; if (@!$args["paged"]) { $args["paged"] = get_query_var( "paged", 1 ); } $query = new WP_Query($args); $posts = array_map(function($post){ return new \Balise\AnchorFramework\PostWrapper($post, true); }, $query->posts); ?> ' ; } ) ; self :: $ renderer -> addCustomCompiler ( 'endquery' , function ( ) { return '<?php $posts = array_pop($__posts); ?> ' ; } ) ; self :: $ renderer -> addCustomCompiler ( 'wp_footer' , function ( $ expression ) { return '<?php wp_footer(); ?>' ; } ) ; } }
Initial function that hook into the functions . php file - Make sure that custom templates are loaded - Make sure the template_loader hierarchy gets saved
30,560
public static function Render ( $ template = null , $ data = null ) { if ( $ template && $ data ) { return self :: $ renderer -> render ( $ template , $ data ) ; } else { self :: $ data = self :: getData ( ) ; self :: $ templates [ ] = "index" ; self :: loadTemplate ( self :: $ templates ) ; } }
render function hook
30,561
private static function getData ( ) { global $ post ; $ return = apply_filters ( 'balise-anchor-getData' , null ) ; if ( ! $ return ) { if ( ! is_singular ( ) || ( function_exists ( 'is_shop' ) && is_shop ( ) ) ) { $ return = new PostWrapper ( $ post , true ) ; if ( ( function_exists ( 'is_shop' ) && is_shop ( ) ) ) { $ return = new PostWrapper ( get_post ( wc_get_page_id ( 'shop' ) ) , true ) ; } if ( get_option ( 'page_for_posts' ) ) { $ return = new PostWrapper ( get_post ( get_option ( 'page_for_posts' ) ) , true ) ; } $ return -> posts = array ( ) ; while ( have_posts ( ) ) { the_post ( ) ; $ subreturn = new PostWrapper ( $ post , true ) ; $ return -> posts [ ] = $ subreturn ; } } else { $ return = new PostWrapper ( $ post , true ) ; } } return $ return ; }
Load data object to include in the blade template
30,562
protected static function getAllBlades ( $ pattern = null , $ traversePostOrder = 0 ) { if ( ! $ pattern ) { $ pattern = get_template_directory ( ) . '/app/views/**/*.blade.php' ; } $ patternParts = explode ( '/**/' , $ pattern ) ; $ dirs = glob ( array_shift ( $ patternParts ) . '/*' , GLOB_ONLYDIR | GLOB_NOSORT ) ; $ files = glob ( str_replace ( '/**/' , '/' , $ pattern ) ) ; foreach ( $ dirs as $ dir ) { $ subDirContent = self :: getAllBlades ( $ dir . '/**/' . implode ( '/**/' , $ patternParts ) , $ traversePostOrder ) ; if ( ! $ traversePostOrder ) { $ files = array_merge ( $ files , $ subDirContent ) ; } else { $ files = array_merge ( $ subDirContent , $ files ) ; } } return $ files ; }
Recursive function to load all blade templates
30,563
public static function loadThemeTemplates ( $ post_templates , $ object = null , $ post = null , $ post_type = null ) { $ blades = self :: getAllBlades ( ) ; foreach ( $ blades as $ blade ) { if ( preg_match ( '/{{--\s*Template Name:(.*)--}}/mi' , file_get_contents ( $ blade ) , $ header ) ) { $ post_templates [ basename ( $ blade , ".blade.php" ) ] = $ header [ 1 ] ; } } return $ post_templates ; }
Load custom template files
30,564
public static function getThemeTemplate ( $ template , $ type , $ templates ) { if ( class_exists ( 'WC_Template_Loader' ) && ! self :: $ woocommerce_loaded ) { self :: $ woocommerce_loaded = true ; if ( is_page_template ( ) ) { self :: $ templates [ ] = get_page_template_slug ( ) ; } if ( is_singular ( 'product' ) ) { $ object = get_queried_object ( ) ; $ name_decoded = urldecode ( $ object -> post_name ) ; if ( $ name_decoded !== $ object -> post_name ) { self :: $ templates [ ] = "single-product-{$name_decoded}" ; } self :: $ templates [ ] = "single-product-{$object->post_name}" ; self :: $ templates [ ] = "single-product" ; } if ( is_product_taxonomy ( ) ) { $ object = get_queried_object ( ) ; self :: $ templates [ ] = 'taxonomy-' . $ object -> taxonomy . '-' . $ object -> slug ; self :: $ templates [ ] = 'taxonomy-' . $ object -> taxonomy ; self :: $ templates [ ] = 'archive-product' ; } if ( is_post_type_archive ( 'product' ) || is_page ( wc_get_page_id ( 'shop' ) ) ) { self :: $ templates [ ] = 'archive-product' ; $ default_file = current_theme_supports ( 'woocommerce' ) ? 'archive-product.php' : '' ; } $ fixed_woocommerce_folder = array ( ) ; foreach ( self :: $ templates as $ item ) { $ fixed_woocommerce_folder [ ] = 'woocommerce.' . $ item ; $ fixed_woocommerce_folder [ ] = $ item ; } self :: $ templates = $ fixed_woocommerce_folder ; } foreach ( $ templates as $ t ) { self :: $ templates [ ] = basename ( $ t , '.php' ) ; if ( substr ( basename ( $ t , '.php' ) , 0 , 6 ) === "single" ) { $ type = substr ( basename ( $ t , '.php' ) , 7 ) ; self :: $ templates [ ] = $ type . '/single' ; } if ( substr ( basename ( $ t , '.php' ) , 0 , 7 ) === "archive" ) { $ type = substr ( basename ( $ t , '.php' ) , 8 ) ; self :: $ templates [ ] = $ type . '/archive' ; } } return $ template ; }
Load template Hierarchy Custom support for WooCommerce
30,565
private static function loadTemplate ( $ array ) { global $ wp_styles , $ wp_scripts ; if ( ! $ array || ! is_array ( $ array ) || count ( $ array ) === 0 ) { return ; } if ( self :: checkTemplatePresence ( $ array [ 0 ] ) ) { $ isadmin = is_admin_bar_showing ( ) ; add_filter ( 'show_admin_bar' , '__return_false' ) ; self :: $ renderer -> render ( $ array [ 0 ] , [ ] ) ; @ $ wp_styles -> done = array ( ) ; @ $ wp_scripts -> done = array ( ) ; if ( $ isadmin ) { add_filter ( 'show_admin_bar' , '__return_true' ) ; } $ template = self :: $ renderer -> render ( $ array [ 0 ] , self :: $ data ) ; $ template = str_replace ( "<html>" , "<html " . get_language_attributes ( ) . ">" , $ template ) ; $ template = str_replace ( "<body>" , '<body class="' . implode ( " " , get_body_class ( ) ) . '">' , $ template ) ; echo $ template ; if ( ! is_admin ( ) ) { $ wp_styles -> done = array ( ) ; $ wp_scripts -> done = array ( ) ; } } else { self :: loadTemplate ( array_slice ( $ array , 1 ) ) ; } }
Load the blade template
30,566
protected static function checkTemplatePresence ( $ raw_name ) { $ name = str_replace ( '.' , '/' , $ raw_name ) ; if ( file_exists ( get_template_directory ( ) . "/app/views/${name}.blade.php" ) ) { return true ; } if ( file_exists ( dirname ( __DIR__ ) . "/views/${name}.blade.php" ) ) { return true ; } return false ; }
check for template existance
30,567
public function render ( ) { $ xml = new SimpleXMLElement ( '<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" />' , LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_ERR_FATAL ) ; foreach ( $ this -> channels as $ channel ) { $ toDom = dom_import_simplexml ( $ xml ) ; $ fromDom = dom_import_simplexml ( $ channel -> asXML ( ) ) ; $ toDom -> appendChild ( $ toDom -> ownerDocument -> importNode ( $ fromDom , true ) ) ; } $ dom = new \ DOMDocument ( '1.0' , 'UTF-8' ) ; $ dom -> appendChild ( $ dom -> importNode ( dom_import_simplexml ( $ xml ) , true ) ) ; $ dom -> formatOutput = true ; return $ dom -> saveXML ( ) ; }
Renders the full XML output for this RSS feed
30,568
public function setDestination ( $ destination ) : void { $ this -> destination = ( substr ( $ destination , - 1 ) == '/' ) ? substr ( $ destination , 0 , - 1 ) : $ destination ; }
Set the destination folder
30,569
public function execute ( ) : void { $ this -> generator -> setNamespace ( $ this -> getNamespace ( ) ) ; $ this -> parseWsdl ( ) ; $ this -> generateStructures ( ) ; $ this -> generateRequests ( ) ; $ this -> generateResponses ( ) ; $ this -> generateMethods ( ) ; $ this -> generateService ( ) ; $ this -> generateClient ( ) ; $ this -> generateClassMap ( ) ; ; }
Execute the wsdl to class
30,570
private function parseWsdl ( ) : void { $ this -> printer -> writeln ( 'Parsing WSDL.' ) ; $ client = new \ SoapClient ( ( string ) $ this -> wsdl ) ; foreach ( $ client -> __getTypes ( ) as $ rawType ) { $ type = $ this -> parser -> parseType ( $ rawType ) ; if ( $ type instanceof Struct ) { $ this -> wsdl -> addStruct ( $ type ) ; } elseif ( $ type instanceof Property ) { $ this -> wsdl -> addSimpleType ( $ type ) ; } } foreach ( $ client -> __getFunctions ( ) as $ rawFunction ) { $ method = $ this -> parser -> parseFunction ( $ rawFunction ) ; $ this -> wsdl -> addMethod ( $ method ) ; } }
Parse a wsdl to the WsdlToClass internals
30,571
private function generateStructures ( ) : void { $ this -> printer -> writeln ( 'Generating structures.' ) ; $ this -> generator -> setChildNamespace ( 'Structure' ) ; foreach ( $ this -> wsdl -> getStructures ( ) as $ name => $ structure ) { $ this -> printer -> writeln ( " |\-Generating structure $name" ) ; $ this -> generate ( $ structure ) ; } }
Generate the structure classes
30,572
private function generateRequests ( ) : void { $ this -> printer -> writeln ( 'Generating requests.' ) ; $ this -> generator -> setChildNamespace ( 'Request' ) ; foreach ( $ this -> wsdl -> getRequests ( ) as $ name => $ request ) { $ this -> printer -> writeln ( " |\-Generating request $name" ) ; $ this -> generate ( $ request ) ; } }
Generate the request classes
30,573
private function generateResponses ( ) : void { $ this -> printer -> writeln ( 'Generating responses.' ) ; $ this -> generator -> setChildNamespace ( 'Response' ) ; foreach ( $ this -> wsdl -> getResponses ( ) as $ name => $ response ) { $ this -> printer -> writeln ( " |\-Generating response $name" ) ; $ this -> generate ( $ response ) ; } }
Generate the response classes
30,574
public function progress ( ) : AchievementCriteriaProgress { if ( ! is_null ( $ this -> progress ) ) { return $ this -> progress ; } return $ this -> progress = new AchievementCriteriaProgress ( $ this -> data [ 'progress' ] [ 'value' ] ?? 0 , $ this -> data [ 'progress' ] [ 'changed' ] ?? false , $ this -> data [ 'progress' ] [ 'completed' ] ?? false , $ this -> data [ 'progress' ] [ 'data' ] ?? [ ] ) ; }
Criteria progress .
30,575
public function masterAction ( string $ connectorName ) { $ connector = $ this -> get ( 'splash.connectors.manager' ) -> getRawConnector ( $ connectorName ) ; if ( ! $ connector ) { return self :: getDefaultResponse ( ) ; } $ controllerAction = $ connector -> getMasterAction ( ) ; if ( ! $ controllerAction ) { return self :: getDefaultResponse ( ) ; } return $ this -> forwardToConnector ( $ controllerAction , $ connector ) ; }
Redirect to Connectors Defined Actions
30,576
public function publicAction ( string $ connectorName , string $ webserviceId , string $ action ) { $ connector = $ this -> getConnectorFromManager ( $ webserviceId ) ; if ( ! $ connector ) { return self :: getDefaultResponse ( ) ; } if ( ! ( $ controllerAction = self :: hasPublicAction ( $ connector , $ connectorName , $ action ) ) ) { return self :: getDefaultResponse ( ) ; } return $ this -> forwardToConnector ( $ controllerAction , $ connector ) ; }
Redirect to Connectors Public Actions
30,577
public static function parseUrl ( $ url ) { $ result = false ; $ entities = array ( '%21' , '%2A' , '%27' , '%28' , '%29' , '%3B' , '%3A' , '%40' , '%26' , '%3D' , '%24' , '%2C' , '%2F' , '%3F' , '%23' , '%5B' , '%5D' ) ; $ replacements = array ( '!' , '*' , "'" , "(" , ")" , ";" , ":" , "@" , "&" , "=" , "$" , "," , "/" , "?" , "#" , "[" , "]" ) ; $ encodedURL = str_replace ( $ entities , $ replacements , urlencode ( $ url ) ) ; $ encodedParts = parse_url ( $ encodedURL ) ; if ( $ encodedParts ) { foreach ( $ encodedParts as $ key => $ value ) { $ result [ $ key ] = urldecode ( str_replace ( $ replacements , $ entities , $ value ) ) ; } } return $ result ; }
Does a UTF - 8 safe version of PHP parse_url function
30,578
static public function buildUrl ( $ path , $ params = null ) { $ parts = explode ( '?' , $ path , 2 ) ; $ pathParams = isset ( $ parts [ 1 ] ) ? static :: parseQuery ( $ parts [ 1 ] ) : [ ] ; if ( is_string ( $ params ) ) { $ params = static :: parseQuery ( $ params ) ; } if ( $ params ) { $ pathParams = array_merge ( $ pathParams , $ params ) ; } return $ parts [ 0 ] . ( $ pathParams ? '?' . http_build_query ( $ pathParams ) : '' ) ; }
build url from path and queryParams
30,579
static public function GetRootDomain ( $ domain = null ) { $ domain = ! empty ( $ domain ) ? $ domain : ( isset ( $ _SERVER [ 'HTTP_HOST' ] ) ? $ _SERVER [ 'HTTP_HOST' ] : null ) ; if ( ! $ domain ) { return 'localhost' ; } $ re_domain = '' ; $ domain_postfix_cn_array = array ( "com" , "net" , "org" , "gov" , "edu" , "com.cn" , "net.cn" , "cn" ) ; $ array_domain = explode ( "." , $ domain ) ; $ array_num = count ( $ array_domain ) - 1 ; if ( $ array_domain [ $ array_num ] == 'cn' ) { if ( in_array ( $ array_domain [ $ array_num - 1 ] , $ domain_postfix_cn_array ) ) { $ re_domain = $ array_domain [ $ array_num - 2 ] . "." . $ array_domain [ $ array_num - 1 ] . "." . $ array_domain [ $ array_num ] ; } else { $ re_domain = $ array_domain [ $ array_num - 1 ] . "." . $ array_domain [ $ array_num ] ; } } else { $ re_domain = $ array_domain [ $ array_num - 1 ] . "." . $ array_domain [ $ array_num ] ; } return $ re_domain ; }
get root domain
30,580
static public function getSecondDomain ( $ domain = null ) { $ domain = ! empty ( $ domain ) ? $ domain : ( isset ( $ _SERVER [ 'HTTP_HOST' ] ) ? $ _SERVER [ 'HTTP_HOST' ] : null ) ; $ n = preg_match ( '/([^.]*\.)?([^.]*\.)?\w+\.\w+$/' , $ domain , $ matches ) ; return $ domain && isset ( $ matches [ 2 ] ) ? $ matches [ 2 ] : ( isset ( $ matches [ 1 ] ) ? $ matches [ 1 ] : '' ) ; }
get second domain
30,581
static public function stripScriptName ( $ path ) { if ( isset ( $ _SERVER [ 'SCRIPT_NAME' ] ) && ( $ pos = strpos ( $ path , $ _SERVER [ 'SCRIPT_NAME' ] ) ) === 0 ) { $ path = substr ( $ path , strlen ( $ _SERVER [ 'SCRIPT_NAME' ] ) ) ; } return $ path ; }
strip script name part
30,582
static public function buildSecondDomainUrl ( $ sdomain , $ url = null ) { $ url = static :: getRootUrl ( $ url ) ; $ parts = parse_url ( $ url ) ; $ names = explode ( '.' , $ parts [ 'host' ] ) ; if ( $ names [ 0 ] == 'www' ) { array_shift ( $ names ) ; } if ( $ sdomain != $ names [ 0 ] ) { array_unshift ( $ names , $ sdomain ) ; } $ host = implode ( '.' , $ names ) ; $ url = $ parts [ 'scheme' ] . '://' . $ host ; $ port = isset ( $ parts [ 'port' ] ) ? $ parts [ 'port' ] : null ; if ( $ port && $ port != 80 && $ port != 443 ) { $ url .= ':' . $ port ; } return $ url ; }
build seconed domain url
30,583
protected function _getValidationRules ( Model $ model ) { $ cachePath = 'validation_rules_' . $ model -> alias ; $ cached = Cache :: read ( $ cachePath , CAKE_LDAP_CACHE_KEY_CONFIG ) ; if ( $ cached !== false ) { return $ cached ; } $ ldapFields = $ this -> _modelConfigSync -> getLdapFieldsInfo ( ) ; if ( empty ( $ ldapFields ) ) { return false ; } $ ldapField = $ this -> _getLdapField ( $ model ) ; if ( empty ( $ ldapField ) ) { return false ; } $ result = Hash :: get ( $ ldapFields , $ ldapField . '.rules' ) ; if ( empty ( $ result ) ) { $ result = true ; } Cache :: write ( $ cachePath , $ result , CAKE_LDAP_CACHE_KEY_CONFIG ) ; return $ result ; }
Return list of validation rules
30,584
public function beforeValidate ( Model $ model , $ options = [ ] ) { $ rules = $ this -> _getValidationRules ( $ model ) ; if ( ( $ rules === false ) || ( $ rules === true ) ) { return $ rules ; } $ validator = $ model -> validator ( ) ; $ validator [ 'value' ] = $ rules ; return true ; }
beforeValidate is called before a model is validated you can use this callback to add behavior validation rules into a models validate array . Returning false will allow you to make the validation fail .
30,585
public function index ( $ memberId ) { $ member = Member :: findOrFail ( $ memberId ) ; $ this -> authorize ( 'view' , $ member ) ; return $ this -> respondRelatedNotes ( $ memberId , 'member' ) ; }
Produce a list of Notes related to a selected Member
30,586
public function exportToDebugBar ( DebugBar $ debugBar ) { $ archive = $ this -> getCollectionRaw ( ) ; foreach ( $ archive as $ logentry ) { if ( false === empty ( $ logentry ) ) { $ debugBar [ 'messages' ] -> { $ logentry [ 'type' ] } ( $ logentry [ 'message' ] ) ; } } return $ debugBar ; }
Exports to current log entries to a debug bar instance .
30,587
protected function output ( ) { $ content = $ this -> getContentRaw ( ) ; $ result = '' ; foreach ( $ content as $ logEntry ) { $ result .= $ logEntry [ 'time' ] . ' ' . '[' . $ logEntry [ 'type' ] . '] ' . $ logEntry [ 'fingerprint' ] . ' ' . $ logEntry [ 'message' ] . $ this -> lineBreak . $ this -> getLineSeparator ( ) . $ this -> lineBreak ; } $ this -> clearContent ( ) ; return $ result ; }
Output method . We need this method cause it differs here from abstract default .
30,588
protected function _setDisplayField ( ) { $ orderField = $ this -> _getOrderField ( ) ; if ( empty ( $ orderField ) ) { return false ; } $ this -> displayField = $ orderField ; return true ; }
Set Display field of model
30,589
protected function _bindModelByCfg ( ) { $ bindModelCfg = $ this -> _getBindModelCfg ( ) ; if ( empty ( $ bindModelCfg ) ) { return true ; } return $ this -> bindModel ( $ bindModelCfg , false ) ; }
Bind associated model by table fields
30,590
protected function _getBindModelCfg ( $ fields = [ ] ) { $ fieldsDb = $ this -> _modelConfigSync -> getListFieldsDb ( ) ; $ fieldsLdap = $ this -> _modelConfigSync -> getListFieldsLdap ( ) ; $ fieldsList = array_keys ( array_flip ( $ fieldsDb ) + array_flip ( $ fieldsLdap ) ) ; if ( ! empty ( $ fields ) ) { $ fieldsList = array_intersect ( $ fieldsList , ( array ) $ fields ) ; } $ result = [ ] ; if ( empty ( $ fieldsList ) ) { return $ result ; } $ bindModelCfg = $ this -> _getListBindModelCfg ( ) ; foreach ( $ bindModelCfg as $ checkField => $ bindInfo ) { if ( ! in_array ( $ checkField , $ fieldsList ) ) { continue ; } foreach ( $ bindInfo as $ bindType => $ targetModels ) { foreach ( $ targetModels as $ targetModel => $ targetModelInfo ) { switch ( $ targetModel ) { case 'Department' : $ modelDepartment = ClassRegistry :: init ( 'Department' , true ) ; if ( $ modelDepartment !== false ) { $ targetModelInfo [ 'className' ] = 'Department' ; $ useBlockDepartment = $ modelDepartment -> hasField ( 'block' ) ; if ( $ useBlockDepartment ) { $ targetModelInfo [ 'fields' ] [ ] = $ targetModel . '.block' ; } } break ; case 'Manager' : case 'Subordinate' : $ modelEmployee = ClassRegistry :: init ( 'Employee' , true ) ; if ( $ modelEmployee !== false ) { $ targetModelInfo [ 'className' ] = 'Employee' ; } $ targetModelInfo [ 'fields' ] [ ] = $ targetModel . '.' . $ this -> displayField . ' AS name' ; if ( $ targetModel === 'Subordinate' ) { $ targetModelInfo [ 'order' ] = [ $ targetModel . '.' . $ this -> displayField => 'asc' ] ; } if ( $ this -> hasField ( CAKE_LDAP_LDAP_ATTRIBUTE_TITLE ) ) { $ targetModelInfo [ 'fields' ] [ ] = $ targetModel . '.' . CAKE_LDAP_LDAP_ATTRIBUTE_TITLE ; } break ; } $ result [ $ bindType ] [ $ targetModel ] = $ targetModelInfo ; } } } return $ result ; }
Return configuration for binding associated models
30,591
protected function _getListFieldsUpdateQueryResult ( ) { $ cachePath = 'local_fields_update_query_res' ; $ cached = Cache :: read ( $ cachePath , CAKE_LDAP_CACHE_KEY_LDAP_SYNC_DB ) ; if ( $ cached !== false ) { return $ cached ; } $ result = [ ] ; $ bindFields = $ this -> _getListFieldsUpdateQueryConditions ( ) ; if ( empty ( $ bindFields ) ) { return $ result ; } foreach ( $ bindFields as $ bindFieldName => $ bindFieldInfo ) { if ( isset ( $ bindFieldInfo [ 'subQuery' ] ) ) { $ result [ ] = $ bindFieldName ; } } Cache :: write ( $ cachePath , $ result , CAKE_LDAP_CACHE_KEY_LDAP_SYNC_DB ) ; return $ result ; }
Return list of fields for updating query result
30,592
protected function _getOrderField ( ) { $ orderList = $ this -> _getOrderList ( ) ; $ result = null ; foreach ( $ orderList as $ orderField ) { if ( ! $ this -> hasField ( $ orderField ) ) { continue ; } $ result = $ orderField ; break ; } return $ result ; }
Return field for ordering data
30,593
protected function _getLocalFieldsValidationRules ( ) { $ result = [ ] ; $ localFields = $ this -> _modelConfigSync -> getLocalFieldsInfo ( ) ; if ( empty ( $ localFields ) ) { return $ result ; } foreach ( $ localFields as $ localFieldName => $ localFieldInfo ) { if ( ! isset ( $ localFieldInfo [ 'rules' ] ) || empty ( $ localFieldInfo [ 'rules' ] ) ) { continue ; } $ result [ $ localFieldName ] = $ localFieldInfo [ 'rules' ] ; } return $ result ; }
Return list of validation rules for local fields
30,594
protected function _prepareQueryConditions ( & $ conditions ) { if ( empty ( $ conditions ) || ! is_array ( $ conditions ) ) { return ; } $ bindFields = $ this -> _getListFieldsUpdateQueryConditions ( ) ; $ newConditions = [ ] ; foreach ( $ conditions as $ field => & $ value ) { if ( ctype_digit ( ( string ) $ field ) ) { $ field = $ value ; } if ( in_array ( $ field , [ 'AND' , 'OR' , 'NOT' ] ) && is_array ( $ value ) ) { $ this -> _prepareQueryConditions ( $ value ) ; continue ; } if ( ! is_string ( $ field ) ) { continue ; } foreach ( $ bindFields as $ bindField => $ bindFieldInfo ) { $ fieldName = $ field ; if ( strpos ( $ fieldName , ' ' ) !== false ) { $ fieldName = explode ( ' ' , $ fieldName , 2 ) ; $ fieldName = array_shift ( $ fieldName ) ; } if ( $ fieldName !== $ this -> alias . '.' . $ bindField ) { continue ; } unset ( $ conditions [ $ field ] ) ; $ field = str_replace ( $ this -> alias . '.' . $ bindField , $ bindFieldInfo [ 'replace' ] , $ field ) ; if ( ! isset ( $ bindFieldInfo [ 'subQuery' ] ) ) { $ newConditions [ $ field ] = $ value ; continue ; } $ conditionsSubQuery = [ $ field => $ value ] ; $ db = $ this -> getDataSource ( ) ; $ subQuery = $ db -> buildStatement ( [ 'limit' => null , 'offset' => null , 'joins' => [ ] , 'conditions' => $ conditionsSubQuery , 'order' => null , 'group' => null ] + $ bindFieldInfo [ 'subQuery' ] , $ this ) ; $ subQuery = 'Employee.id IN (' . $ subQuery . ') ' ; $ subQueryExpression = $ db -> expression ( $ subQuery ) ; $ newConditions [ ] = $ subQueryExpression ; } } $ conditions = array_merge ( $ conditions , $ newConditions ) ; }
Update query conditions for find by multiple value fields .
30,595
public function getFieldsDefaultValue ( ) { $ cachePath = 'local_fields_default_val' ; $ cached = Cache :: read ( $ cachePath , CAKE_LDAP_CACHE_KEY_LDAP_SYNC_DB ) ; if ( $ cached !== false ) { return $ cached ; } $ result = [ ] ; $ fieldsInfo = $ this -> _modelConfigSync -> getLocalFieldsInfo ( ) ; $ fieldsInfo += $ this -> _modelConfigSync -> getLdapFieldsInfo ( ) ; if ( empty ( $ fieldsInfo ) ) { return $ result ; } $ schema = $ this -> schema ( ) ; foreach ( $ fieldsInfo as $ fieldName => $ fieldInfo ) { if ( ! isset ( $ schema [ $ fieldName ] ) ) { continue ; } $ defaultValue = null ; if ( isset ( $ fieldInfo [ 'default' ] ) ) { $ defaultValue = $ fieldInfo [ 'default' ] ; } $ result [ $ fieldName ] = $ defaultValue ; } Cache :: write ( $ cachePath , $ result , CAKE_LDAP_CACHE_KEY_LDAP_SYNC_DB ) ; return $ result ; }
Return list of default values for fields
30,596
protected function _getLdapFieldsValidationRules ( ) { $ result = [ ] ; $ ldapFields = $ this -> _modelConfigSync -> getLdapFieldsInfo ( ) ; if ( empty ( $ ldapFields ) ) { return $ result ; } $ localFields = $ this -> getListLocalFields ( ) ; if ( empty ( $ localFields ) ) { return $ result ; } foreach ( $ ldapFields as $ ldapFieldName => $ ldapFieldInfo ) { if ( ! isset ( $ ldapFieldInfo [ 'rules' ] ) || empty ( $ ldapFieldInfo [ 'rules' ] ) ) { continue ; } if ( ! in_array ( $ ldapFieldName , $ localFields ) ) { continue ; } $ result [ $ ldapFieldName ] = $ ldapFieldInfo [ 'rules' ] ; } return $ result ; }
Return list of validation rules for ldap fields
30,597
protected function _getValidationRules ( ) { $ language = ( string ) Configure :: read ( 'Config.language' ) ; $ cachePath = 'validation_rules_' . $ language ; $ cached = Cache :: read ( $ cachePath , CAKE_LDAP_CACHE_KEY_LDAP_SYNC_DB ) ; if ( $ cached !== false ) { return $ cached ; } $ result = $ this -> _getLocalFieldsValidationRules ( ) ; $ result += $ this -> _getLdapFieldsValidationRules ( ) ; Cache :: write ( $ cachePath , $ result , CAKE_LDAP_CACHE_KEY_LDAP_SYNC_DB ) ; return $ result ; }
Return list of validation rules for local and ldap fields
30,598
public function getListContain ( $ excludeModels = null , $ fields = null , $ excludeFields = null ) { $ excludeModels = ( array ) $ excludeModels ; $ fields = ( array ) $ fields ; $ excludeFields = ( array ) $ excludeFields ; $ bindModelCfgFull = $ this -> _getListBindModelCfg ( ) ; $ fieldsContainCheck = array_keys ( $ bindModelCfgFull ) ; $ listFieldsDb = $ this -> _modelConfigSync -> getListFieldsDb ( ) ; $ listFieldsLdap = $ this -> _modelConfigSync -> getListFieldsLdap ( ) ; if ( ! empty ( $ fields ) ) { $ fieldsContainCheck = array_unique ( array_merge ( $ fieldsContainCheck , $ fields ) ) ; } if ( ! empty ( $ excludeFields ) ) { $ fieldsContainCheck = array_diff ( $ fieldsContainCheck , ( array ) $ excludeFields ) ; } if ( ! empty ( $ fields ) ) { foreach ( $ fieldsContainCheck as $ i => & $ fieldCheck ) { if ( ( in_array ( $ fieldCheck , $ listFieldsDb ) && ! in_array ( $ fieldCheck , $ fields ) ) || ( ! in_array ( $ fieldCheck , $ listFieldsDb ) && ! in_array ( $ fieldCheck , $ listFieldsLdap ) ) ) { unset ( $ fieldsContainCheck [ $ i ] ) ; } } } $ bindModelCfg = $ this -> _getBindModelCfg ( $ fieldsContainCheck ) ; $ result = [ ] ; foreach ( $ bindModelCfg as $ bindType => $ targetModels ) { $ result = array_merge ( $ result , array_keys ( $ targetModels ) ) ; } if ( ! empty ( $ excludeModels ) ) { $ result = array_values ( array_diff ( $ result , $ excludeModels ) ) ; } return $ result ; }
Return list of models for contain behavior
30,599
public function getListLocalFields ( $ excludeFields = null ) { $ excludeFields = ( array ) $ excludeFields ; $ schema = $ this -> schema ( ) ; $ result = array_keys ( $ schema ) ; if ( ! empty ( $ excludeFields ) ) { $ result = array_values ( array_diff ( $ result , ( array ) $ excludeFields ) ) ; } return $ result ; }
Return list of local fields