idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
13,100
|
public function fetchAll ( string $ sql , array $ values = [ ] , int $ fetchMode = null , array $ driverOptions = [ ] ) : Sequence { return Sequence :: of ( new QueryResultIterator ( $ this -> dbConnection -> prepare ( $ sql ) -> execute ( $ values ) , $ fetchMode , $ driverOptions ) ) ; }
|
return all result rows for given sql query
|
13,101
|
public function fetchRow ( string $ sql , array $ values = [ ] , int $ fetchMode = null , array $ driverOptions = [ ] ) : array { return $ this -> dbConnection -> prepare ( $ sql ) -> execute ( $ values ) -> fetch ( $ fetchMode , $ driverOptions ) ; }
|
returns first result row for given sql query
|
13,102
|
public function fetchColumn ( string $ sql , array $ values = [ ] , int $ columnIndex = 0 ) : Sequence { return $ this -> fetchAll ( $ sql , $ values , \ PDO :: FETCH_COLUMN , [ 'columnIndex' => $ columnIndex ] ) ; }
|
return a list with all rows from given result
|
13,103
|
private function compute ( Dataset $ data ) : array { $ dimension = $ data -> dimension ( ) -> rows ( ) ; $ elements = $ dimension -> value ( ) ; $ x = $ data -> abscissas ( ) -> toArray ( ) ; $ y = $ data -> ordinates ( ) -> toArray ( ) ; $ xSum = $ data -> abscissas ( ) -> sum ( ) ; $ ySum = $ data -> ordinates ( ) -> sum ( ) ; $ xxSum = new Integer ( 0 ) ; $ xySum = new Integer ( 0 ) ; for ( $ i = 0 ; $ i < $ elements ; $ i ++ ) { $ xySum = add ( $ xySum , multiply ( $ x [ $ i ] , $ y [ $ i ] ) ) ; $ xxSum = add ( $ xxSum , multiply ( $ x [ $ i ] , $ x [ $ i ] ) ) ; } $ slope = divide ( subtract ( $ dimension -> multiplyBy ( $ xySum ) , $ xSum -> multiplyBy ( $ ySum ) ) , subtract ( $ dimension -> multiplyBy ( $ xxSum ) , $ xSum -> power ( new Integer ( 2 ) ) ) ) ; $ intercept = divide ( subtract ( $ ySum , $ slope -> multiplyBy ( $ xSum ) ) , $ dimension ) ; return [ $ slope , $ intercept ] ; }
|
Determine the slope and intercept for the given dataset
|
13,104
|
public function getMalusToBaseOfWoundsWithWeaponlike ( WeaponlikeCode $ weaponlikeCode , Tables $ tables , bool $ fightsWithTwoWeapons ) : int { if ( $ weaponlikeCode -> isMelee ( ) || $ weaponlikeCode -> isThrowingWeapon ( ) ) { return $ this -> getPhysicalSkills ( ) -> getMalusToBaseOfWoundsWithWeaponlike ( $ weaponlikeCode , $ tables , $ fightsWithTwoWeapons ) ; } if ( $ weaponlikeCode -> isShootingWeapon ( ) ) { return $ this -> getCombinedSkills ( ) -> getMalusToBaseOfWoundsWithShootingWeapon ( $ weaponlikeCode -> convertToRangedWeaponCodeEquivalent ( ) , $ tables ) ; } if ( $ weaponlikeCode -> isProjectile ( ) ) { return 0 ; } throw new Exceptions \ UnknownTypeOfWeapon ( $ weaponlikeCode ) ; }
|
If you want to use shield as a PROTECTIVE item there is no base of wounds malus from that .
|
13,105
|
public function preRemove ( EventArgs $ args ) { $ entity = $ args -> getEntity ( ) ; if ( $ entity instanceof SakonninFile ) { $ this -> removes [ ] = $ entity -> getStoredAs ( ) ; } }
|
Ensures a proxy will be usable in the postRemove .
|
13,106
|
public function updateEntry ( $ package ) { $ this -> verifyCommand ( $ package ) ; $ lines = file ( $ this -> less ) ; $ lines [ 0 ] = '@bg: ' . $ package [ 'bg' ] . ";\n" ; $ lines [ 1 ] = '@gray: ' . $ package [ 'gray' ] . ";\n" ; $ lines [ 2 ] = '@brand-primary: ' . $ package [ 'primary' ] . ";\n" ; $ lines [ 3 ] = '@brand-info: ' . $ package [ 'info' ] . ";\n" ; $ lines [ 4 ] = '@brand-success: ' . $ package [ 'success' ] . ";\n" ; $ lines [ 5 ] = '@brand-warning: ' . $ package [ 'warning' ] . ";\n" ; $ lines [ 6 ] = '@brand-danger: ' . $ package [ 'danger' ] . ";\n" ; $ lines [ 7 ] = '@menuColor: ' . $ package [ 'menu' ] . ";\n" ; $ this -> file -> delete ( $ this -> less ) ; $ this -> file -> put ( $ this -> less , implode ( $ lines ) ) ; }
|
Update the colors . less file to persist the changes
|
13,107
|
public function getLoggingFormatter ( ) { if ( null === $ this -> loggingFormatter ) { @ trigger_error ( sprintf ( 'The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the ContainerBuilder::log() method instead.' , __METHOD__ ) , E_USER_DEPRECATED ) ; $ this -> loggingFormatter = new LoggingFormatter ( ) ; } return $ this -> loggingFormatter ; }
|
Returns the logging formatter which can be used by compilation passes .
|
13,108
|
public function validateJson ( string $ json , string $ schemaName ) : ValidationResult { $ schemaDir = $ this -> config -> get ( 'schema-dir' ) ; $ schemaPath = $ this -> configDirectoryPath . $ schemaDir . '/' . $ schemaName . '.json' ; if ( ! file_exists ( $ schemaPath ) ) { throw new FileNotFoundException ( "File $schemaPath not found" ) ; } $ schemaJsonString = file_get_contents ( $ schemaPath ) ; $ decodedJson = json_decode ( $ json ) ; if ( $ decodedJson === false ) { $ schema = json_decode ( $ schemaJsonString ) ; return ( new ValidationResult ( ) ) -> addError ( new ValidationError ( $ json , [ ] , [ ] , $ schema , "Failed to decode JSON string" ) ) ; } return $ this -> dataValidation ( $ decodedJson , $ schemaJsonString ) ; }
|
Validates JSON strings against a schema .
|
13,109
|
function ExecuteSql ( ) { $ versionCompare = version_compare ( $ this -> installedVersion , $ this -> manifest -> Version ( ) ) ; if ( $ versionCompare > 0 ) { $ bundle = $ this -> manifest -> BundleName ( ) ; throw new \ Exception ( "Error instaling bundle $bundle: Previously installed version is greater than curren code version. Please re-install the bundle." ) ; } else if ( $ versionCompare === 0 ) { return ; } $ engineFolder = $ this -> FindEngineFolder ( ) ; if ( ! $ engineFolder ) { return ; } $ this -> ExecuteScripts ( $ engineFolder ) ; }
|
Executes all necessary sql scripts
|
13,110
|
private function ExecuteScripts ( $ engineFolder ) { $ files = $ this -> SortFilesByVersion ( Folder :: GetFiles ( $ engineFolder ) ) ; $ completeSql = '' ; foreach ( $ files as $ file ) { $ sqlFile = Path :: Combine ( $ engineFolder , $ file ) ; $ completeSql .= "\r\n" . File :: GetContents ( $ sqlFile ) ; } try { $ this -> CleanAllForeignKeys ( ) ; $ this -> connection -> ExecuteMultiQuery ( $ completeSql ) ; } catch ( \ Exception $ exc ) { throw $ exc ; } }
|
Executes all necessary scripts in the engine folder
|
13,111
|
private function CleanForeignKeys ( $ table ) { $ foreignKeys = $ this -> connection -> GetForeignKeys ( $ table ) ; foreach ( $ foreignKeys as $ foreignKey ) { $ this -> connection -> DropForeignKey ( $ table , $ foreignKey ) ; } }
|
Cleans all foreign keys of a table
|
13,112
|
private function SortFilesByVersion ( array $ files ) { $ result = array ( ) ; $ foreignKeysFile = '' ; foreach ( $ files as $ file ) { if ( $ file == 'foreign-keys.sql' ) { $ foreignKeysFile = $ file ; continue ; } $ version = Path :: RemoveExtension ( $ file ) ; if ( $ this -> installedVersion && version_compare ( $ version , $ this -> installedVersion ) <= 0 ) { continue ; } $ result [ $ version ] = $ file ; } uksort ( $ result , "version_compare" ) ; if ( $ foreignKeysFile ) { $ result [ ] = $ foreignKeysFile ; } return $ result ; }
|
Sorts files by version
|
13,113
|
public function actionIndex ( ) { $ query = Client :: find ( ) -> where ( [ 'user_id' => Yii :: $ app -> user -> id ] ) -> orderBy ( [ 'created_at' => SORT_DESC ] ) ; $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , ] ) ; return $ this -> render ( 'index' , [ 'dataProvider' => $ dataProvider , ] ) ; }
|
Lists all App models .
|
13,114
|
public function actionCreate ( ) { $ model = new Client ( ) ; if ( Yii :: $ app -> request -> isAjax && $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { Yii :: $ app -> response -> format = Response :: FORMAT_JSON ; return ActiveForm :: validate ( $ model ) ; } else if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { Yii :: $ app -> getSession ( ) -> setFlash ( 'success' , Yii :: t ( 'oauth2' , 'Successful operation' ) ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> client_id ] ) ; } else { return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; } }
|
Creates a new Rest model . If creation is successful the browser will be redirected to the view page .
|
13,115
|
protected function createHttpRequest ( ) { $ protocol = ( isset ( $ _SERVER [ 'HTTPS' ] ) === true && $ _SERVER [ 'HTTPS' ] === 'on' ) ? HttpRequest :: PROTOCOL_HTTPS : HttpRequest :: PROTOCOL_HTTP ; $ uri = StringUtils :: startsWith ( $ _SERVER [ 'REQUEST_URI' ] , '/index.php' ) ? StringUtils :: afterFirst ( $ _SERVER [ 'REQUEST_URI' ] , '/index.php' ) : $ _SERVER [ 'REQUEST_URI' ] ; $ subFolder = StringUtils :: afterFirst ( getcwd ( ) , $ _SERVER [ 'DOCUMENT_ROOT' ] ) ; $ cleanPath = StringUtils :: between ( $ uri , $ subFolder , '?' ) ; $ languages = array ( ) ; $ langsRates = explode ( ',' , isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ? $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] : null ) ; foreach ( $ langsRates as $ lr ) { $ lrParts = explode ( ';' , $ lr ) ; $ languages [ $ lrParts [ 0 ] ] = isset ( $ lrParts [ 1 ] ) ? ( float ) StringUtils :: afterFirst ( $ lrParts [ 1 ] , 'q=' ) : 1.0 ; } $ requestTime = new \ DateTime ( ) ; $ requestTime -> setTimestamp ( $ _SERVER [ 'REQUEST_TIME' ] ) ; $ httpRequest = new HttpRequest ( ) ; $ httpRequest -> setHost ( $ _SERVER [ 'SERVER_NAME' ] ) ; $ httpRequest -> setPath ( $ cleanPath ) ; $ httpRequest -> setPort ( $ _SERVER [ 'SERVER_PORT' ] ) ; $ httpRequest -> setProtocol ( $ protocol ) ; $ httpRequest -> setQuery ( $ _SERVER [ 'QUERY_STRING' ] ) ; $ httpRequest -> setURI ( $ uri ) ; $ httpRequest -> setRequestTime ( $ requestTime ) ; $ httpRequest -> setRequestMethod ( $ _SERVER [ 'REQUEST_METHOD' ] ) ; $ httpRequest -> setUserAgent ( isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ? $ _SERVER [ 'HTTP_USER_AGENT' ] : null ) ; $ httpRequest -> setLanguages ( $ languages ) ; $ httpRequest -> setAcceptLanguage ( isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ? $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] : null ) ; $ httpRequest -> setRemoteAddress ( $ _SERVER [ 'REMOTE_ADDR' ] ) ; $ httpRequest -> setReferrer ( isset ( $ _SERVER [ 'HTTP_REFERER' ] ) ? $ _SERVER [ 'HTTP_REFERER' ] : null ) ; return $ httpRequest ; }
|
Creates a HttpRequest object for the current request
|
13,116
|
public static function camelTo_ ( $ str ) { if ( ! is_string ( $ str ) ) return '' ; $ str [ 0 ] = strtolower ( $ str [ 0 ] ) ; $ func = create_function ( '$c' , 'return "_" . strtolower($c[1]);' ) ; return preg_replace_callback ( '/([A-Z])/' , $ func , $ str ) ; }
|
Turns camelCasedString to under_scored_string
|
13,117
|
public static function camelToHyphen ( $ str , $ strtolower = true ) { if ( ! is_string ( $ str ) ) return '' ; $ str [ 0 ] = strtolower ( $ str [ 0 ] ) ; $ func = create_function ( '$c' , 'return "-" . $c[1];' ) ; $ str = preg_replace_callback ( '/([A-Z])/' , $ func , $ str ) ; return ( $ strtolower ) ? strtolower ( $ str ) : $ str ; }
|
Turns camelCasedString to hyphened - string
|
13,118
|
public static function camelToSpace ( $ str ) { if ( ! is_string ( $ str ) ) return '' ; $ str [ 0 ] = strtolower ( $ str [ 0 ] ) ; $ func = create_function ( '$c' , 'return " " . $c[1];' ) ; return preg_replace_callback ( '/([A-Z])/' , $ func , $ str ) ; }
|
Turns camelCasedString to spaced out string
|
13,119
|
public static function readDir ( $ dir , $ return = Util :: ALL , $ recursive = false , $ extension = NULL , $ nameOnly = false , array $ options = array ( ) ) { if ( ! is_dir ( $ dir ) ) return array ( 'error' => 'Directory "' . $ dir . '" does not exist' , ) ; if ( ! is_array ( $ extension ) && ! empty ( $ extension ) ) { $ extension = array ( $ extension ) ; } if ( substr ( $ dir , strlen ( $ dir ) - 1 ) !== DIRECTORY_SEPARATOR ) $ dir .= DIRECTORY_SEPARATOR ; $ toReturn = array ( 'dirs' => array ( ) , 'files' => array ( ) ) ; try { foreach ( scandir ( $ dir ) as $ current ) { if ( in_array ( $ current , array ( '.' , '..' ) ) ) continue ; if ( is_dir ( $ dir . $ current ) ) { if ( in_array ( $ return , array ( self :: DIRS_ONLY , self :: ALL ) ) ) { $ toReturn [ 'dirs' ] [ ] = ( $ nameOnly ) ? $ current : $ dir . $ current ; } if ( $ recursive ) { $ toReturn = array_merge_recursive ( $ toReturn , self :: readDir ( $ dir . $ current , self :: ALL , true , $ extension , $ nameOnly , $ options ) ) ; } } else if ( is_file ( $ dir . $ current ) && in_array ( $ return , array ( self :: FILES_ONLY , self :: ALL ) ) ) { if ( $ extension ) $ info = pathinfo ( $ current ) ; if ( empty ( $ extension ) || ( is_array ( $ extension ) && in_array ( $ info [ 'extension' ] , $ extension ) ) ) { $ toReturn [ 'files' ] [ $ dir ] [ ] = ( $ nameOnly ) ? $ current : $ dir . $ current ; } } } if ( $ return == self :: ALL ) return $ toReturn ; elseif ( $ return == self :: DIRS_ONLY ) return $ toReturn [ 'dirs' ] ; elseif ( $ return == self :: FILES_ONLY ) return $ toReturn [ 'files' ] ; } catch ( \ Exception $ ex ) { throw new \ Exception ( $ ex -> getMessage ( ) ) ; } }
|
Reads the required source directory
|
13,120
|
public static function copyDir ( $ source , $ destination , $ permission = 0777 , $ recursive = true ) { if ( substr ( $ source , strlen ( $ destination ) - 1 ) !== DIRECTORY_SEPARATOR ) $ destination .= DIRECTORY_SEPARATOR ; try { if ( ! is_dir ( $ destination ) ) mkdir ( $ destination , $ permission ) ; $ contents = self :: readDir ( $ source , self :: ALL , $ recursive , NULL ) ; if ( isset ( $ contents [ 'dirs' ] ) ) { foreach ( $ contents [ 'dirs' ] as $ fullPath ) { @ mkdir ( str_replace ( array ( $ source , DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) , array ( $ destination , DIRECTORY_SEPARATOR ) , $ fullPath ) , $ permission ) ; } } if ( isset ( $ contents [ 'files' ] ) ) { foreach ( $ contents [ 'files' ] as $ fullPathsArray ) { foreach ( $ fullPathsArray as $ fullPath ) { @ copy ( $ fullPath , str_replace ( array ( $ source , DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) , array ( $ destination , DIRECTORY_SEPARATOR ) , $ fullPath ) ) ; } } } } catch ( \ Exception $ ex ) { throw new \ Exception ( $ ex -> getMessage ( ) ) ; } }
|
Copies a directory to another location
|
13,121
|
public static function delDir ( $ dir ) { $ all = self :: readDir ( $ dir , self :: ALL , true , NULL ) ; if ( isset ( $ all [ 'files' ] ) ) { foreach ( $ all [ 'files' ] as $ file ) { if ( is_array ( $ file ) ) { foreach ( $ file as $ fil ) { if ( ! unlink ( $ fil ) ) { return false ; } } } else { if ( ! unlink ( $ file ) ) { return false ; } } } } if ( isset ( $ all [ 'dirs' ] ) ) { foreach ( array_reverse ( $ all [ 'dirs' ] ) as $ _dir ) { if ( is_array ( $ _dir ) ) { foreach ( $ _dir as $ _dr ) { if ( ! rmdir ( $ _dr ) ) { return false ; } } } else { if ( ! rmdir ( $ _dir ) ) { return false ; } } } } return rmdir ( $ dir ) ; }
|
Deletes a directory and all contents including subdirectories and files
|
13,122
|
public static function resizeImageDirectory ( $ dir , $ desiredWidth = 200 , $ overwrite = false , $ recursive = true , $ subDir = 'resized' ) { foreach ( self :: readDir ( $ dir , self :: FILES_ONLY , $ recursive , null , true ) as $ path => $ filesArray ) { foreach ( $ filesArray as $ file ) { $ destination = null ; if ( ! $ overwrite ) { if ( ! is_dir ( $ path . $ subDir ) ) { mkdir ( $ path . $ subDir ) ; } $ destination = $ path . $ subDir . DIRECTORY_SEPARATOR . $ file ; } self :: resizeImage ( $ path . $ file , $ desiredWidth , $ destination ) ; } } }
|
Resize all images in a directory
|
13,123
|
public static function shortenString ( $ str , $ length = 75 , $ break = '...' ) { if ( strlen ( $ str ) < $ length ) return $ str ; $ str = strip_tags ( $ str ) ; return substr ( $ str , 0 , $ length ) . $ break ; }
|
Shortens a string to desired length
|
13,124
|
public static function randomPassword ( $ length = 8 , $ string = null ) { if ( ! $ string ) $ string = 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ123456789&^%$#@!_-+=' ; $ chars = str_split ( str_shuffle ( $ string ) ) ; $ password = '' ; foreach ( array_rand ( $ chars , $ length ) as $ key ) { $ password .= $ chars [ $ key ] ; } return $ password ; }
|
Generates a random password
|
13,125
|
public static function listTimezones ( ) { if ( self :: $ timezones === null ) { self :: $ timezones = array ( ) ; $ offsets = array ( ) ; $ now = new DateTime ( ) ; foreach ( DateTimeZone :: listIdentifiers ( ) as $ timezone ) { $ now -> setTimezone ( new DateTimeZone ( $ timezone ) ) ; $ offsets [ ] = $ offset = $ now -> getOffset ( ) ; self :: $ timezones [ $ timezone ] = '(' . self :: formatGmtOffset ( $ offset ) . ') ' . self :: formatTimezoneName ( $ timezone ) ; } array_multisort ( $ offsets , self :: $ timezones ) ; } return self :: $ timezones ; }
|
Create a list of time zones
|
13,126
|
public static function formatGmtOffset ( $ offset ) { $ hours = intval ( $ offset / 3600 ) ; $ minutes = abs ( intval ( $ offset % 3600 / 60 ) ) ; return 'GMT' . ( $ offset ? sprintf ( '%+03d:%02d' , $ hours , $ minutes ) : '' ) ; }
|
Formats GMT offset to string
|
13,127
|
public function applyData ( $ data = NULL ) { if ( NULL != $ data && is_array ( $ data ) ) { foreach ( $ data as $ propName => $ propValue ) { $ this -> assignValue ( $ propName , $ propValue ) ; } } else { $ this -> buildVars ( ) ; } }
|
apply given data to properties
|
13,128
|
public function assignExisting ( $ propName , $ propValue ) { if ( is_bool ( $ this -> $ propName ) ) { if ( strtolower ( $ propValue ) == 'false' ) { $ propValue = false ; } $ this -> $ propName = ( bool ) $ propValue ; } elseif ( is_int ( $ this -> $ propName ) ) { $ this -> $ propName = ( int ) $ propValue ; } elseif ( is_bool ( $ this -> $ propName ) ) { $ this -> $ propName = ( bool ) $ propValue ; } elseif ( $ this -> $ propName instanceof Timer || $ this -> $ propName == MapConst :: TIMER ) { $ this -> $ propName = new Timer ( $ propValue ) ; } else { $ this -> $ propName = $ propValue ; } }
|
assign value to a existing propertie and cast depending on defined default value
|
13,129
|
public function assignValue ( $ propNameOrig , $ propValue ) { $ propNameA = str_replace ( self :: $ replaceChars , '_' , $ propNameOrig ) ; $ propName = preg_replace ( "/[^A-Za-z0-9_]/" , "" , $ propNameA ) ; if ( property_exists ( $ this , $ propName ) && $ this -> $ propName !== NULL ) { $ this -> assignExisting ( $ propName , $ propValue ) ; } elseif ( $ propName !== '' ) { $ this -> $ propName = $ propValue ; } }
|
main assign value method .
|
13,130
|
public function getPrincipal ( ) : Principal { if ( $ this -> principal === null && ! $ this -> resume ( ) ) { $ this -> principal = Principal :: getAnonymous ( ) ; } return $ this -> principal ; }
|
Gets the currently authenticated principal .
|
13,131
|
public function login ( ServerRequestInterface $ request , ? Adapter $ adapter = null ) : bool { $ started = $ this -> session -> resume ( ) || $ this -> session -> start ( ) ; if ( ! $ started ) { return false ; } $ login = $ adapter ?? $ this -> adapter ; if ( $ login === null ) { throw new \ InvalidArgumentException ( 'You must specify an adapter for authentication' ) ; } $ this -> principal = $ principal = $ login -> login ( $ request ) ; $ this -> session -> clear ( ) ; $ this -> session -> regenerateId ( ) ; $ this -> values -> offsetSet ( 'principal' , $ principal ) ; $ now = microtime ( true ) ; $ this -> values -> offsetSet ( 'firstActive' , $ now ) ; $ this -> values -> offsetSet ( 'lastActive' , $ now ) ; $ this -> logger -> info ( "Authentication login: {user}" , [ 'user' => $ principal ] ) ; return $ this -> publishLogin ( $ principal ) ; }
|
Authenticates a principal .
|
13,132
|
protected function publishLogin ( Principal $ principal ) : bool { $ this -> publisher -> publish ( new Event \ Login ( $ this , $ principal ) ) ; return true ; }
|
Publishes the login event .
|
13,133
|
public function resume ( ) : bool { if ( $ this -> values -> offsetExists ( 'principal' ) ) { $ this -> principal = $ this -> values -> get ( 'principal' ) ; $ this -> logger -> info ( "Authentication resume: {user}" , [ 'user' => $ this -> principal ] ) ; $ this -> publishResume ( $ this -> principal , $ this -> values ) ; $ this -> values -> offsetSet ( 'lastActive' , microtime ( true ) ) ; return true ; } return false ; }
|
Resumes an existing authenticated session .
|
13,134
|
protected function publishResume ( Principal $ principal , Map $ values ) { $ this -> publisher -> publish ( new Event \ Resume ( $ this , $ principal , $ values -> get ( 'firstActive' ) ?? 0.0 , $ values -> get ( 'lastActive' ) ?? 0.0 ) ) ; }
|
Publishes the resume event .
|
13,135
|
public function logout ( ) : bool { if ( $ this -> values -> offsetExists ( 'principal' ) ) { $ principal = $ this -> getPrincipal ( ) ; $ this -> principal = Principal :: getAnonymous ( ) ; $ this -> session -> destroy ( ) ; $ this -> logger -> info ( "Authentication logout: {user}" , [ 'user' => $ principal ] ) ; return $ this -> publishLogout ( $ principal ) ; } return false ; }
|
Logs out the currently authenticated principal .
|
13,136
|
protected function publishLogout ( Principal $ principal ) : bool { $ this -> publisher -> publish ( new Event \ Logout ( $ this , $ principal ) ) ; return true ; }
|
Publishes the logout event .
|
13,137
|
public static function instance ( $ role ) { if ( ! self :: $ instances ) { self :: $ instances = [ self :: RESPONDER => new self ( self :: RESPONDER ) , self :: AUTHORIZER => new self ( self :: AUTHORIZER ) , self :: FILTER => new self ( self :: FILTER ) , ] ; } if ( ! array_key_exists ( $ role , self :: $ instances ) ) { throw new \ InvalidArgumentException ( "Invalid Role $role" ) ; } return self :: $ instances [ $ role ] ; }
|
Returns an instance of the given role .
|
13,138
|
public function config ( $ eid , $ secret , $ country , $ language , $ currency , $ mode = Klarna :: LIVE , $ pcStorage = 'json' , $ pcURI = 'pclasses.json' , $ ssl = true ) { try { KlarnaConfig :: $ store = false ; $ this -> config = new KlarnaConfig ( null ) ; $ this -> config [ 'eid' ] = $ eid ; $ this -> config [ 'secret' ] = $ secret ; $ this -> config [ 'country' ] = $ country ; $ this -> config [ 'language' ] = $ language ; $ this -> config [ 'currency' ] = $ currency ; $ this -> config [ 'mode' ] = $ mode ; $ this -> config [ 'ssl' ] = $ ssl ; $ this -> config [ 'pcStorage' ] = $ pcStorage ; $ this -> config [ 'pcURI' ] = $ pcURI ; $ this -> init ( ) ; } catch ( Exception $ e ) { $ this -> config = null ; throw new KlarnaException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } }
|
Method of ease for setting common config fields .
|
13,139
|
public function setConfig ( & $ config ) { $ this -> _checkConfig ( $ config ) ; $ this -> config = $ config ; $ this -> init ( ) ; }
|
Sets and initializes this Klarna object using the supplied config object .
|
13,140
|
public function setCountry ( $ country ) { if ( ! is_numeric ( $ country ) && ( strlen ( $ country ) == 2 || strlen ( $ country ) == 3 ) ) { $ country = KlarnaCountry :: fromCode ( $ country ) ; } $ this -> _checkCountry ( $ country ) ; $ this -> _country = $ country ; }
|
Sets the country used .
|
13,141
|
public function getCountryCode ( $ country = null ) { if ( $ country === null ) { $ country = $ this -> _country ; } $ code = KlarnaCountry :: getCode ( $ country ) ; return ( string ) $ code ; }
|
Returns the country code for the set country constant .
|
13,142
|
public function setLanguage ( $ language ) { if ( ! is_numeric ( $ language ) && strlen ( $ language ) == 2 ) { $ this -> setLanguage ( self :: getLanguageForCode ( $ language ) ) ; } else { $ this -> _checkLanguage ( $ language ) ; $ this -> _language = $ language ; } }
|
Sets the language used .
|
13,143
|
public function getLanguageCode ( $ language = null ) { if ( $ language === null ) { $ language = $ this -> _language ; } $ code = KlarnaLanguage :: getCode ( $ language ) ; return ( string ) $ code ; }
|
Returns the language code for the set language constant .
|
13,144
|
public function setCurrency ( $ currency ) { if ( ! is_numeric ( $ currency ) && strlen ( $ currency ) == 3 ) { $ this -> setCurrency ( self :: getCurrencyForCode ( $ currency ) ) ; } else { $ this -> _checkCurrency ( $ currency ) ; $ this -> _currency = $ currency ; } }
|
Sets the currency used .
|
13,145
|
public function getCurrencyCode ( $ currency = null ) { if ( $ currency === null ) { $ currency = $ this -> _currency ; } $ code = KlarnaCurrency :: getCode ( $ currency ) ; return ( string ) $ code ; }
|
Returns the the currency code for the set currency constant .
|
13,146
|
public function setSessionID ( $ name , $ sid ) { $ this -> _checkArgument ( $ name , "name" ) ; $ this -> _checkArgument ( $ sid , "sid" ) ; $ this -> sid [ $ name ] = $ sid ; }
|
Sets the session id s for various device identification behaviour identification software .
|
13,147
|
public function getClientIP ( ) { if ( isset ( $ this -> clientIP ) ) { return $ this -> clientIP ; } $ tmp_ip = '' ; $ x_fwd = null ; if ( array_key_exists ( 'REMOTE_ADDR' , $ _SERVER ) ) { $ tmp_ip = $ _SERVER [ 'REMOTE_ADDR' ] ; } if ( isset ( $ _SERVER [ "HTTP_X_FORWARDED_FOR" ] ) ) { $ x_fwd = $ _SERVER [ "HTTP_X_FORWARDED_FOR" ] ; } if ( self :: $ x_forwarded_for && ( $ x_fwd !== null ) ) { $ forwarded = explode ( "," , $ x_fwd ) ; return trim ( $ forwarded [ 0 ] ) ; } return $ tmp_ip ; }
|
Returns the clients IP address .
|
13,148
|
public function setAddress ( $ type , $ addr ) { if ( ! ( $ addr instanceof KlarnaAddr ) ) { throw new Klarna_InvalidKlarnaAddrException ; } if ( $ addr -> isCompany === null ) { $ addr -> isCompany = false ; } if ( $ type === KlarnaFlags :: IS_SHIPPING ) { $ this -> shipping = $ addr ; self :: printDebug ( "shipping address array" , $ this -> shipping ) ; return ; } if ( $ type === KlarnaFlags :: IS_BILLING ) { $ this -> billing = $ addr ; self :: printDebug ( "billing address array" , $ this -> billing ) ; return ; } throw new Klarna_UnknownAddressTypeException ( $ type ) ; }
|
Sets the specified address for the current order .
|
13,149
|
public function addArticle ( $ qty , $ artNo , $ title , $ price , $ vat , $ discount = 0 , $ flags = KlarnaFlags :: INC_VAT ) { $ this -> _checkQty ( $ qty ) ; if ( ( ( $ artNo === null ) || ( $ artNo == "" ) ) && ( ( $ title === null ) || ( $ title == "" ) ) ) { throw new Klarna_ArgumentNotSetException ( 'Title and ArtNo' , 50026 ) ; } $ this -> _checkPrice ( $ price ) ; $ this -> _checkVAT ( $ vat ) ; $ this -> _checkDiscount ( $ discount ) ; $ this -> _checkInt ( $ flags , 'flags' ) ; if ( ! $ this -> goodsList || ! is_array ( $ this -> goodsList ) ) { $ this -> goodsList = array ( ) ; } $ tmpArr = array ( "artno" => $ artNo , "title" => $ title , "price" => $ price , "vat" => $ vat , "discount" => $ discount , "flags" => $ flags ) ; $ this -> goodsList [ ] = array ( "goods" => $ tmpArr , "qty" => $ qty ) ; if ( count ( $ this -> goodsList ) > 0 ) { self :: printDebug ( "article added" , $ this -> goodsList [ count ( $ this -> goodsList ) - 1 ] ) ; } }
|
Adds an article to the current goods list for the current order .
|
13,150
|
public function summarizeGoodsList ( ) { $ amount = 0 ; if ( ! is_array ( $ this -> goodsList ) ) { return $ amount ; } foreach ( $ this -> goodsList as $ goods ) { $ price = $ goods [ 'goods' ] [ 'price' ] ; if ( ( $ goods [ 'goods' ] [ 'flags' ] & KlarnaFlags :: INC_VAT ) === 0 ) { $ vat = $ goods [ 'goods' ] [ 'vat' ] / 100.0 ; $ price *= ( 1.0 + $ vat ) ; } if ( $ goods [ 'goods' ] [ 'discount' ] > 0 ) { $ discount = $ goods [ 'goods' ] [ 'discount' ] / 100.0 ; $ price *= ( 1.0 - $ discount ) ; } $ amount += $ price * ( int ) $ goods [ 'qty' ] ; } return $ amount ; }
|
Summarizes the prices of the held goods list
|
13,151
|
public function cancelReservation ( $ rno ) { $ this -> _checkRNO ( $ rno ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ this -> _eid , $ rno , $ this -> _secret ) ) ; $ paramList = array ( $ rno , $ this -> _eid , $ digestSecret ) ; self :: printDebug ( 'cancel_reservation' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'cancel_reservation' , $ paramList ) ; return ( $ result == 'ok' ) ; }
|
Cancels a reservation .
|
13,152
|
public function changeReservation ( $ rno , $ amount , $ flags = KlarnaFlags :: NEW_AMOUNT ) { $ this -> _checkRNO ( $ rno ) ; $ this -> _checkAmount ( $ amount ) ; $ this -> _checkInt ( $ flags , 'flags' ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ this -> _eid , $ rno , $ amount , $ this -> _secret ) ) ; $ paramList = array ( $ rno , $ amount , $ this -> _eid , $ digestSecret , $ flags ) ; self :: printDebug ( 'change_reservation' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'change_reservation' , $ paramList ) ; return ( $ result == 'ok' ) ? true : false ; }
|
Changes specified reservation to a new amount .
|
13,153
|
public function update ( $ rno , $ clear = true ) { $ rno = strval ( $ rno ) ; $ digestArray = array ( str_replace ( '.' , ':' , $ this -> PROTO ) , $ this -> VERSION , $ this -> _eid , $ rno ) ; $ digestArray = array_merge ( $ digestArray , $ this -> _addressDigestPart ( $ this -> shipping ) ) ; $ digestArray = array_merge ( $ digestArray , $ this -> _addressDigestPart ( $ this -> billing ) ) ; if ( is_array ( $ this -> goodsList ) && $ this -> goodsList !== array ( ) ) { foreach ( $ this -> goodsList as $ goods ) { if ( strlen ( $ goods [ "goods" ] [ "artno" ] ) > 0 ) { $ digestArray [ ] = $ goods [ "goods" ] [ "artno" ] ; } else { $ digestArray [ ] = $ goods [ "goods" ] [ "title" ] ; } $ digestArray [ ] = $ goods [ "qty" ] ; } } foreach ( $ this -> orderid as $ orderid ) { $ digestArray [ ] = $ orderid ; } $ digestArray [ ] = $ this -> _secret ; $ digestSecret = $ this -> digest ( call_user_func_array ( array ( 'self' , 'colon' ) , $ digestArray ) ) ; $ shipping = array ( ) ; $ billing = array ( ) ; if ( $ this -> shipping !== null && $ this -> shipping instanceof KlarnaAddr ) { $ shipping = $ this -> shipping -> toArray ( ) ; } if ( $ this -> billing !== null && $ this -> billing instanceof KlarnaAddr ) { $ billing = $ this -> billing -> toArray ( ) ; } $ paramList = array ( $ this -> _eid , $ digestSecret , $ rno , array ( 'goods_list' => $ this -> goodsList , 'dlv_addr' => $ shipping , 'bill_addr' => $ billing , 'orderid1' => $ this -> orderid [ 0 ] , 'orderid2' => $ this -> orderid [ 1 ] ) ) ; self :: printDebug ( 'update array' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'update' , $ paramList ) ; self :: printDebug ( 'update result' , $ result ) ; return ( $ result === 'ok' ) ; }
|
Update the reservation matching the given reservation number .
|
13,154
|
private function _addressDigestPart ( KlarnaAddr $ address = null ) { if ( $ address === null ) { return array ( ) ; } $ keyOrder = array ( 'careof' , 'street' , 'zip' , 'city' , 'country' , 'fname' , 'lname' ) ; $ holder = $ address -> toArray ( ) ; $ digest = array ( ) ; foreach ( $ keyOrder as $ key ) { if ( $ holder [ $ key ] != "" ) { $ digest [ ] = $ holder [ $ key ] ; } } return $ digest ; }
|
Help function to sort the address for update digest .
|
13,155
|
public function activate ( $ rno , $ ocr = null , $ flags = null , $ clear = true ) { $ this -> _checkRNO ( $ rno ) ; if ( $ ocr !== null ) { $ this -> setActivateInfo ( 'ocr' , $ ocr ) ; } if ( $ flags !== null ) { $ this -> setActivateInfo ( 'flags' , $ flags ) ; } if ( ! array_key_exists ( 'delay_adjust' , $ this -> shipInfo ) ) { $ this -> setShipmentInfo ( 'delay_adjust' , KlarnaFlags :: NORMAL_SHIPMENT ) ; } $ this -> activateInfo [ 'shipment_info' ] = $ this -> shipInfo ; if ( array_key_exists ( 'flags' , $ this -> activateInfo ) && $ this -> activateInfo [ 'flags' ] === KlarnaFlags :: NO_FLAG ) { unset ( $ this -> activateInfo [ 'flags' ] ) ; } $ digestArray = array ( str_replace ( '.' , ':' , $ this -> PROTO ) , $ this -> VERSION , $ this -> _eid , $ rno ) ; $ optionalDigestKeys = array ( 'bclass' , 'cust_no' , 'flags' , 'ocr' , 'orderid1' , 'orderid2' , 'reference' , 'reference_code' ) ; foreach ( $ optionalDigestKeys as $ key ) { if ( array_key_exists ( $ key , $ this -> activateInfo ) ) { $ digestArray [ ] = $ this -> activateInfo [ $ key ] ; } } if ( array_key_exists ( 'delay_adjust' , $ this -> activateInfo [ 'shipment_info' ] ) ) { $ digestArray [ ] = $ this -> activateInfo [ 'shipment_info' ] [ 'delay_adjust' ] ; } if ( is_array ( $ this -> artNos ) ) { foreach ( $ this -> artNos as $ artNo ) { $ digestArray [ ] = $ artNo [ 'artno' ] ; $ digestArray [ ] = $ artNo [ 'qty' ] ; } $ this -> setActivateInfo ( 'artnos' , $ this -> artNos ) ; } $ digestArray [ ] = $ this -> _secret ; $ digestSecret = self :: digest ( call_user_func_array ( array ( 'self' , 'colon' ) , $ digestArray ) ) ; $ paramList = array ( $ this -> _eid , $ digestSecret , $ rno , $ this -> activateInfo ) ; self :: printDebug ( 'activate array' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'activate' , $ paramList ) ; self :: printDebug ( 'activate result' , $ result ) ; if ( $ clear ) { $ this -> clear ( ) ; } return $ result ; }
|
Activate the reservation matching the given reservation number . Optional information should be set in ActivateInfo .
|
13,156
|
public function activateReservation ( $ pno , $ rno , $ gender , $ ocr = "" , $ flags = KlarnaFlags :: NO_FLAG , $ pclass = KlarnaPClass :: INVOICE , $ encoding = null , $ clear = true ) { $ this -> _checkLocale ( ) ; if ( $ encoding === null ) { $ encoding = $ this -> getPNOEncoding ( ) ; } if ( $ pno !== null ) { $ this -> _checkPNO ( $ pno , $ encoding ) ; } $ this -> _checkRNO ( $ rno ) ; if ( $ gender !== null && strlen ( $ gender ) > 0 ) { $ this -> _checkInt ( $ gender , 'gender' ) ; } $ this -> _checkOCR ( $ ocr ) ; $ this -> _checkRef ( $ this -> reference , $ this -> reference_code ) ; $ this -> _checkGoodslist ( ) ; $ billing = $ shipping = '' ; if ( ! ( $ flags & KlarnaFlags :: RSRV_PHONE_TRANSACTION ) ) { $ billing = $ this -> assembleAddr ( $ this -> billing ) ; $ shipping = $ this -> assembleAddr ( $ this -> shipping ) ; if ( strlen ( $ shipping [ 'country' ] ) > 0 && ( $ shipping [ 'country' ] !== $ this -> _country ) ) { throw new Klarna_ShippingCountryException ; } } $ string = $ this -> _eid . ":" . $ pno . ":" ; foreach ( $ this -> goodsList as $ goods ) { $ string .= $ goods [ "goods" ] [ "artno" ] . ":" . $ goods [ "qty" ] . ":" ; } $ digestSecret = self :: digest ( $ string . $ this -> _secret ) ; if ( ! isset ( $ this -> shipInfo [ 'delay_adjust' ] ) ) { $ this -> setShipmentInfo ( 'delay_adjust' , KlarnaFlags :: NORMAL_SHIPMENT ) ; } $ paramList = array ( $ rno , $ ocr , $ pno , $ gender , $ this -> reference , $ this -> reference_code , $ this -> orderid [ 0 ] , $ this -> orderid [ 1 ] , $ shipping , $ billing , "0.0.0.0" , $ flags , $ this -> _currency , $ this -> _country , $ this -> _language , $ this -> _eid , $ digestSecret , $ encoding , $ pclass , $ this -> goodsList , $ this -> comment , $ this -> shipInfo , $ this -> travelInfo , $ this -> incomeInfo , $ this -> bankInfo , $ this -> extraInfo ) ; self :: printDebug ( 'activate_reservation' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'activate_reservation' , $ paramList ) ; if ( $ clear === true ) { $ this -> clear ( ) ; } self :: printDebug ( 'activate_reservation result' , $ result ) ; return $ result ; }
|
Activates a previously created reservation .
|
13,157
|
public function splitReservation ( $ rno , $ amount , $ flags = KlarnaFlags :: NO_FLAG ) { $ this -> _checkRNO ( $ rno ) ; $ this -> _checkAmount ( $ amount ) ; if ( $ amount <= 0 ) { throw new Klarna_InvalidPriceException ( $ amount ) ; } $ digestSecret = self :: digest ( $ this -> colon ( $ this -> _eid , $ rno , $ amount , $ this -> _secret ) ) ; $ paramList = array ( $ rno , $ amount , $ this -> orderid [ 0 ] , $ this -> orderid [ 1 ] , $ flags , $ this -> _eid , $ digestSecret ) ; self :: printDebug ( 'split_reservation array' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'split_reservation' , $ paramList ) ; self :: printDebug ( 'split_reservation result' , $ result ) ; return $ result ; }
|
Splits a reservation due to for example outstanding articles .
|
13,158
|
public function activatePart ( $ invNo , $ pclass = KlarnaPClass :: INVOICE , $ clear = true ) { $ this -> _checkInvNo ( $ invNo ) ; $ this -> _checkArtNos ( $ this -> artNos ) ; self :: printDebug ( 'activate_part artNos array' , $ this -> artNos ) ; $ string = $ this -> _eid . ":" . $ invNo . ":" ; foreach ( $ this -> artNos as $ artNo ) { $ string .= $ artNo [ "artno" ] . ":" . $ artNo [ "qty" ] . ":" ; } $ digestSecret = self :: digest ( $ string . $ this -> _secret ) ; $ paramList = array ( $ this -> _eid , $ invNo , $ this -> artNos , $ digestSecret , $ pclass , $ this -> shipInfo ) ; self :: printDebug ( 'activate_part array' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'activate_part' , $ paramList ) ; if ( $ clear === true ) { $ this -> clear ( ) ; } self :: printDebug ( 'activate_part result' , $ result ) ; return $ result ; }
|
Partially activates a passive invoice .
|
13,159
|
public function invoiceAmount ( $ invNo ) { $ this -> _checkInvNo ( $ invNo ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ this -> _eid , $ invNo , $ this -> _secret ) ) ; $ paramList = array ( $ this -> _eid , $ invNo , $ digestSecret ) ; self :: printDebug ( 'invoice_amount array' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'invoice_amount' , $ paramList ) ; return ( $ result / 100 ) ; }
|
Retrieves the total amount for an active invoice .
|
13,160
|
public function updateOrderNo ( $ invNo , $ orderid ) { $ this -> _checkInvNo ( $ invNo ) ; $ this -> _checkEstoreOrderNo ( $ orderid ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ invNo , $ orderid , $ this -> _secret ) ) ; $ paramList = array ( $ this -> _eid , $ digestSecret , $ invNo , $ orderid ) ; self :: printDebug ( 'update_orderno array' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'update_orderno' , $ paramList ) ; return $ result ; }
|
Changes the order number of a purchase that was set when the order was made online .
|
13,161
|
public function creditInvoice ( $ invNo , $ credNo = "" ) { $ this -> _checkInvNo ( $ invNo ) ; $ this -> _checkCredNo ( $ credNo ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ this -> _eid , $ invNo , $ this -> _secret ) ) ; $ paramList = array ( $ this -> _eid , $ invNo , $ credNo , $ digestSecret ) ; self :: printDebug ( 'credit_invoice' , $ paramList ) ; return $ this -> xmlrpc_call ( 'credit_invoice' , $ paramList ) ; }
|
Performs a complete refund on an invoice part payment and mobile purchase .
|
13,162
|
public function creditPart ( $ invNo , $ credNo = "" ) { $ this -> _checkInvNo ( $ invNo ) ; $ this -> _checkCredNo ( $ credNo ) ; if ( $ this -> goodsList === null || empty ( $ this -> goodsList ) ) { $ this -> _checkArtNos ( $ this -> artNos ) ; } $ string = $ this -> _eid . ":" . $ invNo . ":" ; if ( $ this -> artNos !== null && ! empty ( $ this -> artNos ) ) { foreach ( $ this -> artNos as $ artNo ) { $ string .= $ artNo [ "artno" ] . ":" . $ artNo [ "qty" ] . ":" ; } } $ digestSecret = self :: digest ( $ string . $ this -> _secret ) ; $ paramList = array ( $ this -> _eid , $ invNo , $ this -> artNos , $ credNo , $ digestSecret ) ; if ( $ this -> goodsList !== null && ! empty ( $ this -> goodsList ) ) { $ paramList [ ] = 0 ; $ paramList [ ] = $ this -> goodsList ; } $ this -> artNos = array ( ) ; self :: printDebug ( 'credit_part' , $ paramList ) ; return $ this -> xmlrpc_call ( 'credit_part' , $ paramList ) ; }
|
Performs a partial refund on an invoice part payment or mobile purchase .
|
13,163
|
public function updateGoodsQty ( $ invNo , $ artNo , $ qty ) { $ this -> _checkInvNo ( $ invNo ) ; $ this -> _checkQty ( $ qty ) ; $ this -> _checkArtNo ( $ artNo ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ invNo , $ artNo , $ qty , $ this -> _secret ) ) ; $ paramList = array ( $ this -> _eid , $ digestSecret , $ invNo , $ artNo , $ qty ) ; self :: printDebug ( 'update_goods_qty' , $ paramList ) ; return $ this -> xmlrpc_call ( 'update_goods_qty' , $ paramList ) ; }
|
Changes the quantity of a specific item in a passive invoice .
|
13,164
|
public function invoiceAddress ( $ invNo ) { $ this -> _checkInvNo ( $ invNo ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ this -> _eid , $ invNo , $ this -> _secret ) ) ; $ paramList = array ( $ this -> _eid , $ invNo , $ digestSecret ) ; self :: printDebug ( 'invoice_address' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'invoice_address' , $ paramList ) ; $ addr = new KlarnaAddr ( ) ; if ( strlen ( $ result [ 0 ] ) > 0 ) { $ addr -> isCompany = false ; $ addr -> setFirstName ( $ result [ 0 ] ) ; $ addr -> setLastName ( $ result [ 1 ] ) ; } else { $ addr -> isCompany = true ; $ addr -> setCompanyName ( $ result [ 1 ] ) ; } $ addr -> setStreet ( $ result [ 2 ] ) ; $ addr -> setZipCode ( $ result [ 3 ] ) ; $ addr -> setCity ( $ result [ 4 ] ) ; $ addr -> setCountry ( $ result [ 5 ] ) ; return $ addr ; }
|
The invoice_address function is used to retrieve the address of a purchase .
|
13,165
|
public function invoicePartAmount ( $ invNo ) { $ this -> _checkInvNo ( $ invNo ) ; $ this -> _checkArtNos ( $ this -> artNos ) ; $ string = $ this -> _eid . ":" . $ invNo . ":" ; foreach ( $ this -> artNos as $ artNo ) { $ string .= $ artNo [ "artno" ] . ":" . $ artNo [ "qty" ] . ":" ; } $ digestSecret = self :: digest ( $ string . $ this -> _secret ) ; $ paramList = array ( $ this -> _eid , $ invNo , $ this -> artNos , $ digestSecret ) ; $ this -> artNos = array ( ) ; self :: printDebug ( 'invoice_part_amount' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'invoice_part_amount' , $ paramList ) ; return ( $ result / 100 ) ; }
|
Retrieves the amount of a specific goods from a purchase .
|
13,166
|
public function getCustomerNo ( $ pno , $ encoding = null ) { if ( $ encoding === null ) { $ encoding = $ this -> getPNOEncoding ( ) ; } $ this -> _checkPNO ( $ pno , $ encoding ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ this -> _eid , $ pno , $ this -> _secret ) ) ; $ paramList = array ( $ pno , $ this -> _eid , $ digestSecret , $ encoding ) ; self :: printDebug ( 'get_customer_no' , $ paramList ) ; return $ this -> xmlrpc_call ( 'get_customer_no' , $ paramList ) ; }
|
Retrieves a list of all the customer numbers associated with the specified pno .
|
13,167
|
public function setCustomerNo ( $ pno , $ custNo , $ encoding = null ) { if ( $ encoding === null ) { $ encoding = $ this -> getPNOEncoding ( ) ; } $ this -> _checkPNO ( $ pno , $ encoding ) ; $ this -> _checkArgument ( $ custNo , 'custNo' ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ this -> _eid , $ pno , $ custNo , $ this -> _secret ) ) ; $ paramList = array ( $ pno , $ custNo , $ this -> _eid , $ digestSecret , $ encoding ) ; self :: printDebug ( 'set_customer_no' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'set_customer_no' , $ paramList ) ; return ( $ result == 'ok' ) ; }
|
Associates a pno with a customer number when you want to make future purchases without a pno .
|
13,168
|
public function removeCustomerNo ( $ custNo ) { $ this -> _checkArgument ( $ custNo , 'custNo' ) ; $ digestSecret = self :: digest ( $ this -> colon ( $ this -> _eid , $ custNo , $ this -> _secret ) ) ; $ paramList = array ( $ custNo , $ this -> _eid , $ digestSecret ) ; self :: printDebug ( 'remove_customer_no' , $ paramList ) ; $ result = $ this -> xmlrpc_call ( 'remove_customer_no' , $ paramList ) ; return ( $ result == 'ok' ) ; }
|
Removes a customer number from association with a pno .
|
13,169
|
public function getPCStorage ( ) { if ( isset ( $ this -> pclasses ) ) { return $ this -> pclasses ; } include_once 'pclasses/storage.intf.php' ; $ className = $ this -> pcStorage . 'storage' ; $ pclassStorage = dirname ( __FILE__ ) . "/pclasses/{$className}.class.php" ; include_once $ pclassStorage ; $ storage = new $ className ; if ( ! ( $ storage instanceof PCStorage ) ) { throw new Klarna_PCStorageInvalidException ( $ className , $ pclassStorage ) ; } return $ storage ; }
|
Returns the configured PCStorage object .
|
13,170
|
public function clearPClasses ( ) { $ this -> _checkConfig ( ) ; $ pclasses = $ this -> getPCStorage ( ) ; $ pclasses -> clear ( $ this -> pcURI ) ; }
|
Removes the stored PClasses if you need to update them .
|
13,171
|
public function getPClasses ( $ type = null ) { $ this -> _checkConfig ( ) ; if ( ! $ this -> pclasses ) { $ this -> pclasses = $ this -> getPCStorage ( ) ; $ this -> pclasses -> load ( $ this -> pcURI ) ; } $ tmp = $ this -> pclasses -> getPClasses ( $ this -> _eid , $ this -> _country , $ type ) ; $ this -> sortPClasses ( $ tmp [ $ this -> _eid ] ) ; return $ tmp [ $ this -> _eid ] ; }
|
Retrieves the specified PClasses .
|
13,172
|
public function getAllPClasses ( ) { if ( ! $ this -> pclasses ) { $ this -> pclasses = $ this -> getPCStorage ( ) ; $ this -> pclasses -> load ( $ this -> pcURI ) ; } return $ this -> pclasses -> getAllPClasses ( ) ; }
|
Retrieve a flattened array of all pclasses stored in the configured pclass storage .
|
13,173
|
public function getPClass ( $ id ) { if ( ! is_numeric ( $ id ) ) { throw new Klarna_InvalidTypeException ( 'id' , 'integer' ) ; } $ this -> _checkConfig ( ) ; if ( ! $ this -> pclasses || ! ( $ this -> pclasses instanceof PCStorage ) ) { $ this -> pclasses = $ this -> getPCStorage ( ) ; $ this -> pclasses -> load ( $ this -> pcURI ) ; } return $ this -> pclasses -> getPClass ( intval ( $ id ) , $ this -> _eid , $ this -> _country ) ; }
|
Returns the specified PClass .
|
13,174
|
public function sortPClasses ( & $ array ) { if ( ! is_array ( $ array ) ) { $ array = array ( ) ; return ; } if ( ! function_exists ( 'pcCmp' ) ) { function pcCmp ( $ a , $ b ) { if ( $ a -> getDescription ( ) == null && $ b -> getDescription ( ) == null ) { return 0 ; } else if ( $ a -> getDescription ( ) == null ) { return 1 ; } else if ( $ b -> getDescription ( ) == null ) { return - 1 ; } else if ( $ b -> getType ( ) === 2 && $ a -> getType ( ) !== 2 ) { return 1 ; } else if ( $ b -> getType ( ) !== 2 && $ a -> getType ( ) === 2 ) { return - 1 ; } return strnatcmp ( $ a -> getDescription ( ) , $ b -> getDescription ( ) ) * - 1 ; } } usort ( $ array , "pcCmp" ) ; }
|
Sorts the specified array of KlarnaPClasses .
|
13,175
|
public function getCheapestPClass ( $ sum , $ flags ) { if ( ! is_numeric ( $ sum ) ) { throw new Klarna_InvalidPriceException ( $ sum ) ; } if ( ! is_numeric ( $ flags ) || ! in_array ( $ flags , array ( KlarnaFlags :: CHECKOUT_PAGE , KlarnaFlags :: PRODUCT_PAGE ) ) ) { throw new Klarna_InvalidTypeException ( 'flags' , KlarnaFlags :: CHECKOUT_PAGE . ' or ' . KlarnaFlags :: PRODUCT_PAGE ) ; } $ lowest_pp = $ lowest = false ; foreach ( $ this -> getPClasses ( ) as $ pclass ) { $ lowest_payment = KlarnaCalc :: get_lowest_payment_for_account ( $ pclass -> getCountry ( ) ) ; if ( $ pclass -> getType ( ) < 2 && $ sum >= $ pclass -> getMinAmount ( ) ) { $ minpay = KlarnaCalc :: calc_monthly_cost ( $ sum , $ pclass , $ flags ) ; if ( $ minpay < $ lowest_pp || $ lowest_pp === false ) { if ( $ pclass -> getType ( ) == KlarnaPClass :: ACCOUNT || $ minpay >= $ lowest_payment ) { $ lowest_pp = $ minpay ; $ lowest = $ pclass ; } } } } return $ lowest ; }
|
Returns the cheapest per month PClass related to the specified sum .
|
13,176
|
protected function initCheckout ( ) { $ dir = dirname ( __FILE__ ) ; include_once $ dir . '/checkout/checkouthtml.intf.php' ; foreach ( glob ( $ dir . '/checkout/*.class.php' ) as $ checkout ) { if ( ! self :: $ debug ) { ob_start ( ) ; } include_once $ checkout ; $ className = basename ( $ checkout , '.class.php' ) ; $ cObj = new $ className ; if ( $ cObj instanceof CheckoutHTML ) { $ cObj -> init ( $ this , $ this -> _eid ) ; $ this -> coObjects [ $ className ] = $ cObj ; } if ( ! self :: $ debug ) { ob_end_clean ( ) ; } } }
|
Initializes the checkoutHTML objects .
|
13,177
|
public function checkoutHTML ( ) { if ( empty ( $ this -> coObjects ) ) { $ this -> initCheckout ( ) ; } $ dir = dirname ( __FILE__ ) ; include_once $ dir . '/checkout/checkouthtml.intf.php' ; $ html = "\n" ; foreach ( $ this -> coObjects as $ cObj ) { if ( ! self :: $ debug ) { ob_start ( ) ; } if ( $ cObj instanceof CheckoutHTML ) { $ html .= $ cObj -> toHTML ( ) . "\n" ; } if ( ! self :: $ debug ) { ob_end_clean ( ) ; } } return $ html ; }
|
Returns the checkout page HTML from the checkout classes .
|
13,178
|
protected function xmlrpc_call ( $ method , $ array ) { $ this -> _checkConfig ( ) ; if ( ! isset ( $ method ) || ! is_string ( $ method ) ) { throw new Klarna_InvalidTypeException ( 'method' , 'string' ) ; } if ( $ array === null || count ( $ array ) === 0 ) { throw new KlarnaException ( "Parameterlist is empty or null!" , 50067 ) ; } if ( self :: $ disableXMLRPC ) { return true ; } try { $ this -> xmlrpc -> verifypeer = false ; $ timestart = microtime ( true ) ; $ msg = new xmlrpcmsg ( $ method ) ; $ params = array_merge ( array ( $ this -> PROTO , $ this -> VERSION ) , $ array ) ; $ msg = new xmlrpcmsg ( $ method ) ; foreach ( $ params as $ p ) { if ( ! $ msg -> addParam ( php_xmlrpc_encode ( $ p , array ( 'extension_api' ) ) ) ) { throw new KlarnaException ( "Failed to add parameters to XMLRPC message." , 50068 ) ; } } $ selectDateTime = microtime ( true ) ; if ( self :: $ xmlrpcDebug ) { $ this -> xmlrpc -> setDebug ( 2 ) ; } $ tmp_xmlrpc_defencoding = $ GLOBALS [ 'xmlrpc_defencoding' ] ; $ tmp_xmlrpc_internalencoding = $ GLOBALS [ 'xmlrpc_internalencoding' ] ; $ GLOBALS [ 'xmlrpc_defencoding' ] = 'ISO-8859-1' ; $ GLOBALS [ 'xmlrpc_internalencoding' ] = 'UTF-8' ; $ xmlrpcresp = $ this -> xmlrpc -> send ( $ msg ) ; $ GLOBALS [ 'xmlrpc_defencoding' ] = $ tmp_xmlrpc_defencoding ; $ GLOBALS [ 'xmlrpc_internalencoding' ] = $ tmp_xmlrpc_internalencoding ; $ timeend = microtime ( true ) ; $ time = ( int ) ( ( $ selectDateTime - $ timestart ) * 1000 ) ; $ selectTime = ( int ) ( ( $ timeend - $ timestart ) * 1000 ) ; $ status = $ xmlrpcresp -> faultCode ( ) ; if ( $ status !== 0 ) { throw new KlarnaException ( $ xmlrpcresp -> faultString ( ) , $ status ) ; } return php_xmlrpc_decode ( $ xmlrpcresp -> value ( ) ) ; } catch ( KlarnaException $ e ) { throw $ e ; } catch ( Exception $ e ) { throw new KlarnaException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } }
|
Creates a XMLRPC call with specified XMLRPC method and parameters from array .
|
13,179
|
public function checkoutService ( $ price , $ currency , $ locale , $ country = null ) { $ this -> _checkAmount ( $ price ) ; $ params = array ( 'merchant_id' => $ this -> config [ 'eid' ] , 'total_price' => $ price , 'currency' => strtoupper ( $ currency ) , 'locale' => strtolower ( $ locale ) ) ; if ( $ country !== null ) { $ params [ 'country' ] = $ country ; } return $ this -> createTransport ( ) -> send ( new CheckoutServiceRequest ( $ this -> config , $ params ) ) ; }
|
Perform a checkout service request .
|
13,180
|
public static function digest ( $ data , $ hash = null ) { if ( $ hash === null ) { $ preferred = array ( 'sha512' , 'sha384' , 'sha256' , 'sha224' , 'md5' ) ; $ hashes = array_intersect ( $ preferred , hash_algos ( ) ) ; if ( count ( $ hashes ) == 0 ) { throw new KlarnaException ( "No available hash algorithm supported!" ) ; } $ hash = array_shift ( $ hashes ) ; } self :: printDebug ( 'digest() using hash' , $ hash ) ; return base64_encode ( pack ( "H*" , hash ( $ hash , $ data ) ) ) ; }
|
Creates a digest hash from the inputted string and the specified or the preferred hash algorithm .
|
13,181
|
public static function num_htmlentities ( $ str ) { $ charset = 'ISO-8859-1' ; if ( ! self :: $ htmlentities ) { self :: $ htmlentities = array ( ) ; $ table = get_html_translation_table ( HTML_ENTITIES , ENT_QUOTES , $ charset ) ; foreach ( $ table as $ char => $ entity ) { self :: $ htmlentities [ $ entity ] = '&#' . ord ( $ char ) . ';' ; } } return str_replace ( array_keys ( self :: $ htmlentities ) , self :: $ htmlentities , htmlentities ( $ str , ENT_COMPAT | ENT_HTML401 , $ charset ) ) ; }
|
Converts special characters to numeric htmlentities .
|
13,182
|
private function _checkArgument ( $ argument , $ name ) { if ( ! is_string ( $ argument ) ) { $ argument = strval ( $ argument ) ; } if ( strlen ( $ argument ) == 0 ) { throw new Klarna_ArgumentNotSetException ( $ name ) ; } }
|
Check so required argument is supplied .
|
13,183
|
public function setPCStorage ( $ pcStorage ) { if ( ! ( $ pcStorage instanceof PCStorage ) ) { throw new Klarna_InvalidTypeException ( 'pcStorage' , 'PCStorage' ) ; } $ this -> pcStorage = $ pcStorage -> getName ( ) ; $ this -> pclasses = $ pcStorage ; }
|
Set the pcStorage method used for this instance
|
13,184
|
private function _checkConfig ( $ config = null ) { if ( $ config === null ) { $ config = $ this -> config ; } if ( ! ( $ config instanceof ArrayAccess ) && ! is_array ( $ config ) ) { throw new Klarna_IncompleteConfigurationException ; } }
|
Ensure the configuration is of the correct type .
|
13,185
|
public function removeHandler ( $ handler ) { if ( ! is_callable ( $ handler ) ) throw new \ InvalidArgumentException ( "Argument 1 of Event->addHandler needs to be a valid callback" ) ; $ i = array_search ( $ handler , $ this -> _handlers , true ) ; if ( $ i !== false ) unset ( $ this -> _handlers [ $ i ] ) ; return $ this ; }
|
Removes an assigned handler
|
13,186
|
public function trigger ( Event \ Args $ args = null , $ reverse = false ) { $ args = $ args ? $ args : new Event \ Args ( ) ; if ( $ reverse ) { for ( $ i = count ( $ this -> _handlers ) ; -- $ i >= 0 ; ) { if ( call_user_func_array ( $ this -> _handlers [ $ i ] , func_get_args ( ) ) === false ) break ; } } else { foreach ( $ this -> _handlers as $ handler ) { if ( call_user_func_array ( $ handler , func_get_args ( ) ) === false ) break ; } } return ! $ args -> isDefaultPrevented ( ) ; }
|
Triggers the event
|
13,187
|
public function render ( $ view , $ params = array ( ) ) { $ viewPath = $ this -> viewPath ; $ viewPath = rtrim ( $ viewPath , '/' ) . '/' ; extract ( $ params ) ; if ( is_file ( $ view ) ) { require_once ( $ view ) ; } else if ( is_file ( $ viewPath . str_replace ( ':' , '/' , $ view ) ) ) { require_once ( $ viewPath . str_replace ( ':' , '/' , $ view ) ) ; } else { echo $ view ; } }
|
Render the content of view file or text
|
13,188
|
public static function create ( ConfigurationBuilder $ builder ) { $ configPath = Framework :: fw ( ) -> buildPath ( '__config' ) ; $ configFile = $ configPath . __ . $ builder -> key ( ) . ".php" ; if ( file_put_contents ( $ configFile , $ builder -> toPhp ( true ) ) === false || ! is_array ( $ data = include ( $ configFile ) ) ) { @ unlink ( $ configFile ) ; throw new FrameworkException ( "Configuration error, either failed to write config file to [" . $ configFile . "] or returned data is not an array." ) ; } Framework :: config ( ) -> set ( $ builder -> key ( ) , $ data ) ; }
|
Saves a builder to the filesystem
|
13,189
|
protected function fetchError ( $ err ) { $ cells = $ err -> section ( Teamspeak :: SEPARATOR_CELL , 1 , 3 ) ; foreach ( $ cells -> split ( Teamspeak :: SEPARATOR_CELL ) as $ pair ) { list ( $ ident , $ value ) = $ pair -> split ( Teamspeak :: SEPARATOR_PAIR ) ; $ this -> err [ $ ident -> toString ( ) ] = $ value -> isInt ( ) ? $ value -> toInt ( ) : $ value -> unescape ( ) ; } Signal :: getInstance ( ) -> emit ( "notifyError" , $ this ) ; if ( $ this -> getErrorProperty ( "id" , 0x00 ) != 0x00 && $ this -> exp ) { if ( $ permid = $ this -> getErrorProperty ( "failed_permid" ) ) { if ( $ permsid = key ( $ this -> con -> request ( "permget permid=" . $ permid , false ) -> toAssocArray ( "permsid" ) ) ) { $ suffix = " (failed on " . $ permsid . ")" ; } else { $ suffix = " (failed on " . $ this -> cmd -> section ( Teamspeak :: SEPARATOR_CELL ) . " " . $ permid . "/0x" . strtoupper ( dechex ( $ permid ) ) . ")" ; } } elseif ( $ details = $ this -> getErrorProperty ( "extra_msg" ) ) { $ suffix = " (" . trim ( $ details ) . ")" ; } else { $ suffix = "" ; } throw new Ts3Exception ( $ this -> getErrorProperty ( "msg" ) . $ suffix , $ this -> getErrorProperty ( "id" ) ) ; } }
|
Parses a ServerQuery error and throws a Ts3Exception object if there s an error .
|
13,190
|
protected function fetchReply ( $ rpl ) { foreach ( $ rpl as $ key => $ val ) { if ( $ val -> startsWith ( Teamspeak :: GREET ) ) { unset ( $ rpl [ $ key ] ) ; } elseif ( $ val -> startsWith ( Teamspeak :: EVENT ) ) { $ this -> evt [ ] = new Event ( $ rpl [ $ key ] , $ this -> con ) ; unset ( $ rpl [ $ key ] ) ; } } $ this -> rpl = new StringHelper ( implode ( Teamspeak :: SEPARATOR_LIST , $ rpl ) ) ; }
|
Parses a ServerQuery reply and creates a String object .
|
13,191
|
public function getHeader ( $ header , $ first = true ) { $ normalizedHeader = str_replace ( '-' , '_' , strtolower ( $ header ) ) ; foreach ( $ this -> headers as $ key => $ value ) { if ( str_replace ( '-' , '_' , strtolower ( $ key ) ) === $ normalizedHeader ) { if ( $ first ) { return is_array ( $ value ) ? ( count ( $ value ) ? $ value [ 0 ] : '' ) : $ value ; } return is_array ( $ value ) ? $ value : array ( $ value ) ; } } return $ first ? null : array ( ) ; }
|
Gets a response header .
|
13,192
|
public function getAction ( $ state ) { $ type = self :: getType ( 'strtolower' , false ) ; $ action = self :: $ defaultAction [ $ type ] ; if ( isset ( $ this -> states [ 'action' ] ) ) { $ action = $ this -> states [ 'action' ] ; } return ( $ state === 'uninstalled' ) ? '' : $ action ; }
|
Get complement action .
|
13,193
|
public function doAction ( $ action ) { $ controller = $ this -> getOption ( 'hooks-controller' ) ; $ instance = $ this -> getControllerInstance ( $ controller ) ; if ( is_object ( $ instance ) && method_exists ( $ instance , $ action ) ) { $ response = call_user_func ( [ $ instance , $ action ] ) ; } $ this -> setAction ( '' ) ; return isset ( $ response ) ; }
|
Execute action hook .
|
13,194
|
private function addActions ( ) { if ( isset ( $ this -> complement [ 'hooks' ] ) ) { Hook :: getInstance ( App :: getCurrentID ( ) ) ; return Hook :: addActions ( $ this -> complement [ 'hooks' ] ) ; } return false ; }
|
Add complement action hooks .
|
13,195
|
private function doActions ( $ action ) { $ type = self :: getType ( 'strtolower' , false ) ; Hook :: getInstance ( App :: getCurrentID ( ) ) ; Hook :: doAction ( $ type . '-load' ) ; Hook :: doAction ( 'after-loading-' . $ this -> complement [ 'slug' ] . '-' . $ type ) ; if ( in_array ( $ action , self :: $ hooks , true ) ) { $ this -> doAction ( $ action ) ; } }
|
Execute action hooks .
|
13,196
|
protected function getAuthHeaderValue ( ) { $ value = "" ; if ( isset ( $ this -> credentials [ 'username' ] ) && isset ( $ this -> credentials [ 'password' ] ) ) { $ value = $ this -> credentials [ 'username' ] . ":" . $ this -> credentials [ 'password' ] ; $ value = base64_encode ( $ value ) ; } return static :: $ _AUTH_TYPE . " " . $ value ; }
|
Parse the Credentials or Token to build out the Auth Header Value
|
13,197
|
public function providesMethod ( $ name ) { if ( method_exists ( $ this , $ name ) ) { return true ; } if ( $ this -> text instanceof Generic ) { return $ this -> text -> providesMethod ( $ name ) ; } return false ; }
|
Returns if the given method is implemented by one of the decorators .
|
13,198
|
public function buildQueryInputs ( $ currentField ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; $ fields = '' ; foreach ( $ request -> query -> all ( ) as $ field => $ value ) { if ( $ field !== $ currentField && $ field !== 'page' ) { $ fields .= sprintf ( '<input type="hidden" name="%s" value="%s">' , $ field , $ value ) ; } } return $ fields ; }
|
Build Hidden fields based on the URL parameters
|
13,199
|
public function inflect ( string $ string , $ pluralize = 0 ) : string { return ( $ pluralize ) ? Inflect :: pluralize ( $ string ) : Inflect :: singularize ( $ string ) ; }
|
Pluralize or Singularize a string
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.