idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
21,200
public function decode ( $ string ) { if ( $ this -> isSerialized ( $ string ) ) { return $ this -> unserialize ( $ string ) ; } $ result = json_decode ( $ string , true ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw new \ InvalidArgumentException ( 'Unable to unserialize value.' ) ; } return $ result ; }
Unserialize the given string
21,201
private function unserialize ( $ string ) { if ( false === $ string || null === $ string || '' === $ string ) { throw new \ InvalidArgumentException ( 'Unable to unserialize value.' ) ; } set_error_handler ( function ( ) { restore_error_handler ( ) ; throw new \ InvalidArgumentException ( 'Unable to unserialize value, string is corrupted.' ) ; } , E_NOTICE ) ; $ result = unserialize ( $ string ) ; restore_error_handler ( ) ; return $ result ; }
Uses the old school unserialization
21,202
public function getBacktrace ( $ exception = null ) { $ skipLimit = false ; if ( $ exception instanceof \ Exception || $ exception instanceof \ Throwable ) { $ backtrace = $ exception -> getTrace ( ) ; foreach ( $ backtrace as $ index => $ backtraceCall ) { unset ( $ backtrace [ $ index ] [ 'args' ] ) ; } } elseif ( version_compare ( PHP_VERSION , '5.4.0' ) >= 0 ) { $ backtrace = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS , $ this -> backtraceLimit ) ; $ skipLimit = true ; } else { $ backtrace = debug_backtrace ( DEBUG_BACKTRACE_IGNORE_ARGS ) ; } if ( $ this -> backtraceLimit > 0 && ! $ skipLimit ) { $ backtrace = array_slice ( $ backtrace , 0 , $ this -> backtraceLimit ) ; } return $ backtrace ; }
Returns a basic backtrace
21,203
public function BEM ( $ block = null , $ element = null , $ modifiers = [ ] ) : array { if ( ! isset ( $ block ) || ! is_string ( $ block ) || ! $ block ) { return [ ] ; } $ baseClass = $ element ? "{$block}__{$element}" : "{$block}" ; $ classes = [ $ baseClass ] ; if ( isset ( $ modifiers ) ) { $ modifiers = self :: modifierArray ( $ modifiers ) ; foreach ( $ modifiers as $ value ) { $ classes [ ] = "{$baseClass}--{$value}" ; } } return $ classes ; }
Generates a BEM array
21,204
private static function modifierArray ( $ modifiers = [ ] ) : array { if ( is_string ( $ modifiers ) ) { return [ $ modifiers ] ; } $ array = [ ] ; if ( is_array ( $ modifiers ) ) { foreach ( $ modifiers as $ key => $ value ) { if ( ! $ value ) { continue ; } if ( is_array ( $ value ) ) { $ array = array_merge ( $ array , self :: modifierArray ( $ value ) ) ; } else if ( is_string ( $ value ) ) { $ array [ ] = $ value ; } else if ( is_string ( $ key ) ) { $ array [ ] = $ key ; } } } return array_unique ( $ array ) ; }
Generate the array for the modifiers
21,205
public function join ( array $ array , string $ separator = ',' ) : string { $ result = '' ; foreach ( $ array as $ item ) { if ( is_array ( $ item ) ) { $ result .= $ this -> join ( $ item , $ separator ) . $ separator ; } else { $ result .= $ item . $ separator ; } } $ result = substr ( $ result , 0 , 0 - strlen ( $ separator ) ) ; return $ result ; }
Join the given array recursively using the given separator string .
21,206
public function extractSubElements ( array $ array , bool $ preserveKeys = false ) : array { $ resultArray = [ ] ; foreach ( $ array as $ element ) { if ( is_array ( $ element ) ) { foreach ( $ element as $ subKey => $ subElement ) { if ( $ preserveKeys ) { $ resultArray [ $ subKey ] = $ subElement ; } else { $ resultArray [ ] = $ subElement ; } } } else { $ resultArray [ ] = $ element ; } } return $ resultArray ; }
This method extracts sub elements to the parent level .
21,207
public static function outputStyles ( $ output = '' ) { self :: lookIfProcessFiles ( 'style' , 'header' ) ; $ template = self :: $ templates [ 'style' ] ; $ styles = self :: $ data [ 'style' ] [ 'header' ] ; foreach ( $ styles as $ value ) { $ output .= sprintf ( $ template , $ value [ 'url' ] ) ; } self :: $ data [ 'style' ] [ 'header' ] = [ ] ; return ! empty ( $ output ) ? $ output : false ; }
Output stylesheet .
21,208
public static function isAdded ( $ type , $ name ) { if ( isset ( self :: $ data [ $ type ] [ 'header' ] [ $ name ] ) ) { return true ; } elseif ( isset ( self :: $ data [ $ type ] [ 'footer' ] [ $ name ] ) ) { return true ; } return false ; }
Check if a particular style or script has been added .
21,209
public static function unify ( $ uniqueID , $ params , $ minify = false ) { self :: $ id = $ uniqueID ; self :: $ unify = $ params ; self :: $ minify = $ minify ; return true ; }
Sets whether to merge the content of files into a single file .
21,210
public static function remove ( $ type , $ name ) { if ( isset ( self :: $ data [ $ type ] [ 'header' ] [ $ name ] ) ) { unset ( self :: $ data [ $ type ] [ 'header' ] [ $ name ] ) ; return true ; } elseif ( isset ( self :: $ data [ $ type ] [ 'footer' ] [ $ name ] ) ) { unset ( self :: $ data [ $ type ] [ 'footer' ] [ $ name ] ) ; return true ; } return false ; }
Remove before script or style have been registered .
21,211
protected static function lookIfProcessFiles ( $ type , $ place ) { if ( is_string ( self :: $ unify ) || isset ( self :: $ unify [ $ type . 's' ] ) ) { return self :: unifyFiles ( self :: prepareFiles ( $ type , $ place ) ) ; } }
Look whether to process files to minify or unify files .
21,212
protected static function prepareFiles ( $ type , $ place ) { self :: getProcessedFiles ( ) ; $ params [ 'type' ] = $ type ; $ params [ 'place' ] = $ place ; $ params [ 'routes' ] = self :: getRoutesToFolder ( $ type ) ; foreach ( self :: $ data [ $ type ] [ $ place ] as $ id => $ file ) { $ path = self :: getPathFromUrl ( $ file [ 'url' ] ) ; $ params [ 'urls' ] [ $ id ] = $ file [ 'url' ] ; $ params [ 'files' ] [ $ id ] = basename ( $ file [ 'url' ] ) ; $ params [ 'paths' ] [ $ id ] = $ path ; if ( is_file ( $ path ) && self :: isModifiedFile ( $ path ) ) { unset ( $ params [ 'urls' ] [ $ id ] ) ; continue ; } $ path = $ params [ 'routes' ] [ 'path' ] . $ params [ 'files' ] [ $ id ] ; if ( is_file ( $ path ) ) { if ( self :: isModifiedHash ( $ file [ 'url' ] , $ path ) ) { continue ; } $ params [ 'paths' ] [ $ id ] = $ path ; } elseif ( self :: isExternalUrl ( $ file [ 'url' ] ) ) { continue ; } unset ( $ params [ 'urls' ] [ $ id ] ) ; } return $ params ; }
Check files and prepare paths and urls .
21,213
protected static function getRoutesToFolder ( $ type ) { $ type = $ type . 's' ; $ url = isset ( self :: $ unify [ $ type ] ) ? self :: $ unify [ $ type ] : self :: $ unify ; return [ 'url' => $ url , 'path' => self :: getPathFromUrl ( $ url ) ] ; }
Get path|url to the minimized file .
21,214
protected static function isModifiedHash ( $ url , $ path ) { if ( self :: isExternalUrl ( $ url ) ) { if ( sha1_file ( $ url ) !== sha1_file ( $ path ) ) { return self :: $ changes = true ; } } return false ; }
Check if it matches the file hash .
21,215
protected static function unifyFiles ( $ params , $ data = '' ) { $ type = $ params [ 'type' ] ; $ place = $ params [ 'place' ] ; $ routes = $ params [ 'routes' ] ; $ ext = ( $ type == 'style' ) ? '.css' : '.js' ; $ hash = sha1 ( implode ( '' , $ params [ 'files' ] ) ) ; $ minFile = $ routes [ 'path' ] . $ hash . $ ext ; if ( ! is_file ( $ minFile ) || self :: $ changes == true ) { foreach ( $ params [ 'paths' ] as $ id => $ path ) { if ( isset ( $ params [ 'urls' ] [ $ id ] ) ) { $ url = $ params [ 'urls' ] [ $ id ] ; $ path = $ routes [ 'path' ] . $ params [ 'files' ] [ $ id ] ; $ data .= self :: saveExternalFile ( $ url , $ path ) ; } $ data .= file_get_contents ( $ path ) ; } $ data = ( self :: $ minify ) ? self :: compressFiles ( $ data ) : $ data ; self :: saveFile ( $ minFile , $ data ) ; } self :: setProcessedFiles ( ) ; return self :: setNewParams ( $ type , $ place , $ hash , $ routes [ 'url' ] , $ ext ) ; }
Unify files .
21,216
protected static function saveExternalFile ( $ url , $ path ) { if ( $ data = file_get_contents ( $ url ) ) { return ( self :: saveFile ( $ path , $ data ) ) ? $ data : '' ; } return '' ; }
Save external file .
21,217
protected static function compressFiles ( $ content ) { $ var = [ "\r\n" , "\r" , "\n" , "\t" , ' ' , ' ' , ' ' ] ; $ content = preg_replace ( '!/\*[^*]*\*+([^/][^*]*\*+)*/!' , '' , $ content ) ; $ content = str_replace ( $ var , '' , $ content ) ; $ content = str_replace ( '{ ' , '{' , $ content ) ; $ content = str_replace ( ' }' , '}' , $ content ) ; $ content = str_replace ( '; ' , ';' , $ content ) ; return $ content ; }
File minifier .
21,218
protected static function setNewParams ( $ type , $ place , $ hash , $ url , $ ext ) { $ data = [ 'name' => self :: $ id , 'url' => $ url . $ hash . $ ext , 'attr' => self :: unifyParams ( $ type , 'attr' ) , 'version' => self :: unifyParams ( $ type , 'version' , '1.0.0' ) , ] ; if ( $ type === 'script' ) { $ data [ 'footer' ] = self :: unifyParams ( $ type , 'footer' , false ) ; } self :: $ data [ $ type ] [ $ place ] = [ $ data [ 'name' ] => $ data ] ; return true ; }
Set new parameters for the unified file .
21,219
protected static function unifyParams ( $ type , $ field , $ default = '' ) { $ data = array_column ( self :: $ data [ $ type ] , $ field ) ; switch ( $ field ) { case 'attr' : case 'footer' : case 'version' : foreach ( $ data as $ value ) { if ( $ data [ 0 ] !== $ value ) { return $ default ; } } return ( isset ( $ data [ 0 ] ) && $ data [ 0 ] ) ? $ data [ 0 ] : $ default ; default : $ params = [ ] ; foreach ( $ data as $ value ) { $ params = array_merge ( $ params , $ value ) ; } return array_unique ( $ params ) ; } }
Obtain all the parameters of a particular field and unify them .
21,220
private function retrievePathScope ( $ path , $ shopNumber ) { $ shopConfigs = $ this -> getShopNumberCollection ( $ shopNumber ) ; if ( ! $ shopConfigs -> getSize ( ) ) { throw new ShopgateLibraryException ( ShopgateLibraryException :: PLUGIN_API_UNKNOWN_SHOP_NUMBER , false , true ) ; } $ firstItem = $ shopConfigs -> getFirstItem ( ) ; foreach ( $ shopConfigs as $ shopConfig ) { $ collection = $ this -> getCollectionByPath ( $ path ) -> addFieldToFilter ( 'scope' , $ shopConfig -> getScope ( ) ) -> addFieldToFilter ( 'scope_id' , $ shopConfig -> getScopeId ( ) ) ; if ( $ collection -> getItems ( ) ) { $ propertyConfig = $ collection -> setOrder ( 'scope_id' ) -> getFirstItem ( ) ; if ( $ propertyConfig -> getData ( 'value' ) ) { return $ propertyConfig ; } } } return $ firstItem ; }
Edge case checker handles scenarios when multiple scope id s have the same shop number . Traverses the given collection of shopConfigs to check whether a value in a given path exists . If not returns the first item of the collection .
21,221
public function getMigrationsLocations ( ) { $ migrationsLocations = [ ] ; foreach ( $ this -> kernel -> getBundles ( ) as $ bundle ) { $ migrationsLocation = $ this -> createMigrationsLocation ( $ bundle ) ; if ( $ this -> filesystem -> exists ( $ migrationsLocation -> getDirectory ( ) ) ) { $ migrationsLocations [ ] = $ migrationsLocation ; } } return $ migrationsLocations ; }
Gets possible locations of migration classes to allow multiple sources of migrations .
21,222
public function createMigrationsLocation ( BundleInterface $ bundle ) { return new MigrationsLocation ( $ bundle -> getPath ( ) . '/' . $ this -> relativeDirectory , $ bundle -> getNamespace ( ) . '\\' . $ this -> relativeNamespace ) ; }
Creates a locations of migration classes for a particular bundle .
21,223
public function setEntity ( MageQuote $ quote ) { $ id = $ this -> sgBase -> getExternalCustomerId ( ) ; $ email = $ this -> sgBase -> getMail ( ) ; try { $ customer = $ id ? $ this -> customerHelper -> getById ( $ id ) : $ this -> customerHelper -> getByEmail ( $ email ) ; } catch ( NoSuchEntityException $ e ) { $ customer = new DataObject ( ) ; $ this -> log -> debug ( 'Could not load customer by id or mail.' ) ; } $ quote -> setCustomerEmail ( $ email ) -> setRemoteIp ( $ this -> sgBase -> getCustomerIp ( ) ) ; if ( $ this -> sgBase -> isGuest ( ) ) { $ quote -> setCustomerIsGuest ( true ) ; } elseif ( $ customer -> getId ( ) ) { $ this -> session -> setCustomerId ( $ customer -> getId ( ) ) -> setCustomerGroupId ( $ customer -> getGroupId ( ) ) ; $ quote -> setCustomer ( $ customer ) -> setCustomerIsGuest ( false ) ; } else { throw new \ ShopgateLibraryException ( \ ShopgateLibraryException :: UNKNOWN_ERROR_CODE , __ ( 'Customer with external id "%1" or email "%2" does not exist' , $ id , $ email ) -> render ( ) ) ; } }
Just sets the customer to quote
21,224
public function setAddress ( MageQuote $ quote ) { $ billing = $ this -> sgBase -> getInvoiceAddress ( ) ; if ( ! empty ( $ billing ) ) { $ data = $ this -> sgCustomer -> createAddressData ( $ this -> sgBase , $ billing , $ quote -> getCustomerId ( ) ) ; $ quote -> getBillingAddress ( ) -> addData ( $ data ) -> setCustomerAddressId ( $ billing -> getId ( ) ) -> setCustomerId ( $ this -> sgBase -> getExternalCustomerId ( ) ) -> setData ( 'should_ignore_validation' , true ) ; } $ shipping = $ this -> sgBase -> getDeliveryAddress ( ) ; if ( ! empty ( $ shipping ) ) { $ data = $ this -> sgCustomer -> createAddressData ( $ this -> sgBase , $ shipping , $ quote -> getCustomerId ( ) ) ; $ quote -> getShippingAddress ( ) -> addData ( $ data ) -> setCustomerAddressId ( $ shipping -> getId ( ) ) -> setCustomerId ( $ this -> sgBase -> getExternalCustomerId ( ) ) -> setData ( 'should_ignore_validation' , true ) ; } if ( ! $ quote -> getShippingAddress ( ) -> getCountryId ( ) ) { $ defaultCountryItem = $ this -> sgCoreConfig -> getConfigByPath ( Custom :: XML_PATH_GENERAL_COUNTRY_DEFAULT ) ; $ quote -> getShippingAddress ( ) -> setCountryId ( $ defaultCountryItem -> getValue ( ) ) ; } }
Sets Billing and Shipping addresses to quote
21,225
public function resetGuest ( MageQuote $ quote ) { if ( $ this -> sgBase -> isGuest ( ) ) { $ quote -> getBillingAddress ( ) -> isObjectNew ( false ) ; $ quote -> getShippingAddress ( ) -> isObjectNew ( false ) ; } }
Helps reset the billing & shipping objects for guests
21,226
public function setValue ( $ name , $ value ) { if ( substr ( $ name , - 1 ) === '_' ) { throw new InvalidArgumentException ( '$name cannot end with "_"' ) ; } $ this -> remove ( $ name ) ; $ this -> { $ name } = $ value ; return $ this ; }
Set a value to be returned without modification
21,227
public function setClassName ( $ name , $ class_name , $ shared = true ) { if ( substr ( $ name , - 1 ) === '_' ) { throw new InvalidArgumentException ( '$name cannot end with "_"' ) ; } $ classname_pattern = self :: CLASS_NAME_PATTERN_53 ; if ( ! is_string ( $ class_name ) || ! preg_match ( $ classname_pattern , $ class_name ) ) { throw new InvalidArgumentException ( 'Class names must be valid PHP class names' ) ; } $ func = function ( ) use ( $ class_name ) { return new $ class_name ( ) ; } ; return $ this -> setFactory ( $ name , $ func , $ shared ) ; }
Set a factory based on instantiating a class with no arguments .
21,228
public function remove ( $ name ) { if ( substr ( $ name , - 1 ) === '_' ) { throw new InvalidArgumentException ( '$name cannot end with "_"' ) ; } unset ( $ this -> { $ name } ) ; unset ( $ this -> factories_ [ $ name ] ) ; return $ this ; }
Remove a value from the container
21,229
public function has ( $ name ) { if ( isset ( $ this -> factories_ [ $ name ] ) ) { return true ; } if ( substr ( $ name , - 1 ) === '_' ) { return false ; } return ( bool ) property_exists ( $ this , $ name ) ; }
Does the container have this value
21,230
public function addAccount ( ChartAccountsAccount $ account ) { foreach ( $ this -> accounts as $ current ) { if ( $ current -> getNumber ( ) === $ account -> getNumber ( ) ) { throw new AccountAlreadyExistsException ( $ account ) ; } } $ this -> accounts [ ] = $ account ; return $ this ; }
Add an account .
21,231
public function removeAccount ( ChartAccountsAccount $ account ) { for ( $ i = count ( $ this -> accounts ) - 1 ; 0 <= $ i ; -- $ i ) { if ( $ account -> getNumber ( ) !== $ this -> accounts [ $ i ] -> getNumber ( ) ) { continue ; } unset ( $ this -> accounts [ $ i ] ) ; } return $ this ; }
Remove an account .
21,232
protected function getCmsPageRenderer ( ) { if ( ! $ this -> cmsPageRenderer ) { $ this -> cmsPageRenderer = $ this -> getLayout ( ) -> createBlock ( 'Shopgate\Base\Block\Adminhtml\Form\Field\CmsMap' , '' , [ 'data' => [ 'is_render_to_js_template' => true ] ] ) ; } return $ this -> cmsPageRenderer ; }
Returns a rendered for cms page mapping
21,233
public static function routes ( Router $ router , $ namespace = 'TeamTeaTime\Filer\Controllers' ) { $ router -> group ( compact ( 'namespace' ) , function ( $ router ) { $ router -> get ( '{id}' , [ 'as' => 'filer.file.view' , 'uses' => 'LocalFileController@view' ] ) ; $ router -> get ( '{id}/download' , [ 'as' => 'filer.file.download' , 'uses' => 'LocalFileController@download' ] ) ; } ) ; }
Define the standard routes .
21,234
public static function checkType ( $ item ) { if ( is_string ( $ item ) ) { if ( filter_var ( $ item , FILTER_VALIDATE_URL , FILTER_FLAG_PATH_REQUIRED ) ) { return Type :: URL ; } elseif ( is_file ( config ( 'filer.path.absolute' ) . "/{$item}" ) ) { return Type :: FILEPATH ; } } elseif ( is_a ( $ item , 'SplFileInfo' ) ) { return Type :: FILE ; } throw new Exception ( 'Unknown item type' ) ; }
Attempts to determine what the given item is between a local filepath a local file object or a URL .
21,235
public static function getRelativeFilepath ( $ file ) { $ storageDir = self :: convertSlashes ( config ( 'filer.path.absolute' ) ) ; $ absolutePath = self :: convertSlashes ( $ file -> getRealPath ( ) ) ; return dirname ( str_replace ( $ storageDir , '' , $ absolutePath ) ) ; }
Returns a file s relative path .
21,236
function _setstat ( $ filename , $ attr , $ recursive ) { if ( ! ( $ this -> bitmap & NET_SSH2_MASK_LOGIN ) ) { return false ; } $ filename = $ this -> _realpath ( $ filename ) ; if ( $ filename === false ) { return false ; } $ this -> _remove_from_stat_cache ( $ filename ) ; if ( $ recursive ) { $ i = 0 ; $ result = $ this -> _setstat_recursive ( $ filename , $ attr , $ i ) ; $ this -> _read_put_responses ( $ i ) ; return $ result ; } if ( ! $ this -> _send_sftp_packet ( NET_SFTP_SETSTAT , pack ( 'Na*a*' , strlen ( $ filename ) , $ filename , $ attr ) ) ) { return false ; } $ response = $ this -> _get_sftp_packet ( ) ; if ( $ this -> packet_type != NET_SFTP_STATUS ) { user_error ( 'Expected SSH_FXP_STATUS' ) ; return false ; } if ( strlen ( $ response ) < 4 ) { return false ; } extract ( unpack ( 'Nstatus' , $ this -> _string_shift ( $ response , 4 ) ) ) ; if ( $ status != NET_SFTP_STATUS_OK ) { $ this -> _logError ( $ response , $ status ) ; return false ; } return true ; }
Sets information about a file
21,237
function rename ( $ oldname , $ newname ) { if ( ! ( $ this -> bitmap & NET_SSH2_MASK_LOGIN ) ) { return false ; } $ oldname = $ this -> _realpath ( $ oldname ) ; $ newname = $ this -> _realpath ( $ newname ) ; if ( $ oldname === false || $ newname === false ) { return false ; } $ packet = pack ( 'Na*Na*' , strlen ( $ oldname ) , $ oldname , strlen ( $ newname ) , $ newname ) ; if ( ! $ this -> _send_sftp_packet ( NET_SFTP_RENAME , $ packet ) ) { return false ; } $ response = $ this -> _get_sftp_packet ( ) ; if ( $ this -> packet_type != NET_SFTP_STATUS ) { user_error ( 'Expected SSH_FXP_STATUS' ) ; return false ; } if ( strlen ( $ response ) < 4 ) { return false ; } extract ( unpack ( 'Nstatus' , $ this -> _string_shift ( $ response , 4 ) ) ) ; if ( $ status != NET_SFTP_STATUS_OK ) { $ this -> _logError ( $ response , $ status ) ; return false ; } $ this -> _remove_from_stat_cache ( $ oldname ) ; $ this -> _remove_from_stat_cache ( $ newname ) ; return true ; }
Renames a file or a directory on the SFTP server
21,238
public function getStackQty ( ) { $ info = $ this -> getInternalOrderInfo ( ) ; $ qty = 1 ; if ( $ info -> getStackQuantity ( ) > 1 ) { $ qty = $ info -> getStackQuantity ( ) ; } return $ qty ; }
Retrieve stack qty if it exists
21,239
public function setInternalOrderInfo ( $ value ) { if ( $ value instanceof ItemInfo ) { $ value = $ value -> toJson ( ) ; } elseif ( is_array ( $ value ) ) { $ value = \ Zend_Json_Encoder :: encode ( $ value ) ; } return parent :: setInternalOrderInfo ( $ value ) ; }
Encodes to JSON if it s not empty or already JSON
21,240
public function setMagentoError ( $ errorText ) { $ code = $ this -> translateMagentoError ( $ errorText ) ; $ message = \ ShopgateLibraryException :: getMessageFor ( $ code ) ; $ this -> setUnhandledError ( $ code , $ message ) ; return $ this ; }
Takes a magento quote exception and translated it into Shopgate error
21,241
public function getExportProductId ( ) { return $ this -> getInternalOrderInfo ( ) -> getItemType ( ) == Grouped :: TYPE_CODE ? $ this -> getChildId ( ) : $ this -> getParentId ( ) ; }
Uses an export ID based on expectations of our backend API
21,242
private function validate ( ) { if ( ! array_key_exists ( 'type' , $ this -> properties ) ) { throw new StatusException ( sprintf ( 'Key %s in %s missing' , 'type' , __CLASS__ ) , 100 , null ) ; } $ type = $ this -> properties [ 'type' ] ; if ( ! in_array ( $ this -> properties [ 'type' ] , $ this -> types ) ) { throw new StatusException ( 'The type specified is invalid' , 100 , null ) ; } switch ( $ type ) { case StatusInterface :: TYPE_INITIAL : case StatusInterface :: TYPE_EXCEPTION : $ mandatoryKeys = [ 'name' ] ; break ; default : $ mandatoryKeys = [ 'name' , 'transitions_from' , 'transitions_to' ] ; break ; } foreach ( $ mandatoryKeys as $ key ) { if ( ! array_key_exists ( $ key , $ this -> properties ) ) { throw new StatusException ( sprintf ( 'Key %s in %s missing' , $ key , __CLASS__ ) , 100 , null ) ; } } if ( StatusInterface :: TYPE_INITIAL != $ type && StatusInterface :: TYPE_EXCEPTION != $ type ) { $ keysMustBeArray = [ 'transitions_from' , 'transitions_to' ] ; foreach ( $ keysMustBeArray as $ key ) { if ( ! is_array ( $ this -> properties [ $ key ] ) ) { throw new StatusException ( sprintf ( 'Key %s is not an array' , $ key ) , 100 , null ) ; } } } }
Validate all required properties on initialization .
21,243
public function has_more ( ) { if ( $ this -> _pointer + 1 == count ( $ this -> _collection ) ) { return false ; } ++ $ this -> _pointer ; return true ; }
If the collection has not been finished yet return false .
21,244
static function line ( $ message = '' , $ newLine = 'after' ) { if ( $ newLine == 'before' || $ newLine == 'both' ) { echo PHP_EOL ; } echo self :: formatMessage ( "Error. $message" , [ 'fg-red' ] ) ; if ( $ newLine == 'after' || $ newLine == 'both' ) { echo PHP_EOL ; } }
Prints error message .
21,245
private static function formatMessage ( $ message , $ styles ) { if ( empty ( $ styles ) || ! self :: ansiColorsSupported ( ) ) { return $ message ; } return sprintf ( "\x1b[%sm" , implode ( ';' , array_map ( 'Output::getStyleCode' , $ styles ) ) ) . $ message . "\x1b[0m" ; }
Formats message using styles if STDOUT supports it .
21,246
public function getSizes ( \ ElggEntity $ entity , array $ icon_sizes = array ( ) ) { $ defaults = ( $ entity && $ entity -> getSubtype ( ) == 'file' ) ? $ this -> config -> getFileIconSizes ( ) : $ this -> config -> getGlobalIconSizes ( ) ; $ sizes = array_merge ( $ defaults , $ icon_sizes ) ; return elgg_trigger_plugin_hook ( 'entity:icon:sizes' , $ entity -> getType ( ) , array ( 'entity' => $ entity , 'subtype' => $ entity -> getSubtype ( ) , ) , $ sizes ) ; }
Get icon size config
21,247
public function getIconDirectory ( \ ElggEntity $ entity , $ size = null , $ directory = null ) { $ sizes = $ this -> getSizes ( $ entity ) ; if ( isset ( $ sizes [ $ size ] [ 'metadata_name' ] ) ) { $ md_name = $ sizes [ $ size ] [ 'metadata_name' ] ; if ( $ entity -> $ md_name ) { $ directory = '' ; } } if ( $ directory === null ) { $ directory = $ directory ? : $ entity -> icon_directory ; if ( $ entity instanceof \ ElggUser ) { $ directory = 'profile' ; } else if ( $ entity instanceof \ ElggGroup ) { $ directory = 'groups' ; } else { $ directory = $ this -> config -> getDefaultIconDirectory ( ) ; } } $ directory = elgg_trigger_plugin_hook ( 'entity:icon:directory' , $ entity -> getType ( ) , array ( 'entity' => $ entity , 'size' => $ size , ) , $ directory ) ; return trim ( $ directory , '/' ) ; }
Determines and normalizes the directory in which the icon is stored
21,248
public function getIconFilename ( \ ElggEntity $ entity , $ size = '' ) { $ mimetype = $ entity -> icon_mimetype ? : $ entity -> mimetype ; switch ( $ mimetype ) { default : $ ext = 'jpg' ; break ; case 'image/png' : $ ext = 'png' ; break ; case 'image/gif' : $ ext = 'gif' ; break ; } $ sizes = $ this -> getSizes ( $ entity ) ; if ( isset ( $ sizes [ $ size ] [ 'metadata_name' ] ) ) { $ md_name = $ sizes [ $ size ] [ 'metadata_name' ] ; $ filename = $ entity -> $ md_name ; } if ( ! $ filename ) { $ filename = "{$entity->guid}{$size}.{$ext}" ; } return elgg_trigger_plugin_hook ( 'entity:icon:directory' , $ entity -> getType ( ) , array ( 'entity' => $ entity , 'size' => $ size , ) , $ filename ) ; }
Determines icon filename
21,249
public function getIconFile ( \ ElggEntity $ entity , $ size = '' ) { $ dir = $ this -> getIconDirectory ( $ entity , $ size ) ; $ filename = $ this -> getIconFilename ( $ entity , $ size ) ; if ( $ entity instanceof \ ElggUser ) { $ owner_guid = $ entity -> guid ; } else if ( $ entity -> owner_guid ) { $ owner_guid = $ entity -> owner_guid ; } else { $ owner_guid = elgg_get_site_entity ( ) ; } $ file = new \ ElggFile ( ) ; $ file -> owner_guid = $ owner_guid ; $ file -> setFilename ( "{$dir}/{$filename}" ) ; $ file -> mimetype = $ file -> detectMimeType ( ) ; return $ file ; }
Returns an ElggFile containing the entity icon
21,250
public function getURL ( \ ElggEntity $ entity , $ size = '' ) { $ icon = $ this -> getIconFile ( $ entity , $ size ) ; if ( ! $ icon -> exists ( ) ) { return ; } $ key = get_site_secret ( ) ; $ guid = $ entity -> guid ; $ path = $ icon -> getFilename ( ) ; $ hmac = hash_hmac ( 'sha256' , $ guid . $ path , $ key ) ; $ query = serialize ( array ( 'uid' => $ guid , 'd' => ( $ entity instanceof \ ElggUser ) ? $ entity -> guid : $ entity -> owner_guid , 'dts' => ( $ entity instanceof \ ElggUser ) ? $ entity -> time_created : $ entity -> getOwnerEntity ( ) -> time_created , 'path' => $ path , 'ts' => $ entity -> icontime , 'mac' => $ hmac , ) ) ; $ url = elgg_http_add_url_query_elements ( 'mod/hypeApps/servers/icon.php' , array ( 'q' => base64_encode ( $ query ) , ) ) ; return elgg_normalize_url ( $ url ) ; }
Prepares a URL that can be used to display an icon bypassing the engine boot
21,251
public function outputRawIcon ( $ entity_guid , $ size = null ) { if ( headers_sent ( ) ) { exit ; } $ ha = access_get_show_hidden_status ( ) ; access_show_hidden_entities ( true ) ; $ entity = get_entity ( $ entity_guid ) ; if ( ! $ entity ) { exit ; } $ size = strtolower ( $ size ? : 'medium' ) ; $ filename = "icons/" . $ entity -> guid . $ size . ".jpg" ; $ etag = md5 ( $ entity -> icontime . $ size ) ; $ filehandler = new \ ElggFile ( ) ; $ filehandler -> owner_guid = $ entity -> owner_guid ; $ filehandler -> setFilename ( $ filename ) ; if ( $ filehandler -> exists ( ) ) { $ filehandler -> open ( 'read' ) ; $ contents = $ filehandler -> grabFile ( ) ; $ filehandler -> close ( ) ; } else { forward ( '' , '404' ) ; } $ mimetype = ( $ entity -> mimetype ) ? $ entity -> mimetype : 'image/jpeg' ; access_show_hidden_entities ( $ ha ) ; header ( "Content-type: $mimetype" ) ; header ( "Etag: $etag" ) ; header ( 'Expires: ' . date ( 'r' , time ( ) + 864000 ) ) ; header ( "Pragma: public" ) ; header ( "Cache-Control: public" ) ; header ( "Content-Length: " . strlen ( $ contents ) ) ; echo $ contents ; exit ; }
Outputs raw icon
21,252
public function getMigrationsToExecute ( $ direction , $ to ) { if ( $ direction === Version :: DIRECTION_DOWN ) { $ this -> throwMethodIsNotAllowedException ( 'Migration down is not allowed.' ) ; } $ migrationVersionsToExecute = [ ] ; $ allMigrationVersions = $ this -> getMigrations ( ) ; $ migratedVersions = $ this -> getMigratedVersions ( ) ; foreach ( $ allMigrationVersions as $ version ) { if ( $ to < $ version -> getVersion ( ) ) { $ this -> throwMethodIsNotAllowedException ( 'Partial migration up in not allowed.' ) ; } if ( $ this -> shouldExecuteMigration ( $ version , $ migratedVersions ) ) { $ migrationVersionsToExecute [ $ version -> getVersion ( ) ] = $ version ; } } return $ migrationVersionsToExecute ; }
Returns the array of migrations to executed based on the given direction and target version number . Because of multiple migrations locations and the lock file only complete UP migrations are allowed .
21,253
public function drawCircle ( $ x , $ y , $ z , $ radius , $ motion = 'G2' , $ plane = 'G17' ) { if ( $ plane == 'G17' ) { $ of = $ x - $ radius ; $ this -> setCode ( "(circle)" ) ; $ this -> setCode ( "G0 X{$of} Y{$y}" ) ; $ this -> setCode ( "G1 Z{$z} (axis spindle start point)" ) ; $ this -> setCode ( "{$plane} {$motion} X{$of} Y{$y} I{$radius} J0.00 Z{$z}" ) ; $ this -> setCode ( "G0 Z{$this->spindleAxisStartPosition} (axis spindle start position)" ) ; $ this -> setCode ( "(/circle)\n" ) ; } if ( $ plane == 'G18' ) { return ; } if ( $ plane == 'G19' ) { return ; } return $ this ; }
Draw a circle on a XY plane With a certain motion clockwise or anticlockwise for conventional or climb milling
21,254
public function drawBox ( $ x1 , $ y1 , $ z1 , $ x2 , $ y2 , $ z2 ) { $ this -> setCode ( "(box)" ) ; $ this -> setCode ( "G0 X{$x1} Y{$y1} Z{$this->spindleAxisStartPosition} (move to spindle axis start position)" ) ; $ this -> setCode ( "G1 Z{$z1}" ) ; $ this -> setCode ( "G1 X{$x1} Y{$y1} Z{$z1}" ) ; $ this -> setCode ( "G1 Y{$y2}" ) ; $ this -> setCode ( "G1 X{$x2}" ) ; $ this -> setCode ( "G1 Y{$y1}" ) ; $ this -> setCode ( "G1 X{$x1}" ) ; $ this -> setCode ( "G0 Z{$z2}" ) ; $ this -> setCode ( "(/box)\n" ) ; return $ this ; }
Draw a box on a XY plane
21,255
public function drawLine ( $ xStart , $ yStart , $ zStart , $ xEnd , $ yEnd , $ zEnd ) { $ this -> setCode ( "(line)" ) ; $ this -> setCode ( "G0 X{$xStart} Y{$yStart} Z{$this->spindleAxisStartPosition}" ) ; $ this -> setCode ( "G1 Z{$zStart}" ) ; $ this -> setCode ( "T1 M08" ) ; $ this -> setCode ( "G41 D4" ) ; $ this -> setCode ( "G1 X{$xStart} Y{$yStart} Z{$zStart}" ) ; $ this -> setCode ( "G1 X{$xEnd} Y{$yEnd} Z{$zEnd}" ) ; $ this -> setCode ( "G0 Z{$this->spindleAxisStartPosition}" ) ; $ this -> setCode ( "G0 X{$xStart} Y{$yStart}" ) ; $ this -> setCode ( "(/line)\n" ) ; return $ this ; }
Draw a line on a XY plane
21,256
public function drawCubicSpline ( $ xStart , $ yStart , $ xFromEnd , $ yFromEnd , $ xEnd , $ yEnd ) { $ this -> setCode ( "(cubic spline)" ) ; $ this -> setCode ( "G0 X{$xStart} Y{$yStart} Z{$this->spindleAxisStartPosition}" ) ; $ this -> setCode ( "G5 I{$xStart} J{$yStart} P{$xFromEnd} Q-{$yFromEnd} X{$xEnd} Y{$yEnd}" ) ; $ this -> setCode ( "G0 Z{$this->spindleAxisStartPosition}" ) ; $ this -> setCode ( "G0 X{$xStart} Y{$yStart}" ) ; $ this -> setCode ( "(/cubic spline)" ) ; return $ this ; }
G5 creates a cubic B - spline in the XY plane with the X and Y axes only . P and Q must both be specified for every G5 command .
21,257
protected function createMessageCallback ( Recipient $ user , $ subject = null , $ callback = null ) { return function ( Message $ message ) use ( $ user , $ subject , $ callback ) { $ message -> to ( $ user -> getRecipientEmail ( ) , $ user -> getRecipientName ( ) ) ; ! empty ( $ subject ) && $ message -> subject ( $ subject ) ; \ is_callable ( $ callback ) && $ callback ( ... func_get_args ( ) ) ; } ; }
Create message callback .
21,258
public function getRoute ( ) { $ req = $ this -> context -> getRequest ( ) ; if ( isset ( $ this -> map [ $ req -> getControllerName ( ) ] ) ) { return $ this -> map [ $ req -> getControllerName ( ) ] ; } return $ this -> map [ Generic :: CONTROLLER_KEY ] ; }
Retrieves the correct route based on the current controller
21,259
public function getPaymentMethods ( ) { $ this -> quote -> setStoreId ( $ this -> storeManager -> getStore ( ) -> getId ( ) ) ; $ export = [ ] ; $ paymentMethods = $ this -> paymentModel -> getAvailableMethods ( $ this -> quote ) ; foreach ( $ paymentMethods as $ method ) { $ export [ ] = [ 'id' => $ method -> getCode ( ) , 'title' => $ method -> getTitle ( ) , 'is_active' => 1 ] ; } return $ export ; }
Retrieves all available payment methods and formats them to Shopgate Merchant API ready format
21,260
public function buildHttpRedirect ( ) { if ( ! is_null ( $ this -> http ) ) { return $ this -> http ; } $ builder = new ShopgateBuilder ( $ this -> initConfig ( ) ) ; $ userAgent = $ this -> header -> getHttpUserAgent ( ) ; try { $ this -> http = $ builder -> buildHttpRedirect ( $ userAgent , $ this -> request -> getParams ( ) , $ _COOKIE ) ; } catch ( \ ShopgateMerchantApiException $ e ) { $ this -> logger -> error ( 'HTTP > oAuth access token for store not set: ' . $ e -> getMessage ( ) ) ; return null ; } catch ( \ Exception $ e ) { $ this -> logger -> error ( 'HTTP > error in HTTP redirect: ' . $ e -> getMessage ( ) ) ; return null ; } return $ this -> http ; }
Instantiates the HTTP redirect object
21,261
public function buildJsRedirect ( ) { if ( ! is_null ( $ this -> js ) ) { return $ this -> js ; } $ builder = new ShopgateBuilder ( $ this -> initConfig ( ) ) ; try { $ this -> js = $ builder -> buildJsRedirect ( $ this -> request -> getParams ( ) , $ _COOKIE ) ; } catch ( \ ShopgateMerchantApiException $ e ) { $ this -> logger -> error ( 'JS > oAuth access token for store not set: ' . $ e -> getMessage ( ) ) ; return null ; } catch ( \ Exception $ e ) { $ this -> logger -> error ( 'JS > error in HTTP redirect: ' . $ e -> getMessage ( ) ) ; return null ; } return $ this -> js ; }
Instantiates the JS script builder object
21,262
public function prepare ( OptionList $ objOptions = null ) : OptionList { if ( is_null ( $ objOptions ) ) { $ objOptions = new OptionList ; } if ( 'post' == $ this -> options -> get ( 'method' ) ) { $ requestBody = $ this -> serverRequest -> getParsedBody ( ) ; if ( is_array ( $ requestBody ) && ! empty ( $ requestBody [ $ this -> getParam ( ) ] ) ) { $ this -> page = intval ( $ requestBody [ $ this -> getParam ( ) ] ) ; } else { $ this -> page = 1 ; } } else { $ queryParams = $ this -> serverRequest -> getQueryParams ( ) ; if ( is_array ( $ queryParams ) && ! empty ( $ queryParams [ $ this -> getParam ( ) ] ) ) { $ this -> page = intval ( $ queryParams [ $ this -> getParam ( ) ] ) ; } else { $ this -> page = 1 ; } } $ this -> nb_per_page = $ this -> options -> is_int ( 'nb_per_page' ) ? $ this -> options -> get ( 'nb_per_page' ) : 20 ; $ objOptions -> set ( 'limitStart' , $ this -> nb_per_page * ( $ this -> page - 1 ) ) ; $ objOptions -> set ( 'limitEnd' , $ objOptions -> get ( 'limitStart' ) + $ this -> nb_per_page ) ; $ objOptions -> set ( 'limitNb' , $ this -> nb_per_page ) ; return $ objOptions ; }
Prepare the OptionList for Collection .
21,263
public function handle ( $ mixed ) : Pagination { if ( $ mixed instanceof Collection ) { $ this -> mixed = $ mixed ; $ this -> nb_pages = ceil ( max ( count ( $ mixed ) , 1 ) / max ( $ this -> nb_per_page , 1 ) ) ; } else { if ( $ mixed instanceof \ Countable ) { $ this -> mixed = $ mixed ; $ this -> nb_pages = ceil ( max ( count ( $ mixed ) , 1 ) / max ( $ this -> nb_per_page , 1 ) ) ; } else { if ( is_int ( $ mixed ) ) { $ this -> mixed = $ mixed ; $ this -> nb_pages = ceil ( max ( $ mixed , 1 ) / max ( $ this -> nb_per_page , 1 ) ) ; } else { trigger_error ( 'Parameter of Pagination::handle must be an Collection object or integer' , E_USER_WARNING ) ; } } } return $ this ; }
Called to complete the Pagination object with the number of elements .
21,264
public function canBeShowed ( ) : bool { return ( $ this -> mixed instanceof Collection || $ this -> mixed instanceof \ Countable || is_int ( $ this -> mixed ) ) ; }
If Pagination can be showed .
21,265
public function getParam ( ) : string { if ( $ this -> options -> is_null ( 'param' ) ) { $ this -> options -> set ( 'param' , 'page' . ( 1 == self :: $ iPagination ? '' : self :: $ iPagination ) ) ; } return $ this -> options -> get ( 'param' ) ; }
Get the GET or POST parameter name .
21,266
public function getHttpQueryString ( array $ moreQuery = null ) : string { $ queries = [ ] ; if ( ! ( is_null ( $ this -> page ) || 1 == $ this -> page ) ) { $ queries [ $ this -> getParam ( ) ] = $ this -> page ; } if ( ! empty ( $ moreQuery ) ) { $ queries = array_merge ( $ queries , $ moreQuery ) ; } return ! empty ( $ queries ) ? '?' . http_build_query ( $ queries ) : '' ; }
Get query string part of URL for navigation between pages .
21,267
protected function parseYAML ( ) { try { $ yaml = $ this -> configuration ; $ yaml_fixed = [ ] ; $ yaml_fixed [ 'class' ] = $ yaml [ 'class' ] ; foreach ( $ yaml [ 'states' ] as $ key => $ value ) { if ( $ value [ 'type' ] != \ Mothership \ StateMachine \ StatusInterface :: TYPE_INITIAL && $ value [ 'type' ] != \ Mothership \ StateMachine \ StatusInterface :: TYPE_EXCEPTION ) { $ state = [ 'name' => $ key , 'type' => $ value [ 'type' ] , 'transitions_from' => $ value [ 'transitions_from' ] , 'transitions_to' => $ value [ 'transitions_to' ] , ] ; $ yaml_fixed [ 'states' ] [ ] = $ state ; } else { $ state = [ 'name' => $ key , 'type' => $ value [ 'type' ] , ] ; $ yaml_fixed [ 'states' ] [ ] = $ state ; } } $ yaml_fixed [ 'yaml' ] = $ this -> configuration ; return $ yaml_fixed ; } catch ( \ Symfony \ Component \ Yaml \ Exception \ ParseException $ ex ) { throw $ ex ; } }
Parse the yaml configuration .
21,268
protected function initWorkflow ( ) { $ className = $ this -> workflowConfiguration [ 'class' ] [ 'name' ] ; if ( ! class_exists ( $ className , true ) ) { throw new StateMachineException ( 'The class ' . $ className . ' does not exist!' , 100 ) ; } try { $ this -> workflow = new $ className ( $ this -> workflowConfiguration ) ; } catch ( WorkflowException $ ex ) { throw new StateMachineException ( 'Workflow with some problems' , 90 , $ ex ) ; } }
Create the workflow .
21,269
public function renderGraph ( $ outputPath = './workflow.png' , $ stopAfterExecution = true ) { $ template = ' digraph finite_state_machine { rankdir=LR; size="%d" node [shape = doublecircle]; start; node [shape = circle]; %s } ' ; $ pattern = ' %s -> %s [ label = "%s" ];' ; $ _transitions = [ ] ; foreach ( $ this -> workflowConfiguration [ 'states' ] as $ state ) { if ( array_key_exists ( 'transitions_from' , $ state ) ) { $ transitions_from = $ state [ 'transitions_from' ] ; foreach ( $ transitions_from as $ from ) { if ( is_array ( $ from ) ) { $ _transitions [ ] = sprintf ( $ pattern , $ from [ 'status' ] , $ state [ 'name' ] , '<< IF ' . $ this -> convertToStringCondition ( $ from [ 'result' ] ) . ' >>' . $ state [ 'name' ] ) ; } else { $ _transitions [ ] = sprintf ( $ pattern , $ from , $ state [ 'name' ] , $ state [ 'name' ] ) ; } } } else { if ( 'type' == 'exception' ) { $ _transitions [ ] = 'node [shape = doublecircle]; exception;' ; } } } file_put_contents ( '/tmp/sm.gv' , sprintf ( $ template , count ( $ _transitions ) * 2 , implode ( "\n" , $ _transitions ) ) ) ; shell_exec ( 'dot -Tpng /tmp/sm.gv -o ' . $ outputPath ) ; if ( $ stopAfterExecution ) { } }
create a graph for the state machine .
21,270
public function run ( array $ args = [ ] , $ enableLog = false ) { try { return $ this -> workflow -> run ( $ args , $ enableLog ) ; } catch ( WorkflowException $ ex ) { throw new StateMachineException ( 'Error running State Machine' , 100 , $ ex ) ; } }
Run the state machine with optional arguments .
21,271
public function generate ( $ pageTitle ) { return [ Shopgate_Helper_Redirect_TagsGenerator :: SITE_PARAMETER_SITENAME => $ this -> getSiteName ( ) , Shopgate_Helper_Redirect_TagsGenerator :: SITE_PARAMETER_DESKTOP_URL => $ this -> getShopUrl ( ) , Shopgate_Helper_Redirect_TagsGenerator :: SITE_PARAMETER_MOBILE_WEB_URL => $ this -> getMobileUrl ( ) , Shopgate_Helper_Redirect_TagsGenerator :: SITE_PARAMETER_TITLE => $ pageTitle ] ; }
Generates a default set of tags
21,272
public static function getInstance ( $ method , CURLConfiguration $ configuration = null , $ resourcePath = null ) { if ( null === $ configuration ) { $ configuration = new CURLConfiguration ( ) ; } switch ( $ method ) { case self :: HTTP_METHOD_DELETE : return new CURLDeleteRequest ( $ configuration , $ resourcePath ) ; case self :: HTTP_METHOD_GET : return new CURLGetRequest ( $ configuration , $ resourcePath ) ; case self :: HTTP_METHOD_HEAD : return new CURLHeadRequest ( $ configuration , $ resourcePath ) ; case self :: HTTP_METHOD_OPTIONS : return new CURLOptionsRequest ( $ configuration , $ resourcePath ) ; case self :: HTTP_METHOD_PATCH : return new CURLPatchRequest ( $ configuration , $ resourcePath ) ; case self :: HTTP_METHOD_POST : return new CURLPostRequest ( $ configuration , $ resourcePath ) ; case self :: HTTP_METHOD_PUT : return new CURLPutRequest ( $ configuration , $ resourcePath ) ; default : throw new InvalidHTTPMethodException ( $ method ) ; } }
Get an instance .
21,273
public function createGraph ( NamedNode $ graph , array $ options = [ ] ) { if ( false === isset ( $ this -> getGraphs ( ) [ $ graph -> getUri ( ) ] ) ) { $ g2t = $ this -> configuration [ 'table-prefix' ] . '_g2t' ; $ id2val = $ this -> configuration [ 'table-prefix' ] . '_id2val' ; $ query = 'INSERT INTO ' . $ id2val . ' (val) VALUES("' . $ graph -> getUri ( ) . '")' ; $ this -> store -> queryDB ( $ query , $ this -> store -> getDBCon ( ) ) ; $ usedId = $ this -> store -> getDBCon ( ) -> insert_id ; $ newIdg2t = 1 + $ this -> getRowCount ( $ g2t ) ; $ query = 'INSERT INTO ' . $ g2t . ' (t, g) VALUES(' . $ newIdg2t . ', ' . $ usedId . ')' ; $ this -> store -> queryDB ( $ query , $ this -> store -> getDBCon ( ) ) ; $ usedId = $ this -> store -> getDBCon ( ) -> insert_id ; } }
Create a new graph with the URI given as NamedNode .
21,274
public function getRowCount ( $ tableName ) { $ result = $ this -> store -> queryDB ( 'SELECT COUNT(*) as count FROM ' . $ tableName , $ this -> store -> getDBCon ( ) ) ; $ row = $ result -> fetch_assoc ( ) ; return $ row [ 'count' ] ; }
Helper function to get the number of rows in a table .
21,275
protected function openConnection ( ) { $ this -> configuration = array_merge ( [ 'host' => 'localhost' , 'database' => '' , 'username' => '' , 'password' => '' , 'table-prefix' => 'saft_' , ] , $ this -> configuration ) ; if ( '' == $ this -> configuration [ 'database' ] ) { throw new \ Exception ( 'ARC2: Field database is not set.' ) ; } elseif ( '' == $ this -> configuration [ 'username' ] ) { throw new \ Exception ( 'ARC2: Field username is not set.' ) ; } elseif ( '' == $ this -> configuration [ 'host' ] ) { throw new \ Exception ( 'ARC2: Field host is not set.' ) ; } $ this -> store = \ ARC2 :: getStore ( [ 'db_host' => $ this -> configuration [ 'host' ] , 'db_name' => $ this -> configuration [ 'database' ] , 'db_user' => $ this -> configuration [ 'username' ] , 'db_pwd' => $ this -> configuration [ 'password' ] , 'store_name' => $ this -> configuration [ 'table-prefix' ] , ] ) ; }
Creates and sets up an instance of ARC2_Store .
21,276
public function start ( $ identifier = null ) { $ this -> loadProfile ( $ identifier ) ; $ this -> currentProfile -> start ( ) ; return $ this ; }
Loads and starts a profile . If nothing is provided then it starts a generic profile .
21,277
protected function loadProfile ( $ identifier = null ) { if ( ! $ identifier ) { $ identifier = 'generic' ; } if ( isset ( $ this -> profiles [ $ identifier ] ) ) { $ this -> currentProfile = $ this -> profiles [ $ identifier ] ; } else { $ this -> currentProfile = new SgProfile ( ) ; $ this -> profiles [ $ identifier ] = $ this -> currentProfile ; } return $ this -> currentProfile ; }
Retrieves the current profile
21,278
public function debug ( $ message = "%s seconds" ) { $ this -> logger -> debug ( sprintf ( $ message , $ this -> currentProfile -> getDuration ( ) ) ) ; }
Prints a message to debug log
21,279
public function weeks ( $ weeks ) { return sprintf ( $ this -> formatPattern , $ weeks , $ this -> week_words [ $ this -> pluralization ( $ weeks ) ] ) ; }
Returns weeks ago like string
21,280
public function months ( $ months ) { return sprintf ( $ this -> formatPattern , $ months , $ this -> month_words [ $ this -> pluralization ( $ months ) ] ) ; }
Returns months ago like string
21,281
public function years ( $ years ) { return sprintf ( $ this -> formatPattern , $ years , $ this -> year_words [ $ this -> pluralization ( $ years ) ] ) ; }
Returns years ago like string
21,282
public function leftJoinWithout ( ) { $ buffer = TimeSlotHelper :: merge ( $ this -> getTimeSlots ( ) ) ; $ number = count ( $ buffer ) ; if ( 0 === $ number ) { return [ $ this ] ; } $ output = [ $ this ] ; for ( $ i = 0 ; $ i < $ number ; ++ $ i ) { $ j = count ( $ output ) - 1 ; $ res = TimeSlotHelper :: leftJoinWithout ( $ output [ $ j ] , $ buffer [ $ i ] ) ; if ( null === $ res ) { continue ; } $ output [ $ j ] = $ res [ 0 ] ; if ( 2 === count ( $ res ) ) { $ output [ ] = $ res [ 1 ] ; } } if ( 1 === count ( $ output ) && $ this === $ output [ 0 ] ) { return [ ] ; } return $ output ; }
Left join without .
21,283
public function removeTimeSlot ( TimeSlot $ timeSlot ) { for ( $ i = count ( $ this -> timeSlots ) - 1 ; 0 <= $ i ; -- $ i ) { if ( true !== TimeSlotHelper :: equals ( $ timeSlot , $ this -> timeSlots [ $ i ] ) ) { continue ; } unset ( $ this -> timeSlots [ $ i ] ) ; } return $ this ; }
Remove a time slot .
21,284
private function setConfigDirectory ( string $ dirName ) : void { $ dirName = realpath ( $ this -> getDirectory ( Config :: DIR_ROOT ) . $ dirName ) ; if ( is_dir ( $ dirName ) ) { $ this -> configDirectory = $ dirName ; } else { if ( $ dirName !== false ) { throw new \ InvalidArgumentException ( sprintf ( 'Directory "%s" does not exists' , $ dirName ) ) ; } else { throw new \ InvalidArgumentException ( sprintf ( 'Config directory does not exists' , $ dirName ) ) ; } } }
Set configuration directory .
21,285
public function getCustomerGroups ( ) { $ groups = [ ] ; foreach ( $ this -> customerGroupCollection -> getItems ( ) as $ customerGroup ) { $ group = [ ] ; $ group [ 'id' ] = $ customerGroup -> getId ( ) ; $ group [ 'name' ] = $ customerGroup -> getCode ( ) ; $ group [ 'is_default' ] = intval ( $ customerGroup -> getId ( ) == GroupInterface :: NOT_LOGGED_IN_ID ) ; $ matchingTaxClasses = $ this -> taxCollection -> getItemsByColumnValue ( 'class_id' , $ customerGroup -> getTaxClassId ( ) ) ; if ( count ( $ matchingTaxClasses ) ) { $ group [ 'customer_tax_class_key' ] = array_pop ( $ matchingTaxClasses ) -> getClassName ( ) ; } $ groups [ ] = $ group ; } return $ groups ; }
Retrieves Customer Group data
21,286
protected function create_error_message ( $ message_name , $ value ) { $ message = $ this -> get_message_template ( $ message_name ) ; if ( ! is_scalar ( $ value ) ) { $ value = $ this -> get_value_as_string ( $ value ) ; } $ message = str_replace ( '%value%' , $ value , $ message ) ; foreach ( $ this -> options as $ search => $ replace ) { $ replace = $ this -> get_value_as_string ( $ replace ) ; $ message = str_replace ( '%' . $ search . '%' , $ replace , $ message ) ; } return $ message ; }
Creating an Error - Message for the given messageName from an messageTemplate .
21,287
protected function get_value_as_string ( $ value ) { if ( is_object ( $ value ) && ! in_array ( '__toString' , get_class_methods ( $ value ) ) ) { $ value = get_class ( $ value ) . ' object' ; } else if ( is_array ( $ value ) ) { $ value = var_export ( $ value , TRUE ) ; } return ( string ) $ value ; }
Converts non - scalar values into a readable string .
21,288
public function addOid ( $ oid , $ type = STRING , $ value = NULL , $ allowed = [ ] ) { $ this -> tree [ $ oid ] = [ 'type' => $ type , 'value' => $ value , 'allowed' => $ allowed ] ; return $ this ; }
Add an OID to your base OID
21,289
public function resize ( $ props = array ( ) , $ coords = null ) { $ croppable = elgg_extract ( 'croppable' , $ props , false ) ; $ width = elgg_extract ( 'w' , $ props ) ; $ height = elgg_extract ( 'h' , $ props ) ; if ( is_array ( $ coords ) && $ croppable ) { $ master_width = elgg_extract ( 'master_width' , $ coords , self :: MASTER ) ; $ master_height = elgg_extract ( 'master_height' , $ coords , self :: MASTER ) ; $ x1 = elgg_extract ( 'x1' , $ coords , 0 ) ; $ y1 = elgg_extract ( 'y1' , $ coords , 0 ) ; $ x2 = elgg_extract ( 'x2' , $ coords , self :: MASTER ) ; $ y2 = elgg_extract ( 'y2' , $ coords , self :: MASTER ) ; $ this -> source = $ this -> source -> resize ( $ master_width , $ master_height , 'inside' , 'down' ) -> crop ( $ x1 , $ y1 , $ x2 - $ x1 , $ y2 - $ y1 ) -> resize ( $ width ) ; } else if ( $ croppable ) { $ this -> source = $ this -> source -> resize ( $ width , $ height , 'outside' , 'any' ) -> crop ( 'center' , 'center' , $ width , $ height ) ; } else { $ this -> source = $ this -> source -> resize ( $ width , $ height , 'inside' , 'down' ) ; } return $ this ; }
Resizes the image to dimensions found in props and crops if coords are provided
21,290
public function save ( $ path , $ quality = array ( ) ) { $ ext = pathinfo ( $ path , PATHINFO_EXTENSION ) ; $ jpeg_quality = elgg_extract ( 'jpeg_quality' , $ quality ) ; $ png_quality = elgg_extract ( 'png_quality' , $ quality ) ; $ png_filter = elgg_extract ( 'png_filter' , $ quality ) ; switch ( $ ext ) { default : $ this -> source -> saveToFile ( $ path , $ jpeg_quality ) ; break ; case 'gif' ; $ this -> source -> saveToFile ( $ path ) ; break ; case 'png' : $ this -> source -> saveToFile ( $ path , $ png_quality , $ png_filter ) ; break ; } return $ this ; }
Saves resized image to a file
21,291
private function clearStats ( ) { $ this -> queries_executed = 0 ; $ this -> queries_released = 0 ; $ this -> queries_erroneous = 0 ; $ this -> sentences_executed = 0 ; $ this -> sentences_erroneous = 0 ; $ this -> inserts_executed = 0 ; $ this -> inserts_erroneous = 0 ; $ this -> updates_executed = 0 ; $ this -> updates_erroneous = 0 ; $ this -> deletes_executed = 0 ; $ this -> deletes_erroneous = 0 ; }
Reset all stats .
21,292
public function enqueueStatement ( CNabuDBAbstractStatement $ statement ) { if ( $ statement instanceof CMySQLStatement ) { $ hash = $ statement -> getHash ( ) ; if ( ! is_array ( $ this -> statements ) || count ( $ this -> statements ) === 0 ) { $ this -> statements = array ( $ hash => $ statement ) ; } else { $ this -> statements [ $ hash ] = $ statement ; } } }
Equeues a statement in the stack to control it .
21,293
public function dequeueStatement ( CNabuDBAbstractStatement $ statement ) { if ( $ statement instanceof CMySQLStatement ) { $ hash = $ statement -> getHash ( ) ; if ( $ hash !== null && count ( $ this -> statements ) > 0 && array_key_exists ( $ hash , $ this -> statements ) ) { unset ( $ this -> statements [ $ hash ] ) ; } } }
Dequeues a statement .
21,294
private function clearLeadingAndTrailingSpaces ( string $ sentence ) : string { if ( $ this -> trailing_optimization ) { $ sentence = preg_replace ( '/^\\s+/' , '' , $ sentence ) ; $ sentence = preg_replace ( '/\\s+$/' , '' , $ sentence ) ; $ sentence = preg_replace ( '/\\s*\\n\\s*/' , ' ' , $ sentence ) ; } return $ sentence ; }
Clean all leading and trailing spaces in a sentence . To prevent to alter literals in the sentence this method could to be called before apply variable values .
21,295
public function initializeLdap ( ) { $ this -> initialize ( ) ; $ ldapSettings = $ this -> _passwordAuthenticationPlatformSettings ; if ( ! ( array_key_exists ( 'ldap_account_suffix' , $ ldapSettings ) ) || ! ( array_key_exists ( 'ad_password' , $ ldapSettings ) ) || ! ( array_key_exists ( 'ad_username' , $ ldapSettings ) ) || ! ( array_key_exists ( 'base_dn' , $ ldapSettings ) ) || ! ( array_key_exists ( 'cn_identifier' , $ ldapSettings ) ) || ! ( array_key_exists ( 'domain_controllers' , $ ldapSettings ) ) || ! ( array_key_exists ( 'group_attribute' , $ ldapSettings ) ) || ! ( array_key_exists ( 'group_cn_identifier' , $ ldapSettings ) ) || ! ( array_key_exists ( 'ldap_server_type' , $ ldapSettings ) ) || ! ( array_key_exists ( 'network_timeout' , $ ldapSettings ) ) || ! ( array_key_exists ( 'port' , $ ldapSettings ) ) || ! ( array_key_exists ( 'recursive_groups' , $ ldapSettings ) ) || ! ( array_key_exists ( 'time_limit' , $ ldapSettings ) ) || ! ( array_key_exists ( 'use_ssl' , $ ldapSettings ) ) || ! ( array_key_exists ( 'cache_support' , $ ldapSettings ) ) || ! ( array_key_exists ( 'cache_folder' , $ ldapSettings ) ) || ! ( array_key_exists ( 'expired_password_valid' , $ ldapSettings ) ) ) { throw new UserCredentialException ( "The LDAP feature of the usercredential login service is not initialized with all parameters" , 2000 ) ; } $ this -> _passwordAuthenticationPlatformSettings = $ ldapSettings ; $ this -> initializeLdapAuthenticationHandler ( ) ; }
Check that the initialization parameters array for LDAP authentication is enriched with the required keys
21,296
protected function initializeLdapAuthenticationHandler ( ) { $ ldapSettings = $ this -> _passwordAuthenticationPlatformSettings ; $ ldapAuthenticationHandler = new MultiotpWrapper ( ) ; $ ldapAuthenticationHandler -> SetLdapServerPassword ( $ this -> getCurrentPassword ( ) ) ; $ ldapAuthenticationHandler -> SetLdapBindDn ( $ this -> getCurrentUsername ( ) ) ; $ ldapAuthenticationHandler -> SetLdapAccountSuffix ( $ ldapSettings [ 'ldap_account_suffix' ] ) ; $ ldapAuthenticationHandler -> SetLdapBaseDn ( $ ldapSettings [ 'base_dn' ] ) ; $ ldapAuthenticationHandler -> SetLdapCnIdentifier ( $ ldapSettings [ 'cn_identifier' ] ) ; $ ldapAuthenticationHandler -> SetLdapDomainControllers ( $ ldapSettings [ 'domain_controllers' ] ) ; $ ldapAuthenticationHandler -> SetLdapGroupAttribute ( $ ldapSettings [ 'group_attribute' ] ) ; $ ldapAuthenticationHandler -> SetLdapGroupCnIdentifier ( $ ldapSettings [ 'group_cn_identifier' ] ) ; $ ldapAuthenticationHandler -> SetLdapServerType ( $ ldapSettings [ 'ldap_server_type' ] ) ; $ ldapAuthenticationHandler -> SetLdapNetworkTimeout ( $ ldapSettings [ 'network_timeout' ] ) ; $ ldapAuthenticationHandler -> SetLdapPort ( $ ldapSettings [ 'port' ] ) ; $ ldapAuthenticationHandler -> SetLdapRecursiveGroups ( $ ldapSettings [ 'recursive_groups' ] ) ; $ ldapAuthenticationHandler -> SetLdapTimeLimit ( $ ldapSettings [ 'time_limit' ] ) ; $ ldapAuthenticationHandler -> SetLdapSsl ( $ ldapSettings [ 'use_ssl' ] ) ; $ ldapAuthenticationHandler -> SetLdapCacheOn ( $ ldapSettings [ 'cache_support' ] ) ; $ ldapAuthenticationHandler -> SetLdapCacheFolder ( $ ldapSettings [ 'cache_folder' ] ) ; $ ldapAuthenticationHandler -> SetLdapExpiredPasswordValid ( $ ldapSettings [ 'expired_password_valid' ] ) ; $ this -> ldapAuthenticationHandler = $ ldapAuthenticationHandler ; }
Instantiate the LDAP handler and inject appropriate settings into it
21,297
public function execute ( \ Magento \ Framework \ Event \ Observer $ observer ) { if ( ! $ this -> redirect -> isAllowed ( ) ) { $ this -> session -> unsetScript ( ) ; return ; } foreach ( $ this -> getRedirects ( ) as $ redirect ) { $ redirect -> run ( ) ; } }
Runs the redirect list
21,298
private function getRedirects ( ) { $ httpWithJsBackup = [ $ this -> httpRedirect , $ this -> jsRedirect ] ; return $ this -> redirect -> isTypeJavaScript ( ) ? [ $ this -> jsRedirect ] : $ httpWithJsBackup ; }
By default will run HTTP redirect with JS fallback if HTTP does not work . If JS is set as the main redirect it will just run the JS redirect
21,299
protected function getStatement ( Query $ queryObject ) { $ queryParts = $ queryObject -> getQueryParts ( ) ; $ tupleInformaton = null ; $ tupleType = null ; if ( true === isset ( $ queryParts [ 'triple_pattern' ] ) ) { $ tupleInformation = $ queryParts [ 'triple_pattern' ] ; $ tupleType = 'triple' ; } elseif ( true === isset ( $ queryParts [ 'quad_pattern' ] ) ) { $ tupleInformation = $ queryParts [ 'quad_pattern' ] ; $ tupleType = 'quad' ; } else { throw new \ Exception ( 'Neither triple nor quad information available in given query object: ' . $ queryObject -> getQuery ( ) ) ; } if ( 1 > count ( $ tupleInformation ) ) { throw new \ Exception ( 'Query contains more than one triple- respectivly quad pattern.' ) ; } if ( 'triple' == $ tupleType ) { $ subject = $ this -> createNodeByValueAndType ( $ tupleInformation [ 0 ] [ 's' ] , $ tupleInformation [ 0 ] [ 's_type' ] ) ; $ predicate = $ this -> createNodeByValueAndType ( $ tupleInformation [ 0 ] [ 'p' ] , $ tupleInformation [ 0 ] [ 'p_type' ] ) ; $ object = $ this -> createNodeByValueAndType ( $ tupleInformation [ 0 ] [ 'o' ] , $ tupleInformation [ 0 ] [ 'o_type' ] ) ; $ graph = null ; } elseif ( 'quad' == $ tupleType ) { $ subject = $ this -> createNodeByValueAndType ( $ tupleInformation [ 0 ] [ 's' ] , $ tupleInformation [ 0 ] [ 's_type' ] ) ; $ predicate = $ this -> createNodeByValueAndType ( $ tupleInformation [ 0 ] [ 'p' ] , $ tupleInformation [ 0 ] [ 'p_type' ] ) ; $ object = $ this -> createNodeByValueAndType ( $ tupleInformation [ 0 ] [ 'o' ] , $ tupleInformation [ 0 ] [ 'o_type' ] ) ; $ graph = $ this -> createNodeByValueAndType ( $ tupleInformation [ 0 ] [ 'g' ] , 'uri' ) ; } return $ this -> statementFactory -> createStatement ( $ subject , $ predicate , $ object , $ graph ) ; }
Create Statement instance based on a given Query instance .