idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
22,900
public function setJstype ( \ google \ protobuf \ FieldOptions \ JSType $ value = null ) { $ this -> jstype = $ value ; }
Set jstype value
22,901
protected function whereNotIn ( Builder $ query , $ where ) { if ( empty ( $ where [ 'values' ] ) ) { return '1 = 1' ; } $ values = $ this -> parameterize ( $ where [ 'values' ] ) ; return $ this -> wrap ( $ where [ 'column' ] ) . ' not in (' . $ values . ')' ; }
Compile a where not in clause .
22,902
public function compileReplace ( Builder $ query , array $ values ) { $ table = $ this -> wrapTable ( $ query -> from ) ; if ( ! is_array ( reset ( $ values ) ) ) { $ values = [ $ values ] ; } $ columns = $ this -> columnize ( array_keys ( reset ( $ values ) ) ) ; $ parameters = [ ] ; foreach ( $ values as $ record ) { $ parameters [ ] = '(' . $ this -> parameterize ( $ record ) . ')' ; } $ parameters = implode ( ', ' , $ parameters ) ; return "replace into $table ($columns) values $parameters" ; }
Compile an replace statement into SQL .
22,903
protected function getVariableValue ( array $ matches ) { $ res = $ matches [ 0 ] ; $ variable = substr ( $ matches [ 0 ] , 1 , - 1 ) ; if ( isset ( $ this -> frontmatter [ $ variable ] ) ) { $ res = $ this -> frontmatter [ $ variable ] ; } return $ res ; }
Detect and extract inline variables .
22,904
public function MemberAdd ( MemberAddRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.Cluster/MemberAdd' , $ argument , [ '\Etcdserverpb\MemberAddResponse' , 'decode' ] , $ metadata , $ options ) ; }
MemberAdd adds a member into the cluster .
22,905
public function MemberRemove ( MemberRemoveRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.Cluster/MemberRemove' , $ argument , [ '\Etcdserverpb\MemberRemoveResponse' , 'decode' ] , $ metadata , $ options ) ; }
MemberRemove removes an existing member from the cluster .
22,906
public function MemberUpdate ( MemberUpdateRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.Cluster/MemberUpdate' , $ argument , [ '\Etcdserverpb\MemberUpdateResponse' , 'decode' ] , $ metadata , $ options ) ; }
MemberUpdate updates the member configuration .
22,907
public function MemberList ( MemberListRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.Cluster/MemberList' , $ argument , [ '\Etcdserverpb\MemberListResponse' , 'decode' ] , $ metadata , $ options ) ; }
MemberList lists all the members in the cluster .
22,908
public static function checkReconnectError ( $ errorCode , $ errorInfo , $ exception ) { if ( $ exception ) { if ( stripos ( $ exception -> getMessage ( ) , self :: MYSQL_GONE_AWAY ) !== false || stripos ( $ exception -> getMessage ( ) , self :: MYSQL_REFUSED ) !== false ) { return true ; } } elseif ( $ errorInfo ) { if ( stripos ( $ errorInfo [ 2 ] , self :: MYSQL_GONE_AWAY ) !== false || stripos ( $ errorInfo [ 2 ] , self :: MYSQL_REFUSED ) !== false ) { return true ; } } return false ; }
Check whether we need to reconnect database
22,909
public function setTimeStep ( $ timeStep ) { $ timeStep = abs ( intval ( $ timeStep ) ) ; $ this -> timeStep = $ timeStep ; return $ this ; }
Set the timestep value
22,910
private static function timestampToCounter ( $ timestamp , $ timeStep ) { $ timestamp = abs ( intval ( $ timestamp ) ) ; $ counter = intval ( ( $ timestamp * 1000 ) / ( $ timeStep * 1000 ) ) ; return $ counter ; }
Convert a timestamp into a usable counter value
22,911
public function countFiles ( ) { $ nbFiles = $ this -> entity -> files -> count ( ) ; $ label = $ nbFiles ? 'label-success' : 'label-default' ; $ html = [ ] ; $ html [ ] = '<span class="label ' . $ label . '">' ; $ html [ ] = $ nbFiles ; $ html [ ] = '</span>' ; return implode ( "\r\n" , $ html ) ; }
Files in list .
22,912
protected function addResolversSection ( ArrayNodeDefinition $ node , array $ factories ) { $ resolverNodeBuilder = $ node -> fixXmlConfig ( 'resolver' ) -> children ( ) -> arrayNode ( 'resolvers' ) -> useAttributeAsKey ( 'name' ) -> prototype ( 'array' ) -> performNoDeepMerging ( ) -> children ( ) ; foreach ( $ factories as $ name => $ factory ) { $ factoryNode = $ resolverNodeBuilder -> arrayNode ( $ name ) -> canBeUnset ( ) ; $ factory -> addConfiguration ( $ factoryNode ) ; } }
Add resolvers section
22,913
protected function getValidators ( $ key ) { $ treeBuilder = new TreeBuilder ( ) ; $ rootNode = $ treeBuilder -> root ( $ key ) ; $ rootNode -> defaultValue ( array ( ) ) -> prototype ( 'variable' ) -> end ( ) -> beforeNormalization ( ) -> always ( ) -> then ( function ( $ values ) { foreach ( $ values as $ key => $ value ) { if ( $ value === null ) { $ values [ $ key ] = array ( ) ; } } return $ values ; } ) -> end ( ) ; $ this -> addValidatorValidation ( $ rootNode ) ; return $ rootNode ; }
Add a custom validator key to configuration
22,914
protected function addValidatorValidation ( ArrayNodeDefinition $ node ) { $ node -> validate ( ) -> ifTrue ( function ( $ value ) { if ( ! is_array ( $ value ) ) { return true ; } if ( count ( array_filter ( array_keys ( $ value ) , 'is_string' ) ) != count ( $ value ) ) { return true ; } if ( count ( array_filter ( array_values ( $ value ) , 'is_array' ) ) != count ( $ value ) ) { return true ; } return false ; } ) -> thenInvalid ( 'Invalid validators configuration' ) -> end ( ) ; }
Add validation to a validator key
22,915
protected function applyDQL ( QueryBuilder $ qb , string $ column , $ data ) : string { $ input = $ data [ 'input' ] ; $ uid = uniqid ( 'text' , false ) ; switch ( $ data [ 'option' ] ) { case 'exact' : $ qb -> setParameter ( $ uid , $ input ) ; return "{$column} = :{$uid}" ; case 'like_' : $ qb -> setParameter ( $ uid , trim ( $ input , '%' ) . '%' ) ; return "{$column} LIKE :{$uid}" ; case '_like' : $ qb -> setParameter ( $ uid , '%' . trim ( $ input , '%' ) ) ; return "{$column} LIKE :{$uid}" ; case '_like_' : $ qb -> setParameter ( $ uid , '%' . trim ( $ input , '%' ) . '%' ) ; return "{$column} LIKE :{$uid}" ; case 'notlike_' : $ qb -> setParameter ( $ uid , trim ( $ input , '%' ) . '%' ) ; return "{$column} NOT LIKE :{$uid}" ; case '_notlike' : $ qb -> setParameter ( $ uid , '%' . trim ( $ input , '%' ) ) ; return "{$column} NOT LIKE :{$uid}" ; case '_notlike_' : $ qb -> setParameter ( $ uid , '%' . trim ( $ input , '%' ) . '%' ) ; return "{$column} NOT LIKE :{$uid}" ; case 'empty' : return "{$column} = ''" ; case 'notempty' : return "{$column} != ''" ; case 'null' : return "{$column} IS NULL" ; case 'notnull' : return "{$column} IS NOT NULL" ; } throw new \ UnexpectedValueException ( "Unknown option '{$data['option']}'" ) ; }
Must return the DQL statement and set the proper parameters in the QueryBuilder
22,916
private function fixMessages ( $ messages , $ name , $ realName , $ subName ) { $ toRemove = null ; foreach ( $ messages as $ messageRule => $ message ) { if ( strpos ( $ messageRule , $ name . '.' ) !== false ) { $ toRemove = $ messageRule ; $ messageRule = substr ( $ messageRule , strpos ( $ messageRule , '.' ) + 1 ) ; $ messages [ $ realName . '_' . $ subName . '.' . $ messageRule ] = $ message ; } } if ( isset ( $ toRemove ) ) { $ this -> messageKey = $ toRemove ; } return $ messages ; }
Fixes error messages to reflect subrules names .
22,917
private function removeMessage ( $ messages ) { if ( ! is_null ( $ this -> messageKey ) ) { unset ( $ messages [ $ this -> messageKey ] ) ; $ this -> messageKey = null ; } return $ messages ; }
Removes a set message key .
22,918
private function fixRules ( $ rules , $ rule , $ name , $ realName , $ subName ) { if ( isset ( $ rules [ $ name ] ) ) { $ key = array_search ( $ name , array_keys ( $ rules ) ) ; $ rules = array_slice ( $ rules , 0 , $ key , true ) + array ( $ realName . '_' . $ subName => $ rule ) + array_slice ( $ rules , $ key , count ( $ rules ) - $ key , true ) ; } return $ rules ; }
Modifies the ruleset so that dynamically created subrules are added to their original position .
22,919
public function Range ( RangeRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.KV/Range' , $ argument , [ '\Etcdserverpb\RangeResponse' , 'decode' ] , $ metadata , $ options ) ; }
Range gets the keys in the range from the key - value store .
22,920
public function Put ( PutRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.KV/Put' , $ argument , [ '\Etcdserverpb\PutResponse' , 'decode' ] , $ metadata , $ options ) ; }
Put puts the given key into the key - value store . A put request increments the revision of the key - value store and generates one event in the event history .
22,921
public function DeleteRange ( DeleteRangeRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.KV/DeleteRange' , $ argument , [ '\Etcdserverpb\DeleteRangeResponse' , 'decode' ] , $ metadata , $ options ) ; }
DeleteRange deletes the given range from the key - value store . A delete request increments the revision of the key - value store and generates a delete event in the event history for every deleted key .
22,922
public function Txn ( TxnRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.KV/Txn' , $ argument , [ '\Etcdserverpb\TxnResponse' , 'decode' ] , $ metadata , $ options ) ; }
Txn processes multiple requests in a single transaction . A txn request increments the revision of the key - value store and generates events with the same revision for every completed request . It is not allowed to modify the same key several times within one txn .
22,923
public function Compact ( CompactionRequest $ argument , $ metadata = [ ] , $ options = [ ] ) { return $ this -> _simpleRequest ( '/etcdserverpb.KV/Compact' , $ argument , [ '\Etcdserverpb\CompactionResponse' , 'decode' ] , $ metadata , $ options ) ; }
Compact compacts the event history in the etcd key - value store . The key - value store should be periodically compacted or the event history will continue to grow indefinitely .
22,924
public function add ( ValidationResult $ validation , $ prefix = null ) { $ prefix = $ this -> translate ( $ prefix ) ; foreach ( $ validation -> getErrors ( ) as $ err ) { $ this -> errors [ ] = ( $ prefix ? trim ( $ prefix ) . ' ' : '' ) . $ err ; } }
Add errors from a validation object
22,925
public function getPreset ( $ application , $ version , array $ options = null ) { $ presets = [ ] ; foreach ( $ this -> presets as $ preset ) { if ( $ preset [ 'application' ] === $ application && $ this -> matchVersion ( $ version , $ preset ) && $ this -> matchOptions ( $ options , $ preset ) ) { $ presets [ ] = $ preset [ 'backup' ] ; } } if ( 0 === count ( $ presets ) ) { return [ ] ; } if ( 1 === count ( $ presets ) ) { return $ presets [ 0 ] ; } return call_user_func_array ( 'array_merge' , $ presets ) ; }
Returns preset for given application and version .
22,926
private function matchVersion ( $ actual , array $ preset ) { if ( ! $ actual || ! array_key_exists ( 'version' , $ preset ) ) { return false ; } return Semver :: satisfies ( $ actual , $ preset [ 'version' ] ) ; }
Matches actual version with preset version .
22,927
private function matchOptions ( $ actual , array $ preset ) { if ( ! $ actual || ! array_key_exists ( 'options' , $ preset ) ) { return true ; } foreach ( $ actual as $ key => $ value ) { if ( array_key_exists ( $ key , $ preset [ 'options' ] ) && $ value !== $ preset [ 'options' ] [ $ key ] ) { return false ; } } return true ; }
Matches actual options with preset options .
22,928
public static function fromFactory ( $ factory , $ interface , $ exception = null ) { $ reason = $ exception instanceof Exception ? " Reason: {$exception->getMessage()}" : '' ; if ( is_callable ( $ factory ) ) { $ message = sprintf ( 'Could not instantiate object of type "%1$s" from factory of type: "%2$s".%3$s' , $ interface , gettype ( $ factory ) , $ reason ) ; } elseif ( is_string ( $ factory ) ) { $ message = sprintf ( 'Could not instantiate object of type "%1$s" from class name: "%2$s".%3$s' , $ interface , $ factory , $ reason ) ; } else { $ message = sprintf ( 'Could not instantiate object of type "%1$s" from invalid argument of type: "%2$s".%3$s' , $ interface , $ factory , $ reason ) ; } return new static ( $ message , 0 , $ exception ) ; }
Create a new instance from a passed - in class name or factory callable .
22,929
public function onRestore ( RestoreEvent $ event ) { $ plugin = $ this -> pluginRegistry -> getPlugin ( $ event -> getOption ( 'plugin' ) ) ; $ optionsResolver = new OptionsResolver ( ) ; $ plugin -> configureOptionsResolver ( $ optionsResolver ) ; $ parameter = $ optionsResolver -> resolve ( $ event -> getOption ( 'parameter' ) ) ; try { $ plugin -> restore ( $ event -> getSource ( ) , $ event -> getDestination ( ) , $ event -> getDatabase ( ) , $ parameter ) ; $ event -> setStatus ( BackupStatus :: STATE_SUCCESS ) ; } catch ( \ Exception $ exception ) { $ event -> setStatus ( BackupStatus :: STATE_FAILED ) ; $ event -> setException ( $ exception ) ; } }
Executes restore for given event .
22,930
public function applyValidator ( $ value , array $ configuration ) { $ resolver = new OptionsResolver ( ) ; $ this -> configureOptions ( $ resolver ) ; $ configuration = $ resolver -> resolve ( $ configuration ) ; $ this -> validate ( $ value , $ configuration ) ; }
Apply the validator
22,931
public function getButtons ( ) { if ( $ this -> buttons && is_array ( $ this -> buttons ) ) { return $ this -> buttons ; } else { return $ this -> config ( ) -> default_buttons ; } }
Get all the current buttons
22,932
public function addButton ( $ button ) { $ buttons = $ this -> buttons ; if ( ! is_array ( $ buttons ) ) { $ buttons = array ( ) ; } $ buttons [ ] = $ button ; $ this -> buttons = $ buttons ; return $ this ; }
Set our array of buttons
22,933
public function getButtonsJS ( ) { $ buttons = $ this -> getButtons ( ) ; $ str = "" ; for ( $ x = 0 ; $ x < count ( $ buttons ) ; $ x ++ ) { $ str .= "'" . $ buttons [ $ x ] . "'" ; if ( $ x < ( count ( $ buttons ) - 1 ) ) { $ str .= "," ; } } return $ str ; }
Get all the current buttons rendered as a string for JS
22,934
public function refreshDimensions ( ) { if ( '\\' === DIRECTORY_SEPARATOR ) { if ( preg_match ( '/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/' , trim ( getenv ( 'ANSICON' ) ) , $ matches ) ) { $ this -> width = ( int ) $ matches [ 1 ] ; $ this -> height = isset ( $ matches [ 4 ] ) ? ( int ) $ matches [ 4 ] : ( int ) $ matches [ 2 ] ; } elseif ( null !== $ dimensions = $ this -> getConsoleMode ( ) ) { $ this -> width = ( int ) $ dimensions [ 0 ] ; $ this -> height = ( int ) $ dimensions [ 1 ] ; } } elseif ( $ sttyString = $ this -> getSttyColumns ( ) ) { if ( preg_match ( '/rows.(\d+);.columns.(\d+);/i' , $ sttyString , $ matches ) ) { $ this -> width = ( int ) $ matches [ 2 ] ; $ this -> height = ( int ) $ matches [ 1 ] ; } elseif ( preg_match ( '/;.(\d+).rows;.(\d+).columns/i' , $ sttyString , $ matches ) ) { $ this -> width = ( int ) $ matches [ 2 ] ; $ this -> height = ( int ) $ matches [ 1 ] ; } } $ this -> initialised = true ; }
Refresh the current dimensions from the terminal
22,935
private function getConsoleMode ( ) { if ( ! function_exists ( 'proc_open' ) ) { return null ; } $ spec = [ 1 => [ 'pipe' , 'w' ] , 2 => [ 'pipe' , 'w' ] , ] ; $ process = proc_open ( 'mode CON' , $ spec , $ pipes , null , null , [ 'suppress_errors' => true ] ) ; if ( is_resource ( $ process ) ) { $ info = stream_get_contents ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 2 ] ) ; proc_close ( $ process ) ; if ( preg_match ( '/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/' , $ info , $ matches ) ) { return [ ( int ) $ matches [ 2 ] , ( int ) $ matches [ 1 ] ] ; } } return null ; }
Runs and parses mode CON if it s available suppressing any error output .
22,936
private function getSttyColumns ( ) { if ( ! function_exists ( 'proc_open' ) ) { return null ; } $ spec = [ 1 => [ 'pipe' , 'w' ] , 2 => [ 'pipe' , 'w' ] , ] ; $ process = proc_open ( 'stty -a | grep columns' , $ spec , $ pipes , null , null , [ 'suppress_errors' => true ] ) ; if ( is_resource ( $ process ) ) { $ info = stream_get_contents ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 2 ] ) ; proc_close ( $ process ) ; return $ info ; } return null ; }
Runs and parses stty - a if it s available suppressing any error output .
22,937
private function stable ( Updater $ updater ) { $ updater -> setStrategy ( Updater :: STRATEGY_GITHUB ) ; $ updater -> getStrategy ( ) -> setPackageName ( 'nanbando/core' ) ; $ updater -> getStrategy ( ) -> setPharName ( 'nanbando.phar' ) ; $ updater -> getStrategy ( ) -> setCurrentLocalVersion ( '@git_version@' ) ; $ updater -> getStrategy ( ) -> setStability ( GithubStrategy :: STABLE ) ; }
Configure updater to use unstable builds .
22,938
protected function is_needed ( $ context = null ) { $ is_needed = $ this -> hasConfigKey ( 'is_needed' ) ? $ this -> getConfigKey ( 'is_needed' ) : true ; if ( is_callable ( $ is_needed ) ) { return $ is_needed ( $ context ) ; } return ( bool ) $ is_needed ; }
Check whether an element is needed .
22,939
public static function resolvetoFIDtoURI ( int $ fid ) { if ( ! is_integer ( $ fid ) ) { return null ; } $ file = \ Drupal :: entityTypeManager ( ) -> getStorage ( 'file' ) -> load ( $ fid ) ; return $ file ; }
Given an fid return the Drupal URI to that file ..
22,940
public function transformFile ( array $ data ) { return $ this -> filterManager -> apply ( $ this -> dataManager -> find ( 'original' , $ data [ 'filename' ] ) , array ( 'filters' => array ( 'crop' => array ( 'start' => array ( $ data [ 'x' ] , $ data [ 'y' ] ) , 'size' => array ( $ data [ 'width' ] , $ data [ 'height' ] ) ) ) ) ) ; }
Transform the file
22,941
public function saveTransformedFile ( $ endpoint , BinaryInterface $ cropedFile , array $ data ) { $ this -> filesystemMap -> get ( $ this -> configuration -> getValue ( $ endpoint , 'croped_fs' ) ) -> write ( $ data [ 'filename' ] , $ cropedFile -> getContent ( ) ) ; }
Save the transformed file
22,942
public function isTracked ( EntityManagerInterface $ em , $ entity ) { $ class = get_class ( $ entity ) ; $ annotations = $ this -> reader -> getClassAnnotations ( $ em -> getClassMetadata ( $ class ) -> getReflectionClass ( ) ) ; foreach ( $ annotations as $ annotation ) { if ( $ annotation instanceof Tracked ) { return true ; } } return false ; }
Get the annotation from a class or null if it doesn t exists .
22,943
protected function render ( $ template , $ data = [ ] ) { $ view = new View ( ) ; $ view -> type ( View :: VIEW_TYPE_CELL ) ; $ view -> set ( $ data ) ; $ className = get_class ( $ this ) ; $ namePrefix = '\View\Cell\\' ; $ name = substr ( $ className , strpos ( $ className , $ namePrefix ) + strlen ( $ namePrefix ) ) ; $ view -> context ( str_replace ( '\\' , DIRECTORY_SEPARATOR , $ name ) ) ; return $ view -> render ( $ template ) ; }
Rendeing the cell
22,944
public function routeMatched ( ApiRoute $ route , Request $ request ) : void { if ( ( $ format = $ request -> getParameter ( self :: API_DOCU_STARTER_QUERY_KEY_GENERATE ) ) !== null ) { $ this -> generator -> generateAll ( $ this -> router ) ; exit ( 0 ) ; } if ( ( $ format = $ request -> getParameter ( self :: API_DOCU_STARTER_QUERY_KEY_TARGET ) ) !== null ) { $ this -> generator -> generateTarget ( $ route , $ request ) ; exit ( 0 ) ; } }
Event thatis firex when particular ApiRoute is matched
22,945
public function get ( $ name ) { if ( ! $ this -> exists ( $ name ) ) { throw new PropertyNotExistsException ( $ name ) ; } return $ this -> data [ $ name ] ; }
Returns value for name .
22,946
public function assertAttributeContains ( $ needle , $ haystackAttributeName , $ haystackClassOrObject , $ message = '' , $ ignoreCase = false , $ checkForObjectIdentity = true , $ checkForNonObjectIdentity = false ) { $ this -> callAssertMethod ( __FUNCTION__ , [ 'expected' => $ key , ] ) ; }
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object contains a needle .
22,947
public function assertAttributeContainsOnly ( $ type , $ haystackAttributeName , $ haystackClassOrObject , $ isNativeType = null ) { $ this -> callAssertMethod ( __FUNCTION__ , [ 'expected' => $ key , ] ) ; }
Asserts that a haystack that is stored in a static attribute of a class or an attribute of an object contains only values of a given type .
22,948
public function assertAttributeEquals ( $ expected , $ actualAttributeName , $ actualClassOrObject , $ message = '' , $ delta = 0.0 , $ maxDepth = 10 , $ canonicalize = false , $ ignoreCase = false ) { $ this -> callAssertMethod ( __FUNCTION__ , [ 'expected' => $ key , ] ) ; }
Asserts that a variable is equal to an attribute of an object .
22,949
public function assertFileEquals ( $ expected , $ canonicalize = false , $ ignoreCase = false ) { $ this -> callAssertMethod ( __FUNCTION__ , [ 'expected' => $ expected , 'additionalParams' => [ $ canonicalize , $ ignoreCase , ] , ] ) ; }
Asserts that the contents of one file is equal to the contents of another file .
22,950
public function assertFileNotEquals ( $ expected , $ canonicalize = false , $ ignoreCase = false ) { $ this -> callAssertMethod ( __FUNCTION__ , [ 'expected' => $ expected , 'additionalParams' => [ $ canonicalize , $ ignoreCase , ] , ] ) ; }
Asserts that the contents of one file is not equal to the contents of another file .
22,951
public function assertStringEqualsFile ( $ expectedFile , $ canonicalize = false , $ ignoreCase = false ) { $ this -> callAssertMethod ( __FUNCTION__ , [ 'expected' => $ expectedFile , 'additionalParams' => [ $ canonicalize , $ ignoreCase , ] , ] ) ; }
Asserts that the contents of a string is equal to the contents of a file .
22,952
public function assertStringNotEqualsFile ( $ expectedFile , $ canonicalize = false , $ ignoreCase = false ) { $ this -> callAssertMethod ( __FUNCTION__ , [ 'expected' => $ expectedFile , 'additionalParams' => [ $ canonicalize , $ ignoreCase , ] , ] ) ; }
Asserts that the contents of a string is not equal to the contents of a file .
22,953
public function assertEqualXMLStructure ( \ DOMElement $ expectedElement , $ checkAttributes = false ) { $ this -> callAssertMethod ( __FUNCTION__ , [ 'expected' => $ expectedElement , 'options' => [ $ checkAttributes , ] , ] ) ; }
Asserts that a hierarchy of DOMElements matches .
22,954
protected static function runCallback ( $ method , $ args ) { $ instance = static :: resolveFacadeInstance ( ) ; if ( empty ( $ args ) ) { throw new InvalidArgumentException ( "Please provide an argument to this method" ) ; } switch ( count ( $ args ) ) { case 0 : return $ instance -> $ method ( ) ; case 1 : return $ instance -> $ method ( $ args [ 0 ] ) ; case 2 : return $ instance -> $ method ( $ args [ 0 ] , $ args [ 1 ] ) ; case 3 : return $ instance -> $ method ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] ) ; case 4 : return $ instance -> $ method ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] , $ args [ 3 ] ) ; default : return call_user_func_array ( array ( $ instance , $ method ) , $ args ) ; } }
Facotory method to call the handler methods
22,955
public function set_value ( $ field = '' , $ default = '' ) { if ( ! isset ( $ this -> _field_data [ $ field ] , $ this -> _field_data [ $ field ] [ 'postdata' ] ) ) { return $ default ; } return $ this -> _field_data [ $ field ] [ 'postdata' ] ; }
Get the value from a form
22,956
public function run ( $ group = '' ) { if ( ! empty ( $ this -> validation_data ) || $ this -> CI -> input -> method ( ) === 'post' ) { $ this -> ran = true ; return parent :: run ( $ group ) ; } return false ; }
Run the Validator
22,957
public function redirect404 ( MvcEvent $ e , $ idpage = null ) { $ sm = $ e -> getApplication ( ) -> getServiceManager ( ) ; $ eventManager = $ e -> getApplication ( ) -> getEventManager ( ) ; $ melisTree = $ sm -> get ( 'MelisEngineTree' ) ; $ melisSiteDomain = $ sm -> get ( 'MelisEngineTableSiteDomain' ) ; $ melisSite404 = $ sm -> get ( 'MelisEngineTableSite404' ) ; if ( $ idpage == null ) { $ router = $ e -> getRouter ( ) ; $ uri = $ router -> getRequestUri ( ) ; $ domainTxt = $ uri -> getHost ( ) ; } else { $ domainTxt = $ melisTree -> getDomainByPageId ( $ idpage , true ) ; if ( empty ( $ domainTxt ) ) { $ router = $ e -> getRouter ( ) ; $ uri = $ router -> getRequestUri ( ) ; $ domainTxt = $ uri -> getHost ( ) ; } $ domainTxt = str_replace ( 'http://' , '' , $ domainTxt ) ; $ domainTxt = str_replace ( 'https://' , '' , $ domainTxt ) ; } if ( $ domainTxt ) { $ domain = $ melisSiteDomain -> getEntryByField ( 'sdom_domain' , $ domainTxt ) ; $ domain = $ domain -> current ( ) ; if ( $ domain ) $ siteId = $ domain -> sdom_site_id ; else return '' ; } else return '' ; $ site404 = $ melisSite404 -> getEntryByField ( 's404_site_id' , $ siteId ) ; if ( $ site404 ) { $ site404 = $ site404 -> current ( ) ; if ( empty ( $ site404 ) ) { $ site404 = $ melisSite404 -> getEntryByField ( 's404_site_id' , - 1 ) ; $ site404 = $ site404 -> current ( ) ; } } if ( empty ( $ site404 ) ) { return '' ; } else { $ melisPage = $ sm -> get ( 'MelisEnginePage' ) ; $ datasPage = $ melisPage -> getDatasPage ( $ site404 -> s404_page_id , 'published' ) ; $ pageTree = $ datasPage -> getMelisPageTree ( ) ; if ( empty ( $ pageTree ) ) return '' ; $ link = $ melisTree -> getPageLink ( $ site404 -> s404_page_id , true ) ; return $ link ; } }
Get the 404 page s URL 404 can occur if page is not found or if page is not published This function will try to find the 404 defined for the site of this page if not the general 404 then an empty string if nothing is defined
22,958
public function getQueryParameters ( $ e ) { $ request = $ e -> getRequest ( ) ; $ getString = $ request -> getQuery ( ) -> toString ( ) ; if ( $ getString != '' ) $ getString = '?' . $ getString ; return $ getString ; }
Gets the GET parameters Used to add the possible parameters in a redirected URL
22,959
public function createTranslations ( $ e , $ siteFolder , $ locale ) { $ sm = $ e -> getApplication ( ) -> getServiceManager ( ) ; $ translator = $ sm -> get ( 'translator' ) ; $ langFileTarget = $ _SERVER [ 'DOCUMENT_ROOT' ] . '/../module/MelisSites/' . $ siteFolder . '/language/' . $ locale . '.php' ; if ( ! file_exists ( $ langFileTarget ) ) { $ langFileTarget = $ _SERVER [ 'DOCUMENT_ROOT' ] . '/../module/MelisSites/' . $ siteFolder . '/language/en_EN.php' ; if ( ! file_exists ( $ langFileTarget ) ) { $ langFileTarget = null ; } } else { $ langFileTarget = null ; } if ( ! is_null ( $ langFileTarget ) && ! empty ( $ siteFolder ) && ! empty ( $ locale ) ) { $ translator -> addTranslationFile ( 'phparray' , $ langFileTarget ) ; } }
Creates translation for the appropriate site
22,960
private function createSshConnectionDefinition ( $ sshId , $ serverName , $ directory , $ executable , array $ sshConfig ) { $ connectionDefinition = new Definition ( SshConnection :: class , [ new Reference ( $ sshId ) , new Reference ( 'input' ) , new Reference ( 'output' ) , $ serverName , $ directory , $ executable , $ sshConfig , ] ) ; $ connectionDefinition -> setLazy ( true ) ; return $ connectionDefinition ; }
Create a new ssh - connection .
22,961
private function createCommandDefinition ( $ id , $ connectionId , $ class , $ serverName , $ command ) { $ commandDefinition = new DefinitionDecorator ( $ id ) ; $ commandDefinition -> setClass ( $ class ) ; $ commandDefinition -> setLazy ( true ) ; $ commandDefinition -> replaceArgument ( 0 , new Reference ( $ connectionId ) ) ; $ commandDefinition -> addTag ( 'nanbando.server_command' , [ 'server' => $ serverName , 'command' => $ command ] ) ; return $ commandDefinition ; }
Create a new command definition .
22,962
public function start ( ) { try { $ this -> createClientSocket ( ) ; $ this -> createWorkerJobSocket ( ) ; $ this -> createWorkerReplySocket ( ) ; $ this -> startWorkerPools ( ) ; $ this -> loop -> addPeriodicTimer ( 5 , [ $ this , 'monitorChildProcesses' ] ) ; $ this -> loop -> addPeriodicTimer ( 10 , [ $ this , 'monitorQueue' ] ) ; $ this -> loop -> run ( ) ; } catch ( ServerException $ e ) { $ errorMsgPattern = 'Server error: %s (%s:%d)' ; $ this -> logger -> emergency ( sprintf ( $ errorMsgPattern , $ e -> getMessage ( ) , $ e -> getFile ( ) , $ e -> getLine ( ) ) ) ; } }
Creates sockets and fires up worker processes .
22,963
public function stop ( ) { $ this -> stopWorkerPools ( ) ; $ this -> workerJobSocket -> disconnect ( $ this -> config [ 'sockets' ] [ 'worker_job' ] ) ; $ this -> workerReplySocket -> close ( ) ; $ this -> clientSocket -> close ( ) ; $ this -> loop -> stop ( ) ; }
Close sockets stop worker processes and stop main event loop .
22,964
protected function createClientSocket ( ) { $ clientContext = new Context ( $ this -> loop ) ; $ this -> clientSocket = $ clientContext -> getSocket ( \ ZMQ :: SOCKET_ROUTER ) ; $ this -> clientSocket -> bind ( $ this -> config [ 'sockets' ] [ 'client' ] ) ; $ this -> clientSocket -> on ( 'messages' , [ $ this , 'onClientMessage' ] ) ; }
Creates client - socket and assigns listener .
22,965
protected function createWorkerJobSocket ( ) { $ workerJobContext = new \ ZMQContext ; $ this -> workerJobSocket = $ workerJobContext -> getSocket ( \ ZMQ :: SOCKET_PUB ) ; $ this -> workerJobSocket -> bind ( $ this -> config [ 'sockets' ] [ 'worker_job' ] ) ; }
Creates worker - job - socket .
22,966
protected function createWorkerReplySocket ( ) { $ workerReplyContext = new Context ( $ this -> loop ) ; $ this -> workerReplySocket = $ workerReplyContext -> getSocket ( \ ZMQ :: SOCKET_REP ) ; $ this -> workerReplySocket -> bind ( $ this -> config [ 'sockets' ] [ 'worker_reply' ] ) ; $ this -> workerReplySocket -> on ( 'message' , [ $ this , 'onWorkerReplyMessage' ] ) ; }
Creates worker - reply - socket and assigns listener .
22,967
public function onClientMessage ( array $ message ) { try { $ clientAddress = $ message [ 0 ] ; $ data = json_decode ( $ message [ 2 ] , true ) ; if ( empty ( $ clientAddress ) || empty ( $ data ) || ! isset ( $ data [ 'action' ] ) ) { throw new ServerException ( 'Received malformed client message.' ) ; } switch ( $ data [ 'action' ] ) { case 'command' : $ this -> handleCommand ( $ clientAddress , $ data [ 'command' ] [ 'name' ] ) ; break ; case 'job' : $ this -> handleJobRequest ( $ clientAddress , $ data [ 'job' ] [ 'name' ] , $ data [ 'job' ] [ 'workload' ] , false ) ; break ; case 'background_job' : $ this -> handleJobRequest ( $ clientAddress , $ data [ 'job' ] [ 'name' ] , $ data [ 'job' ] [ 'workload' ] , true ) ; break ; default : $ this -> clientSocket -> send ( 'error: unknown action' ) ; throw new ServerException ( 'Received request for invalid action.' ) ; } } catch ( ServerException $ e ) { $ errorMsgPattern = 'Client message error: %s (%s:%d)' ; $ this -> logger -> error ( sprintf ( $ errorMsgPattern , $ e -> getMessage ( ) , $ e -> getFile ( ) , $ e -> getLine ( ) ) ) ; } }
Handles incoming client requests .
22,968
public function onWorkerReplyMessage ( string $ message ) { try { $ data = json_decode ( $ message , true ) ; if ( empty ( $ data ) || ! isset ( $ data [ 'request' ] ) ) { throw new ServerException ( 'Invalid worker request received.' ) ; } $ result = null ; switch ( $ data [ 'request' ] ) { case 'register_job' : $ result = $ this -> registerJob ( $ data [ 'job_name' ] , $ data [ 'worker_id' ] ) ; break ; case 'unregister_job' : $ result = $ this -> unregisterJob ( $ data [ 'job_name' ] , $ data [ 'worker_id' ] ) ; break ; case 'change_state' : $ result = $ this -> changeWorkerState ( $ data [ 'worker_id' ] , $ data [ 'state' ] ) ; break ; case 'job_completed' : $ this -> onJobCompleted ( $ data [ 'worker_id' ] , $ data [ 'job_id' ] , $ data [ 'result' ] ) ; break ; } $ response = ( $ result === true ) ? 'ok' : 'error' ; $ this -> workerReplySocket -> send ( $ response ) ; } catch ( ServerException $ e ) { $ errorMsgPattern = 'Worker message error: %s (%s:%d)' ; $ this -> logger -> error ( sprintf ( $ errorMsgPattern , $ e -> getMessage ( ) , $ e -> getFile ( ) , $ e -> getLine ( ) ) ) ; } }
Handles incoming worker requests .
22,969
public function onChildProcessExit ( $ exitCode , $ termSignal ) { $ this -> logger -> error ( sprintf ( 'Child process exited. (Code: %d, Signal: %d)' , $ exitCode , $ termSignal ) ) ; $ this -> monitorChildProcesses ( ) ; }
Handles exit signals of child processes .
22,970
protected function respondToClient ( string $ address , string $ payload = '' ) { try { $ clientSocket = $ this -> clientSocket -> getWrappedSocket ( ) ; $ clientSocket -> send ( $ address , \ ZMQ :: MODE_SNDMORE ) ; $ clientSocket -> send ( '' , \ ZMQ :: MODE_SNDMORE ) ; $ clientSocket -> send ( $ payload ) ; } catch ( \ ZMQException $ e ) { $ this -> logger -> error ( 'Error respoding to client: ' . $ e -> getMessage ( ) ) ; } }
Responds to a client request .
22,971
protected function registerJob ( string $ jobName , string $ workerId ) : bool { if ( ! isset ( $ this -> workerJobCapabilities [ $ workerId ] ) ) { $ this -> workerJobCapabilities [ $ workerId ] = [ ] ; } if ( ! in_array ( $ jobName , $ this -> workerJobCapabilities [ $ workerId ] ) ) { array_push ( $ this -> workerJobCapabilities [ $ workerId ] , $ jobName ) ; } return true ; }
Registers a new job - type a workers is capable of doing .
22,972
protected function unregisterJob ( string $ jobName , string $ workerId ) : bool { if ( ! isset ( $ this -> workerJobCapabilities [ $ jobName ] ) ) { return true ; } if ( ( $ key = array_search ( $ workerId , $ this -> workerJobCapabilities [ $ jobName ] ) ) !== false ) { unset ( $ this -> workerJobCapabilities [ $ jobName ] [ $ key ] ) ; } if ( empty ( $ this -> workerJobCapabilities [ $ jobName ] ) ) { unset ( $ this -> workerJobCapabilities [ $ jobName ] ) ; } return true ; }
Unregisters a job - type so the worker will no longer receive jobs of this type .
22,973
protected function changeWorkerState ( string $ workerId , int $ workerState ) : bool { $ this -> workerStates [ $ workerId ] = $ workerState ; if ( $ workerState === Worker :: WORKER_STATE_IDLE ) { $ this -> pushJobs ( ) ; } return true ; }
Changes the state a worker currently has .
22,974
protected function onJobCompleted ( string $ workerId , string $ jobId , string $ result = '' ) { $ jobType = $ this -> jobTypes [ $ jobId ] ; $ clientAddress = $ this -> jobAddresses [ $ jobId ] ; if ( $ jobType === 'normal' ) { $ this -> respondToClient ( $ clientAddress , $ result ) ; } unset ( $ this -> jobTypes [ $ jobId ] , $ this -> jobAddresses [ $ jobId ] , $ this -> workerJobMap [ $ workerId ] ) ; }
Handles a completed job . Sends results back to client if it was not a background job .
22,975
protected function handleCommand ( string $ clientAddress , string $ command ) : bool { switch ( $ command ) { case 'stop' : $ this -> respondToClient ( $ clientAddress , 'ok' ) ; $ this -> stop ( ) ; return true ; case 'status' : $ statusData = $ this -> getStatusData ( ) ; $ this -> respondToClient ( $ clientAddress , json_encode ( $ statusData ) ) ; return true ; case 'flush_queue' : $ result = ( $ this -> flushQueue ( ) === true ) ? 'ok' : 'error' ; $ this -> respondToClient ( $ clientAddress , $ result ) ; return true ; } $ this -> respondToClient ( $ clientAddress , 'error' ) ; throw new ServerException ( 'Received unknown command.' ) ; }
Executes commands received from a client .
22,976
protected function handleJobRequest ( string $ clientAddress , string $ jobName , string $ payload = '' , bool $ backgroundJob = false ) : string { $ jobId = $ this -> addJobToQueue ( $ jobName , $ payload ) ; $ this -> jobTypes [ $ jobId ] = ( $ backgroundJob === true ) ? 'background' : 'normal' ; $ this -> jobAddresses [ $ jobId ] = $ clientAddress ; $ this -> pushJobs ( ) ; if ( $ backgroundJob === true ) { $ this -> respondToClient ( $ clientAddress , $ jobId ) ; } $ this -> totalJobRequests ++ ; return $ jobId ; }
Handles job - requests received from a client .
22,977
protected function addJobToQueue ( string $ jobName , string $ payload = '' ) : string { if ( ! isset ( $ this -> jobQueues [ $ jobName ] ) ) { $ this -> jobQueues [ $ jobName ] = [ ] ; } $ jobId = $ this -> getJobId ( ) ; array_push ( $ this -> jobQueues [ $ jobName ] , [ 'job_id' => $ jobId , 'payload' => $ payload ] ) ; $ this -> jobsInQueue ++ ; return $ jobId ; }
Adds a new job - requests to corresponding queue .
22,978
protected function pushJobs ( ) : bool { if ( empty ( $ this -> jobQueues ) ) { return true ; } foreach ( $ this -> workerStates as $ workerId => $ workerState ) { if ( $ workerState !== Worker :: WORKER_STATE_IDLE ) { continue ; } $ jobData = $ this -> getJobFromQueue ( $ workerId ) ; if ( empty ( $ jobData ) ) { continue ; } try { $ this -> workerStats [ $ workerId ] ++ ; $ this -> workerJobMap [ $ workerId ] = $ jobData [ 'job_id' ] ; $ this -> workerJobSocket -> send ( $ jobData [ 'job_name' ] , \ ZMQ :: MODE_SNDMORE ) ; $ this -> workerJobSocket -> send ( $ jobData [ 'job_id' ] , \ ZMQ :: MODE_SNDMORE ) ; $ this -> workerJobSocket -> send ( $ workerId , \ ZMQ :: MODE_SNDMORE ) ; $ this -> workerJobSocket -> send ( $ jobData [ 'payload' ] ) ; } catch ( \ ZMQException $ e ) { $ this -> logger -> error ( 'Error sending job to worker: ' . $ e -> getMessage ( ) ) ; } } return true ; }
Runs trough the job queue and pushes jobs to workers if an idle worker is available .
22,979
protected function startWorkerPools ( ) : bool { if ( empty ( $ this -> config [ 'pool' ] ) ) { throw new ServerException ( 'No worker pool defined. Check config file.' ) ; } foreach ( $ this -> config [ 'pool' ] as $ poolName => $ poolConfig ) { $ this -> startWorkerPool ( $ poolName , $ poolConfig ) ; } return true ; }
Starts all worker pools defined in configuration .
22,980
protected function startWorkerPool ( string $ poolName , array $ poolConfig ) { if ( ! isset ( $ poolConfig [ 'worker_file' ] ) ) { throw new ServerException ( 'Path to worker file not set in pool config.' ) ; } $ this -> processes [ $ poolName ] = [ ] ; $ processesToStart = $ poolConfig [ 'cp_start' ] ?? 5 ; for ( $ i = 0 ; $ i < $ processesToStart ; $ i ++ ) { try { $ process = $ this -> startChildProcess ( $ poolConfig [ 'worker_file' ] ) ; $ this -> registerChildProcess ( $ process , $ poolName ) ; } catch ( \ Exception $ e ) { throw new ServerException ( 'Could not start child process.' ) ; } } }
Starts child processes as defined in pool configuration .
22,981
protected function stopWorkerPools ( ) : bool { if ( empty ( $ this -> processes ) ) { return true ; } foreach ( array_keys ( $ this -> processes ) as $ poolName ) { $ this -> stopWorkerPool ( $ poolName ) ; } return true ; }
Stops processes of all pools .
22,982
protected function stopWorkerPool ( string $ poolName ) : bool { if ( empty ( $ this -> processes [ $ poolName ] ) ) { return true ; } foreach ( $ this -> processes [ $ poolName ] as $ process ) { $ process -> terminate ( ) ; } return true ; }
Terminates all child processes of given pool .
22,983
protected function monitorPoolProcesses ( string $ poolName ) : bool { if ( empty ( $ this -> processes [ $ poolName ] ) ) { return true ; } foreach ( $ this -> processes [ $ poolName ] as $ i => $ process ) { $ pid = $ process -> getPid ( ) ; $ workerId = $ this -> config [ 'server_id' ] . '_' . $ pid ; if ( $ process -> isRunning ( ) === true ) { continue ; } $ this -> unregisterChildProcess ( $ workerId ) ; unset ( $ this -> processes [ $ poolName ] [ $ i ] ) ; $ workerFile = $ this -> config [ 'pool' ] [ $ poolName ] [ 'worker_file' ] ; $ process = $ this -> startChildProcess ( $ workerFile ) ; $ this -> registerChildProcess ( $ process , $ poolName ) ; } return true ; }
Checks state of every process in pool and restarts processes if necessary .
22,984
public function monitorQueue ( ) : bool { if ( $ this -> jobsInQueue === 0 ) { return true ; } foreach ( array_keys ( $ this -> jobQueues ) as $ jobName ) { if ( empty ( $ this -> jobQueues [ $ jobName ] ) ) { continue ; } if ( $ this -> jobCanBeProcessed ( $ jobName ) ) { continue ; } $ jobsCount = count ( $ this -> jobQueues [ $ jobName ] ) ; $ this -> jobQueues [ $ jobName ] = [ ] ; $ this -> jobsInQueue -= $ jobsCount ; } return $ this -> pushJobs ( ) ; }
Cleanup jobs that are not handled correctly for some reason .
22,985
protected function jobCanBeProcessed ( string $ jobName ) : bool { foreach ( $ this -> workerJobCapabilities as $ workerId => $ jobs ) { if ( in_array ( $ jobName , $ jobs ) ) { return true ; } } return false ; }
Check if there is a least one worker capable of doing requested job type .
22,986
protected function getStatusData ( ) : array { $ statusData = [ 'version' => self :: VERSION , 'starttime' => '' , 'uptime' => '' , 'active_worker' => [ ] , 'job_info' => [ ] , ] ; $ starttime = date ( 'Y-m-d H:i:s' , $ this -> startTime ) ; $ start = new \ DateTime ( $ starttime ) ; $ now = new \ DateTime ( 'now' ) ; $ uptime = $ start -> diff ( $ now ) -> format ( '%ad %Hh %Im %Ss' ) ; $ statusData [ 'starttime' ] = $ starttime ; $ statusData [ 'uptime' ] = $ uptime ; foreach ( array_keys ( $ this -> processes ) as $ poolName ) { if ( ! isset ( $ statusData [ 'active_worker' ] [ $ poolName ] ) ) { $ statusData [ 'active_worker' ] [ $ poolName ] = 0 ; } foreach ( $ this -> processes [ $ poolName ] as $ process ) { $ processIsRunning = $ process -> isRunning ( ) ; if ( $ processIsRunning === true ) { $ statusData [ 'active_worker' ] [ $ poolName ] ++ ; } } } $ statusData [ 'job_info' ] [ 'job_requests_total' ] = $ this -> totalJobRequests ; $ statusData [ 'job_info' ] [ 'queue_length' ] = $ this -> jobsInQueue ; $ statusData [ 'job_info' ] [ 'worker_stats' ] = $ this -> workerStats ; return $ statusData ; }
Collects server and worker status information to send back to client .
22,987
protected function registerChildProcess ( Process $ process , string $ poolName ) : bool { array_push ( $ this -> processes [ $ poolName ] , $ process ) ; $ workerPid = $ process -> getPid ( ) ; $ workerId = $ this -> config [ 'server_id' ] . '_' . $ workerPid ; $ this -> workerStates [ $ workerId ] = Worker :: WORKER_STATE_IDLE ; $ this -> workerStats [ $ workerId ] = 0 ; return true ; }
Registers new child - process at server .
22,988
protected function flushQueue ( ) : bool { foreach ( array_keys ( $ this -> jobQueues ) as $ jobName ) { $ this -> jobQueues [ $ jobName ] = [ ] ; } $ this -> jobsInQueue = 0 ; return true ; }
Removes jobs from all queues .
22,989
public function addName ( \ google \ protobuf \ UninterpretedOption \ NamePart $ value ) { if ( $ this -> name === null ) { $ this -> name = new \ Protobuf \ MessageCollection ( ) ; } $ this -> name -> add ( $ value ) ; }
Add a new element to name
22,990
public function setStringValue ( $ value = null ) { if ( $ value !== null && ! $ value instanceof \ Protobuf \ Stream ) { $ value = \ Protobuf \ Stream :: wrap ( $ value ) ; } $ this -> string_value = $ value ; }
Set string_value value
22,991
protected function prepareAttributes ( ) { try { $ parentId = $ this -> getValue ( ColumnKeys :: IMAGE_PARENT_SKU , null , array ( $ this , 'mapParentSku' ) ) ; } catch ( \ Exception $ e ) { throw $ this -> wrapException ( array ( ColumnKeys :: IMAGE_PARENT_SKU ) , $ e ) ; } $ storeId = $ this -> getRowStoreId ( StoreViewCodes :: ADMIN ) ; $ valueId = $ this -> getParentValueId ( ) ; $ position = $ this -> raisePositionCounter ( ) ; $ imageLabel = $ this -> getValue ( ColumnKeys :: IMAGE_LABEL ) ; return $ this -> initializeEntity ( array ( MemberNames :: VALUE_ID => $ valueId , MemberNames :: STORE_ID => $ storeId , MemberNames :: ENTITY_ID => $ parentId , MemberNames :: LABEL => $ imageLabel , MemberNames :: POSITION => $ position , MemberNames :: DISABLED => 0 ) ) ; }
Prepare the product media gallery value that has to be persisted .
22,992
protected function getRequestData ( ) { if ( $ this -> PWE -> getHeader ( 'content-type' ) != 'application/json' ) { throw new HTTP4xxException ( "API requires 'application/json' as type for request body" , HTTP4xxException :: UNSUPPORTED_MEDIA_TYPE ) ; } return json_decode ( file_get_contents ( "php://input" ) , true ) ; }
Reads request body as JSON
22,993
protected function handleGet ( $ item = null ) { PWELogger :: debug ( $ _SERVER [ 'REQUEST_METHOD' ] . ": %s" , $ item ) ; throw new HTTP5xxException ( 'Not supported method for this call: ' . $ _SERVER [ 'REQUEST_METHOD' ] , HTTP5xxException :: UNIMPLEMENTED ) ; }
Should implement get collection or single item
22,994
protected function handlePut ( $ item , $ data ) { PWELogger :: debug ( $ _SERVER [ 'REQUEST_METHOD' ] . ": %s %s" , $ item , $ data ) ; throw new HTTP5xxException ( 'Not supported method for this call: ' . $ _SERVER [ 'REQUEST_METHOD' ] , HTTP5xxException :: UNIMPLEMENTED ) ; }
Should implement update
22,995
protected function handlePost ( $ data ) { PWELogger :: debug ( $ _SERVER [ 'REQUEST_METHOD' ] . ": %s" , $ data ) ; throw new HTTP5xxException ( 'Not supported method for this call: ' . $ _SERVER [ 'REQUEST_METHOD' ] , HTTP5xxException :: UNIMPLEMENTED ) ; }
Should implement create and return code 201 on success
22,996
protected function handleDelete ( $ item ) { PWELogger :: debug ( $ _SERVER [ 'REQUEST_METHOD' ] . ": %s" , $ item ) ; throw new HTTP5xxException ( 'Not supported method for this call: ' . $ _SERVER [ 'REQUEST_METHOD' ] , HTTP5xxException :: UNIMPLEMENTED ) ; }
Should implement deleting item
22,997
protected function handlePatch ( $ item , $ data ) { PWELogger :: debug ( $ _SERVER [ 'REQUEST_METHOD' ] . ": %s %s" , $ item , $ data ) ; throw new HTTP5xxException ( 'Not supported method for this call: ' . $ _SERVER [ 'REQUEST_METHOD' ] , HTTP5xxException :: UNIMPLEMENTED ) ; }
Should implement partial update
22,998
protected function init_shortcode ( $ tag ) { $ shortcode_class = $ this -> get_shortcode_class ( $ tag ) ; $ shortcode_atts_parser = $ this -> get_shortcode_atts_parser_class ( $ tag ) ; $ atts_parser = $ this -> instantiate ( ShortcodeAttsParserInterface :: class , $ shortcode_atts_parser , [ 'config' => $ this -> config -> getSubConfig ( $ tag ) ] ) ; $ this -> shortcodes [ ] = $ this -> instantiate ( ShortcodeInterface :: class , $ shortcode_class , [ 'shortcode_tag' => $ tag , 'config' => $ this -> config -> getSubConfig ( $ tag ) , 'atts_parser' => $ atts_parser , 'dependencies' => $ this -> dependencies , 'view_builder' => $ this -> view_builder , ] ) ; if ( $ this -> hasConfigKey ( $ tag , self :: KEY_UI ) ) { $ this -> init_shortcode_ui ( $ tag ) ; } }
Initialize a single shortcode .
22,999
protected function get_shortcode_class ( $ tag ) { $ shortcode_class = $ this -> hasConfigKey ( $ tag , self :: KEY_CUSTOM_CLASS ) ? $ this -> getConfigKey ( $ tag , self :: KEY_CUSTOM_CLASS ) : self :: DEFAULT_SHORTCODE ; return $ shortcode_class ; }
Get the class name of an implementation of the ShortcodeInterface .