idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
47,800
|
public function validate ( $ wId , $ source , $ initialStatusId , $ startStatusIdIndex , $ endStatusIdIndex ) { if ( $ this -> validate === true ) { if ( ! \ in_array ( $ initialStatusId , $ startStatusIdIndex ) ) { throw new WorkflowValidationException ( "Initial status not defined : $initialStatusId" ) ; } $ missingStatusIdSuspects = \ array_diff ( $ endStatusIdIndex , $ startStatusIdIndex ) ; if ( count ( $ missingStatusIdSuspects ) != 0 ) { $ missingStatusId = [ ] ; foreach ( $ missingStatusIdSuspects as $ id ) { list ( $ thisWid , $ thisSid ) = $ source -> parseStatusId ( $ id , $ wId ) ; if ( $ thisWid == $ wId ) { $ missingStatusId [ ] = $ id ; } } if ( count ( $ missingStatusId ) != 0 ) { throw new WorkflowValidationException ( "One or more end status are not defined : " . VarDumper :: dumpAsString ( $ missingStatusId ) ) ; } } } }
|
Validates an array that contains a workflow definition .
|
47,801
|
public function createEnterWorkflowSequence ( $ initalStatus , $ sender ) { $ config = [ 'end' => $ initalStatus , 'sender' => $ sender ] ; return [ 'before' => [ new WorkflowEvent ( WorkflowEvent :: beforeEnterWorkflow ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeEnterWorkflow ( $ initalStatus -> getWorkflowId ( ) ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeEnterStatus ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeEnterStatus ( $ initalStatus -> getId ( ) ) , $ config ) ] , 'after' => [ new WorkflowEvent ( WorkflowEvent :: afterEnterWorkflow ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterEnterWorkflow ( $ initalStatus -> getWorkflowId ( ) ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterEnterStatus ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterEnterStatus ( $ initalStatus -> getId ( ) ) , $ config ) ] ] ; }
|
Produces the following event sequence when a model enters a workflow .
|
47,802
|
public function createLeaveWorkflowSequence ( $ finalStatus , $ sender ) { $ config = [ 'start' => $ finalStatus , 'sender' => $ sender ] ; return [ 'before' => [ new WorkflowEvent ( WorkflowEvent :: beforeLeaveStatus ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeLeaveStatus ( $ finalStatus -> getId ( ) ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeLeaveWorkflow ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeLeaveWorkflow ( $ finalStatus -> getWorkflowId ( ) ) , $ config ) ] , 'after' => [ new WorkflowEvent ( WorkflowEvent :: afterLeaveStatus ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterLeaveStatus ( $ finalStatus -> getId ( ) ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterLeaveWorkflow ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterLeaveWorkflow ( $ finalStatus -> getWorkflowId ( ) ) , $ config ) ] ] ; }
|
Produces the following event sequence when a model leaves a workflow .
|
47,803
|
public function createChangeStatusSequence ( $ transition , $ sender ) { $ config = [ 'start' => $ transition -> getStartStatus ( ) , 'end' => $ transition -> getEndStatus ( ) , 'transition' => $ transition , 'sender' => $ sender ] ; return [ 'before' => [ new WorkflowEvent ( WorkflowEvent :: beforeLeaveStatus ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeLeaveStatus ( $ transition -> getStartStatus ( ) -> getId ( ) ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeChangeStatus ( $ transition -> getStartStatus ( ) -> getId ( ) , $ transition -> getEndStatus ( ) -> getId ( ) ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeEnterStatus ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: beforeEnterStatus ( $ transition -> getEndStatus ( ) -> getId ( ) ) , $ config ) ] , 'after' => [ new WorkflowEvent ( WorkflowEvent :: afterLeaveStatus ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterLeaveStatus ( $ transition -> getStartStatus ( ) -> getId ( ) ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterChangeStatus ( $ transition -> getStartStatus ( ) -> getId ( ) , $ transition -> getEndStatus ( ) -> getId ( ) ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterEnterStatus ( ) , $ config ) , new WorkflowEvent ( WorkflowEvent :: afterEnterStatus ( $ transition -> getEndStatus ( ) -> getId ( ) ) , $ config ) ] ] ; }
|
Produces the following event sequence when a model changes from status A to status B .
|
47,804
|
public function attach ( $ owner ) { parent :: attach ( $ owner ) ; if ( $ this -> owner instanceof \ yii \ db \ BaseActiveRecord ) { if ( ! $ this -> owner -> hasAttribute ( $ this -> statusAttribute ) && ! $ this -> owner -> hasProperty ( $ this -> statusAttribute ) ) { throw new InvalidConfigException ( 'Attribute or property not found for owner model : \'' . $ this -> statusAttribute . '\'' ) ; } } elseif ( $ this -> owner instanceof \ yii \ base \ BaseObject ) { if ( ! $ this -> owner -> hasProperty ( $ this -> statusAttribute ) ) { throw new InvalidConfigException ( 'Property not found for owner model : \'' . $ this -> statusAttribute . '\'' ) ; } } $ this -> initStatus ( ) ; if ( ! $ this -> hasWorkflowStatus ( ) ) { $ this -> doAutoInsert ( ) ; } }
|
Attaches the behavior to the model .
|
47,805
|
public function initStatus ( ) { if ( $ this -> getStatusAccessor ( ) != null ) { $ oStatus = $ this -> _statusAccessor -> readStatus ( $ this -> owner ) ; } else { $ oStatus = $ this -> getOwnerStatus ( ) ; } if ( ! empty ( $ oStatus ) ) { $ status = $ this -> _wfSource -> getStatus ( $ oStatus , self :: isAttachedTo ( $ this -> owner ) ? $ this -> selectDefaultWorkflowId ( ) : null ) ; if ( $ status === null ) { throw new WorkflowException ( 'Status not found : ' . $ oStatus ) ; } $ this -> setStatusInternal ( $ status ) ; } else { $ this -> _status = null ; } }
|
Initialize the internal status value based on the owner model status attribute .
|
47,806
|
private function sendToStatusInternal ( $ status , $ delayed ) { $ this -> _pendingEvents = [ ] ; list ( $ newStatus , , $ events ) = $ this -> createTransitionItems ( $ status , false , true ) ; $ delayedStop = false ; if ( ! empty ( $ events [ 'before' ] ) ) { foreach ( $ events [ 'before' ] as $ eventBefore ) { $ this -> owner -> trigger ( $ eventBefore -> name , $ eventBefore ) ; if ( $ eventBefore -> isValid === false ) { if ( $ this -> propagateErrorsToModel === true && count ( $ eventBefore -> getErrors ( ) ) != 0 ) { $ this -> owner -> addErrors ( [ $ this -> statusAttribute => $ eventBefore -> getErrors ( ) ] ) ; } if ( $ this -> stopOnFirstInvalidEvent === true ) { return false ; } else { $ delayedStop = true ; } } } } if ( $ delayedStop ) { return false ; } $ this -> setStatusInternal ( $ newStatus ) ; if ( ! empty ( $ events [ 'after' ] ) ) { if ( $ delayed ) { $ this -> _pendingEvents = $ events [ 'after' ] ; } else { foreach ( $ events [ 'after' ] as $ eventAfter ) { $ this -> owner -> trigger ( $ eventAfter -> name , $ eventAfter ) ; } } } if ( $ this -> getStatusAccessor ( ) != null ) { $ this -> _statusAccessor -> updateStatus ( $ this -> owner , $ newStatus ) ; } return true ; }
|
Performs status change and event fire .
|
47,807
|
public function getEventSequence ( $ status ) { list ( , , $ events ) = $ this -> createTransitionItems ( $ status , false , true ) ; return $ events ; }
|
Creates and returns the list of events that will be fire when the owner model is sent from its current status to the one passed as argument .
|
47,808
|
public function getScenarioSequence ( $ status ) { list ( , $ scenario ) = $ this -> createTransitionItems ( $ status , true , false ) ; return $ scenario ; }
|
Creates and returns the list of scenario names that will be used to validate the owner model when it is sent from its current status to the one passed as argument .
|
47,809
|
public function getDefaultWorkflowId ( ) { if ( empty ( $ this -> _defaultWorkflowId ) ) { $ tokens = explode ( '\\' , get_class ( $ this -> owner ) ) ; $ this -> _defaultWorkflowId = end ( $ tokens ) . 'Workflow' ; } return $ this -> _defaultWorkflowId ; }
|
Returns the id of the default workflow associated with the owner model .
|
47,810
|
public function getWorkflow ( ) { return $ this -> hasWorkflowStatus ( ) ? $ this -> getWorkflowSource ( ) -> getWorkflow ( $ this -> getWorkflowStatus ( ) -> getWorkflowId ( ) ) : null ; }
|
Returns the current Workflow instance the model is in or NULL if the model is not in a workflow .
|
47,811
|
public function statusEquals ( $ status = null ) { if ( ! empty ( $ status ) ) { try { $ oStatus = $ this -> ensureStatusInstance ( $ status ) ; } catch ( Exception $ e ) { return false ; } } else { $ status = $ oStatus = null ; } if ( $ oStatus == null ) { return ! $ this -> hasWorkflowStatus ( ) ; } elseif ( $ this -> hasWorkflowStatus ( ) ) { return $ this -> getWorkflowStatus ( ) -> getId ( ) == $ oStatus -> getId ( ) ; } else { return false ; } }
|
Tests if the current status is equal to the status passed as argument .
|
47,812
|
private function ensureStatusInstance ( $ mixed , $ strict = false ) { if ( empty ( $ mixed ) ) { if ( $ strict ) { throw new WorkflowException ( 'Invalid argument : null' ) ; } else { return null ; } } elseif ( $ mixed instanceof StatusInterface ) { return $ mixed ; } else { $ status = $ this -> _wfSource -> getStatus ( $ mixed , $ this -> selectDefaultWorkflowId ( ) ) ; if ( $ status === null && $ strict ) { throw new WorkflowException ( 'Status not found : ' . $ mixed ) ; } return $ status ; } }
|
Returns a Status instance for the value passed as argument .
|
47,813
|
private function setStatusInternal ( $ status ) { if ( $ status !== null && ! $ status instanceof StatusInterface ) { throw new WorkflowException ( 'Status instance expected' ) ; } $ this -> _status = $ status ; $ statusId = ( $ status === null ? null : $ status -> getId ( ) ) ; if ( $ this -> getStatusConverter ( ) != null ) { $ statusId = $ this -> _statusConverter -> toModelAttribute ( $ statusId ) ; } $ this -> owner -> { $ this -> statusAttribute } = $ statusId ; }
|
Set the internal status value and the owner model status attribute .
|
47,814
|
private function firePendingEvents ( ) { if ( ! empty ( $ this -> _pendingEvents ) ) { foreach ( $ this -> _pendingEvents as $ event ) { $ this -> owner -> trigger ( $ event -> name , $ event ) ; } $ this -> _pendingEvents = [ ] ; if ( $ this -> getStatusAccessor ( ) != null ) { $ this -> _statusAccessor -> commitStatus ( $ this -> owner ) ; } } }
|
Send pending events .
|
47,815
|
public static function isAttachedTo ( $ model ) { if ( $ model instanceof yii \ base \ Component ) { foreach ( $ model -> getBehaviors ( ) as $ behavior ) { if ( $ behavior instanceof SimpleWorkflowBehavior ) { return true ; } } } else { throw new WorkflowException ( 'Invalid argument type : $model must be a BaseActiveRecord' ) ; } return false ; }
|
Tests that a SimpleWorkflowBehavior behavior is attached to the object passed as argument .
|
47,816
|
public function getDefinitionCache ( ) { if ( ! isset ( $ this -> definitionCache ) ) { return null ; } if ( ! isset ( $ this -> _dc ) ) { if ( is_string ( $ this -> definitionCache ) ) { $ this -> _dc = Yii :: $ app -> get ( $ this -> definitionCache ) ; } elseif ( is_array ( $ this -> definitionCache ) ) { $ this -> _dc = Yii :: createObject ( $ this -> definitionCache ) ; } elseif ( is_object ( $ this -> definitionCache ) ) { $ this -> _dc = $ this -> definitionCache ; } else { throw new InvalidConfigException ( 'invalid "definitionCache" attribute : string or object expected' ) ; } if ( ! $ this -> _dc instanceof yii \ caching \ Cache ) { throw new InvalidConfigException ( 'the workflow definition cache must implement the yii\caching\Cache interface' ) ; } } return $ this -> _dc ; }
|
Return the workflow definition cache component used by this workflow source or NULL if no cache is used .
|
47,817
|
public function getTransitions ( $ statusId , $ defaultWorkflowId = null ) { list ( $ wId , $ lid ) = $ this -> parseStatusId ( $ statusId , $ defaultWorkflowId ) ; $ statusId = $ wId . self :: SEPARATOR_STATUS_NAME . $ lid ; if ( ! array_key_exists ( $ statusId , $ this -> _t ) ) { $ start = $ this -> getStatus ( $ statusId ) ; if ( $ start == null ) { throw new WorkflowException ( 'start status not found : id = ' . $ statusId ) ; } $ wDef = $ this -> getWorkflowDefinition ( $ wId ) ; $ trDef = isset ( $ wDef [ self :: KEY_NODES ] [ $ start -> getId ( ) ] [ self :: KEY_EDGES ] ) ? $ wDef [ self :: KEY_NODES ] [ $ start -> getId ( ) ] [ self :: KEY_EDGES ] : null ; $ transitions = [ ] ; if ( $ trDef != null ) { foreach ( $ trDef as $ endStId => $ trCfg ) { $ ids = $ this -> parseStatusId ( $ endStId , $ wId ) ; $ endId = implode ( self :: SEPARATOR_STATUS_NAME , $ ids ) ; $ end = $ this -> getStatus ( $ endId ) ; if ( $ end == null ) { throw new WorkflowException ( 'end status not found : start(id=' . $ statusId . ') end(id=' . $ endStId . ')' ) ; } else { $ trCfg [ 'class' ] = $ this -> getClassMapByType ( self :: TYPE_TRANSITION ) ; $ trCfg [ 'start' ] = $ start ; $ trCfg [ 'end' ] = $ end ; $ trCfg [ 'source' ] = $ this ; $ transitions [ $ endId ] = Yii :: createObject ( $ trCfg ) ; } } } $ this -> _t [ $ statusId ] = $ transitions ; } return $ this -> _t [ $ statusId ] ; }
|
Returns all out going transitions leaving the status whose id is passed as argument . This method also create instances for the initial status and all statuses that can be reached from it .
|
47,818
|
public function getWorkflow ( $ id ) { if ( ! array_key_exists ( $ id , $ this -> _w ) ) { $ workflow = null ; $ def = $ this -> getWorkflowDefinition ( $ id ) ; if ( $ def != null ) { unset ( $ def [ self :: KEY_NODES ] ) ; $ def [ 'id' ] = $ id ; if ( isset ( $ def [ Workflow :: PARAM_INITIAL_STATUS_ID ] ) ) { $ ids = $ this -> parseStatusId ( $ def [ Workflow :: PARAM_INITIAL_STATUS_ID ] , $ id ) ; $ def [ Workflow :: PARAM_INITIAL_STATUS_ID ] = implode ( self :: SEPARATOR_STATUS_NAME , $ ids ) ; } else { throw new WorkflowException ( 'failed to load Workflow ' . $ id . ' : missing initial status id' ) ; } $ def [ 'class' ] = $ this -> getClassMapByType ( self :: TYPE_WORKFLOW ) ; $ def [ 'source' ] = $ this ; $ workflow = Yii :: createObject ( $ def ) ; } $ this -> _w [ $ id ] = $ workflow ; } return $ this -> _w [ $ id ] ; }
|
Returns the Workflow instance whose id is passed as argument .
|
47,819
|
public function getWorkflowDefinition ( $ id ) { if ( ! $ this -> isValidWorkflowId ( $ id ) ) { throw new WorkflowException ( 'Invalid workflow Id : ' . VarDumper :: dumpAsString ( $ id ) ) ; } if ( ! isset ( $ this -> _workflowDef [ $ id ] ) ) { if ( $ this -> getDefinitionCache ( ) != null ) { $ cache = $ this -> getDefinitionCache ( ) ; $ key = $ cache -> buildKey ( 'yii2-workflow-def-' . $ id ) ; if ( $ cache -> exists ( $ key ) ) { $ this -> _workflowDef [ $ id ] = $ cache -> get ( $ key ) ; } else { $ this -> _workflowDef [ $ id ] = $ this -> getDefinitionLoader ( ) -> loadDefinition ( $ id , $ this ) ; $ cache -> set ( $ key , $ this -> _workflowDef [ $ id ] ) ; } } else { $ this -> _workflowDef [ $ id ] = $ this -> getDefinitionLoader ( ) -> loadDefinition ( $ id , $ this ) ; } } return $ this -> _workflowDef [ $ id ] ; }
|
Loads definition for the workflow whose id is passed as argument .
|
47,820
|
public function validateWorkflowDefinition ( $ wId , $ definition ) { $ errors = [ ] ; $ stat = [ ] ; $ startStatusIds = array_keys ( $ definition [ self :: KEY_NODES ] ) ; $ stat [ 'statusCount' ] = count ( $ startStatusIds ) ; if ( ! in_array ( $ definition [ 'initialStatusId' ] , $ startStatusIds ) ) { $ errors [ 'missingInitialStatus' ] = [ 'message' => 'Initial status not defined' , 'status' => $ definition [ 'initialStatusId' ] ] ; } $ endStatusIds = [ ] ; $ finalStatusIds = [ ] ; $ stat [ 'transitionCount' ] = 0 ; foreach ( $ startStatusIds as $ statusId ) { if ( $ definition [ self :: KEY_NODES ] [ $ statusId ] [ self :: KEY_EDGES ] != null ) { $ stat [ 'transitionCount' ] += count ( $ definition [ self :: KEY_NODES ] [ $ statusId ] [ self :: KEY_EDGES ] ) ; $ endStatusIds = array_merge ( $ endStatusIds , array_keys ( $ definition [ self :: KEY_NODES ] [ $ statusId ] [ self :: KEY_EDGES ] ) ) ; } else { $ finalStatusIds [ ] = $ statusId ; } } $ stat [ 'endStatusCount' ] = count ( $ endStatusIds ) ; $ stat [ 'finalStatus' ] = $ finalStatusIds ; $ missingStatusIdSuspects = \ array_diff ( $ endStatusIds , $ startStatusIds ) ; if ( count ( $ missingStatusIdSuspects ) != 0 ) { $ missingStatusId = [ ] ; foreach ( $ missingStatusIdSuspects as $ id ) { list ( $ thisWid , $ thisSid ) = $ this -> parseStatusId ( $ id , $ wId ) ; if ( $ thisWid == $ wId ) { $ missingStatusId [ ] = $ id ; } } if ( count ( $ missingStatusId ) != 0 ) { $ errors [ 'missingStatus' ] = [ 'message' => 'One or more end status are not defined' , 'status' => $ missingStatusId ] ; } } $ orphanStatusIds = \ array_diff ( $ startStatusIds , $ endStatusIds ) ; if ( \ in_array ( $ definition [ 'initialStatusId' ] , $ orphanStatusIds ) ) { $ orphanStatusIds = \ array_diff ( $ orphanStatusIds , [ $ definition [ 'initialStatusId' ] ] ) ; } if ( count ( $ orphanStatusIds ) != 0 ) { $ errors [ 'unreachableStatus' ] = [ 'message' => 'One or more statuses are unreachable' , 'status' => $ orphanStatusIds ] ; } return [ 'errors' => $ errors , 'stat' => $ stat ] ; }
|
Validate the workflow definition passed as argument . The workflow definition array format is the one used internally by this class and that should have been provided by the configured workflow definition provider component .
|
47,821
|
public function getAllStatuses ( $ workflowId ) { $ wDef = $ this -> getWorkflowDefinition ( $ workflowId ) ; if ( $ wDef == null ) { throw new WorkflowException ( 'No workflow found with id ' . $ workflowId ) ; } $ allStatuses = [ ] ; foreach ( $ wDef [ self :: KEY_NODES ] as $ statusId => $ statusDef ) { $ allStatuses [ $ statusId ] = $ this -> getStatus ( $ statusId ) ; } return $ allStatuses ; }
|
Returns an array containing all statuses belonging to a workflow .
|
47,822
|
public function init ( ) { parent :: init ( ) ; if ( $ this -> parser === null ) { $ this -> _p = Yii :: createObject ( [ 'class' => DefaultArrayParser :: className ( ) ] ) ; } elseif ( $ this -> parser === false ) { $ this -> _p = null ; } elseif ( is_array ( $ this -> parser ) ) { $ this -> _p = Yii :: createObject ( $ this -> parser ) ; } elseif ( is_string ( $ this -> parser ) ) { $ this -> _p = Yii :: $ app -> get ( $ this -> parser ) ; } elseif ( is_object ( $ this -> parser ) ) { $ this -> _p = $ this -> parser ; } else { throw new InvalidConfigException ( 'invalid "parser" attribute : string or array expected' ) ; } if ( $ this -> _p !== null && ! $ this -> _p instanceof WorkflowArrayParser ) { throw new InvalidConfigException ( 'the parser component must implement the WorkflowArrayParser interface' ) ; } }
|
Initialize the parser component to use .
|
47,823
|
public function allow ( string $ route , $ control ) { $ routeUri = $ this -> getUriArray ( $ route ) ; if ( $ this -> uriCount !== count ( $ routeUri ) ) { return ; } if ( in_array ( '?' , $ routeUri ) ) { $ this -> routesVariable [ $ route ] = [ 'c' => $ control , 'u' => $ routeUri ] ; return ; } $ this -> routesExact [ $ route ] = [ 'c' => $ control , 'u' => $ routeUri ] ; }
|
Allow a route
|
47,824
|
public function match ( ) { if ( $ this -> forceSlash && ! $ this -> hasTrailingSlash ( $ this -> uriRelative ) ) { $ this -> forceSlash ( ) ; } if ( $ this -> matchExact ( ) || $ this -> matchVariable ( ) ) { return $ this -> control ; } return null ; }
|
Get the matching control for the current request - optionally force a trailing slash on current request
|
47,825
|
public function getVar ( int $ index = 0 ) { return isset ( $ this -> vars [ $ index ] ) ? $ this -> vars [ $ index ] : null ; }
|
Get a URI variable based on index
|
47,826
|
private function getGlobal ( string $ global , string $ name ) { if ( ! isset ( $ GLOBALS [ $ global ] ) || ! is_array ( $ GLOBALS [ $ global ] ) || ( $ name && ! isset ( $ GLOBALS [ $ global ] [ $ name ] ) ) ) { return null ; } if ( ! $ name ) { return $ GLOBALS [ $ global ] ; } return $ GLOBALS [ $ global ] [ $ name ] ; }
|
get a value from a global array or the whole global array
|
47,827
|
private function forceSlash ( ) { $ url = $ this -> getCurrentFull ( ) . '/' ; $ queryString = $ this -> getServer ( 'QUERY_STRING' ) ; if ( ! empty ( $ queryString ) ) { $ url .= '?' . $ queryString ; } $ this -> redirect ( $ url ) ; }
|
Force a trailing slash on the current request
|
47,828
|
private function matchExact ( ) : bool { foreach ( $ this -> routesExact as $ route ) { if ( $ this -> uri === $ route [ 'u' ] ) { $ this -> control = $ route [ 'c' ] ; return true ; } } return false ; }
|
Match URI to an exact route
|
47,829
|
private function matchVariable ( ) : bool { foreach ( $ this -> routesVariable as $ route ) { $ this -> matchVariableVars ( $ route [ 'u' ] ) ; if ( empty ( $ this -> vars ) ) { continue ; } $ this -> control = $ route [ 'c' ] ; return true ; } return false ; }
|
Match URI to a variable route
|
47,830
|
private function matchVariableVars ( array $ routeUri ) { $ this -> vars = [ ] ; foreach ( $ routeUri as $ index => $ route ) { if ( ! in_array ( $ route , [ '?' , $ this -> uri [ $ index ] ] ) ) { $ this -> vars = [ ] ; return ; } if ( $ route === '?' ) { $ this -> vars [ ] = $ this -> uri [ $ index ] ; } } }
|
Populate an ordered array of URI segment variables
|
47,831
|
protected function normalize ( array & $ array ) { foreach ( $ array as $ key => $ value ) { if ( array_key_exists ( $ key , self :: $ apcFix ) ) { unset ( $ array [ $ key ] ) ; $ array [ self :: $ apcFix [ $ key ] ] = $ value ; } } }
|
Fix inconsistencies between APC and APCu
|
47,832
|
public function apc_add ( $ key , $ var = null , $ ttl = 0 ) { if ( is_string ( $ key ) && $ var === null ) { throw new \ InvalidArgumentException ( 'When $key is set $var cannot be null' ) ; } $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apc_add(%s, %s, %s);' , var_export ( $ key , true ) , var_export ( $ var , true ) , var_export ( $ ttl , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Caches a variable in the data store only if it s not already stored
|
47,833
|
public function apc_bin_dump ( array $ files = null , $ user_vars = null ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apc_bin_dump(%s, %s);' , var_export ( $ files , true ) , var_export ( $ user_vars , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Get a binary dump of the given files and user variables
|
47,834
|
public function apc_bin_dumpfile ( array $ files , array $ user_vars , $ filename , $ flags = 0 , $ context = null ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apc_bin_dumpfile(%s, %s, %s, %s, %s);' , var_export ( $ files , true ) , var_export ( $ user_vars , true ) , var_export ( $ filename , true ) , var_export ( $ flags , true ) , var_export ( $ context , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Outputs a binary dump of the given files and user variables from the APC cache to the named file .
|
47,835
|
public function apc_cache_info ( $ cache_type = "" , $ limited = false ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apc_cache_info(%s, %s);' , var_export ( $ cache_type , true ) , var_export ( $ limited , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Retrieves cached information from APC s data store
|
47,836
|
public function apc_compile_file ( $ filename , $ atomic = true ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apc_compile_file(%s, %s);' , var_export ( $ filename , true ) , var_export ( $ atomic , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Stores a file in the bytecode cache bypassing all filters .
|
47,837
|
public function apc_define_constants ( $ key , array $ constants , $ case_sensitive = true ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apc_define_constants(%s, %s, %s);' , var_export ( $ key , true ) , var_export ( $ constants , true ) , var_export ( $ case_sensitive , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Defines a set of constants for retrieval and mass - definition
|
47,838
|
public function apc_inc ( $ key , $ step = 1 , $ ref = false ) { $ code = new Code ( ) ; $ code -> addStatement ( '$success = false;' ) ; $ code -> addStatement ( sprintf ( '$result = apc_inc(%s, %s, $success);' , var_export ( $ key , true ) , var_export ( $ step , true ) ) ) ; $ code -> addStatement ( 'return array($result, $success);' ) ; list ( $ result , $ success ) = $ this -> adapter -> run ( $ code ) ; if ( is_object ( $ ref ) ) { $ ref -> success = $ success ; } return $ result ; }
|
Increase a stored number
|
47,839
|
public function apc_load_constants ( $ key , $ case_sensitive = true ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apc_load_constants(%s, %s);' , var_export ( $ key , true ) , var_export ( $ case_sensitive , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Loads a set of constants from the cache
|
47,840
|
public function apc_sma_info ( $ limited = false ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apc_sma_info(%s);' , var_export ( $ limited , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Retrieves APC s Shared Memory Allocation information
|
47,841
|
protected static function getUserHomeDir ( ) { $ home = getenv ( 'HOME' ) ; if ( ! empty ( $ home ) ) { $ home = rtrim ( $ home , '/' ) ; } elseif ( ! empty ( $ _SERVER [ 'HOMEDRIVE' ] ) && ! empty ( $ _SERVER [ 'HOMEPATH' ] ) ) { $ home = $ _SERVER [ 'HOMEDRIVE' ] . $ _SERVER [ 'HOMEPATH' ] ; $ home = rtrim ( $ home , '\\/' ) ; } return empty ( $ home ) ? NULL : $ home ; }
|
Return the user s home directory . From drush
|
47,842
|
public function extension_loaded ( $ name ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( "return extension_loaded(%s);" , var_export ( $ name , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Find out whether an extension is loaded
|
47,843
|
public function phpversion ( $ extension = null ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( "return phpversion(%s);" , var_export ( $ extension , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Returns a string containing the version of the currently running PHP parser or extension .
|
47,844
|
public function _eval ( $ expression ) { $ code = new Code ( ) ; $ code -> addStatement ( $ expression ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Evaluate a string as PHP code
|
47,845
|
protected function getFunction ( $ name ) { if ( empty ( $ this -> functions ) ) { foreach ( $ this -> proxies as $ proxy ) { $ this -> logger -> info ( sprintf ( 'Loading Proxy: %s' , get_class ( $ proxy ) ) ) ; $ proxy -> setAdapter ( $ this -> adapter ) ; foreach ( $ proxy -> getFunctions ( ) as $ fn ) { $ this -> logger -> debug ( sprintf ( 'Loading Function: %s' , $ fn ) ) ; $ this -> functions [ $ fn ] = array ( $ proxy , $ fn ) ; } } } if ( isset ( $ this -> functions [ $ name ] ) ) { return $ this -> functions [ $ name ] ; } throw new \ InvalidArgumentException ( "Function with name: {$name} is not provided by any Proxy." ) ; }
|
Initializes functions and return callable
|
47,846
|
public function opcache_compile_file ( $ file ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return opcache_compile_file(%s);' , var_export ( $ file , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Compiles and caches a PHP script without executing it
|
47,847
|
public function apcu_delete ( $ key ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apcu_delete(%s);' , var_export ( $ key , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Removes a stored variable from the cache
|
47,848
|
public function apcu_regexp_delete ( $ regexp = null ) { if ( $ regexp && ! preg_match ( "/^\/.+\/[a-z]*$/i" , $ regexp ) ) { throw new \ RuntimeException ( "{$regexp} is not a valid Regex" ) ; } $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( '$keys = new \APCIterator("user", %s, APC_ITER_KEY, 10);' , var_export ( $ regexp , true ) ) ) ; $ code -> addStatement ( 'return apc_delete($keys);' ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Retrieves caches keys & TTL from APCu s data store
|
47,849
|
public function apcu_exists ( $ keys ) { $ code = new Code ( ) ; $ code -> addStatement ( sprintf ( 'return apcu_exists(%s);' , var_export ( $ keys , true ) ) ) ; return $ this -> adapter -> run ( $ code ) ; }
|
Checks if one or more APCu keys exist .
|
47,850
|
public static function getValidators ( ) { if ( isset ( static :: $ validators ) ) { return static :: $ validators ; } return static :: $ validators = [ new MethodValidator , new ConditionalValidator , new SchemeValidator , new HostValidator , new UriValidator , ] ; }
|
Get the route validators for the instance .
|
47,851
|
public function update ( array $ attributes = [ ] ) { $ attributes = array_merge ( $ attributes , [ 'ID' => $ this -> ID ] ) ; if ( is_wp_error ( wp_update_user ( $ attributes ) ) ) { return false ; } $ this -> setRawAttributes ( $ attributes , true ) ; return true ; }
|
Update the user properties .
|
47,852
|
protected function parseValue ( FieldBuilder $ field , $ value = null ) { $ parsedValue = null ; switch ( $ field -> getFieldType ( ) ) { case 'checkbox' : case 'checkboxes' : case 'radio' : case 'select' : case 'collection' : $ parsedValue = $ this -> parseArrayable ( $ field , $ value ) ; break ; case 'infinite' : $ parsedValue = $ this -> parseInfinite ( $ field , $ value ) ; break ; default : $ parsedValue = $ this -> parseString ( $ field , $ value ) ; } return $ parsedValue ; }
|
Set a default value for a given field .
|
47,853
|
private function parseArrayable ( FieldBuilder $ field , $ value = [ ] ) { if ( is_null ( $ value ) || ( '0' !== $ value && empty ( $ value ) ) ) { if ( isset ( $ field [ 'default' ] ) ) { return ( array ) $ field [ 'default' ] ; } return [ ] ; } return ( array ) $ value ; }
|
Parse default value for fields using array values .
|
47,854
|
private function parseString ( FieldBuilder $ field , $ value = '' ) { return ( empty ( $ value ) && isset ( $ field [ 'default' ] ) ) ? $ field [ 'default' ] : $ value ; }
|
Parse default value for fields with string values .
|
47,855
|
public function fillRawData ( string $ rawData ) : TelegramResponse { $ this -> rawData = $ rawData ; $ this -> decodedData = json_decode ( $ this -> rawData , true ) ; if ( $ this -> decodedData [ 'ok' ] === false ) { $ exception = new ClientException ( ) ; $ exception -> setError ( new UnsuccessfulRequest ( $ this -> decodedData ) ) ; throw $ exception ; } return $ this ; }
|
Fills in the raw data
|
47,856
|
public function getTypeOfResult ( ) : string { switch ( gettype ( $ this -> decodedData [ 'result' ] ) ) { case 'array' : case 'integer' : case 'boolean' : return gettype ( $ this -> decodedData [ 'result' ] ) ; default : throw new InvalidResultType ( sprintf ( 'The passed data type ("%s") is not supported' , gettype ( $ this -> decodedData [ 'result' ] ) ) ) ; } }
|
To quickly find out what type of request we are dealing with
|
47,857
|
public static function bindToObject ( TelegramResponse $ data , LoggerInterface $ logger ) : TelegramTypes { return new Message ( $ data -> getResult ( ) , $ logger ) ; }
|
Most of the methods will return a Message object on success so set that as the default .
|
47,858
|
public function performSpecialConditions ( ) : TelegramMethods { if ( ! empty ( $ this -> reply_markup ) ) { $ this -> reply_markup = json_encode ( $ this -> formatReplyMarkup ( $ this -> reply_markup ) ) ; } return $ this ; }
|
Before making the actual request this method will be called
|
47,859
|
final public function export ( ) : array { $ finalArray = [ ] ; $ mandatoryFields = $ this -> getMandatoryFields ( ) ; $ cleanObject = new $ this ( ) ; foreach ( $ cleanObject as $ fieldId => $ value ) { if ( $ this -> $ fieldId === $ cleanObject -> $ fieldId ) { if ( \ in_array ( $ fieldId , $ mandatoryFields , true ) ) { $ missingMandatoryField = new MissingMandatoryField ( sprintf ( 'The field "%s" for class "%s" is mandatory and empty, please correct' , $ fieldId , \ get_class ( $ cleanObject ) ) ) ; $ missingMandatoryField -> method = \ get_class ( $ cleanObject ) ; $ missingMandatoryField -> methodInstance = $ this ; throw $ missingMandatoryField ; } } else { $ finalArray [ $ fieldId ] = $ this -> $ fieldId ; } } return $ finalArray ; }
|
Exports the class to an array in order to send it to the Telegram servers without extra fields that we don t need
|
47,860
|
final protected function mandatoryUserOrInlineMessageId ( array & $ return ) : array { if ( empty ( $ this -> chat_id ) && empty ( $ this -> message_id ) ) { $ return [ ] = 'inline_message_id' ; } if ( empty ( $ this -> inline_message_id ) ) { $ return [ ] = 'chat_id' ; $ return [ ] = 'message_id' ; } return $ return ; }
|
Will resolve the dependency of a mandatory inline_message_id OR a chat_id + message_id
|
47,861
|
private function formatReplyMarkup ( TelegramTypes $ replyMarkup ) : TelegramTypes { if ( $ replyMarkup instanceof Markup ) { $ replyMarkup -> inline_keyboard = $ this -> getArrayFromKeyboard ( $ replyMarkup -> inline_keyboard ) ; } elseif ( $ replyMarkup instanceof ReplyKeyboardMarkup ) { $ replyMarkup -> keyboard = $ this -> getArrayFromKeyboard ( $ replyMarkup -> keyboard ) ; } return $ replyMarkup ; }
|
ReplyMarkup fields require a bit of work before sending them
|
47,862
|
private function exportReplyMarkupItem ( TelegramTypes $ markupItem ) : array { $ finalArray = [ ] ; $ cleanObject = new $ markupItem ; foreach ( $ markupItem as $ fieldId => $ value ) { if ( $ markupItem -> $ fieldId !== $ cleanObject -> $ fieldId ) { $ finalArray [ $ fieldId ] = $ markupItem -> $ fieldId ; } } return $ finalArray ; }
|
Does the definitive export of those fields in a reply markup item that are filled in
|
47,863
|
protected function mapSubObjects ( string $ key , array $ data ) : TelegramTypes { switch ( $ key ) { case 'from' : case 'forward_from' : case 'new_chat_member' : case 'left_chat_member' : return new User ( $ data , $ this -> logger ) ; case 'new_chat_members' : return new UserArray ( $ data , $ this -> logger ) ; case 'photo' : case 'new_chat_photo' : return new PhotoSizeArray ( $ data , $ this -> logger ) ; case 'chat' : case 'forward_from_chat' : return new Chat ( $ data , $ this -> logger ) ; case 'reply_to_message' : case 'pinned_message' : return new Message ( $ data , $ this -> logger ) ; case 'entities' : case 'caption_entities' : return new MessageEntityArray ( $ data , $ this -> logger ) ; case 'audio' : return new Audio ( $ data , $ this -> logger ) ; case 'document' : return new Document ( $ data , $ this -> logger ) ; case 'animation' : return new Animation ( $ data , $ this -> logger ) ; case 'game' : return new Game ( $ data , $ this -> logger ) ; case 'sticker' : return new Sticker ( $ data , $ this -> logger ) ; case 'video' : return new Video ( $ data , $ this -> logger ) ; case 'voice' : return new Voice ( $ data , $ this -> logger ) ; case 'video_note' : return new VideoNote ( $ data , $ this -> logger ) ; case 'contact' : return new Contact ( $ data , $ this -> logger ) ; case 'location' : return new Location ( $ data , $ this -> logger ) ; case 'venue' : return new Venue ( $ data , $ this -> logger ) ; case 'invoice' : return new Invoice ( $ data , $ this -> logger ) ; case 'successful_payment' : return new SuccessfulPayment ( $ data , $ this -> logger ) ; } return parent :: mapSubObjects ( $ key , $ data ) ; }
|
A message may contain one or more subobjects map them always in this function
|
47,864
|
final protected function populateObject ( array $ data = [ ] ) : TelegramTypes { foreach ( $ data as $ key => $ value ) { $ candidateKey = null ; if ( \ is_array ( $ value ) ) { $ this -> logger -> debug ( 'Array detected, mapping subobjects for key' , [ 'key' => $ key ] ) ; $ candidateKey = $ this -> mapSubObjects ( $ key , $ value ) ; } if ( ! empty ( $ candidateKey ) ) { if ( $ candidateKey instanceof CustomType ) { $ this -> logger -> debug ( 'Done with mapping, injecting custom data type to class' , [ 'key' => $ key ] ) ; $ this -> $ key = $ candidateKey -> data ; } else { $ this -> logger -> debug ( 'Done with mapping, injecting native data type to class' , [ 'key' => $ key ] ) ; $ this -> $ key = $ candidateKey ; } } else { $ this -> logger -> debug ( 'Performing direct assign for key' , [ 'key' => $ key ] ) ; $ this -> $ key = $ value ; } } return $ this ; }
|
Fills the class with the data passed on through the constructor
|
47,865
|
protected function mapSubObjects ( string $ key , array $ data ) : TelegramTypes { if ( ! isset ( $ this -> $ key ) ) { $ this -> logger -> error ( sprintf ( 'The key "%s" does not exist in the class! Maybe a recent Telegram Bot API update? In any way, please ' . 'submit an issue (bug report) at %s with this complete log line' , $ key , 'https://github.com/unreal4u/telegram-api/issues' ) , [ 'object' => \ get_class ( $ this ) , 'data' => $ data , ] ) ; } return new ResultArray ( $ data , $ this -> logger ) ; }
|
The default is that we have no subobjects at all so this function will return nothing
|
47,866
|
public function performApiRequest ( TelegramMethods $ method ) : PromiseInterface { $ this -> logger -> debug ( 'Request for async API call, resetting internal values' , [ \ get_class ( $ method ) ] ) ; $ this -> resetObjectValues ( ) ; $ option = $ this -> formConstructor -> constructOptions ( $ method ) ; return $ this -> sendRequestToTelegram ( $ method , $ option ) -> then ( function ( TelegramResponse $ response ) use ( $ method ) { return $ method :: bindToObject ( $ response , $ this -> logger ) ; } , function ( $ error ) { $ this -> logger -> error ( $ error ) ; throw $ error ; } ) ; }
|
Performs the request to the Telegram servers
|
47,867
|
protected function sendRequestToTelegram ( TelegramMethods $ method , array $ formData ) : PromiseInterface { $ this -> logger -> debug ( 'About to perform async HTTP call to Telegram\'s API' ) ; return $ this -> requestHandler -> post ( $ this -> composeApiMethodUrl ( $ method ) , $ formData ) ; }
|
This is the method that actually makes the call which can be easily overwritten so that our unit tests can work
|
47,868
|
protected function composeApiMethodUrl ( TelegramMethods $ call ) : string { $ completeClassName = \ get_class ( $ call ) ; $ this -> methodName = substr ( $ completeClassName , strrpos ( $ completeClassName , '\\' ) + 1 ) ; $ this -> logger -> info ( 'About to perform API request' , [ 'method' => $ this -> methodName ] ) ; return $ this -> apiUrl . $ this -> methodName ; }
|
Builds up the URL with which we can work with
|
47,869
|
private function setStream ( ) : InputFile { if ( is_readable ( $ this -> path ) ) { $ this -> stream = fopen ( $ this -> path , 'rb' ) ; } else { throw new FileNotReadable ( sprintf ( 'Can not read local file "%s", please check' , $ this -> path ) ) ; } return $ this ; }
|
Will setup the stream
|
47,870
|
public function constructOptions ( TelegramMethods $ method ) : array { $ result = $ this -> checkIsMultipart ( $ method ) ; if ( ! empty ( $ result ) ) { return $ this -> constructMultipartOptions ( $ method -> export ( ) , $ result ) ; } $ body = http_build_query ( $ method -> export ( ) , '' , '&' ) ; return [ 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded' , 'Content-Length' => \ strlen ( $ body ) , 'User-Agent' => 'PHP7+ Bot API' , ] , 'body' => $ body ] ; }
|
Builds up the form elements to be sent to Telegram
|
47,871
|
private function checkIsMultipart ( TelegramMethods $ method ) : array { $ this -> logger -> debug ( 'Checking whether to apply special conditions to this request' ) ; $ method -> performSpecialConditions ( ) ; $ return = [ ] ; foreach ( $ method as $ key => $ value ) { if ( ( \ is_object ( $ value ) && $ value instanceof InputFile ) || ( \ is_object ( $ value ) && $ value instanceof Photo ) || ( ( is_array ( $ value ) || $ value instanceof Countable ) && \ count ( $ value ) > 1 && ( reset ( $ value ) instanceof InputFile || reset ( $ value ) instanceof Photo ) ) ) { $ this -> logger -> debug ( 'About to send a file, so changing request to use multi-part instead' ) ; $ this -> formType = 'multipart/form-data' ; if ( $ value instanceof InputFile ) { $ return [ $ key ] = [ 'id' => $ key , 'filename' => $ value -> path , 'stream' => $ value -> getStream ( ) ] ; } elseif ( $ value instanceof Photo ) { $ return [ $ key ] = [ 'id' => $ key , 'filename' => $ value -> media -> path , 'stream' => $ value -> media -> getStream ( ) ] ; } elseif ( ( is_array ( $ value ) || $ value instanceof Countable ) ) { foreach ( $ value as $ kk => $ vv ) { if ( $ vv instanceof InputFile ) { $ return [ $ kk ] = [ 'id' => $ kk , 'filename' => $ vv -> path , 'stream' => $ vv -> getStream ( ) ] ; } elseif ( $ vv instanceof Photo ) { $ return [ $ kk ] = [ 'id' => $ kk , 'filename' => $ vv -> media -> path , 'stream' => $ vv -> media -> getStream ( ) ] ; } } } } } return $ return ; }
|
Check if the given TelegramMethod should be handled as a multipart .
|
47,872
|
public function constructMultipartOptions ( array $ data , array $ multipart_data ) : array { $ builder = new Builder ( ) ; $ this -> logger -> debug ( 'Creating multi-part form array data (complex and expensive)' ) ; foreach ( $ data as $ id => $ value ) { if ( array_key_exists ( $ id , $ multipart_data ) ) { $ data = new MultipartData ( ( string ) $ multipart_data [ $ id ] [ 'id' ] , stream_get_contents ( $ multipart_data [ $ id ] [ 'stream' ] ) , pathinfo ( $ multipart_data [ $ id ] [ 'filename' ] , PATHINFO_BASENAME ) ) ; $ builder -> append ( $ data ) ; } elseif ( $ id == 'mediagroup' ) { foreach ( $ multipart_data as $ ii => $ mdata ) { $ data = new MultipartData ( pathinfo ( $ mdata [ 'filename' ] , PATHINFO_BASENAME ) , stream_get_contents ( $ mdata [ 'stream' ] ) , pathinfo ( $ mdata [ 'filename' ] , PATHINFO_BASENAME ) ) ; $ builder -> append ( $ data ) ; } } else { $ data = new MultipartData ( ( string ) $ id , ( string ) $ value ) ; $ builder -> append ( $ data ) ; } } $ body = $ builder -> buildAll ( ) ; $ array = [ 'headers' => [ 'Content-Type' => 'multipart/form-data; boundary="' . $ builder -> getBoundary ( ) . '"' , 'Content-Length' => \ strlen ( $ body ) ] , 'body' => $ body ] ; return $ array ; }
|
Builds up a multipart form - like array for Guzzle
|
47,873
|
public function getRootContext ( ) { if ( $ parentContext = $ this -> getParentContext ( ) ) { if ( $ parentContext instanceof ParentDelegationBuilder ) { return $ parentContext -> getRootContext ( ) ; } return $ parentContext ; } return $ this ; }
|
Returns the root context
|
47,874
|
public function conditional ( $ name , $ operator , $ value ) { $ conditionalBuilder = new ConditionalBuilder ( $ name , $ operator , $ value ) ; $ conditionalBuilder -> setParentContext ( $ this ) ; $ this -> setConfig ( 'conditional_logic' , $ conditionalBuilder ) ; return $ conditionalBuilder ; }
|
Add a conditional logic statement that will determine if the last added field will display or not . You can add or or and calls after to build complex logic . Any other function call will return you to the parentContext .
|
47,875
|
public function setWidth ( $ width ) { $ wrapper = $ this -> getWrapper ( ) ; $ wrapper [ 'width' ] = $ width ; return $ this -> setWrapper ( $ wrapper ) ; }
|
Set width of a Wrapper container
|
47,876
|
public function setAttr ( $ name , $ value = null ) { $ wrapper = $ this -> getWrapper ( ) ; $ wrapper [ $ name ] = $ value ; return $ this -> setWrapper ( $ wrapper ) ; }
|
Set specified Attr of a Wrapper container
|
47,877
|
public function build ( ) { $ config = array_merge ( [ 'type' => $ this -> type , ] , $ this -> getConfig ( ) ) ; foreach ( $ config as $ key => $ value ) { if ( $ value instanceof Builder ) { $ config [ $ key ] = $ value -> build ( ) ; } } return $ config ; }
|
Build the field configuration array
|
47,878
|
public function transform ( $ config ) { array_walk ( $ config , function ( & $ value , $ key ) { if ( in_array ( $ key , $ this -> getKeys ( ) , true ) ) { $ value = $ this -> transformValue ( $ value ) ; } else { if ( $ this -> shouldRecurse ( $ value , $ key ) ) { $ value = $ this -> transform ( $ value ) ; } } } ) ; return $ config ; }
|
Apply the transformValue function to all values in multidementional associative array where the key matches one of the keys defined on the RecursiveTransform .
|
47,879
|
public function build ( ) { return array_merge ( $ this -> config , [ 'fields' => $ this -> buildFields ( ) , 'location' => $ this -> buildLocation ( ) , 'key' => $ this -> namespaceGroupKey ( $ this -> config [ 'key' ] ) , ] ) ; }
|
Build the final config array . Build any other builders that may exist in the config .
|
47,880
|
private function buildFields ( ) { $ fields = array_map ( function ( $ field ) { return ( $ field instanceof Builder ) ? $ field -> build ( ) : $ field ; } , $ this -> getFields ( ) ) ; return $ this -> transformFields ( $ fields ) ; }
|
Return a fields config array
|
47,881
|
private function transformFields ( $ fields ) { $ conditionalTransform = new Transform \ ConditionalLogic ( $ this ) ; $ namespaceFieldKeyTransform = new Transform \ NamespaceFieldKey ( $ this ) ; return $ namespaceFieldKeyTransform -> transform ( $ conditionalTransform -> transform ( $ fields ) ) ; }
|
Apply field transforms
|
47,882
|
public function addFields ( $ fields ) { if ( $ fields instanceof FieldsBuilder ) { $ builder = clone $ fields ; $ fields = $ builder -> getFields ( ) ; } foreach ( $ fields as $ field ) { $ this -> getFieldManager ( ) -> pushField ( $ field ) ; } return $ this ; }
|
Add multiple fields either via an array or from another builder
|
47,883
|
public function addField ( $ name , $ type , array $ args = [ ] ) { return $ this -> initializeField ( new FieldBuilder ( $ name , $ type , $ args ) ) ; }
|
Add a field of a specific type
|
47,884
|
public function addChoiceField ( $ name , $ type , array $ args = [ ] ) { return $ this -> initializeField ( new ChoiceFieldBuilder ( $ name , $ type , $ args ) ) ; }
|
Add a field of a choice type allows choices to be added .
|
47,885
|
protected function initializeField ( $ field ) { $ field -> setParentContext ( $ this ) ; $ this -> getFieldManager ( ) -> pushField ( $ field ) ; return $ field ; }
|
Initialize the FieldBuilder add to FieldManager
|
47,886
|
public function addMessage ( $ label , $ message , array $ args = [ ] ) { $ name = $ this -> generateName ( $ label ) . '_message' ; $ args = array_merge ( [ 'label' => $ label , 'message' => $ message , ] , $ args ) ; return $ this -> addField ( $ name , 'message' , $ args ) ; }
|
Addes a message field
|
47,887
|
public function modifyField ( $ name , $ modify ) { if ( is_array ( $ modify ) ) { $ this -> getFieldManager ( ) -> modifyField ( $ name , $ modify ) ; } elseif ( $ modify instanceof \ Closure ) { $ field = $ this -> getField ( $ name ) ; $ modifyBuilder = new FieldsBuilder ( '' ) ; $ modifyBuilder -> addFields ( [ $ field ] ) ; $ modifyBuilder = $ modify ( $ modifyBuilder ) ; if ( ! $ modifyBuilder instanceof FieldsBuilder ) { throw new ModifyFieldReturnTypeException ( gettype ( $ modifyBuilder ) ) ; } $ this -> getFieldManager ( ) -> replaceField ( $ name , $ modifyBuilder -> getFields ( ) ) ; } return $ this ; }
|
Modify an already defined field
|
47,888
|
public function build ( ) { $ config = parent :: build ( ) ; $ fields = $ this -> fieldsBuilder -> build ( ) ; $ config [ 'sub_fields' ] = $ fields [ 'fields' ] ; return $ config ; }
|
Return a group field configuration array
|
47,889
|
public function addChoice ( $ choice , $ label = null ) { $ label ? : $ label = $ choice ; $ this -> choices [ $ choice ] = $ label ; return $ this ; }
|
Add a choice with optional label . If label not supplied choice value will be used .
|
47,890
|
public function addChoices ( $ choices ) { if ( func_num_args ( ) > 1 ) { $ choices = func_get_args ( ) ; } foreach ( $ choices as $ key => $ value ) { $ label = $ choice = $ value ; if ( is_array ( $ choice ) ) { $ label = array_values ( $ choice ) [ 0 ] ; $ choice = array_keys ( $ choice ) [ 0 ] ; } else if ( is_string ( $ key ) ) { $ choice = $ key ; $ label = $ value ; } $ this -> addChoice ( $ choice , $ label ) ; } return $ this ; }
|
Add multiple choices . Also accepts multiple arguments one for each choice .
|
47,891
|
public function setChoices ( $ choices ) { if ( func_num_args ( ) > 1 ) { $ choices = func_get_args ( ) ; } $ this -> choices = [ ] ; return $ this -> addChoices ( $ choices ) ; }
|
Discards existing choices and adds multiple choices . Also accepts multiple arguments one for each choice .
|
47,892
|
private function buildLayouts ( ) { return array_map ( function ( $ layout ) { $ layout = ( $ layout instanceof Builder ) ? $ layout -> build ( ) : $ layout ; return $ this -> transformLayout ( $ layout ) ; } , $ this -> getLayouts ( ) ) ; }
|
Return a configuration array for each layout
|
47,893
|
private function transformLayout ( $ layout ) { $ layoutTransform = new Transform \ FlexibleContentLayout ( $ this ) ; $ namespaceTransform = new Transform \ NamespaceFieldKey ( $ this ) ; return $ namespaceTransform -> transform ( $ layoutTransform -> transform ( $ layout ) ) ; }
|
Apply transformations to a layout
|
47,894
|
public function addLayout ( $ layout , $ args = [ ] ) { if ( $ layout instanceof FieldsBuilder ) { $ layout = clone $ layout ; } else { $ layout = new FieldsBuilder ( $ layout , $ args ) ; } $ layout = $ this -> initializeLayout ( $ layout , $ args ) ; $ this -> pushLayout ( $ layout ) ; return $ layout ; }
|
Add a layout which is a FieldsBuilder . addLayout can be chained to add multiple layouts to the Flexible Content field .
|
47,895
|
protected function initializeLayout ( FieldsBuilder $ layout , $ args = [ ] ) { $ layout -> setGroupConfig ( 'name' , $ layout -> getName ( ) ) ; $ layout -> setGroupConfig ( 'display' , 'block' ) ; foreach ( $ args as $ key => $ value ) { $ layout -> setGroupConfig ( $ key , $ value ) ; } $ layout -> setParentContext ( $ this ) ; return $ layout ; }
|
Configures the layout FieldsBuilder
|
47,896
|
public function popField ( ) { if ( $ this -> getCount ( ) > 0 ) { $ fields = $ this -> removeFieldAtIndex ( $ this -> getCount ( ) - 1 ) ; return $ fields [ 0 ] ; } throw new \ OutOfRangeException ( "Can't call popField when the field count is 0" ) ; }
|
Remove last field from end of array
|
47,897
|
public function insertFields ( $ fields , $ index ) { if ( ! $ fields instanceof NamedBuilder && ! is_array ( $ fields ) ) { return ; } if ( $ fields instanceof NamedBuilder ) { $ fields = [ $ fields ] ; } foreach ( $ fields as $ i => $ field ) { if ( $ this -> validateField ( $ field ) ) { array_splice ( $ this -> fields , $ index + $ i , 0 , [ $ field ] ) ; } } }
|
Insert of field at a specific index
|
47,898
|
public function replaceField ( $ name , $ field ) { $ index = $ this -> getFieldIndex ( $ name ) ; $ this -> removeFieldAtIndex ( $ index ) ; $ this -> insertFields ( $ field , $ index ) ; }
|
Replace a field with a single field or array of fields
|
47,899
|
public function modifyField ( $ name , $ modifications ) { $ field = $ this -> getField ( $ name ) -> updateConfig ( $ modifications ) ; $ this -> replaceField ( $ name , $ field ) ; }
|
Modify the configuration of a field
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.