idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
12,600
public static function oxford ( array $ items , $ conjunction = 'and' ) { $ count = count ( $ items ) ; if ( $ count < 2 ) { return ( string ) reset ( $ items ) ; } elseif ( $ count === 2 ) { return reset ( $ items ) . ' ' . $ conjunction . ' ' . end ( $ items ) ; } else { $ items [ ] = $ conjunction . ' ' . array_pop ( $ items ) ; return implode ( ', ' , $ items ) ; } }
Formats a set of strings with an Oxford comma .
12,601
public static function entityClass ( EntityTypeInterface $ entity_type , $ replacement_class ) { if ( get_parent_class ( $ replacement_class ) == $ entity_type -> getClass ( ) ) { $ entity_type -> setClass ( $ replacement_class ) ; } }
Overrides the entity class for an entity type .
12,602
public static function entityForm ( EntityTypeInterface $ entity_type , $ replacement_class , $ operation = 'default' ) { if ( get_parent_class ( $ replacement_class ) == $ entity_type -> getFormClass ( $ operation ) ) { $ entity_type -> setFormClass ( $ operation , $ replacement_class ) ; } }
Overrides the class used for an entity form .
12,603
public static function entityHandler ( EntityTypeInterface $ entity_type , $ handler_type , $ replacement_class ) { if ( get_parent_class ( $ replacement_class ) == $ entity_type -> getHandlerClass ( $ handler_type ) ) { $ entity_type -> setHandlerClass ( $ handler_type , $ replacement_class ) ; } }
Overrides the class used for an entity handler .
12,604
public function processUploadElement ( array $ element , FormStateInterface $ form_state ) { $ element = AjaxUpload :: process ( $ element , $ form_state ) ; $ element [ 'upload' ] [ '#ajax' ] [ 'callback' ] = $ element [ 'remove' ] [ '#ajax' ] [ 'callback' ] = [ static :: class , 'ajax' ] ; $ element [ 'remove' ] [ '#value' ] = $ this -> t ( 'Cancel' ) ; return $ element ; }
Processes the upload element .
12,605
public function loadEntitiesByProperties ( $ entity_type , array $ values ) { $ entities = $ this -> entityTypeManager -> getStorage ( $ entity_type ) -> loadByProperties ( $ values ) ; if ( ! empty ( $ entities ) ) { return $ entities ; } }
Load entity by property .
12,606
public function mapBasicField ( array & $ values , $ field_name ) { $ item = $ this -> item ; if ( ! empty ( $ item [ $ field_name ] ) ) { $ values [ $ field_name ] = $ item [ $ field_name ] ; } }
Maps a base field .
12,607
public function mapParagraphField ( array $ paragraphs ) { $ entities = \ Drupal :: classResolver ( ) -> getInstanceFromDefinition ( InstallHelper :: class ) -> importParagraphs ( $ paragraphs ) ; if ( ! empty ( $ entities ) ) { return $ entities ; } return [ ] ; }
Maps a paragraph field .
12,608
public function populateMediaField ( $ field_name ) { $ item = $ this -> item ; $ assets = [ ] ; if ( ! empty ( $ item [ $ field_name ] ) ) { $ data = $ this -> loadDataArray ( 'media_image' ) ; foreach ( $ item [ $ field_name ] as $ k => $ value ) { if ( ! empty ( $ data [ $ value ] ) ) { $ name = $ data [ $ value ] [ 'name' ] ; $ entities = $ this -> loadEntitiesByProperties ( 'media' , [ 'name' => $ name ] ) ; foreach ( $ entities as $ entity ) { $ assets [ ] = [ 'target_id' => $ entity -> id ( ) ] ; } } } return $ assets ; } }
Finds a media asset by name .
12,609
public function mapTaxonomyTermField ( $ field_name , $ vid ) { $ entities = $ this -> populateTaxonomyTermField ( $ field_name , $ vid ) ; if ( ! empty ( $ entities ) ) { return $ entities ; } return [ ] ; }
Maps a taxonomy field .
12,610
public function populateTaxonomyTermField ( $ field_name , $ vid ) { $ item = $ this -> item ; $ terms = [ ] ; if ( ! empty ( $ item [ $ field_name ] ) ) { $ data = $ this -> loadDataArray ( 'taxonomy' ) ; foreach ( $ item [ $ field_name ] as $ k => $ value ) { if ( ! empty ( $ data [ $ value ] ) ) { $ name = $ data [ $ value ] [ 'name' ] ; $ entities = $ this -> loadEntitiesByProperties ( 'taxonomy_term' , [ 'name' => $ name , 'vid' => $ vid ] ) ; foreach ( $ entities as $ entity ) { $ terms [ ] = [ 'target_id' => $ entity -> id ( ) ] ; } } } return $ terms ; } }
Finds taxonomy terms by name and vid .
12,611
public function populateEntityReferenceField ( $ field_name ) { $ item = $ this -> item ; $ node = [ ] ; if ( ! empty ( $ item [ $ field_name ] ) ) { $ data = $ this -> loadDataArray ( 'node' ) ; foreach ( $ item [ $ field_name ] as $ k => $ value ) { if ( ! empty ( $ data [ $ value ] ) ) { $ title = $ data [ $ value ] [ 'title' ] ; $ entities = $ this -> loadEntitiesByProperties ( 'node' , [ 'title' => $ title ] ) ; foreach ( $ entities as $ entity ) { $ node [ ] = [ 'target_id' => $ entity -> id ( ) ] ; } } } } return $ node ; }
Finds nodes by machine name .
12,612
protected function importPages ( ) { $ data = $ this -> loadDataArray ( 'node' ) ; if ( ! empty ( $ data ) ) { $ uuids = [ ] ; foreach ( $ data as $ item ) { $ values = [ 'type' => $ item [ 'type' ] , 'title' => $ item [ 'title' ] , ] ; if ( ! empty ( $ item [ 'body' ] ) ) { $ body = $ this -> getBodyData ( $ item [ 'body' ] ) ; if ( $ body !== FALSE ) { $ values [ 'body' ] = [ 'value' => $ body , 'format' => 'rich_text' , ] ; } } if ( ! empty ( $ item [ 'summary' ] ) ) { $ values [ 'body' ] [ 'summary' ] = $ item [ 'summary' ] ; } if ( ! empty ( $ item [ 'path' ] ) ) { $ values [ 'path' ] = [ 'alias' => $ item [ 'path' ] , 'pathauto' => 0 , ] ; } $ this -> loadProcessorPlugins ( $ values , $ item , 'node' ) ; $ values [ 'uid' ] = 1 ; $ node = $ this -> entityTypeManager -> getStorage ( 'node' ) -> create ( $ values ) ; $ node -> setPublished ( TRUE ) ; $ node -> set ( 'moderation_state' , "published" ) ; $ node -> save ( ) ; if ( ! empty ( $ item [ 'menu' ] ) ) { $ item [ 'menu' ] [ 'link' ] = [ 'uri' => 'internal:/node/' . $ node -> id ( ) , ] ; $ menu_link = $ this -> entityTypeManager -> getStorage ( 'menu_link_content' ) -> create ( $ item [ 'menu' ] ) ; $ menu_link -> save ( ) ; } if ( ! empty ( $ item [ 'front_page' ] ) && $ item [ 'front_page' ] == TRUE ) { \ Drupal :: service ( 'config.factory' ) -> getEditable ( 'system.site' ) -> set ( 'page.front' , '/node/' . $ node -> id ( ) ) -> save ( ) ; } $ uuids [ $ node -> uuid ( ) ] = 'node' ; } $ this -> storeCreatedContentUuids ( $ uuids ) ; } return $ this ; }
Imports pages .
12,613
protected function importMediaImages ( ) { $ data = $ this -> loadDataArray ( 'media_image' ) ; if ( ! empty ( $ data ) ) { $ uuids = [ ] ; foreach ( $ data as $ item ) { $ values = [ 'bundle' => $ item [ 'bundle' ] , 'name' => $ item [ 'name' ] , ] ; $ file = $ this -> saveFile ( $ item [ 'file' ] ) ; if ( ! empty ( $ file ) && $ file instanceof File ) { $ values [ 'field_media_image' ] = [ 'target_id' => $ file -> id ( ) , 'alt' => $ item [ 'alt' ] , ] ; } $ values [ 'uid' ] = 1 ; $ entity = $ this -> entityTypeManager -> getStorage ( 'media' ) -> create ( $ values ) ; $ entity -> save ( ) ; $ uuids [ $ entity -> uuid ( ) ] = 'media' ; } $ this -> storeCreatedContentUuids ( $ uuids ) ; } return $ this ; }
Import media assets .
12,614
protected function importTaxonomyTerms ( ) { $ data = $ this -> loadDataArray ( 'taxonomy' ) ; if ( ! empty ( $ data ) ) { $ uuids = [ ] ; foreach ( $ data as $ item ) { $ values = [ 'vid' => $ item [ 'vid' ] , 'name' => $ item [ 'name' ] , ] ; $ values [ 'uid' ] = 1 ; $ entity = $ this -> entityTypeManager -> getStorage ( 'taxonomy_term' ) -> create ( $ values ) ; $ entity -> save ( ) ; $ uuids [ $ entity -> uuid ( ) ] = 'taxonomy_term' ; } $ this -> storeCreatedContentUuids ( $ uuids ) ; } return $ this ; }
Import taxonomy terms .
12,615
public function importParagraphs ( array $ paragraphs ) { $ data = $ this -> loadDataArray ( 'paragraph' ) ; $ paragraph_items = [ ] ; $ uuids = [ ] ; foreach ( $ paragraphs as $ k => $ paragraph_data ) { $ item = $ data [ $ paragraph_data ] ; if ( ! empty ( $ item ) ) { $ values = [ 'type' => $ item [ 'type' ] , ] ; if ( ! empty ( $ item [ 'field_body' ] ) ) { $ body = $ this -> getBodyData ( $ item [ 'field_body' ] ) ; if ( $ body !== FALSE ) { $ values [ 'field_body' ] = [ 'value' => $ body , 'format' => 'rich_text' , ] ; } } if ( ! empty ( $ item [ 'field_title' ] ) ) { $ values [ 'field_title' ] = $ item [ 'field_title' ] ; } if ( ! empty ( $ item [ 'field_heading' ] ) ) { $ values [ 'field_heading' ] = $ item [ 'field_heading' ] ; } $ this -> loadProcessorPlugins ( $ values , $ item , 'paragraph' ) ; $ values [ 'uid' ] = 1 ; $ entity = $ this -> entityTypeManager -> getStorage ( 'paragraph' ) -> create ( $ values ) ; $ entity -> save ( ) ; $ uuids [ $ entity -> uuid ( ) ] = 'paragraph' ; $ paragraph_items [ ] = $ entity ; } } $ this -> storeCreatedContentUuids ( $ uuids ) ; return $ paragraph_items ; }
Import paragraphs .
12,616
public function getBodyData ( $ body ) { $ module_path = $ this -> moduleHandler -> getModule ( 'govcms8_default_content' ) -> getPath ( ) ; if ( ! empty ( $ body ) ) { if ( is_array ( $ body ) && ! empty ( $ body [ 'file' ] ) ) { $ file = $ body [ 'file' ] ; $ body_path = $ module_path . '/import/html_body/' . $ file ; $ body_html = file_get_contents ( $ body_path ) ; if ( $ body_html !== FALSE ) { return $ body_html ; } } else { return $ body ; } } }
Retrieves the body data from the array value or an HTML file .
12,617
public function loadProcessorPlugins ( & $ values , $ item , $ entity_type ) { $ manager = \ Drupal :: service ( 'plugin.manager.import_processor' ) ; $ import_processors = $ manager -> getDefinitions ( ) ; foreach ( $ import_processors as $ plugin_id => $ import_processor ) { if ( $ import_processor [ 'type' ] == $ entity_type . ':' . $ item [ 'type' ] ) { $ processor = $ manager -> createInstance ( $ plugin_id ) ; $ processor -> setItem ( $ item ) ; $ processor -> process ( $ values ) ; } } }
Helper method used to load the correct plugin .
12,618
public function saveFile ( $ file_name ) { $ path = 'public://govcms8-demo' ; if ( file_prepare_directory ( $ path , FILE_CREATE_DIRECTORY ) ) { $ source = DRUPAL_ROOT . '/' . drupal_get_path ( 'module' , 'govcms8_default_content' ) . '/import/images/' . $ file_name ; $ data = file_get_contents ( $ source ) ; return file_save_data ( $ data , "public://govcms8-demo/" . $ file_name , FILE_EXISTS_RENAME ) ; } }
Save a file during the media import .
12,619
public function deleteImportedContent ( ) { $ uuids = $ this -> state -> get ( 'govcms8_default_content_uuids' , [ ] ) ; $ by_entity_type = array_reduce ( array_keys ( $ uuids ) , function ( $ carry , $ uuid ) use ( $ uuids ) { $ entity_type_id = $ uuids [ $ uuid ] ; $ carry [ $ entity_type_id ] [ ] = $ uuid ; return $ carry ; } , [ ] ) ; foreach ( $ by_entity_type as $ entity_type_id => $ entity_uuids ) { $ storage = $ this -> entityTypeManager -> getStorage ( $ entity_type_id ) ; $ entities = $ storage -> loadByProperties ( [ 'uuid' => $ entity_uuids ] ) ; $ storage -> delete ( $ entities ) ; } return $ this ; }
Deletes any content imported by this module .
12,620
protected function getUser ( $ name ) { $ user_storage = $ this -> entityTypeManager -> getStorage ( 'user' ) ; $ users = $ user_storage -> loadByProperties ( [ 'name' => $ name ] ) ; ; if ( empty ( $ users ) ) { $ user = $ user_storage -> create ( [ 'name' => $ name , 'status' => 1 , ] ) ; $ user -> enforceIsNew ( ) ; $ user -> save ( ) ; $ this -> storeCreatedContentUuids ( [ $ user -> uuid ( ) => 'user' ] ) ; return $ user -> id ( ) ; } $ user = reset ( $ users ) ; return $ user -> id ( ) ; }
Looks up a user by name if it is missing the user is created .
12,621
protected function getTerm ( $ term_name , $ vocabulary_id = 'tags' ) { $ term_name = trim ( $ term_name ) ; $ term_storage = $ this -> entityTypeManager -> getStorage ( 'taxonomy_term' ) ; $ terms = $ term_storage -> loadByProperties ( [ 'name' => $ term_name , 'vid' => $ vocabulary_id , ] ) ; if ( ! $ terms ) { $ term = $ term_storage -> create ( [ 'name' => $ term_name , 'vid' => $ vocabulary_id , 'path' => [ 'alias' => '/' . Html :: getClass ( $ vocabulary_id ) . '/' . Html :: getClass ( $ term_name ) ] , ] ) ; $ term -> save ( ) ; $ this -> storeCreatedContentUuids ( [ $ term -> uuid ( ) => 'taxonomy_term' ] ) ; return $ term -> id ( ) ; } $ term = reset ( $ terms ) ; return $ term -> id ( ) ; }
Looks up a term by name if it is missing the term is created .
12,622
protected function createFileEntity ( $ path ) { $ uri = $ this -> fileUnmanagedCopy ( $ path ) ; $ file = $ this -> entityTypeManager -> getStorage ( 'file' ) -> create ( [ 'uri' => $ uri , 'status' => 1 , ] ) ; $ file -> save ( ) ; $ this -> storeCreatedContentUuids ( [ $ file -> uuid ( ) => 'file' ] ) ; return $ file -> id ( ) ; }
Creates a file entity based on an image path .
12,623
protected function storeCreatedContentUuids ( array $ uuids ) { $ uuids = $ this -> state -> get ( 'govcms8_default_content_uuids' , [ ] ) + $ uuids ; $ this -> state -> set ( 'govcms8_default_content_uuids' , $ uuids ) ; }
Stores record of content entities created by this import .
12,624
private function toDms ( float $ decimal , string $ axis = self :: LATITUDE ) : string { $ d = ( int ) floor ( abs ( $ decimal ) ) ; $ m = ( int ) floor ( ( abs ( $ decimal ) - $ d ) * 60 ) ; $ s = ( ( abs ( $ decimal ) - $ d ) * 60 - $ m ) * 60 ; if ( self :: LATITUDE === $ axis ) { $ h = ( $ decimal < 0 ) ? 'S' : 'N' ; } else { $ h = ( $ decimal < 0 ) ? 'W' : 'E' ; } return sprintf ( '%d %d %.3f %s' , $ d , $ m , $ s , $ h ) ; }
Determine the degree minute seconds value from decimal .
12,625
private static function fullyQualify ( string $ subdomain , string $ parent ) : string { if ( '@' === $ subdomain ) { return $ parent ; } if ( '.' !== substr ( $ subdomain , - 1 , 1 ) ) { return $ subdomain . '.' . $ parent ; } return $ subdomain ; }
Add the parent domain to the sub - domain if the sub - domain if it is not fully qualified .
12,626
private function processResourceName ( \ ArrayIterator $ iterator , ResourceRecord $ resourceRecord ) : void { if ( $ this -> isResourceName ( $ iterator ) ) { $ this -> previousName = $ iterator -> current ( ) ; $ iterator -> next ( ) ; } $ resourceRecord -> setName ( $ this -> previousName ) ; }
Processes a ResourceRecord name .
12,627
private function processTtl ( \ ArrayIterator $ iterator , ResourceRecord $ resourceRecord ) : void { if ( $ this -> isTTL ( $ iterator ) ) { $ resourceRecord -> setTtl ( $ iterator -> current ( ) ) ; $ iterator -> next ( ) ; } }
Set RR s TTL if there is one .
12,628
private function processClass ( \ ArrayIterator $ iterator , ResourceRecord $ resourceRecord ) : void { if ( Classes :: isValid ( strtoupper ( $ iterator -> current ( ) ) ) ) { $ resourceRecord -> setClass ( strtoupper ( $ iterator -> current ( ) ) ) ; $ iterator -> next ( ) ; } }
Set RR s class if there is one .
12,629
private function isResourceName ( \ ArrayIterator $ iterator ) : bool { return ! ( $ this -> isTTL ( $ iterator ) || Classes :: isValid ( strtoupper ( $ iterator -> current ( ) ) ) || RDataTypes :: isValid ( strtoupper ( $ iterator -> current ( ) ) ) ) ; }
Determine if iterant is a resource name .
12,630
public static function newRdataFromName ( string $ name ) : RdataInterface { if ( ! self :: isTypeImplemented ( $ name ) ) { throw new UnsupportedTypeException ( $ name ) ; } $ namespace = '\\Badcow\\DNS\\Rdata\\' ; $ className = $ namespace . strtoupper ( $ name ) ; if ( ! class_exists ( $ className ) ) { $ className = $ namespace . 'DNSSEC\\' . strtoupper ( $ name ) ; } return new $ className ( ) ; }
Creates a new RData object from a name .
12,631
private function handleComment ( ) : void { if ( $ this -> string -> isNot ( Tokens :: SEMICOLON ) ) { return ; } while ( $ this -> string -> isNot ( Tokens :: LINE_FEED ) && $ this -> string -> valid ( ) ) { $ this -> string -> next ( ) ; } }
Ignores the comment section .
12,632
private function handleTxt ( ) : void { if ( $ this -> string -> isNot ( Tokens :: DOUBLE_QUOTES ) ) { return ; } $ this -> append ( ) ; while ( $ this -> string -> isNot ( Tokens :: DOUBLE_QUOTES ) ) { if ( ! $ this -> string -> valid ( ) ) { throw new ParseException ( 'Unbalanced double quotation marks. End of file reached.' ) ; } if ( $ this -> string -> is ( Tokens :: BACKSLASH ) ) { $ this -> append ( ) ; } if ( $ this -> string -> is ( Tokens :: LINE_FEED ) ) { throw new ParseException ( 'Line Feed found within double quotation marks context.' , $ this -> string ) ; } $ this -> append ( ) ; } }
Handle text inside of double quotations . When this function is called the String pointer MUST be at the double quotation mark .
12,633
private function handleMultiline ( ) : void { if ( $ this -> string -> isNot ( Tokens :: OPEN_BRACKET ) ) { return ; } $ this -> string -> next ( ) ; while ( $ this -> string -> valid ( ) ) { $ this -> handleTxt ( ) ; $ this -> handleComment ( ) ; if ( $ this -> string -> is ( Tokens :: LINE_FEED ) ) { $ this -> string -> next ( ) ; continue ; } if ( $ this -> string -> is ( Tokens :: CLOSE_BRACKET ) ) { $ this -> string -> next ( ) ; return ; } $ this -> append ( ) ; } throw new ParseException ( 'End of file reached. Unclosed bracket.' ) ; }
Move multi - line records onto single line .
12,634
private function removeWhitespace ( ) : void { $ string = preg_replace ( '/ {2,}/' , Tokens :: SPACE , $ this -> normalisedString ) ; $ lines = [ ] ; foreach ( explode ( Tokens :: LINE_FEED , $ string ) as $ line ) { if ( '' !== $ line = trim ( $ line ) ) { $ lines [ ] = $ line ; } } $ this -> normalisedString = implode ( Tokens :: LINE_FEED , $ lines ) ; }
Remove superfluous whitespace characters from string .
12,635
public static function fullyQualifiedDomainName ( string $ name ) : bool { $ isValid = strlen ( $ name ) < 254 ; $ isValid &= 1 === preg_match ( '/^(?:(?!-)[a-z0-9\-]{1,63}(?<!-)\.){1,127}$/i' , $ name ) ; return $ isValid ; }
Validate the string is a Fully Qualified Domain Name .
12,636
private static function countClasses ( Zone $ zone ) : int { $ classes = [ ] ; foreach ( $ zone as $ rr ) { if ( null !== $ rr -> getClass ( ) ) { $ classes [ $ rr -> getClass ( ) ] = null ; } } return count ( $ classes ) ; }
Determine the number of unique non - null classes in a Zone . In a valid zone this MUST be 1 .
12,637
private static function makeLine ( string $ text , ? string $ comment , int $ longestVarLength , int $ padding ) : string { $ output = str_repeat ( ' ' , $ padding ) . str_pad ( $ text , $ longestVarLength ) ; if ( null !== $ comment ) { $ output .= ' ' . self :: COMMENT_DELIMINATOR . $ comment ; } return $ output . PHP_EOL ; }
Returns a padded line with comment .
12,638
private static function getPadding ( Zone $ zone ) { $ name = $ ttl = $ type = 0 ; foreach ( $ zone as $ resourceRecord ) { $ name = max ( $ name , strlen ( $ resourceRecord -> getName ( ) ) ) ; $ ttl = max ( $ ttl , strlen ( $ resourceRecord -> getTtl ( ) ) ) ; $ type = max ( $ type , strlen ( $ resourceRecord -> getType ( ) ) ) ; } return [ $ name , $ ttl , $ type , $ name + $ ttl + $ type + 6 , ] ; }
Get the padding required for a zone .
12,639
public function getClass ( ) : string { foreach ( $ this -> resourceRecords as $ resourceRecord ) { if ( null !== $ resourceRecord -> getClass ( ) ) { return $ resourceRecord -> getClass ( ) ; } } return Classes :: INTERNET ; }
Return the class of the zone defaults to IN .
12,640
public static function getMnemonic ( int $ algorithmId ) { if ( ! array_key_exists ( $ algorithmId , self :: $ mnemonic ) ) { throw new \ InvalidArgumentException ( sprintf ( '"%d" id not a valid algorithm.' , $ algorithmId ) ) ; } return self :: $ mnemonic [ $ algorithmId ] ; }
Get the associated mnemonic of an algorithm .
12,641
public static function expandIpv6 ( string $ ip ) : string { if ( ! Validator :: ipv6 ( $ ip ) ) { throw new \ InvalidArgumentException ( sprintf ( '"%s" is not a valid IPv6 address.' , $ ip ) ) ; } $ hex = unpack ( 'H*hex' , inet_pton ( $ ip ) ) ; return implode ( ':' , str_split ( $ hex [ 'hex' ] , 4 ) ) ; }
Expands an IPv6 address to its full non - shorthand representation .
12,642
public static function contractIpv6 ( string $ ip ) : string { if ( ! Validator :: ipv6 ( $ ip ) ) { throw new \ InvalidArgumentException ( sprintf ( '"%s" is not a valid IPv6 address.' , $ ip ) ) ; } return inet_ntop ( inet_pton ( $ ip ) ) ; }
Takes a valid IPv6 address and contracts it to its shorter version .
12,643
public static function reverseIpv4 ( string $ ip ) : string { $ octets = array_reverse ( explode ( '.' , $ ip ) ) ; return implode ( '.' , $ octets ) . '.in-addr.arpa.' ; }
Creates a reverse IPv4 address .
12,644
public static function reverseIpv6 ( string $ ip , bool $ appendSuffix = true ) : string { try { $ ip = self :: expandIpv6 ( $ ip ) ; } catch ( \ InvalidArgumentException $ e ) { $ ip = self :: expandIncompleteIpv6 ( $ ip ) ; } $ ip = str_replace ( ':' , '' , $ ip ) ; $ ip = strrev ( $ ip ) ; $ ip = implode ( '.' , str_split ( $ ip ) ) ; $ ip .= $ appendSuffix ? '.ip6.arpa.' : '' ; return $ ip ; }
Creates a reverse IPv6 address .
12,645
private function getLineNumber ( ) : int { $ pos = $ this -> stringIterator -> key ( ) ; $ this -> stringIterator -> rewind ( ) ; $ lineNo = 1 ; while ( $ this -> stringIterator -> key ( ) < $ pos ) { if ( $ this -> stringIterator -> is ( Tokens :: LINE_FEED ) ) { ++ $ lineNo ; } $ this -> stringIterator -> next ( ) ; } return $ lineNo ; }
Get line number of current entry on the StringIterator .
12,646
public static function dmsToDecimal ( int $ deg , int $ min , float $ sec , string $ hemisphere ) : float { $ multiplier = ( 'S' === $ hemisphere || 'W' === $ hemisphere ) ? - 1 : 1 ; return $ multiplier * ( $ deg + ( $ min / 60 ) + ( $ sec / 3600 ) ) ; }
Transform a DMS string to a decimal representation . Used for LOC records .
12,647
public static function catchAll ( string $ type , \ ArrayIterator $ iterator ) : Rdata \ RdataInterface { if ( ! Rdata \ Factory :: isTypeImplemented ( $ type ) ) { return new Rdata \ PolymorphicRdata ( $ type , implode ( Tokens :: SPACE , self :: getAllRemaining ( $ iterator ) ) ) ; } return call_user_func_array ( [ Rdata \ Factory :: class , $ type ] , self :: getAllRemaining ( $ iterator ) ) ; }
Returns RData instances for types that do not have explicitly declared handler methods .
12,648
private static function pop ( \ ArrayIterator $ iterator ) : string { $ current = $ iterator -> current ( ) ; $ iterator -> next ( ) ; return $ current ; }
Return current entry and moves the iterator to the next entry .
12,649
private static function getAllRemaining ( \ ArrayIterator $ iterator ) : array { $ values = [ ] ; while ( $ iterator -> valid ( ) ) { $ values [ ] = $ iterator -> current ( ) ; $ iterator -> next ( ) ; } return $ values ; }
Get all the remaining values of an iterator as an array .
12,650
public function allowClientIncoming ( $ clientName ) { if ( preg_match ( '/\W/' , $ clientName ) ) { throw new \ InvalidArgumentException ( 'Only alphanumeric characters allowed in client name.' ) ; } if ( strlen ( $ clientName ) == 0 ) { throw new \ InvalidArgumentException ( 'Client name must not be a zero length string.' ) ; } $ this -> clientName = $ clientName ; $ this -> allow ( 'client' , 'incoming' , array ( 'clientName' => $ clientName ) ) ; }
If the user of this token should be allowed to accept incoming connections then configure the TwilioCapability through this method and specify the client name .
12,651
public function generateToken ( $ ttl = 3600 ) { $ payload = array_merge ( $ this -> customClaims , array ( 'scope' => array ( ) , 'iss' => $ this -> accountSid , 'exp' => time ( ) + $ ttl , ) ) ; $ scopeStrings = array ( ) ; foreach ( $ this -> scopes as $ scope ) { if ( $ scope -> privilege == "outgoing" && $ this -> clientName ) $ scope -> params [ "clientName" ] = $ this -> clientName ; $ scopeStrings [ ] = $ scope -> toString ( ) ; } $ payload [ 'scope' ] = implode ( ' ' , $ scopeStrings ) ; return JWT :: encode ( $ payload , $ this -> authToken , 'HS256' ) ; }
Generates a new token based on the credentials and permissions that previously has been granted to this token .
12,652
public static function compare ( $ a , $ b ) { $ result = true ; if ( strlen ( $ a ) != strlen ( $ b ) ) { return false ; } if ( ! $ a && ! $ b ) { return true ; } $ limit = strlen ( $ a ) ; for ( $ i = 0 ; $ i < $ limit ; ++ $ i ) { if ( $ a [ $ i ] != $ b [ $ i ] ) { $ result = false ; } } return $ result ; }
Time insensitive compare function s runtime is governed by the length of the first argument not the difference between the arguments .
12,653
public function create ( $ messagingServiceSid , $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'MessagingServiceSid' => $ messagingServiceSid , 'FriendlyName' => $ options [ 'friendlyName' ] , 'Attributes' => $ options [ 'attributes' ] , 'DateCreated' => Serialize :: iso8601DateTime ( $ options [ 'dateCreated' ] ) , 'DateUpdated' => Serialize :: iso8601DateTime ( $ options [ 'dateUpdated' ] ) , 'CreatedBy' => $ options [ 'createdBy' ] , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new SessionInstance ( $ this -> version , $ payload ) ; }
Create a new SessionInstance
12,654
public function create ( $ identity , $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'Identity' => $ identity , 'RoleSid' => $ options [ 'roleSid' ] , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new InviteInstance ( $ this -> version , $ payload , $ this -> solution [ 'serviceSid' ] , $ this -> solution [ 'channelSid' ] ) ; }
Create a new InviteInstance
12,655
public function stream ( $ options = array ( ) , $ limit = null , $ pageSize = null ) { $ limits = $ this -> version -> readLimits ( $ limit , $ pageSize ) ; $ page = $ this -> page ( $ options , $ limits [ 'pageSize' ] ) ; return $ this -> version -> stream ( $ page , $ limits [ 'limit' ] , $ limits [ 'pageLimit' ] ) ; }
Streams InviteInstance records from the API as a generator stream . This operation lazily loads records as efficiently as possible until the limit is reached . The results are returned as a generator so this operation is memory efficient .
12,656
public function getContext ( $ sid ) { return new InviteContext ( $ this -> version , $ this -> solution [ 'serviceSid' ] , $ this -> solution [ 'channelSid' ] , $ sid ) ; }
Constructs a InviteContext
12,657
public function create ( $ availableAddOnSid , $ acceptTermsOfService , $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'AvailableAddOnSid' => $ availableAddOnSid , 'AcceptTermsOfService' => Serialize :: booleanToString ( $ acceptTermsOfService ) , 'Configuration' => Serialize :: jsonObject ( $ options [ 'configuration' ] ) , 'UniqueName' => $ options [ 'uniqueName' ] , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new InstalledAddOnInstance ( $ this -> version , $ payload ) ; }
Create a new InstalledAddOnInstance
12,658
public function create ( $ to , $ from , $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'To' => $ to , 'From' => $ from , 'Parameters' => Serialize :: jsonObject ( $ options [ 'parameters' ] ) , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new EngagementInstance ( $ this -> version , $ payload , $ this -> solution [ 'flowSid' ] ) ; }
Create a new EngagementInstance
12,659
public function create ( $ credentials , $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'Credentials' => $ credentials , 'FriendlyName' => $ options [ 'friendlyName' ] , 'AccountSid' => $ options [ 'accountSid' ] , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new AwsInstance ( $ this -> version , $ payload ) ; }
Create a new AwsInstance
12,660
public function getContext ( $ sid ) { return new ReservationContext ( $ this -> version , $ this -> solution [ 'workspaceSid' ] , $ this -> solution [ 'taskSid' ] , $ sid ) ; }
Constructs a ReservationContext
12,661
protected function getSessions ( ) { if ( ! $ this -> _sessions ) { $ this -> _sessions = new SessionList ( $ this -> version , $ this -> solution [ 'sid' ] ) ; } return $ this -> _sessions ; }
Access the sessions
12,662
protected function getPhoneNumbers ( ) { if ( ! $ this -> _phoneNumbers ) { $ this -> _phoneNumbers = new PhoneNumberList ( $ this -> version , $ this -> solution [ 'sid' ] ) ; } return $ this -> _phoneNumbers ; }
Access the phoneNumbers
12,663
protected function getShortCodes ( ) { if ( ! $ this -> _shortCodes ) { $ this -> _shortCodes = new ShortCodeList ( $ this -> version , $ this -> solution [ 'sid' ] ) ; } return $ this -> _shortCodes ; }
Access the shortCodes
12,664
protected function getAssignedAddOns ( ) { if ( ! $ this -> _assignedAddOns ) { $ this -> _assignedAddOns = new AssignedAddOnList ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'sid' ] ) ; } return $ this -> _assignedAddOns ; }
Access the assignedAddOns
12,665
protected function getFactors ( ) { if ( ! $ this -> _factors ) { $ this -> _factors = new FactorList ( $ this -> version , $ this -> solution [ 'serviceSid' ] , $ this -> solution [ 'identity' ] ) ; } return $ this -> _factors ; }
Access the factors
12,666
public function request ( $ method , $ uri , $ params = array ( ) , $ data = array ( ) , $ headers = array ( ) , $ username = null , $ password = null , $ timeout = null ) { $ username = $ username ? $ username : $ this -> username ; $ password = $ password ? $ password : $ this -> password ; $ headers [ 'User-Agent' ] = 'twilio-php/' . VersionInfo :: string ( ) . ' (PHP ' . phpversion ( ) . ')' ; $ headers [ 'Accept-Charset' ] = 'utf-8' ; if ( $ method == 'POST' && ! array_key_exists ( 'Content-Type' , $ headers ) ) { $ headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' ; } if ( ! array_key_exists ( 'Accept' , $ headers ) ) { $ headers [ 'Accept' ] = 'application/json' ; } if ( $ this -> region ) { list ( $ head , $ tail ) = explode ( '.' , $ uri , 2 ) ; if ( strpos ( $ tail , $ this -> region ) !== 0 ) { $ uri = implode ( '.' , array ( $ head , $ this -> region , $ tail ) ) ; } } return $ this -> getHttpClient ( ) -> request ( $ method , $ uri , $ params , $ data , $ headers , $ username , $ password , $ timeout ) ; }
Makes a request to the Twilio API using the configured http client Authentication information is automatically added if none is provided
12,667
public function validateSslCertificate ( $ client ) { $ response = $ client -> request ( 'GET' , 'https://api.twilio.com:8443' ) ; if ( $ response -> getStatusCode ( ) < 200 || $ response -> getStatusCode ( ) > 300 ) { throw new TwilioException ( "Failed to validate SSL certificate" ) ; } }
Validates connection to new SSL certificate endpoint
12,668
protected function getAddOnResults ( ) { if ( ! $ this -> _addOnResults ) { $ this -> _addOnResults = new AddOnResultList ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'sid' ] ) ; } return $ this -> _addOnResults ; }
Access the addOnResults
12,669
protected function getFieldValues ( ) { if ( ! $ this -> _fieldValues ) { $ this -> _fieldValues = new FieldValueList ( $ this -> version , $ this -> solution [ 'assistantSid' ] , $ this -> solution [ 'sid' ] ) ; } return $ this -> _fieldValues ; }
Access the fieldValues
12,670
public function create ( $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'FriendlyName' => $ options [ 'friendlyName' ] , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new FleetInstance ( $ this -> version , $ payload ) ; }
Create a new FleetInstance
12,671
protected function getHighriskSpecialPrefixes ( ) { if ( ! $ this -> _highriskSpecialPrefixes ) { $ this -> _highriskSpecialPrefixes = new HighriskSpecialPrefixList ( $ this -> version , $ this -> solution [ 'isoCode' ] ) ; } return $ this -> _highriskSpecialPrefixes ; }
Access the highriskSpecialPrefixes
12,672
public function fetch ( ) { $ params = Values :: of ( array ( ) ) ; $ payload = $ this -> version -> fetch ( 'GET' , $ this -> uri , $ params ) ; return new StepInstance ( $ this -> version , $ payload , $ this -> solution [ 'flowSid' ] , $ this -> solution [ 'engagementSid' ] , $ this -> solution [ 'sid' ] ) ; }
Fetch a StepInstance
12,673
public function getContext ( $ sid ) { return new PublishedTrackContext ( $ this -> version , $ this -> solution [ 'roomSid' ] , $ this -> solution [ 'participantSid' ] , $ sid ) ; }
Constructs a PublishedTrackContext
12,674
public function create ( $ friendlyName , $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'FriendlyName' => $ friendlyName , 'ActivitySid' => $ options [ 'activitySid' ] , 'Attributes' => $ options [ 'attributes' ] , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new WorkerInstance ( $ this -> version , $ payload , $ this -> solution [ 'workspaceSid' ] ) ; }
Create a new WorkerInstance
12,675
protected function getSyncListItems ( ) { if ( ! $ this -> _syncListItems ) { $ this -> _syncListItems = new SyncListItemList ( $ this -> version , $ this -> solution [ 'serviceSid' ] , $ this -> solution [ 'sid' ] ) ; } return $ this -> _syncListItems ; }
Access the syncListItems
12,676
protected function getSyncListPermissions ( ) { if ( ! $ this -> _syncListPermissions ) { $ this -> _syncListPermissions = new SyncListPermissionList ( $ this -> version , $ this -> solution [ 'serviceSid' ] , $ this -> solution [ 'sid' ] ) ; } return $ this -> _syncListPermissions ; }
Access the syncListPermissions
12,677
protected function getDependentHostedNumberOrders ( ) { if ( ! $ this -> _dependentHostedNumberOrders ) { $ this -> _dependentHostedNumberOrders = new DependentHostedNumberOrderList ( $ this -> version , $ this -> solution [ 'sid' ] ) ; } return $ this -> _dependentHostedNumberOrders ; }
Access the dependentHostedNumberOrders
12,678
public function create ( $ to , $ mediaUrl , $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'To' => $ to , 'MediaUrl' => $ mediaUrl , 'Quality' => $ options [ 'quality' ] , 'StatusCallback' => $ options [ 'statusCallback' ] , 'From' => $ options [ 'from' ] , 'SipAuthUsername' => $ options [ 'sipAuthUsername' ] , 'SipAuthPassword' => $ options [ 'sipAuthPassword' ] , 'StoreMedia' => Serialize :: booleanToString ( $ options [ 'storeMedia' ] ) , 'Ttl' => $ options [ 'ttl' ] , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new FaxInstance ( $ this -> version , $ payload ) ; }
Create a new FaxInstance
12,679
protected function getLocal ( ) { if ( ! $ this -> _local ) { $ this -> _local = new LocalList ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'countryCode' ] ) ; } return $ this -> _local ; }
Access the local
12,680
protected function getTollFree ( ) { if ( ! $ this -> _tollFree ) { $ this -> _tollFree = new TollFreeList ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'countryCode' ] ) ; } return $ this -> _tollFree ; }
Access the tollFree
12,681
protected function getMobile ( ) { if ( ! $ this -> _mobile ) { $ this -> _mobile = new MobileList ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'countryCode' ] ) ; } return $ this -> _mobile ; }
Access the mobile
12,682
protected function getNational ( ) { if ( ! $ this -> _national ) { $ this -> _national = new NationalList ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'countryCode' ] ) ; } return $ this -> _national ; }
Access the national
12,683
protected function getVoip ( ) { if ( ! $ this -> _voip ) { $ this -> _voip = new VoipList ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'countryCode' ] ) ; } return $ this -> _voip ; }
Access the voip
12,684
protected function getSharedCost ( ) { if ( ! $ this -> _sharedCost ) { $ this -> _sharedCost = new SharedCostList ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'countryCode' ] ) ; } return $ this -> _sharedCost ; }
Access the sharedCost
12,685
protected function getMachineToMachine ( ) { if ( ! $ this -> _machineToMachine ) { $ this -> _machineToMachine = new MachineToMachineList ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'countryCode' ] ) ; } return $ this -> _machineToMachine ; }
Access the machineToMachine
12,686
public function create ( $ language , $ query , $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'Language' => $ language , 'Query' => $ query , 'Tasks' => $ options [ 'tasks' ] , 'ModelBuild' => $ options [ 'modelBuild' ] , 'Field' => $ options [ 'field' ] , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new QueryInstance ( $ this -> version , $ payload , $ this -> solution [ 'assistantSid' ] ) ; }
Create a new QueryInstance
12,687
public function setOutgoingApplication ( $ sid , $ params ) { $ this -> outgoingApplicationSid = $ sid ; $ this -> outgoingApplicationParams = $ params ; return $ this ; }
Set the outgoing application of the the grant
12,688
protected function getChannels ( ) { if ( ! $ this -> _channels ) { $ this -> _channels = new ChannelList ( $ this -> version , $ this -> solution [ 'sid' ] ) ; } return $ this -> _channels ; }
Access the channels
12,689
protected function getRoles ( ) { if ( ! $ this -> _roles ) { $ this -> _roles = new RoleList ( $ this -> version , $ this -> solution [ 'sid' ] ) ; } return $ this -> _roles ; }
Access the roles
12,690
protected function getUsers ( ) { if ( ! $ this -> _users ) { $ this -> _users = new UserList ( $ this -> version , $ this -> solution [ 'sid' ] ) ; } return $ this -> _users ; }
Access the users
12,691
protected function getBindings ( ) { if ( ! $ this -> _bindings ) { $ this -> _bindings = new BindingList ( $ this -> version , $ this -> solution [ 'sid' ] ) ; } return $ this -> _bindings ; }
Access the bindings
12,692
public function dial ( $ number = null , $ attributes = array ( ) ) { return $ this -> nest ( new Voice \ Dial ( $ number , $ attributes ) ) ; }
Add Dial child .
12,693
public function enqueue ( $ name = null , $ attributes = array ( ) ) { return $ this -> nest ( new Voice \ Enqueue ( $ name , $ attributes ) ) ; }
Add Enqueue child .
12,694
public function play ( $ url = null , $ attributes = array ( ) ) { return $ this -> nest ( new Voice \ Play ( $ url , $ attributes ) ) ; }
Add Play child .
12,695
public function getContext ( $ sid ) { return new CredentialListMappingContext ( $ this -> version , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'domainSid' ] , $ sid ) ; }
Constructs a CredentialListMappingContext
12,696
public function getContext ( $ identity ) { return new SyncMapPermissionContext ( $ this -> version , $ this -> solution [ 'serviceSid' ] , $ this -> solution [ 'mapSid' ] , $ identity ) ; }
Constructs a SyncMapPermissionContext
12,697
public function create ( $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'Identity' => Serialize :: map ( $ options [ 'identity' ] , function ( $ e ) { return $ e ; } ) , 'Tag' => Serialize :: map ( $ options [ 'tag' ] , function ( $ e ) { return $ e ; } ) , 'Body' => $ options [ 'body' ] , 'Priority' => $ options [ 'priority' ] , 'Ttl' => $ options [ 'ttl' ] , 'Title' => $ options [ 'title' ] , 'Sound' => $ options [ 'sound' ] , 'Action' => $ options [ 'action' ] , 'Data' => Serialize :: jsonObject ( $ options [ 'data' ] ) , 'Apn' => Serialize :: jsonObject ( $ options [ 'apn' ] ) , 'Gcm' => Serialize :: jsonObject ( $ options [ 'gcm' ] ) , 'Sms' => Serialize :: jsonObject ( $ options [ 'sms' ] ) , 'FacebookMessenger' => Serialize :: jsonObject ( $ options [ 'facebookMessenger' ] ) , 'Fcm' => Serialize :: jsonObject ( $ options [ 'fcm' ] ) , 'Segment' => Serialize :: map ( $ options [ 'segment' ] , function ( $ e ) { return $ e ; } ) , 'Alexa' => Serialize :: jsonObject ( $ options [ 'alexa' ] ) , 'ToBinding' => Serialize :: map ( $ options [ 'toBinding' ] , function ( $ e ) { return $ e ; } ) , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new NotificationInstance ( $ this -> version , $ payload , $ this -> solution [ 'serviceSid' ] ) ; }
Create a new NotificationInstance
12,698
public function create ( $ publicKey , $ options = array ( ) ) { $ options = new Values ( $ options ) ; $ data = Values :: of ( array ( 'PublicKey' => $ publicKey , 'FriendlyName' => $ options [ 'friendlyName' ] , 'AccountSid' => $ options [ 'accountSid' ] , ) ) ; $ payload = $ this -> version -> create ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new PublicKeyInstance ( $ this -> version , $ payload ) ; }
Create a new PublicKeyInstance
12,699
public function update ( $ url , $ method ) { $ data = Values :: of ( array ( 'Url' => $ url , 'Method' => $ method , ) ) ; $ payload = $ this -> version -> update ( 'POST' , $ this -> uri , array ( ) , $ data ) ; return new MemberInstance ( $ this -> version , $ payload , $ this -> solution [ 'accountSid' ] , $ this -> solution [ 'queueSid' ] , $ this -> solution [ 'callSid' ] ) ; }
Update the MemberInstance