idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
58,200
static public function mosaicQuantityToXEM ( $ divisibility , $ supply , $ quantity , $ multiplier = Amount :: XEM ) { if ( ( int ) $ supply <= 0 ) return 0 ; if ( ( int ) $ divisibility <= 0 ) $ divisibility = 0 ; return self :: XEM_SUPPLY * $ quantity * $ multiplier / $ supply / pow ( 10 , $ divisibility + 6 ) ; }
Helper to get the XEM equivalent for a given mosaic definition definition and attachment quantity quantity .
58,201
public function getSerializer ( ) { if ( ! $ this -> serializer || ! ( $ this -> serializer instanceof Serializer ) ) { $ this -> serializer = Serializer :: getInstance ( ) ; } return $ this -> serializer ; }
Getter for the serializer property .
58,202
public function mutate ( $ name , $ attributes ) { $ modelClass = "\\NEM\\Models\\" . Str :: studly ( $ name ) ; if ( ! class_exists ( $ modelClass ) ) { throw new BadMethodCallException ( "Model class '" . $ modelClass . "' could not be found in \\NEM\\Model namespace." ) ; } $ instance = new $ modelClass ( $ attribut...
Mutate a Model object .
58,203
public function toDTO ( $ filterByKey = null ) { $ dtos = [ ] ; foreach ( $ this -> getAttributes ( ) as $ attrib => $ data ) { $ attribDTO = $ data ; if ( $ data instanceof DataTransferObject || $ data instanceof ModelCollection ) { $ attribDTO = $ data -> toDTO ( ) ; } elseif ( in_array ( $ attrib , $ this -> relatio...
Generic helper to convert a Model instance to a Data Transfer Object .
58,204
public function getFields ( ) { $ fields = array_keys ( $ this -> fillable ) ; if ( ! empty ( $ fields ) && is_integer ( $ fields [ 0 ] ) ) $ fields = array_values ( $ this -> fillable ) ; return array_merge ( $ fields , $ this -> appends , array_keys ( $ this -> attributes ) ) ; }
Getter for the model s field names .
58,205
public function setAttributes ( array $ attributes ) { $ flattened = array_dot ( $ attributes ) ; $ fields = $ this -> getFields ( ) ; if ( empty ( $ fields ) ) $ fields = array_keys ( $ attributes ) ; foreach ( $ fields as $ field ) : $ fillableKeys = array_keys ( $ this -> fillable ) ; $ aliasedFields = ! empty ( $ f...
Setter for the attributes property .
58,206
public function getAttributes ( ) { $ sortedAttribs = [ ] ; foreach ( $ this -> sortedFields as $ ix => $ attribute ) { $ sortedAttribs [ $ attribute ] = $ this -> attributes [ $ attribute ] ; } return $ sortedAttribs ; }
Getter for the attributes property .
58,207
public function castValue ( $ field , $ value , $ cast = true ) { if ( ! array_key_exists ( $ field , $ this -> casts ) || ! $ cast ) return $ value ; $ types = [ "boolean" , "bool" , "integer" , "int" , "float" , "double" , "string" , "array" , "object" , "null" ] ; $ type = $ this -> casts [ $ field ] ; if ( ! in_arr...
This method will read the casts instance property and automatically cast the value provided in the set cast type .
58,208
public function resolveRelationship ( $ alias , $ data ) { if ( ! in_array ( $ alias , $ this -> relations ) && ! method_exists ( $ this , $ alias ) ) { throw new BadMethodCallException ( "Relationship for field '" . $ alias . "' not configured in " . get_class ( $ this ) ) ; } if ( method_exists ( $ this , $ alias ) )...
Build a Model Relationship between \ NEM \ Contracts \ DataTransferObject objects .
58,209
static public function create ( array $ data = null ) { if ( empty ( $ data [ "type" ] ) && isset ( $ data [ "transaction" ] ) ) { $ type = $ data [ "transaction" ] [ "type" ] ; } elseif ( ! $ data || empty ( $ data [ "type" ] ) ) { return new static ( $ data ) ; } else { $ type = $ data [ "type" ] ; } $ validTypes = a...
Class method to create a Transaction object out of a DTO data set .
58,210
public function timeStamp ( $ timestamp = null ) { $ ts = $ timestamp ? : $ this -> getAttribute ( "timeStamp" ) ; if ( is_integer ( $ ts ) || $ ts instanceof TimeWindow ) { return new TimeWindow ( [ "timeStamp" => $ ts ] ) ; } return new TimeWindow ( ) ; }
Returns timestamp of the transaction .
58,211
public function deadline ( $ deadline = null ) { $ ts = $ deadline ? : $ this -> getAttribute ( "deadline" ) ; if ( is_integer ( $ ts ) || $ ts instanceof TimeWindow ) { return new TimeWindow ( [ "timeStamp" => $ ts ] ) ; } return new TimeWindow ( ) ; }
Returns deadline associated with the transaction
58,212
public function fee ( $ fee = null ) { $ amount = $ fee ? : $ this -> getAttribute ( "fee" ) ; if ( ! $ amount ) $ amount = ( int ) Fee :: calculateForTransaction ( $ this ) ; return new Fee ( [ "amount" => $ amount ] ) ; }
Mutator for the fee amount object .
58,213
public function toDTO ( $ filterByKey = null ) { if ( ! $ this -> getAttribute ( "recipient" ) || ! $ this -> getAttribute ( "mosaicId" ) ) return [ ] ; return [ "type" => $ this -> type , "recipient" => $ this -> recipient ( ) -> address ( ) -> toClean ( ) , "mosaicId" => $ this -> mosaicId ( ) -> toDTO ( ) , "fee" =>...
Mosaic Levy DTO builds a package with offsets type recipient mosaicId and fee .
58,214
public function serialize ( $ data ) { if ( null === $ data ) { return $ this -> serializeInt ( null ) ; } elseif ( is_array ( $ data ) ) { return $ this -> serializeUInt8 ( $ data ) ; } elseif ( is_integer ( $ data ) ) { return $ this -> serializeLong ( $ data ) ; } elseif ( is_string ( $ data ) ) { return $ this -> s...
Serialize any input for the NEM network .
58,215
public function serializeInt ( int $ number = null ) { if ( null === $ number ) { return $ this -> serializeInt ( self :: NULL_SENTINEL ) ; } else { $ uint8 = [ $ number & 0xff , ( $ number >> 8 ) & 0xff , ( $ number >> 16 ) & 0xff , ( $ number >> 24 ) & 0xff ] ; } return $ uint8 ; }
Internal method to serialize a decimal number into a Integer on 4 Bytes .
58,216
public function serializeString ( string $ str = null ) { if ( null === $ str ) { $ uint8 = $ this -> serializeInt ( null ) ; } else { $ count = strlen ( $ str ) ; $ uint8 = $ this -> serializeInt ( $ count ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ dec = Ed25519 :: chrToInt ( substr ( $ str , $ i , 1 ) ) ; array...
Serialize string data . The serialized string will be prefixed with a 4 - bytes long Size field followed by the UInt8 representation of the given str .
58,217
public function serializeUInt8 ( array $ uint8Str = null ) { if ( null === $ uint8Str ) { $ uint8 = $ this -> serializeInt ( null ) ; } else { $ count = count ( $ uint8Str ) ; $ uint8 = $ this -> serializeInt ( $ count ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { array_push ( $ uint8 , $ uint8Str [ $ i ] ) ; } } retu...
Serialize unsigned char data . The serialized string will be prefixed with a 4 - bytes long Size field followed by the given str .
58,218
public function serializeLong ( int $ long = null ) { if ( null === $ long ) { $ uint8 = array_merge ( $ this -> serializeInt ( null ) , $ this -> serializeInt ( 0 ) ) ; } else { $ uint64L = $ this -> serializeInt ( $ long ) ; $ uint64H = $ this -> serializeInt ( $ long >> 32 ) ; $ uint8 = array_merge ( $ uint64L , $ u...
Serialize UInt64 numbers . This corresponds to the long variable type in C .
58,219
public function aggregate ( ) { $ count = func_num_args ( ) ; if ( ! $ count ) { return [ ] ; } $ concat = [ ] ; $ length = 0 ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ argument = func_get_arg ( $ i ) ; if ( ! is_array ( $ argument ) ) { $ argument = $ this -> serialize ( $ argument ) ; } $ concat = array_merge ( $...
This method lets you aggregate multiple serialized byte arrays .
58,220
public function cosignatoryOf ( array $ data = null ) { $ multisigs = $ data ? : $ this -> getAttribute ( "cosignatoryOf" ) ? : [ ] ; return ( new CollectionMutator ( ) ) -> mutate ( "account" , $ multisigs ) ; }
Mutator for the cosignatoryOf object collection .
58,221
public function cosignatories ( array $ data = null ) { $ cosignatories = $ data ? : $ this -> getAttribute ( "cosignatories" ) ? : [ ] ; return ( new CollectionMutator ( ) ) -> mutate ( "account" , $ cosignatories ) ; }
Mutator for the cosignatories object collection .
58,222
static public function hash ( $ algorithm , $ data , $ raw_output = false ) { $ hashBits = self :: getHashBitLength ( $ algorithm ) ; return Keccak :: hash ( $ data , ( int ) $ hashBits , ( bool ) $ raw_output ) ; }
Non - Incremental Keccak Hash implementation .
58,223
static public function getHashBitLength ( $ algorithm = null ) { if ( ! $ algorithm ) { return self :: HASH_BIT_LENGTH ; } if ( is_integer ( $ algorithm ) ) { return ( int ) $ algorithm ; } elseif ( strpos ( strtolower ( $ algorithm ) , "keccak-" ) !== false ) { $ bits = ( int ) substr ( $ algorithm , - 3 ) ; if ( ! in...
Helper function used to determine each hash s Bits length by a given algorithm .
58,224
public function setProtocol ( $ protocol ) { $ lowerProtocol = strtolower ( $ protocol ) ; if ( "websocket" == $ lowerProtocol ) $ lowerProtocol = "ws" ; if ( in_array ( $ lowerProtocol , [ "https" , "wss" ] ) ) { $ this -> setUseSsl ( true ) ; $ lowerProtocol = substr ( $ lowerProtocol , 0 , - 1 ) ; } $ this -> protoc...
This method should implement a protocol setter which will be used to determine which Protocol is used in the Base URL .
58,225
public function getBaseUrl ( ) { return $ this -> getScheme ( ) . $ this -> getBasicAuth ( ) . $ this -> getHost ( ) . ":" . $ this -> getPort ( ) . $ this -> getEndpoint ( ) ; }
Getter for base_url property .
58,226
public function fillFromBaseUrl ( $ baseUrl ) { $ reg = "/^(https?):\/\/((www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6})(:([0-9]+))?/" ; $ matches = [ ] ; $ scheme = "http" ; $ host = "hugealice.nem.ninja" ; $ port = 7890 ; if ( ( bool ) preg_match_all ( $ reg , $ baseUrl , $ matches ) ) { $ scheme = $ matches [ 1 ]...
Helper class method to create a Connectabl object from a fully qualified base url .
58,227
public function getEndpoint ( $ forceNew = false ) { $ index = $ forceNew === true ? ++ $ this -> poolIndex : $ this -> poolIndex ; if ( $ index == count ( $ this -> nodes ) ) { $ index = 0 ; } if ( ! isset ( $ this -> endpoints [ $ this -> network ] [ $ index ] ) ) { $ api = new API ( [ "use_ssl" => false , "protocol"...
Get a connected API using the NEM node configured at the current poolIndex
58,228
public function hex2bin ( $ hex ) { $ binLen = ceil ( mb_strlen ( $ hex ) / 2 ) ; $ buffer = Buffer :: fromHex ( $ hex , $ binLen ) ; return $ buffer -> getBinary ( ) ; }
Encode a Hexadecimal string to corresponding string characters using the Buffer class as a backbone .
58,229
public function ua2bin ( array $ uint8 ) { $ bin = "" ; foreach ( $ uint8 as $ ix => $ char ) { $ buf = Buffer :: fromInt ( $ char , 1 ) ; $ bin .= $ buf -> getBinary ( ) ; } $ buffer = new Buffer ( $ bin ) ; return $ buffer -> getBinary ( ) ; }
Encode a UInt8 array to its bytes representation .
58,230
public function minCosignatories ( $ minCosignatories = null ) { $ minCosignatories = $ minCosignatories ? : $ this -> getAttribute ( "minCosignatories" ) ? : $ this -> relativeChange ; if ( is_integer ( $ minCosignatories ) ) { $ relativeChange = $ minCosignatories ; } elseif ( is_array ( $ minCosignatories ) && isset...
Mutator for the modifications collection .
58,231
public function attachMosaic ( $ mosaic , $ quantity = null ) { $ attachment = $ this -> prepareAttachment ( $ mosaic ) ; $ actualAmt = $ attachment -> quantity ? : $ quantity ? : 0 ; $ attachment -> setAttribute ( "quantity" , $ actualAmt ) ; $ attachments = $ this -> getAttribute ( "mosaics" ) ? : [ ] ; array_push ( ...
Helper to easily attach mosaics to the attachments .
58,232
protected function prepareAttachment ( $ mosaic ) { if ( $ mosaic instanceof MosaicAttachment ) { return $ mosaic ; } elseif ( $ mosaic instanceof MosaicAttachments ) { return $ mosaic -> shift ( ) ; } elseif ( $ mosaic instanceof Mosaic ) { return new MosaicAttachment ( [ "mosaicId" => $ mosaic -> toDTO ( ) ] ) ; } el...
Helper to prepare a MosaicAttachment object out of any one of string
58,233
static public function create ( KeyPair $ kp , $ data , $ algorithm = 'keccak-512' ) { $ sig = new static ( $ privateKey , $ publicKey , $ algorithm ) ; return $ sig ; }
This method creates a Signature of said data with the given keyPair KeyPair object .
58,234
protected function prepareData ( $ data ) { if ( $ data instanceof Buffer ) { $ this -> data = $ data ; } elseif ( is_string ( $ data ) ) { $ this -> data = new Buffer ( $ data ) ; } elseif ( is_array ( $ data ) ) { $ this -> data = Buffer :: fromUInt8 ( $ data ) ; } else { throw new NISInvalidSignatureContent ( "Inval...
This method will prepare the given data and populate the data property with a prepared and correctly sized Buffer .
58,235
public function generateAccount ( ) { $ params = [ ] ; $ apiUrl = $ this -> getPath ( 'generate' , $ params ) ; $ response = $ this -> api -> getJSON ( $ apiUrl ) ; $ object = json_decode ( $ response , true ) ; return $ this -> createAccountModel ( $ object ) ; }
Let NIS generate an account KeyPair .
58,236
public function incomingTransactions ( $ address , $ hash = null , $ id = null ) { $ params = [ "address" => $ address ] ; if ( $ hash !== null ) $ params [ "hash" ] = $ hash ; if ( $ id !== null ) $ params [ "id" ] = $ id ; $ apiUrl = $ this -> getPath ( 'transfers/incoming' , $ params ) ; $ response = $ this -> api -...
A transaction is said to be incoming with respect to an account if the account is the recipient of the transaction . In the same way outgoing transaction are the transactions where the account is the sender of the transaction . Unconfirmed transactions are those transactions that have not yet been included in a block ....
58,237
public function unconfirmedTransactions ( $ address , $ hash = null ) { $ params = [ "address" => $ address ] ; if ( $ hash !== null ) $ params [ "hash" ] = $ hash ; $ apiUrl = $ this -> getPath ( 'unconfirmedTransactions' , $ params ) ; $ response = $ this -> api -> getJSON ( $ apiUrl ) ; $ data = json_decode ( $ resp...
Gets the array of transactions for which an account is the sender or receiver and which have not yet been included in a block
58,238
public function getHarvestInfo ( $ address , $ hash = null ) { $ params = [ "address" => $ address ] ; if ( $ hash !== null ) $ params [ "hash" ] = $ hash ; $ apiUrl = $ this -> getPath ( 'harvests' , $ params ) ; $ response = $ this -> api -> getJSON ( $ apiUrl ) ; $ data = json_decode ( $ response , true ) ; return $...
Gets an array of harvest info objects for an account .
58,239
public function getAccountImportances ( $ address ) { $ params = [ "address" => $ address ] ; $ apiUrl = $ this -> getPath ( 'importances' , $ params ) ; $ response = $ this -> api -> getJSON ( $ apiUrl ) ; $ object = json_decode ( $ response , true ) ; return $ this -> createBaseCollection ( $ object [ 'data' ] ) ; }
Gets an array of account importance view model objects .
58,240
public function getOwnedNamespaces ( $ address , $ parent = null , $ id = null , $ pageSize = null ) { $ params = [ "address" => $ address ] ; if ( $ hash !== null ) $ params [ "hash" ] = $ hash ; if ( $ id !== null ) $ params [ "id" ] = $ id ; if ( $ pageSize !== null ) $ params [ "pageSize" ] = $ pageSize ; $ apiUrl ...
Gets an array of namespace objects for a given account address . The parent parameter is optional . If supplied only sub - namespaces of the parent namespace are returned .
58,241
public function getCreatedMosaics ( $ address , $ parent = null , $ id = null ) { $ params = [ "address" => $ address ] ; if ( $ parent !== null ) $ params [ "parent" ] = $ parent ; if ( $ id !== null ) $ params [ "id" ] = $ id ; $ apiUrl = $ this -> getPath ( 'mosaic/definition/page' , $ params ) ; $ response = $ this...
Gets an array of mosaic definition objects for a given account address . The parent parameter is optional . If supplied only mosaic definitions for the given parent namespace are returned . The id parameter is optional and allows retrieving mosaic definitions in batches of 25 mosaic definitions .
58,242
public function getOwnedMosaics ( $ address ) { $ params = [ "address" => $ address ] ; $ apiUrl = $ this -> getPath ( 'mosaic/owned' , $ params ) ; $ response = $ this -> api -> getJSON ( $ apiUrl ) ; $ object = json_decode ( $ response , true ) ; return $ this -> createMosaicCollection ( $ object [ 'data' ] ) ; }
Gets an array of mosaic objects for a given account address .
58,243
public function getHistoricalAccountData ( $ address , $ startHeight = null , $ endHeight = null , $ increment = null ) { $ params = [ "address" => $ address ] ; if ( $ startHeight !== null ) $ params [ "startHeight" ] = $ startHeight ; if ( $ endHeight !== null ) $ params [ "endHeight" ] = $ endHeight ; if ( $ increme...
Gets historical information for an account .
58,244
public function getUnlockInfo ( ) { $ params = [ ] ; $ apiUrl = $ this -> getPath ( 'unlocked/info' , [ ] ) ; $ response = $ this -> api -> post ( $ apiUrl , $ params ) ; $ object = json_decode ( $ response ) ; return $ this -> createBaseModel ( $ object ) ; }
Each node can allow users to harvest with their delegated key on that node . The NIS configuration has entries for configuring the maximum number of allowed harvesters and optionally allow harvesting only for certain account addresses . The unlock info gives information about the maximum number of allowed harvesters an...
58,245
protected function setupConfig ( ) { $ source = realpath ( __DIR__ . '/../config' ) . "/nem.php" ; if ( ! $ this -> isLumen ( ) ) $ this -> publishes ( [ $ source => config_path ( 'nem.php' ) ] ) ; else $ this -> app -> configure ( 'nem.config' ) ; $ this -> mergeConfigFrom ( $ source , 'nem.config' ) ; }
Setup the NEM blockchain config .
58,246
protected function registerPreConfiguredApiClients ( ) { $ this -> app -> bindIf ( "nem" , function ( ) { $ environment = env ( "APP_ENV" , "testing" ) ; $ envConfig = $ environment == "production" ? "primary" : "testing" ; $ config = $ this -> app [ "nem.config" ] ; $ nisConf = $ config [ "nis" ] [ $ envConfig ] ; $ c...
Register all pre - configured NEM API clients .
58,247
public function signTransaction ( TxModel $ transaction , KeyPair $ kp = null ) { if ( null !== $ kp ) { $ transaction -> setAttribute ( "signer" , $ kp -> getPublicKey ( "hex" ) ) ; } $ serialized = $ transaction -> serialize ( ) ; $ serialHex = Buffer :: fromUInt8 ( $ serialized ) -> getHex ( ) ; $ serialBin = hex2bi...
Helper method to sign a transaction with a given keypair kp .
58,248
public function announce ( TxModel $ transaction , KeyPair $ kp = null ) { if ( null !== $ kp ) { $ transaction -> setAttribute ( "signer" , $ kp -> getPublicKey ( "hex" ) ) ; } $ serialized = $ transaction -> serialize ( ) ; $ signature = $ this -> signTransaction ( $ transaction , $ kp , $ serialized ) ; $ broadcast ...
Announce a transaction . The transaction will be serialized before it is sent to the server .
58,249
public function byHash ( $ hash ) { $ params = [ "hash" => $ hash ] ; $ apiUrl = $ this -> getPath ( 'get' , $ params ) ; $ response = $ this -> api -> getJSON ( $ apiUrl ) ; $ object = json_decode ( $ response , true ) ; return $ this -> createTransactionModel ( $ object [ 'data' ] ) ; }
Gets a transaction meta data pair where the transaction hash corresponds to the said hash parameter .
58,250
public function setOptions ( array $ options ) { foreach ( $ options as $ option => $ config ) { if ( ! ( bool ) preg_match ( "/^[0-9A-Za-z_]+$/" , $ option ) ) throw new InvalidArgumentException ( "Invalid option name provided to evias\\NEMBlockchain\\API@setOptions: " . var_export ( $ option , true ) ) ; $ upper = st...
This method allows to set the API configuration through an array rather than using the Laravel and Lumen Config contracts .
58,251
public function getRequestHandler ( ) { if ( isset ( $ this -> requestHandler ) ) return $ this -> requestHandler ; $ handlerClass = "\\" . ltrim ( $ this -> handlerClass , "\\" ) ; if ( ! class_exists ( $ handlerClass ) ) throw new RuntimeException ( "Unable to create HTTP Handler instance with class: " . var_export (...
The getRequestHandler method creates an instance of the handlerClass and returns it .
58,252
protected function encodeKey ( Buffer $ key , $ enc = null ) { if ( "hex" === $ enc || ( int ) $ enc == 16 ) { return $ key -> getHex ( ) ; } elseif ( "uint8" === $ enc || ( int ) $ enc == 8 ) { return $ key -> toUInt8 ( ) ; } elseif ( "int32" === $ enc || ( int ) $ enc == 32 ) { $ encoder = new Encoder ; return $ enco...
This method encodes a given key to the given enc codec or returns the Buffer itself if no encoding was specified .
58,253
static public function bufferize ( $ data , $ byteSize = null , $ paddingDirection = self :: PAD_LEFT ) { if ( is_integer ( $ data ) ) { return Buffer :: fromInt ( $ data , $ byteSize , null , $ paddingDirection ) ; } $ charLen = strlen ( $ data ) ; if ( ctype_xdigit ( $ data ) && $ charLen % 32 === 0 ) { return Buffer...
Build a Buffer from data .
58,254
static public function fromString ( $ string , $ paddingDirection = self :: PAD_LEFT ) { if ( ! class_exists ( "Normalizer" ) ) { return new Buffer ( $ string , null , $ paddingDirection ) ; } $ normalized = \ Normalizer :: normalize ( $ string , \ Normalizer :: FORM_KD ) ; return new Buffer ( $ normalized , null , $ p...
Build Buffer from string
58,255
static public function clampBits ( $ unsafeSecret , $ bytes = 64 ) { if ( $ unsafeSecret instanceof Buffer ) { $ toBuffer = new Buffer ( $ unsafeSecret -> getBinary ( ) , $ bytes ) ; } elseif ( ! ctype_xdigit ( $ unsafeSecret ) ) { $ toBuffer = new Buffer ( $ unsafeSecret , $ bytes ) ; } else { $ toBuffer = Buffer :: f...
Convert 64 Bytes Keccak SHA3 - 512 Hashes into a Secret Key .
58,256
static public function fromAddress ( $ address ) { if ( $ address instanceof Address ) { $ addr = $ address -> toClean ( ) ; $ prefix = substr ( $ addr , 0 , 1 ) ; } elseif ( is_string ( $ address ) ) { $ prefix = substr ( $ address , 0 , 1 ) ; } else { throw new \ InvalidArgumentException ( "Could not identify address...
Load a NetworkInfo object from an address .
58,257
static public function getPrefixFromId ( $ networkId ) { foreach ( self :: $ networkInfos as $ name => $ spec ) { if ( $ networkId === $ spec [ 'id' ] ) return $ spec [ 'hex' ] ; } throw new NISInvalidNetworkId ( "Network Id '" . $ networkId . "' is invalid." ) ; }
Helper to get a network address prefix hexadecimal representation from a network id .
58,258
static public function getFromId ( $ networkId , $ field = "name" ) { foreach ( self :: $ networkInfos as $ name => $ spec ) { if ( $ spec [ "id" ] !== ( int ) $ networkId ) continue ; if ( $ field === "name" ) return $ name ; elseif ( in_array ( $ field , array_keys ( $ spec ) ) ) return $ spec [ $ field ] ; else retu...
Helper to load a network field from a given networkId .
58,259
public function getDefinition ( $ mosaic ) { if ( ! $ this -> count ( ) ) { return false ; } $ mosaic = $ this -> prepareMosaic ( $ mosaic ) ; foreach ( $ this -> all ( ) as $ definition ) { if ( $ mosaic -> getFQN ( ) != $ definition -> id ( ) -> getFQN ( ) ) { continue ; } return $ definition ; } return false ; }
This method will find a said MosaicDefinition for the given mosaic in the current definitions collection .
58,260
protected function prepareMosaic ( $ mosaic ) { if ( $ mosaic instanceof Mosaic ) { return $ mosaic ; } elseif ( is_string ( $ mosaic ) ) { return Mosaic :: create ( $ mosaic ) ; } elseif ( is_array ( $ mosaic ) ) { $ fqmn = $ mosaic [ "namespaceId" ] . ":" . $ mosaic [ "name" ] ; return Mosaic :: create ( $ fqmn ) ; }...
Internal helper to wrap a mosaic FQN into a \ NEM \ Models \ Mosaic instance .
58,261
public function toHex ( $ prefixHexContent = false ) { $ chars = $ this -> getPlain ( ) ; if ( $ prefixHexContent && ctype_xdigit ( $ chars ) ) { return "fe" . $ chars ; } $ payload = "" ; for ( $ c = 0 , $ cnt = strlen ( $ chars ) ; $ c < $ cnt ; $ c ++ ) { $ decimal = ord ( $ chars [ $ c ] ) ; $ hexCode = dechex ( $ ...
Helper to retrieve the hexadecimal representation of a message .
58,262
protected static function prepareInputBuffer ( $ data ) { if ( $ data instanceof Buffer ) { return $ data ; } elseif ( is_string ( $ data ) && ctype_xdigit ( $ data ) ) { return Buffer :: fromHex ( $ data ) ; } elseif ( is_string ( $ data ) ) { return new Buffer ( $ data ) ; } elseif ( is_array ( $ data ) ) { return Bu...
Helper to prepare a data attribute into a \ NEM \ Core \ Buffer object for easier internal data representations .
58,263
public static function hash ( $ algo , $ data , $ returnRaw = false ) { $ data = self :: prepareInputBuffer ( $ data ) ; if ( in_array ( $ algo , hash_algos ( ) ) ) { $ hash = hash ( $ algo , $ data -> getBinary ( ) , true ) ; } elseif ( strpos ( strtolower ( $ algo ) , "keccak-" ) !== false ) { $ hash = KeccakHasher :...
Helper to hash the provided buffer data s content with algorithm algo .
58,264
public static function checksum ( $ algo , $ data , $ checksumLen = 4 ) { $ data = self :: prepareInputBuffer ( $ data ) ; $ hash = self :: hash ( $ algo , $ data , false ) -> getBinary ( ) ; $ out = new Buffer ( substr ( $ hash , 0 , $ checksumLen ) , $ checksumLen ) ; return $ out ; }
Generate a checksum of data buffer data and of length checksumLen . Default length is 4 bytes .
58,265
public static function sign ( KeyPair $ keyPair , $ data , $ algorithm = "keccak-512" ) { $ data = self :: prepareInputBuffer ( $ data ) ; $ secretKey = $ keyPair -> getSecretKey ( ) -> getBinary ( ) ; $ publicKey = $ keyPair -> getPublicKey ( ) -> getBinary ( ) ; $ data = self :: prepareInputBuffer ( $ data ) ; $ mess...
This method lets you sign data with a given keyPair .
58,266
protected function promiseResponse ( Client $ client , Request $ request , array $ options = [ ] ) { $ successCallback = isset ( $ options [ "onSuccess" ] ) && is_callable ( $ options [ "onSuccess" ] ) ? $ options [ "onSuccess" ] : null ; $ errorCallback = isset ( $ options [ "onError" ] ) && is_callable ( $ options [ ...
Use GuzzleHTTP Promises v6 Implementation to send the request asynchronously . As mentioned in the source code this method will only leverage the advantages of Asynchronous execution in later versions .
58,267
public function get ( $ uri , $ bodyJSON = null , array $ options = [ ] , $ usePromises = false ) { $ headers = [ ] ; if ( ! empty ( $ options [ "headers" ] ) ) $ headers = $ options [ "headers" ] ; if ( is_string ( $ bodyJSON ) ) { $ headers [ "Content-Length" ] = strlen ( $ bodyJSON ) ; } $ headers = $ this -> normal...
This method triggers a GET request to the given URI using the GuzzleHttp client .
58,268
public function post ( $ uri , $ bodyJSON , array $ options = [ ] , $ usePromises = false ) { $ headers = [ ] ; if ( ! empty ( $ options [ "headers" ] ) ) $ headers = $ options [ "headers" ] ; if ( is_string ( $ bodyJSON ) ) { $ headers [ "Content-Length" ] = strlen ( $ bodyJSON ) ; } $ headers = $ this -> normalizeHea...
This method triggers a POST request to the given URI using the GuzzleHttp client .
58,269
public function toNIS ( ) { if ( $ this -> getAttribute ( "timeStamp" ) ) { $ ts = $ this -> getAttribute ( "timeStamp" ) ; if ( ! empty ( $ ts ) ) return $ ts ; return $ this -> diff ( "now" , static :: $ nemesis ) ; } else { $ utc = $ this -> getAttribute ( "utc" ) ; return $ this -> diff ( $ utc , static :: $ nemesi...
Returns timestamp since NEM Nemesis block .
58,270
public function toUTC ( ) { $ ts = time ( ) ; if ( $ this -> getAttribute ( "timeStamp" ) ) { $ ts = ( int ) $ this -> getAttribute ( "timeStamp" ) ; return self :: $ nemesis + ( 1000 * $ ts ) ; } else { return $ this -> getAttribute ( "utc" ) ; } }
Returns timestamp in UTC format .
58,271
public function getPath ( $ uri , array $ params , $ withQuery = true ) { $ cleanUrl = trim ( $ this -> getBaseUrl ( ) , "/ " ) ; $ cleanUri = trim ( $ uri , "/ " ) ; if ( $ withQuery === false || empty ( $ params ) ) return sprintf ( "%s/%s" , $ this -> getBaseUrl ( ) , $ cleanUri ) ; $ query = http_build_query ( $ pa...
Helper for creating HTTP request full paths .
58,272
static public function getDefinition ( $ mosaic ) { if ( $ mosaic instanceof Mosaic ) { $ fqn = $ mosaic -> getFQN ( ) ; } elseif ( $ mosaic instanceof MosaicAttachment ) { $ fqn = $ mosaic -> mosaicId ( ) -> getFQN ( ) ; } elseif ( is_string ( $ mosaic ) ) { $ fqn = $ mosaic ; } else { throw new InvalidArgumentExcepti...
Load a pre - configured mosaic definition or fetch it using the Infrastructure service for Mosaics .
58,273
static public function morphClass ( $ fqn ) { $ namespace = "\\NEM\\Mosaics" ; $ classPath = [ ] ; if ( ( bool ) preg_match ( "/([^:]+):([^:]+)$/" , $ fqn , $ classPath ) ) { $ nsParts = explode ( "." , $ classPath [ 1 ] ) ; $ className = ucfirst ( $ classPath [ 2 ] ) ; $ transReg = "/[^a-zA-Z0-9]/" ; $ classPath = arr...
Helper to format a fully qualified mosaic name into a PHP class namespaced .
58,274
public function getProperty ( $ name ) { $ propertiesNames = [ "divisibility" => 0 , "initialSupply" => 1 , "supplyMutable" => 2 , "transferable" => 3 , ] ; if ( ! array_key_exists ( $ name , $ propertiesNames ) ) { throw new InvalidArgumentException ( "Mosaic property name '" . $ name . "' is invalid. Must be one of '...
Helper to read a given name mosaic property name .
58,275
final public function disableCrypto ( ) : Promise { if ( ( $ resource = $ this -> reader -> getResource ( ) ) === null ) { return new Failure ( new ClosedException ( 'The socket has been closed' ) ) ; } return Internal \ disableCrypto ( $ resource ) ; }
Disables encryption on this socket .
58,276
private function isAddressValid ( string $ address ) : bool { $ position = \ strrpos ( $ address , ':' ) ; if ( $ position === false ) { return ( $ address [ 0 ] ?? '' ) === "\0" ; } $ ip = \ trim ( \ substr ( $ address , 0 , $ position ) , '[]' ) ; $ port = ( int ) \ substr ( $ address , $ position + 1 ) ; return \ in...
Rough address validation to catch programming mistakes .
58,277
public function withMinimumVersion ( int $ version ) : self { if ( $ version !== self :: TLSv1_0 && $ version !== self :: TLSv1_1 && $ version !== self :: TLSv1_2 ) { throw new \ Error ( 'Invalid minimum version, only TLSv1.0, TLSv1.1 or TLSv1.2 allowed' ) ; } $ clone = clone $ this ; $ clone -> minVersion = $ version ...
Minimum TLS version to negotiate .
58,278
public function withCertificates ( array $ certificates ) : self { foreach ( $ certificates as $ key => $ certificate ) { if ( ! \ is_string ( $ key ) ) { throw new \ TypeError ( 'Expected an array mapping domain names to Certificate instances' ) ; } if ( ! $ certificate instanceof Certificate ) { throw new \ TypeError...
Certificates to use for the given host names .
58,279
public function withSecurityLevel ( int $ level ) : self { if ( $ level < 0 || $ level > 5 ) { throw new \ Error ( "Invalid security level ({$level}), must be between 0 and 5." ) ; } if ( \ OPENSSL_VERSION_NUMBER < 0x10100000 ) { throw new \ Error ( "Can't set a security level, as PHP is compiled with OpenSSL < 1.1.0."...
Security level to use .
58,280
public function addLocale ( Locale $ locale ) { if ( isset ( $ this -> localeCollection [ ( string ) $ locale ] ) ) { return false ; } $ this -> localeParentCollection = [ ] ; $ this -> localeCollection [ ( string ) $ locale ] = $ locale ; return true ; }
Adds a locale to the collection .
58,281
public function getParentLocaleOf ( Locale $ locale ) { $ localeIdentifier = ( string ) $ locale ; if ( ! isset ( $ this -> localeCollection [ $ localeIdentifier ] ) ) { return null ; } if ( isset ( $ this -> localeParentCollection [ $ localeIdentifier ] ) ) { return $ this -> localeParentCollection [ $ localeIdentifie...
Returns a parent Locale object of the locale provided .
58,282
public function getRaw ( string $ name ) : array { if ( strtolower ( $ name ) === 'cache-control' ) { return $ this -> getCacheControlDirectives ( ) ; } if ( strtolower ( $ name ) === 'set-cookie' ) { $ cookies = $ this -> fields [ 'Set-Cookie' ] ?? [ ] ; foreach ( $ this -> cookies as $ cookie ) { $ cookies [ ] = ( st...
Get raw header values
58,283
public function get ( $ name ) { if ( strtolower ( $ name ) === 'cache-control' ) { return $ this -> getCacheControlHeader ( ) ; } if ( strtolower ( $ name ) === 'set-cookie' ) { $ cookies = $ this -> fields [ 'Set-Cookie' ] ?? [ ] ; foreach ( $ this -> cookies as $ cookie ) { $ cookies [ ] = ( string ) $ cookie ; } re...
Returns the specified HTTP header
58,284
public function getAll ( ) { $ fields = $ this -> fields ; $ cacheControlHeader = $ this -> getCacheControlHeader ( ) ; $ fields [ 'Cache-Control' ] = [ $ cacheControlHeader ] ; if ( empty ( $ cacheControlHeader ) ) { unset ( $ fields [ 'Cache-Control' ] ) ; } return $ fields ; }
Returns all header fields
58,285
public function has ( $ name ) { if ( $ name === 'Cache-Control' ) { return ( $ this -> getCacheControlHeader ( ) !== null ) ; } return isset ( $ this -> fields [ $ name ] ) ; }
Checks if the specified HTTP header exists
58,286
public function getCacheControlDirective ( $ name ) { $ value = null ; switch ( $ name ) { case 'public' : $ value = ( $ this -> cacheDirectives [ 'visibility' ] === 'public' ? true : null ) ; break ; case 'private' : case 'no-cache' : preg_match ( '/^(' . $ name . ')(?:="([^"]+)")?$/' , $ this -> cacheDirectives [ 'vi...
Returns the value of the specified Cache - Control directive .
58,287
protected function setCacheControlDirectivesFromRawHeader ( $ rawFieldValue ) { foreach ( array_keys ( $ this -> cacheDirectives ) as $ key ) { $ this -> cacheDirectives [ $ key ] = '' ; } preg_match_all ( '/([a-zA-Z][a-zA-Z_-]*)\s*(?:=\s*(?:"([^"]*)"|([^,;\s"]*)))?/' , $ rawFieldValue , $ matches , PREG_SET_ORDER ) ; ...
Internally sets the cache directives correctly by parsing the given Cache - Control field value .
58,288
protected function getCacheControlHeader ( ) { $ cacheControl = '' ; foreach ( $ this -> cacheDirectives as $ cacheDirective ) { $ cacheControl .= ( $ cacheDirective !== '' ? $ cacheDirective . ', ' : '' ) ; } $ cacheControl = trim ( $ cacheControl , ' ,' ) ; return ( $ cacheControl === '' ? null : $ cacheControl ) ; }
Renders and returns a Cache - Control header based on the previously set cache control directives .
58,289
protected function setCookiesFromRawHeader ( $ rawFieldValue ) { $ cookiePairs = explode ( ';' , $ rawFieldValue ) ; foreach ( $ cookiePairs as $ cookiePair ) { if ( strpos ( $ cookiePair , '=' ) === false ) { continue ; } list ( $ name , $ value ) = explode ( '=' , $ cookiePair , 2 ) ; $ trimmedName = trim ( $ name ) ...
Internally sets cookie objects based on the Cookie header field value .
58,290
public function resolvePlaceholders ( $ textWithPlaceholders , array $ arguments , Locale $ locale = null ) { if ( $ locale === null ) { $ locale = $ this -> localizationService -> getConfiguration ( ) -> getDefaultLocale ( ) ; } $ lastPlaceHolderAt = 0 ; while ( $ lastPlaceHolderAt < strlen ( $ textWithPlaceholders ) ...
Replaces all placeholders in text with corresponding values .
58,291
protected function getFormatter ( $ formatterType ) { $ foundFormatter = false ; $ formatterType = ltrim ( $ formatterType , '\\' ) ; if ( isset ( $ this -> formatters [ $ formatterType ] ) ) { $ foundFormatter = $ this -> formatters [ $ formatterType ] ; } if ( $ foundFormatter === false ) { if ( $ this -> objectManag...
Returns instance of concrete formatter .
58,292
public function authenticate ( TokenInterface $ authenticationToken ) { if ( ! ( $ authenticationToken instanceof PasswordToken ) ) { throw new UnsupportedAuthenticationTokenException ( 'This provider cannot authenticate the given token.' , 1217339840 ) ; } $ credentials = $ authenticationToken -> getCredentials ( ) ; ...
Sets isAuthenticated to true for all tokens .
58,293
public function destroyAllCommand ( ) { $ this -> cacheManager -> getCache ( 'Flow_Session_Storage' ) -> flush ( ) ; $ this -> cacheManager -> getCache ( 'Flow_Session_MetaData' ) -> flush ( ) ; $ this -> outputLine ( 'Destroyed all sessions.' ) ; $ this -> sendAndExit ( 0 ) ; }
Destroys all sessions . This special command is needed because sessions are kept in persistent storage and are not flushed with other caches by default .
58,294
public function initializeObject ( ) { if ( $ this -> cache -> has ( 'typeConverterMap' ) ) { $ this -> typeConverters = $ this -> cache -> get ( 'typeConverterMap' ) ; return ; } $ this -> typeConverters = $ this -> prepareTypeConverterMap ( ) ; $ this -> cache -> set ( 'typeConverterMap' , $ this -> typeConverters ) ...
Lifecycle method called after all dependencies have been injected . Here the typeConverter array gets initialized .
58,295
protected function doMapping ( $ source , $ targetType , PropertyMappingConfigurationInterface $ configuration , & $ currentPropertyPath ) { $ targetTypeWithoutNull = TypeHandling :: stripNullableType ( $ targetType ) ; $ isNullableType = $ targetType !== $ targetTypeWithoutNull ; if ( $ source === null && $ isNullable...
Internal function which actually does the property mapping .
58,296
protected function findTypeConverter ( $ source , $ targetType , PropertyMappingConfigurationInterface $ configuration ) { if ( $ configuration -> getTypeConverter ( ) !== null ) { return $ configuration -> getTypeConverter ( ) ; } if ( ! is_string ( $ targetType ) ) { throw new Exception \ InvalidTargetException ( 'Th...
Determine the type converter to be used . If no converter has been found an exception is raised .
58,297
protected function findFirstEligibleTypeConverterInObjectHierarchy ( $ source , $ sourceType , $ targetType ) { $ targetClass = TypeHandling :: truncateElementType ( $ targetType ) ; if ( ! class_exists ( $ targetClass ) && ! interface_exists ( $ targetClass ) ) { throw new Exception \ InvalidTargetException ( sprintf ...
Tries to find a suitable type converter for the given source and target type .
58,298
protected function determineSourceTypes ( $ source ) { if ( is_string ( $ source ) ) { return [ 'string' ] ; } elseif ( is_array ( $ source ) ) { return [ 'array' ] ; } elseif ( is_float ( $ source ) ) { return [ 'float' ] ; } elseif ( is_integer ( $ source ) ) { return [ 'integer' ] ; } elseif ( is_bool ( $ source ) )...
Determine the type of the source data or throw an exception if source was an unsupported format .
58,299
protected function prepareTypeConverterMap ( ) { $ typeConverterMap = [ ] ; $ typeConverterClassNames = static :: getTypeConverterImplementationClassNames ( $ this -> objectManager ) ; foreach ( $ typeConverterClassNames as $ typeConverterClassName ) { $ typeConverter = $ this -> objectManager -> get ( $ typeConverterC...
Collects all TypeConverter implementations in a multi - dimensional array with source and target types .