idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
21,300
protected function getStatements ( Query $ queryObject ) { $ queryParts = $ queryObject -> getQueryParts ( ) ; $ statementArray = [ ] ; if ( true === isset ( $ queryParts [ 'triple_pattern' ] ) && false === isset ( $ queryParts [ 'quad_pattern' ] ) ) { foreach ( $ queryParts [ 'triple_pattern' ] as $ pattern ) { $ s = $ this -> createNodeByValueAndType ( $ pattern [ 's' ] , $ pattern [ 's_type' ] ) ; $ p = $ this -> createNodeByValueAndType ( $ pattern [ 'p' ] , $ pattern [ 'p_type' ] ) ; $ o = $ this -> createNodeByValueAndType ( $ pattern [ 'o' ] , $ pattern [ 'o_type' ] ) ; $ g = null ; $ statementArray [ ] = $ this -> statementFactory -> createStatement ( $ s , $ p , $ o , $ g ) ; } } elseif ( false === isset ( $ queryParts [ 'triple_pattern' ] ) && true === isset ( $ queryParts [ 'quad_pattern' ] ) ) { foreach ( $ queryParts [ 'quad_pattern' ] as $ pattern ) { $ s = $ this -> createNodeByValueAndType ( $ pattern [ 's' ] , $ pattern [ 's_type' ] ) ; $ p = $ this -> createNodeByValueAndType ( $ pattern [ 'p' ] , $ pattern [ 'p_type' ] ) ; $ o = $ this -> createNodeByValueAndType ( $ pattern [ 'o' ] , $ pattern [ 'o_type' ] ) ; $ g = $ this -> createNodeByValueAndType ( $ pattern [ 'g' ] , $ pattern [ 'g_type' ] ) ; $ statementArray [ ] = $ this -> statementFactory -> createStatement ( $ s , $ p , $ o , $ g ) ; } } elseif ( true === isset ( $ queryParts [ 'triple_pattern' ] ) && true === isset ( $ queryParts [ 'quad_pattern' ] ) ) { throw new \ Exception ( 'Query contains quads and triples. That is not supported yet.' ) ; } else { throw new \ Exception ( 'Query contains neither quads nor triples.' ) ; } return $ this -> statementIteratorFactory -> createStatementIteratorFromArray ( $ statementArray ) ; }
Create statements from query .
21,301
public function create ( $ type , array $ properties = [ ] ) { if ( $ type instanceof ValidatorInterface && ! $ properties ) { return $ type ; } if ( $ type instanceof ValidatorInterface ) { $ type = get_class ( $ type ) ; } if ( ! is_string ( $ type ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Validator identifier must be in a string, %s given.' , gettype ( $ type ) ) ) ; } if ( is_subclass_of ( $ type , ValidatorInterface :: class , TRUE ) ) { return new $ type ( $ properties ) ; } if ( is_subclass_of ( __NAMESPACE__ . '\\' . $ type , ValidatorInterface :: class , TRUE ) ) { $ class = __NAMESPACE__ . '\\' . $ type ; return new $ class ( $ properties ) ; } $ type = trim ( $ type ) ; $ lower_case_type = strtolower ( $ type ) ; if ( isset ( self :: $ classes_map [ $ lower_case_type ] ) ) { $ class = self :: $ classes_map [ $ lower_case_type ] ; return new $ class ( $ properties ) ; } $ alt_types [ ] = strtolower ( preg_replace ( [ '/([a-z\d])([A-Z])/' , '/([^_])([A-Z][a-z])/' ] , '$1_$2' , $ type ) ) ; $ alt_types [ ] = preg_replace ( '/[^a-z]+/' , '_' , $ lower_case_type ) ; foreach ( $ alt_types as $ alt_type ) { if ( isset ( self :: $ classes_map [ $ alt_type ] ) ) { $ class = self :: $ classes_map [ $ alt_type ] ; return new $ class ( $ properties ) ; } } throw new Exception \ InvalidArgumentException ( sprintf ( '%s is not an accepted validator identifier for %s.' , $ type , __METHOD__ ) ) ; }
Creates and returns a new validator instance of the given type .
21,302
private function parseNamespace ( $ filePath ) : string { preg_match ( '/namespace(.*);/' , file_get_contents ( $ filePath ) , $ result ) ; return isset ( $ result [ 1 ] ) ? $ result [ 1 ] . "\\" : '' ; }
Parse the given file to find the namespace .
21,303
public static function getServiceProvider ( ) { if ( is_callable ( '_elgg_services' ) ) { return _elgg_services ( ) ; } global $ CONFIG ; if ( ! isset ( $ CONFIG ) ) { $ path = self :: getRootPath ( ) . '/engine/settings.php' ; if ( ! is_file ( $ path ) ) { $ path = self :: getRootPath ( ) . '/elgg-config/settings.php' ; } require_once $ path ; } return new \ Elgg \ Di \ ServiceProvider ( new \ Elgg \ Config ( $ CONFIG ) ) ; }
Returns Elgg ServiceProvider instance
21,304
public static function getElggVersion ( ) { if ( isset ( self :: $ version ) ) { return self :: $ version ; } if ( is_callable ( 'elgg_get_version' ) ) { return elgg_get_version ( true ) ; } else { $ path = self :: getRootPath ( ) . '/version.php' ; if ( ! include ( $ path ) ) { return false ; } self :: $ version = $ release ; return self :: $ version ; } }
Returns Elgg version
21,305
function Parse ( ) { $ this -> parser = xml_parser_create ( ) ; xml_set_object ( $ this -> parser , $ this ) ; xml_set_element_handler ( $ this -> parser , 'StartElement' , 'EndElement' ) ; xml_set_character_data_handler ( $ this -> parser , 'CharacterData' ) ; if ( ! xml_parse ( $ this -> parser , $ this -> xml ) ) $ this -> HandleError ( xml_get_error_code ( $ this -> parser ) , xml_get_current_line_number ( $ this -> parser ) , xml_get_current_column_number ( $ this -> parser ) , xml_get_current_byte_index ( $ this -> parser ) ) ; xml_parser_free ( $ this -> parser ) ; }
Initiates and runs PHP s XML parser
21,306
function HandleError ( $ code , $ line , $ col , $ byte_index = 0 ) { $ sample_size = 80 ; $ sample_start = $ byte_index - ( $ sample_size / 2 ) ; if ( $ sample_start < 0 ) { $ sample_start = 0 ; } trigger_error ( 'XML Parsing Error at ' . $ line . ':' . $ col . ( ( $ byte_index != 0 ) ? ' (byte index: ' . $ byte_index . ')' : '' ) . '. Error ' . $ code . ': ' . xml_error_string ( $ code ) . ' check sample which starts at position ' . $ sample_start . ': html encoded: ' . htmlentities ( substr ( $ this -> xml , $ sample_start , $ sample_size ) ) . ' (hex: ' . bin2hex ( substr ( $ this -> xml , $ sample_start , $ sample_size ) ) . ', raw: ' . ( substr ( $ this -> xml , $ sample_start , $ sample_size ) ) . ')' ) ; }
Handles an XML parsing error
21,307
function StartElement ( $ parser , $ name , $ attrs = array ( ) ) { $ name = strtolower ( $ name ) ; if ( count ( $ this -> stack ) == 0 ) { $ this -> document = new MultiotpXMLTag ( $ name , $ attrs ) ; $ this -> stack = array ( 'document' ) ; } else { $ parent = $ this -> GetStackLocation ( ) ; eval ( '$this->' . $ parent . '->AddChild($name, $attrs, ' . count ( $ this -> stack ) . ', $this->cleanTagNames);' ) ; if ( $ this -> cleanTagNames ) $ name = str_replace ( array ( ':' , '-' ) , '_' , $ name ) ; eval ( '$this->stack[] = $name.\'[\'.(count($this->' . $ parent . '->' . $ name . ') - 1).\']\';' ) ; } }
Handler function for the start of a tag
21,308
function AddChild ( $ name , $ attrs , $ parents , $ cleanTagName = true ) { if ( in_array ( $ name , array ( 'tagChildren' , 'tagAttrs' , 'tagParents' , 'tagData' , 'tagName' ) ) ) { trigger_error ( 'You have used a reserved name as the name of an XML tag. Please consult the documentation (http://www.criticaldevelopment.net/xml/) and rename the tag named "' . $ name . '" to something other than a reserved name.' , E_USER_ERROR ) ; return ; } $ child = new MultiotpXMLTag ( $ name , $ attrs , $ parents ) ; if ( $ cleanTagName ) $ name = str_replace ( array ( ':' , '-' ) , '_' , $ name ) ; elseif ( strstr ( $ name , ':' ) || strstr ( $ name , '-' ) ) trigger_error ( 'Your tag named "' . $ name . '" contains either a dash or a colon. Neither of these characters are friendly with PHP variable names, and, as such, they cannot be accessed and will cause the parser to not work. You must enable the cleanTagName feature (pass true as the second argument of the MultiotpXmlParser constructor). For more details, see http://www.criticaldevelopment.net/xml/' , E_USER_ERROR ) ; if ( ! isset ( $ this -> $ name ) ) $ this -> $ name = array ( ) ; $ this -> { $ name } [ ] = & $ child ; $ this -> tagChildren [ ] = & $ child ; }
Adds a direct child to this object
21,309
function GetXML ( ) { $ out = "\n" . str_repeat ( "\t" , $ this -> tagParents ) . '<' . $ this -> tagName ; foreach ( $ this -> tagAttrs as $ attr => $ value ) $ out .= ' ' . $ attr . '="' . $ value . '"' ; if ( empty ( $ this -> tagChildren ) && empty ( $ this -> tagData ) ) $ out .= " />" ; else { if ( ! empty ( $ this -> tagChildren ) ) { $ out .= '>' ; foreach ( $ this -> tagChildren as $ child ) { if ( is_object ( $ child ) ) $ out .= $ child -> GetXML ( ) ; } $ out .= "\n" . str_repeat ( "\t" , $ this -> tagParents ) ; } elseif ( ! empty ( $ this -> tagData ) ) $ out .= '>' . $ this -> tagData ; $ out .= '</' . $ this -> tagName . '>' ; } return $ out ; }
Returns the string of the XML document which would be generated from this object
21,310
function DeleteChildren ( ) { for ( $ x = 0 ; $ x < count ( $ this -> tagChildren ) ; $ x ++ ) { $ this -> tagChildren [ $ x ] -> DeleteChildren ( ) ; $ this -> tagChildren [ $ x ] = null ; unset ( $ this -> tagChildren [ $ x ] ) ; } }
Removes all of the children of this tag in both name and value
21,311
public function isTypeJavaScript ( ) { $ redirectType = $ this -> coreConfig -> getConfigByPath ( SgCoreInterface :: PATH_REDIRECT_TYPE ) ; return $ redirectType -> getValue ( ) === SgCoreInterface :: VALUE_REDIRECT_JS ; }
Checks if setting for JavaScript type redirect is set in core_config_data table
21,312
public function view ( $ id ) { $ file = LocalFile :: getByIdentifier ( $ id ) ; $ response = response ( $ file -> getContents ( ) , 200 ) -> withHeaders ( [ 'Content-Type' => $ file -> getFile ( ) -> getMimeType ( ) , 'Cache-Control' => 'max-age=86400, public' , 'Expires' => Carbon :: now ( ) -> addSeconds ( 86400 ) -> format ( 'D, d M Y H:i:s \G\M\T' ) ] ) ; return $ response ; }
Attempt to render the specified file .
21,313
public function download ( $ id ) { $ file = LocalFile :: getByIdentifier ( $ id ) ; return response ( ) -> download ( $ file -> getAbsolutePath ( ) , $ file -> getDownloadName ( ) ) ; }
Return a download response for the specified file .
21,314
public function createInstanceByQueryString ( $ query ) { switch ( $ this -> rdfHelpers -> getQueryType ( $ query ) ) { case 'askQuery' : return new AskQueryImpl ( $ query , $ this -> rdfHelpers ) ; case 'constructQuery' : return new ConstructQueryImpl ( $ query , $ this -> rdfHelpers ) ; case 'describeQuery' : return new DescribeQueryImpl ( $ query , $ this -> rdfHelpers ) ; case 'graphQuery' : return new GraphQueryImpl ( $ query , $ this -> rdfHelpers ) ; case 'selectQuery' : return new SelectQueryImpl ( $ query , $ this -> rdfHelpers ) ; case 'updateQuery' : return new UpdateQueryImpl ( $ query , $ this -> rdfHelpers ) ; default : throw new \ Exception ( 'Unknown query type: ' . $ query ) ; } }
Creates an instance of Query based on given query string .
21,315
public function toFullArray ( ) : array { $ result = get_object_vars ( $ this ) ; foreach ( $ result as $ key => $ value ) { if ( preg_match ( '#^_#' , $ key ) === 1 ) { unset ( $ result [ $ key ] ) ; } } return $ result ; }
Since Phalcon 3 they pass model objet throught the toArray function when we call json_encode that can fuck u up if you modify the obj so we need a way to convert it to array without loosing all the extra info we add
21,316
public function getApp ( ) : App { if ( ! is_null ( $ this -> getTemplateEngine ( ) -> getApp ( ) ) ) { return $ this -> getTemplateEngine ( ) -> getApp ( ) ; } else { throw new RuntimeException ( 'Template engine is not initialized with application' ) ; } }
Get application .
21,317
public function filterDateFormat ( $ datetime , string $ pattern = 'dd/MM/yyyy' , string $ locale = null ) : string { if ( empty ( $ locale ) ) { $ locale = $ this -> getApp ( ) -> getProfile ( ) -> getLocale ( ) ; } return b_date_format ( $ datetime , $ pattern , $ locale ) ; }
Filter to format date .
21,318
public function functionPath ( string $ name , array $ parameters = [ ] ) : string { return $ this -> getApp ( ) -> getService ( 'routing' ) -> generate ( $ name , $ parameters ) ; }
Function path to generate path .
21,319
public function functionPreload ( string $ link , array $ parameters = [ ] ) : string { $ push = ! ( ! empty ( $ parameters [ 'nopush' ] ) && $ parameters [ 'nopush' ] == true ) ; if ( ! $ push || ! in_array ( md5 ( $ link ) , $ this -> h2pushCache ) ) { $ header = sprintf ( 'Link: <%s>; rel=preload' , $ link ) ; if ( ! empty ( $ parameters [ 'as' ] ) ) { $ header = sprintf ( '%s; as=%s' , $ header , $ parameters [ 'as' ] ) ; } if ( ! empty ( $ parameters [ 'type' ] ) ) { $ header = sprintf ( '%s; type=%s' , $ header , $ parameters [ 'as' ] ) ; } if ( ! empty ( $ parameters [ 'crossorigin' ] ) && $ parameters [ 'crossorigin' ] == true ) { $ header .= '; crossorigin' ; } if ( ! $ push ) { $ header .= '; nopush' ; } header ( $ header , false ) ; if ( $ push ) { $ this -> h2pushCache [ ] = md5 ( $ link ) ; setcookie ( sprintf ( '%s[%s]' , self :: H2PUSH_CACHE_COOKIE , md5 ( $ link ) ) , 1 , 0 , '/' , '' , false , true ) ; } } return $ link ; }
Function preload to pre loading of request for HTTP 2 protocol .
21,320
private function run ( $ type ) { $ this -> init ( ) ; $ this -> getTarget ( ) ; if ( $ type == 'del' ) { return Asset :: delAsset ( $ this -> name ) ; } $ this -> boot ( ) ; foreach ( $ this -> loop as $ kind => $ contents ) { if ( ! empty ( $ contents ) ) { foreach ( $ contents as $ index => $ content ) { if ( ! $ this -> isPublic ( $ this -> baseDir . $ content ) ) { $ index = $ this -> baseDir . $ content ; $ this -> copy [ $ kind ] [ $ index ] = public_path ( ) . $ this -> target . $ content ; } else { $ this -> target = '' ; } $ this -> destination [ $ kind ] [ ] = $ this -> target . $ content ; } } } if ( ! empty ( $ this -> loop [ 'ignore' ] ) ) { foreach ( $ this -> loop as $ kind => $ contents ) { if ( $ kind != 'ignore' && ! empty ( $ contents ) ) { $ this -> copy [ $ kind ] = array_diff ( $ this -> copy [ $ kind ] , $ this -> copy [ 'ignore' ] ) ; $ this -> destination [ $ kind ] = array_diff ( $ this -> destination [ $ kind ] , $ this -> destination [ 'ignore' ] ) ; } } unset ( $ this -> copy [ 'ignore' ] ) ; unset ( $ this -> destination [ 'ignore' ] ) ; } if ( array_key_exists ( 'include' , $ this -> destination ) ) { unset ( $ this -> destination [ 'include' ] ) ; } $ copyTemp = [ ] ; foreach ( $ this -> copy as $ kind => $ contents ) { foreach ( $ contents as $ from => $ to ) { $ copyTemp [ $ from ] = $ to ; } } $ this -> copy = $ copyTemp ; if ( $ type == 'add' ) { $ result = array_merge ( $ this -> destination , [ 'name' => $ this -> name , 'copy' => $ this -> copy , 'forceCopy' => $ this -> forceCopy , 'chmod' => $ this -> chmod , 'style' => $ this -> style , 'script' => $ this -> script , 'cssOption' => $ this -> cssOption , 'jsOption' => $ this -> jsOption , ] ) ; Asset :: addAsset ( $ result ) ; } self :: $ instance = null ; }
run all the process and give the result to AssetHolder
21,321
private function getTarget ( ) { $ this -> name = str_replace ( 'Asset' , '' , class_basename ( static :: class ) ) ; $ name = $ this -> name ; if ( ! empty ( $ this -> cacheFolder ) ) { $ name = $ this -> cacheFolder ; } $ cacheName = trim ( config ( 'asset.public_cache_folder' ) , '/' ) ; $ this -> target = '/' . $ cacheName . '/' . studly_case ( $ name ) . '/' ; }
return the folder path of the assets in cache folder
21,322
private function getDefaultMethod ( $ price , $ cost = null ) { $ method = $ this -> rateMethodFactory -> create ( ) ; $ method -> setData ( 'carrier' , $ this -> getCarrierCode ( ) ) ; $ method -> setData ( 'carrier_title' , 'Shopgate' ) ; $ method -> setData ( 'method' , $ this -> method ) ; $ method -> setData ( 'method_title' , $ this -> getConfigData ( 'name' ) ) ; $ method -> setData ( 'cost' , $ cost ? : $ price ) ; $ method -> setPrice ( $ price ) ; return $ method ; }
Return the default shopgate payment method
21,323
public function fill ( $ image ) { $ fill = $ this -> getConfig ( 'fill' ) ; $ r = $ fill [ 0 ] ; $ g = $ fill [ 1 ] ; $ b = $ fill [ 2 ] ; $ a = isset ( $ fill [ 3 ] ) ? $ fill [ 3 ] : 127 ; imagefill ( $ image , 0 , 0 , imagecolorallocatealpha ( $ image , $ r , $ g , $ b , $ a ) ) ; return $ image ; }
Fill the background with an RGB color .
21,324
public static function getWeekNumberToApply ( DateTime $ date , DateTime $ startDate , $ weekCount , $ weekOffset = 1 ) { if ( $ weekCount <= 0 || $ weekOffset <= 0 || $ weekCount < $ weekOffset ) { return - 1 ; } $ result = intval ( $ date -> diff ( $ startDate ) -> d / 7 ) ; $ result %= $ weekCount ; $ result += $ weekOffset ; if ( $ weekCount < $ result ) { $ result -= $ weekCount ; } return $ result ; }
Get a week number to apply with a schedule .
21,325
public static function translateWeekday ( $ date , $ locale = "en" ) { $ template = __DIR__ . "/../Resources/translations/messages.%locale%.yml" ; $ filename = str_replace ( "%locale%" , $ locale , $ template ) ; if ( false === file_exists ( $ filename ) ) { $ filename = str_replace ( "%locale%" , "en" , $ template ) ; } $ translations = Yaml :: parse ( file_get_contents ( $ filename ) ) ; return str_ireplace ( array_keys ( $ translations [ "weekdays" ] ) , array_values ( $ translations [ "weekdays" ] ) , $ date ) ; }
Translate the weekday part .
21,326
public function getBacktrace ( $ exception = null ) { $ backtrace = parent :: getBacktrace ( $ exception ) ; foreach ( $ backtrace as $ index => $ backtraceCall ) { $ functionName = $ this -> buildFunctionName ( $ backtraceCall ) ; foreach ( $ this -> filteredFunctions as $ pattern ) { if ( preg_match ( '/' . $ pattern . '/' , $ functionName ) ) { unset ( $ backtrace [ $ index ] ) ; break ; } } } return array_values ( $ backtrace ) ; }
Returns a filtered backtrace using regular expressions
21,327
public function get ( DateTime $ date , DateTime $ reference_date = null ) { if ( is_null ( $ reference_date ) ) { $ reference_date = new DateTime ( ) ; } $ diff = $ reference_date -> diff ( $ date ) ; return $ this -> getText ( $ diff , $ date ) ; }
Get string representation of the date with given translator
21,328
public function getText ( DateInterval $ diff , $ date ) { if ( $ this -> now ( $ diff ) ) { return $ this -> text_translator -> now ( ) ; } if ( $ this -> minutes ( $ diff ) ) { return $ this -> text_translator -> minutes ( $ this -> minutes ( $ diff ) ) ; } if ( $ this -> hours ( $ diff ) ) { return $ this -> text_translator -> hours ( $ this -> hours ( $ diff ) ) ; } if ( $ this -> days ( $ diff ) ) { return $ this -> text_translator -> days ( $ this -> days ( $ diff ) ) ; } if ( $ this -> text_translator -> supportsWeeks ( ) && $ this -> weeks ( $ diff ) ) { return $ this -> text_translator -> weeks ( $ this -> weeks ( $ diff ) ) ; } if ( $ this -> text_translator -> supportsMonths ( ) && $ this -> months ( $ diff ) ) { return $ this -> text_translator -> months ( $ this -> months ( $ diff ) ) ; } if ( $ this -> text_translator -> supportsYears ( ) && $ this -> years ( $ diff ) ) { return $ this -> text_translator -> years ( $ this -> years ( $ diff ) ) ; } return $ date -> format ( $ this -> format ) ; }
Get string related to DateInterval object
21,329
public function daily ( $ diff ) { if ( ( $ diff -> y == 0 ) && ( $ diff -> m == 0 ) && ( ( $ diff -> d == 0 ) || ( ( $ diff -> d == 1 ) && ( $ diff -> h == 0 ) && ( $ diff -> i == 0 ) ) ) ) { return true ; } return false ; }
Is date limit by day
21,330
public function hourly ( $ diff ) { if ( $ this -> daily ( $ diff ) && ( $ diff -> d == 0 ) && ( ( $ diff -> h == 0 ) || ( ( $ diff -> h == 1 ) && ( $ diff -> i == 0 ) ) ) ) { return true ; } return false ; }
Is date limit by hour
21,331
public function days ( DateInterval $ diff ) { if ( $ diff -> days <= $ this -> max_days_count ) { return $ diff -> days ; } return false ; }
Number of days related to the interval or false if more .
21,332
public function weeks ( DateInterval $ diff ) { if ( $ diff -> days < 30 ) { return ( int ) floor ( $ diff -> days / 7 ) ; } return false ; }
Get Number of weeks
21,333
public function months ( DateInterval $ diff ) { if ( $ diff -> days >= 365 ) { return FALSE ; } $ x = ( int ) floor ( $ diff -> days / 30.417 ) ; if ( $ x === 0 ) { return 1 ; } else { return $ x ; } }
Get Number of months
21,334
protected function addClassOption ( $ name , $ value ) { $ value = trim ( $ value ) ; if ( substr ( $ value , 0 , 1 ) == '.' || substr ( $ value , 0 , 1 ) == '#' ) { $ value = substr ( $ value , 1 ) ; } if ( $ value != '' ) { $ this -> addOption ( 'class' , $ name , $ value ) ; } }
Adds class option removes dot and hash .
21,335
protected function addContentOption ( $ name , $ value ) { $ value = trim ( $ value ) ; if ( ! empty ( $ value ) && is_string ( $ value ) ) { $ this -> addOption ( 'content' , $ name , $ value ) ; } }
Adds content option .
21,336
protected function addCookieBoolOption ( $ name , $ value ) { if ( $ value === true || $ value === false ) { $ this -> addOption ( 'cookie' , $ name , $ value ) ; } }
Adds boolean cookie option .
21,337
protected function addCookieIntOption ( $ name , $ value ) { $ value = trim ( $ value ) ; if ( $ value !== null && $ value !== '' && is_numeric ( $ value ) ) { $ this -> addOption ( 'cookie' , $ name , ( int ) $ value ) ; } }
Adds integer cookie option .
21,338
protected function addCookieOption ( $ name , $ value ) { if ( is_string ( $ value ) ) { $ value = preg_replace ( "~^;? ?$name=~" , '' , trim ( $ value ) ) ; if ( $ value !== '' ) { $ this -> addOption ( 'cookie' , $ name , $ value ) ; } } }
Adds cookie option removes ; name = part .
21,339
protected function addParamsOption ( $ name , $ value ) { if ( is_array ( $ value ) && count ( $ value ) ) { $ this -> addOption ( 'content' , $ name , $ value ) ; } }
Adds content parameters option .
21,340
protected function addStyle ( $ what , $ value ) { if ( is_array ( $ value ) && count ( $ value ) ) { $ type = 'inner' ; switch ( $ what ) { case 0 : $ type = 'outer' ; break ; case 2 : $ type = 'button' ; break ; } foreach ( $ value as $ name => $ set ) { if ( ! empty ( $ set ) && is_string ( $ set ) ) { $ this -> { $ type . 'Style' } [ $ name ] = str_replace ( ';' , '' , trim ( $ set ) ) ; } } } }
Adds the CSS styles for selected part .
21,341
protected function checkContent ( ) { if ( is_array ( $ this -> content ) && count ( $ this -> content ) ) { foreach ( $ this -> content as $ name => $ value ) { switch ( $ name ) { case 'category' : case 'mainMessage' : case 'buttonMessage' : case 'language' : $ this -> addContentOption ( $ name , $ value ) ; break ; case 'mainParams' : case 'buttonParams' : $ this -> addParamsOption ( $ name , $ value ) ; break ; } } } }
Validates content parameters .
21,342
protected function checkCookie ( ) { if ( is_array ( $ this -> cookie ) && count ( $ this -> cookie ) ) { foreach ( $ this -> cookie as $ name => $ value ) { switch ( $ name ) { case 'domain' : case 'path' : $ this -> addCookieOption ( $ name , $ value ) ; break ; case 'max-age' : case 'expires' : $ this -> addCookieIntOption ( $ name , $ value ) ; break ; case 'secure' : $ this -> addCookieBoolOption ( $ name , $ value ) ; break ; } } } }
Validates cookie parameters .
21,343
protected function initCookie ( ) { $ cookieOptions = Json :: encode ( array_merge ( $ this -> cookieOptions , [ 'classOuter' => str_replace ( ' ' , '.' , $ this -> classOptions [ 'classOuter' ] ) , 'classInner' => str_replace ( ' ' , '.' , $ this -> classOptions [ 'classInner' ] ) , 'classButton' => str_replace ( ' ' , '.' , $ this -> classOptions [ 'classButton' ] ) , ] ) ) ; $ view = $ this -> getView ( ) ; assets \ CookieMonsterAsset :: register ( $ view ) ; $ view -> registerJs ( "CookieMonster.init($cookieOptions);" ) ; }
Initialises the js file prepares the JSON js options .
21,344
protected function prepareViewParams ( ) { $ outerStyle = [ ] ; $ innerStyle = [ ] ; $ buttonStyle = [ ] ; foreach ( $ this -> outerStyle as $ name => $ value ) { $ outerStyle [ ] = $ name . ':' . $ value ; } foreach ( $ this -> innerStyle as $ name => $ value ) { $ innerStyle [ ] = $ name . ':' . $ value ; } foreach ( $ this -> buttonStyle as $ name => $ value ) { $ buttonStyle [ ] = $ name . ':' . $ value ; } return [ 'content' => $ this -> contentOptions , 'outerHtmlOptions' => array_merge ( $ this -> outerHtml , [ 'style' => implode ( ';' , $ outerStyle ) , 'class' => $ this -> classOptions [ 'classOuter' ] ] ) , 'innerHtmlOptions' => array_merge ( $ this -> innerHtml , [ 'style' => implode ( ';' , $ innerStyle ) , 'class' => $ this -> classOptions [ 'classInner' ] ] ) , 'buttonHtmlOptions' => array_merge ( $ this -> buttonHtml , [ 'style' => implode ( ';' , $ buttonStyle ) , 'class' => $ this -> classOptions [ 'classButton' ] ] ) , 'params' => $ this -> params ] ; }
Prepares the list of parameters to send to the view .
21,345
protected function replaceStyle ( $ what , $ value ) { if ( is_array ( $ value ) && count ( $ value ) ) { $ type = 'inner' ; switch ( $ what ) { case 0 : $ type = 'outer' ; break ; case 2 : $ type = 'button' ; break ; } foreach ( $ value as $ name => $ set ) { if ( isset ( $ this -> { $ type . 'Style' } [ $ name ] ) ) { if ( $ set === false || $ set === null ) { unset ( $ this -> { $ type . 'Style' } [ $ name ] ) ; } else { $ this -> { $ type . 'Style' } [ $ name ] = str_replace ( ';' , '' , trim ( $ set ) ) ; } } } } }
Replaces the CSS styles for selected part .
21,346
protected function setDefaults ( ) { if ( ! isset ( $ this -> contentOptions [ 'category' ] ) || ( isset ( $ this -> contentOptions [ 'category' ] ) && empty ( $ this -> contentOptions [ 'category' ] ) ) ) { $ this -> contentOptions [ 'category' ] = 'app' ; } if ( ! isset ( $ this -> contentOptions [ 'mainParams' ] ) ) { $ this -> contentOptions [ 'mainParams' ] = [ ] ; } if ( ! isset ( $ this -> contentOptions [ 'buttonParams' ] ) ) { $ this -> contentOptions [ 'buttonParams' ] = [ ] ; } if ( ! isset ( $ this -> contentOptions [ 'language' ] ) ) { $ this -> contentOptions [ 'language' ] = null ; } if ( ! isset ( $ this -> contentOptions [ 'mainMessage' ] ) ) { $ this -> contentOptions [ 'mainMessage' ] = 'We use cookies on our websites to help us offer you the best online experience. By continuing to use our website, you are agreeing to our use of cookies. Alternatively, you can manage them in your browser settings.' ; } if ( ! isset ( $ this -> contentOptions [ 'buttonMessage' ] ) ) { $ this -> contentOptions [ 'buttonMessage' ] = 'I understand' ; } if ( ! isset ( $ this -> cookieOptions [ 'path' ] ) ) { $ this -> cookieOptions [ 'path' ] = '/' ; } if ( ! isset ( $ this -> cookieOptions [ 'expires' ] ) ) { $ this -> cookieOptions [ 'expires' ] = 30 ; } if ( ! isset ( $ this -> cookieOptions [ 'secure' ] ) ) { $ this -> cookieOptions [ 'secure' ] = false ; } if ( ! isset ( $ this -> classOptions [ 'classOuter' ] ) ) { $ this -> classOptions [ 'classOuter' ] = 'CookieMonsterBox' ; } if ( ! isset ( $ this -> classOptions [ 'classInner' ] ) ) { $ this -> classOptions [ 'classInner' ] = '' ; } if ( ! isset ( $ this -> classOptions [ 'classButton' ] ) ) { $ this -> classOptions [ 'classButton' ] = 'CookieMonsterOk' ; } }
Sets default values .
21,347
protected function setHtmlOptions ( $ what , $ value ) { if ( is_array ( $ value ) && count ( $ value ) ) { $ type = 'inner' ; switch ( $ what ) { case 0 : $ type = 'outer' ; break ; case 2 : $ type = 'button' ; break ; } foreach ( $ value as $ name => $ set ) { if ( $ name == 'class' || $ name == 'style' ) { continue ; } else { $ this -> { $ type . 'Html' } [ $ name ] = trim ( $ set ) ; } } } }
Sets HTML options for selected part .
21,348
protected function setMode ( ) { $ this -> outerStyle = [ 'display' => 'none' , 'z-index' => 10000 , 'position' => 'fixed' , 'background-color' => '#fff' , 'font-size' => '12px' , 'color' => '#000' ] ; $ this -> innerStyle = [ 'margin' => '10px' ] ; $ this -> buttonStyle = [ 'margin-left' => '10px' ] ; switch ( $ this -> mode ) { case 'bottom' : $ this -> outerStyle = array_merge ( $ this -> outerStyle , [ 'bottom' => 0 , 'left' => 0 , 'width' => '100%' , 'box-shadow' => '0 -2px 2px #000' , ] ) ; break ; case 'box' : $ this -> outerStyle = array_merge ( $ this -> outerStyle , [ 'bottom' => '20px' , 'right' => '20px' , 'width' => '300px' , 'box-shadow' => '-2px 2px 2px #000' , 'border-radius' => '10px' , ] ) ; break ; case 'custom' : $ this -> outerStyle = [ ] ; $ this -> innerStyle = [ ] ; $ this -> buttonStyle = [ ] ; break ; case 'top' : default : $ this -> outerStyle = array_merge ( $ this -> outerStyle , [ 'top' => 0 , 'left' => 0 , 'width' => '100%' , 'box-shadow' => '0 2px 2px #000' , ] ) ; } }
Sets the mode with default CSS styles .
21,349
protected function setCookieView ( $ value ) { $ value = trim ( $ value ) ; if ( ! empty ( $ value ) ) { $ this -> cookieView = $ value ; } }
Sets custom user s view path .
21,350
public function buildFieldReplacement ( array $ field_descriptor , $ alias = false ) { if ( $ alias === false ) { $ alias = $ field_descriptor [ 'name' ] ; } switch ( $ field_descriptor [ 'data_type' ] ) { case 'int' : $ retval = "%d$alias\$d" ; break ; case 'float' : case 'double' : $ retval = "%F$alias\$d" ; break ; case 'varchar' : case 'text' : case 'longtext' : case 'enum' : case 'set' : case 'tinytext' : $ retval = "'%s$alias\$s'" ; break ; default : $ retval = false ; } return $ retval ; }
Builds a well formed replacement string for a field value .
21,351
public function buildFieldValue ( $ field_descriptor , $ value ) { if ( $ value === null ) { $ retval = 'NULL' ; } elseif ( $ value === false ) { $ retval = 'false' ; } elseif ( $ value === true ) { $ retval = 'true' ; } else { if ( ! is_array ( $ value ) ) { $ value = array ( $ value ) ; } switch ( $ field_descriptor [ 'data_type' ] ) { case 'int' : $ retval = $ this -> nb_connector -> buildSentence ( '%d' , $ value ) ; break ; case 'float' : case 'double' : $ retval = $ this -> nb_connector -> buildSentence ( '%F' , $ value ) ; break ; case 'varchar' : case 'text' : case 'longtext' : case 'enum' : case 'set' : case 'tinytext' : $ retval = $ this -> nb_connector -> buildSentence ( "'%s'" , $ value ) ; break ; case 'date' : case 'datetime' : if ( $ field_descriptor [ 'name' ] !== $ this -> storage_descriptor [ 'name' ] . '_creation_datetime' ) { if ( $ value === null ) { $ retval = 'null' ; } else { $ retval = $ this -> nb_connector -> buildSentence ( "'%s'" , $ value ) ; } } else { $ retval = false ; } break ; default : error_log ( $ field_descriptor [ 'data_type' ] ) ; throw new ENabuCoreException ( ENabuCoreException :: ERROR_FEATURE_NOT_IMPLEMENTED ) ; } } return $ retval ; }
Builds a well formed string for a field value containing their value represented in MySQL SQL syntax . This method prevents SQL Injection .
21,352
public function signParams ( $ method , $ path , array $ params = array ( ) ) { $ params = $ this -> completeParams ( $ params ) ; $ params [ 'signature' ] = $ this -> signature ( $ method , $ path , $ params ) ; return $ params ; }
Generates the signature for a given set of request parameters and add this signature to the set of parameters .
21,353
public function signature ( $ method , $ path , array $ params = array ( ) ) { $ params = $ this -> completeParams ( $ params ) ; ksort ( $ params ) ; if ( isset ( $ params [ 'file' ] ) ) { unset ( $ params [ 'file' ] ) ; } $ canonicalQueryString = str_replace ( array ( '+' , '%5B' , '%5D' ) , array ( '%20' , '[' , ']' ) , http_build_query ( $ params , '' , '&' ) ) ; $ stringToSign = sprintf ( "%s\n%s\n%s\n%s" , strtoupper ( $ method ) , $ this -> account -> getApiHost ( ) , $ path , $ canonicalQueryString ) ; $ hmac = hash_hmac ( 'sha256' , $ stringToSign , $ this -> account -> getSecretKey ( ) , true ) ; return base64_encode ( $ hmac ) ; }
Generates the signature for an API requests based on its parameters .
21,354
public static function getInstance ( $ cloudId , Account $ account ) { $ signer = new PandaSigner ( ) ; $ signer -> setCloudId ( $ cloudId ) ; $ signer -> setAccount ( $ account ) ; return $ signer ; }
Returns a Signing instance for a Cloud .
21,355
public function getItems ( ) { $ batch = $ this -> getBatch ( ) ; $ items = array ( ) ; foreach ( $ batch as $ b ) { $ items [ ] = $ b ; } return $ items ; }
Returns an array of items in the batch
21,356
public function export ( array $ params = array ( ) ) { $ result = array ( 'type' => 'list' , 'count' => $ this -> getCount ( ) , 'limit' => elgg_extract ( 'limit' , $ this -> options , elgg_get_config ( 'default_limit' ) ) , 'offset' => elgg_extract ( 'offset' , $ this -> options , 0 ) , 'items' => array ( ) , ) ; $ batch = $ this -> getBatch ( ) ; foreach ( $ batch as $ entity ) { $ result [ 'items' ] [ ] = hypeApps ( ) -> graph -> export ( $ entity , $ params ) ; } return $ result ; }
Export batch into an array
21,357
protected function prepareBatchOptions ( array $ options = array ( ) ) { if ( ! in_array ( $ this -> getter , array ( 'elgg_get_entities' , 'elgg_get_entities_from_metadata' , 'elgg_get_entities_from_relationship' , ) ) ) { return $ options ; } $ sort = elgg_extract ( 'sort' , $ options ) ; unset ( $ options [ 'sort' ] ) ; if ( ! is_array ( $ sort ) ) { return $ options ; } $ dbprefix = elgg_get_config ( 'dbprefix' ) ; $ order_by = array ( ) ; foreach ( $ sort as $ field => $ direction ) { $ field = sanitize_string ( $ field ) ; $ direction = strtoupper ( sanitize_string ( $ direction ) ) ; if ( ! in_array ( $ direction , array ( 'ASC' , 'DESC' ) ) ) { $ direction = 'ASC' ; } switch ( $ field ) { case 'alpha' : if ( elgg_extract ( 'types' , $ options ) == 'user' ) { $ options [ 'joins' ] [ 'ue' ] = "JOIN {$dbprefix}users_entity ue ON ue.guid = e.guid" ; $ order_by [ ] = "ue.name {$direction}" ; } else if ( elgg_extract ( 'types' , $ options ) == 'group' ) { $ options [ 'joins' ] [ 'ge' ] = "JOIN {$dbprefix}groups_entity ge ON ge.guid = e.guid" ; $ order_by [ ] = "ge.name {$direction}" ; } else if ( elgg_extract ( 'types' , $ options ) == 'object' ) { $ options [ 'joins' ] [ 'oe' ] = "JOIN {$dbprefix}objects_entity oe ON oe.guid = e.guid" ; $ order_by [ ] = "oe.title {$direction}" ; } break ; case 'type' : case 'subtype' : case 'guid' : case 'owner_guid' : case 'container_guid' : case 'site_guid' : case 'enabled' : case 'time_created' ; case 'time_updated' : case 'last_action' : case 'access_id' : $ order_by [ ] = "e.{$field} {$direction}" ; break ; } } $ options [ 'order_by' ] = implode ( ',' , $ order_by ) ; return $ options ; }
Prepares batch options
21,358
public function castItemValueToProperType ( $ value ) { $ normalized = $ value ; if ( in_array ( $ value , [ 'true' , 'on' , 'yes' ] ) ) { $ normalized = true ; } elseif ( in_array ( $ value , [ 'false' , 'off' , 'no' , 'none' ] ) ) { $ normalized = false ; } elseif ( 'null' == $ value ) { $ normalized = null ; } elseif ( is_numeric ( $ value ) ) { $ number = $ value + 0 ; if ( intval ( $ number ) == $ number ) { $ normalized = ( int ) $ number ; } elseif ( floatval ( $ number ) == $ number ) { $ normalized = ( float ) $ number ; } } elseif ( is_array ( $ value ) ) { foreach ( $ value as $ itemKey => $ itemValue ) { $ normalized [ $ itemKey ] = $ this -> castItemValueToProperType ( $ itemValue ) ; } } return $ normalized ; }
Cast item string value to proper type
21,359
public static function createFromReflection ( \ ReflectionMethod $ reflectionMethod , string $ basePath = '' ) { $ routes = [ ] ; if ( is_a ( $ reflectionMethod -> class , '\Berlioz\Core\Controller\Controller' , true ) ) { try { if ( $ reflectionMethod -> isPublic ( ) ) { if ( $ methodDoc = $ reflectionMethod -> getDocComment ( ) ) { $ docBlock = Router :: getDocBlockFactory ( ) -> create ( $ methodDoc ) ; if ( $ docBlock -> hasTag ( 'route' ) ) { foreach ( $ docBlock -> getTagsByName ( 'route' ) as $ tag ) { $ route = new Route ; $ route -> setRouteDeclaration ( $ tag -> getDescription ( ) -> render ( ) , $ basePath ) ; $ route -> setSummary ( $ docBlock -> getSummary ( ) ) ; $ route -> setDescription ( $ docBlock -> getDescription ( ) -> render ( ) ) ; $ route -> setInvoke ( $ reflectionMethod -> class , $ reflectionMethod -> getName ( ) ) ; $ route -> getRouteRegex ( ) ; $ routes [ ] = $ route ; } } } } else { throw new BerliozException ( 'Must be public' ) ; } } catch ( BerliozException $ e ) { throw new BerliozException ( sprintf ( 'Method "%s::%s" route error: %s' , $ reflectionMethod -> class , $ reflectionMethod -> getName ( ) , $ e -> getMessage ( ) ) ) ; } } else { throw new BerliozException ( sprintf ( 'Class "%s" must be a sub class of "\Berlioz\Core\Controller\Controller"' , $ reflectionMethod -> class ) ) ; } return $ routes ; }
Create Route from \ ReflectionMethod object .
21,360
private function filterParameters ( array $ params ) : array { return array_filter ( $ params , function ( & $ value ) { if ( is_array ( $ value ) ) { $ value = $ this -> filterParameters ( $ value ) ; return count ( $ value ) > 0 ; } else { return ! is_null ( $ value ) ; } } ) ; }
Filter parameters and remove null parameters .
21,361
private function as_string ( $ value ) { if ( is_object ( $ value ) && method_exists ( $ value , '__toString' ) ) { $ value = ( string ) $ value ; } if ( is_string ( $ value ) ) { return $ value ; } elseif ( is_null ( $ value ) ) { return 'NULL' ; } elseif ( is_bool ( $ value ) ) { return $ value ? '(boolean) TRUE' : '(boolean) FALSE' ; } if ( is_object ( $ value ) ) { $ value = get_class ( $ value ) ; $ type = '(object) ' ; } elseif ( is_array ( $ value ) ) { $ type = '' ; $ value = var_export ( $ value , TRUE ) ; } isset ( $ type ) or $ type = '(' . gettype ( $ value ) . ') ' ; return $ type . ( string ) $ value ; }
Returns a string representation of any value .
21,362
public function createNodeInstanceFromNodeParameter ( $ value , $ type , $ datatype = null , $ language = null ) { switch ( $ type ) { case 'uri' : return $ this -> createNamedNode ( $ value ) ; case 'bnode' : return $ this -> createBlankNode ( $ value ) ; case 'literal' : return $ this -> createLiteral ( $ value , $ datatype , $ language ) ; case 'typed-literal' : return $ this -> createLiteral ( $ value , $ datatype , $ language ) ; case 'var' : return $ this -> createAnyPattern ( ) ; default : throw new \ Exception ( 'Unknown $type given: ' . $ type ) ; } }
Helper function which is useful if you have all the meta information about a Node and want to create the according Node instance .
21,363
private function methodLoader ( $ methods ) { foreach ( $ methods as $ key => $ param ) { if ( is_array ( $ param ) ) { $ methods [ $ key ] = $ this -> methodLoader ( $ this -> getExportParams ( $ key ) ) ; continue ; } $ method = 'get' . SimpleDataObjectConverter :: snakeCaseToUpperCamelCase ( $ param ) ; if ( method_exists ( $ this , $ method ) ) { $ methods [ $ param ] = $ this -> { $ method } ( ) ; unset ( $ methods [ $ key ] ) ; } } return $ methods ; }
Traverses method array and calls the functions of this class
21,364
private function getExportParams ( $ key = null ) { if ( $ key && isset ( $ this -> exportParams [ $ key ] ) ) { return $ this -> exportParams [ $ key ] ; } return $ this -> exportParams ; }
Retrieves all parameters if no key is specified
21,365
public function setPaths ( $ paths ) { $ this -> paths = $ paths ; self :: $ pathsMap [ $ this -> namespace ] = $ this -> paths ; }
Set paths .
21,366
protected function _toHtml ( ) { if ( ! $ this -> getOptions ( ) ) { $ cmsPages = $ this -> cmsPageCollection -> addStoreFilter ( $ this -> getStoreFromContext ( ) ) ; foreach ( $ cmsPages as $ cmsPage ) { $ this -> addOption ( $ cmsPage -> getId ( ) , $ cmsPage -> getTitle ( ) ) ; } } return parent :: _toHtml ( ) ; }
Retrieves all the pages that are allowed to be viewed in the current context
21,367
public function getStoreFromContext ( ) { $ params = $ this -> getRequest ( ) -> getParams ( ) ; if ( isset ( $ params [ 'store' ] ) ) { return [ $ params [ 'store' ] ] ; } elseif ( isset ( $ params [ 'website' ] ) ) { $ website = $ this -> storeManager -> getWebsite ( $ params [ 'website' ] ) ; return $ website -> getStoreIds ( ) ; } return array_keys ( $ this -> storeManager -> getStores ( ) ) ; }
Retrieves the stores that are allowed in the context E . g . Store X will just return itself E . g . Website Y will return an array of all stores under it E . g . Default will return all store ids
21,368
private function _initializeProfile ( $ userProfile ) { die ( print_r ( $ userProfile ) ) ; if ( ! is_array ( $ userProfile ) || ! isset ( $ userProfile [ 'username' ] ) || ! isset ( $ userProfile [ 'password' ] ) || ! isset ( $ userProfile [ 'fullname' ] ) || ! isset ( $ userProfile [ 'passhash' ] ) || ! is_string ( $ userProfile [ 'passhash' ] ) || ! isset ( $ userProfile [ 'passhist' ] ) || ! is_array ( $ userProfile [ 'passhist' ] ) || ! isset ( $ userProfile [ 'account_state' ] ) || ! isset ( $ userProfile [ 'policyinfo' ] ) || ! is_array ( $ userProfile [ 'policyinfo' ] ) || ! is_array ( $ userProfile [ 'platforminfo' ] ) ) { throw new UserCredentialException ( 'The user profile is not properly initialized' , 1000 ) ; } if ( array_key_exists ( 'tenancy_expiry' , $ userProfile [ 'policyinfo' ] ) ) { $ tenancyExpiry = $ userProfile [ 'policyinfo' ] [ 'tenancy_expiry' ] ; if ( ( $ tenancyExpiry instanceof \ DateTime ) === false ) { throw new UserCredentialException ( 'The user profile is not properly initialized' , 1000 ) ; } } if ( ! isset ( $ userProfile [ 'totpinfo' ] ) ) { $ userProfile [ 'totpinfo' ] = array ( ) ; } $ this -> _userProfile = $ userProfile ; }
initializes the user profiles data as per the user credentials provided to the constructor method
21,369
final protected function _validateConsecutiveCharacterRepeat ( ) { if ( ! isset ( $ this -> _userProfile [ 'username' ] ) || ! isset ( $ this -> _userProfile [ 'password' ] ) || ! isset ( $ this -> _userProfile [ 'fullname' ] ) || ! isset ( $ this -> _userProfile [ 'passhist' ] ) ) { throw new UserCredentialException ( 'The username and password are not set' , 1016 ) ; } $ entropyObj = $ this -> _udfEntropySetting ; $ maxConsecutiveChars = ( int ) ( $ entropyObj [ 'max_consecutive_chars' ] ) ; if ( ! ( $ maxConsecutiveChars >= 2 ) ) { $ maxConsecutiveChars = 2 ; } $ maxConsecutiveCharsRegexOffset = ++ $ maxConsecutiveChars - 2 ; $ maxConsecutiveCharsRegex = '/' . $ this -> _regexBuildPattern ( 5 , $ maxConsecutiveCharsRegexOffset ) . '/' ; $ testVal = preg_match ( $ maxConsecutiveCharsRegex , $ this -> _userProfile [ 'password' ] ) ; if ( $ testVal === false ) { throw new UserCredentialException ( 'A fatal error occured in the password validation' , 1018 ) ; } elseif ( $ testVal == true ) { throw new UserCredentialException ( 'The password violates policy about consecutive character repetitions. ' . $ this -> _getPasswordCharacterRepeatDescription ( ) , \ USERCREDENTIAL_ACCOUNTPOLICY_WEAKPASSWD ) ; } else { } $ maxConsecutiveCharsSameClass = ( int ) ( $ entropyObj [ 'max_consecutive_chars_of_same_class' ] ) ; if ( ! ( $ maxConsecutiveCharsSameClass >= 2 ) ) { $ maxConsecutiveCharsSameClass = 2 ; } $ maxConsecutiveCharsSameClassRegexOffset = ++ $ maxConsecutiveCharsSameClass ; $ maxConsecutiveCharsSameClassRegex = '/' . $ this -> _regexBuildPattern ( 6 , $ maxConsecutiveCharsSameClassRegexOffset ) . '/' ; $ testValSameClass = preg_match ( $ maxConsecutiveCharsSameClassRegex , $ this -> _userProfile [ 'password' ] ) ; if ( $ testValSameClass === false ) { throw new UserCredentialException ( 'A fatal error occured in the password validation' , 1018 ) ; } elseif ( $ testValSameClass == true ) { throw new UserCredentialException ( 'The password violates policy about consecutive repetition of characters of the same class. ' . $ this -> _getPasswordCharacterClassRepeatDescription ( ) , \ USERCREDENTIAL_ACCOUNTPOLICY_WEAKPASSWD ) ; } else { return true ; } return true ; }
validate that there are no instances of consecutive character repetitions beyond allowed number in the users password string
21,370
final protected function _validatePolicy ( ) { if ( ! isset ( $ this -> _userProfile [ 'username' ] ) || ! isset ( $ this -> _userProfile [ 'password' ] ) || ! isset ( $ this -> _userProfile [ 'fullname' ] ) || ! isset ( $ this -> _userProfile [ 'passhist' ] ) ) { throw new UserCredentialException ( 'The username and password are not set' , 1016 ) ; } $ policyObj = $ this -> _udfPasswordPolicy ; if ( $ this -> _userProfile [ 'account_state' ] == \ USERCREDENTIAL_ACCOUNTSTATE_AUTHFAILED ) { if ( $ this -> _userProfile [ 'policyinfo' ] [ 'failed_attempt_count' ] > $ policyObj [ 'illegal_attempts_limit' ] ) { throw new UserCredentialException ( 'The account has exceeded login attempts and is locked. Contact admin' , \ USERCREDENTIAL_ACCOUNTPOLICY_ATTEMPTLIMIT2 ) ; } elseif ( $ this -> _userProfile [ 'policyinfo' ] [ 'failed_attempt_count' ] == $ policyObj [ 'illegal_attempts_limit' ] ) { throw new UserCredentialException ( 'The account has failed login ' . ( ++ $ policyObj [ 'illegal_attempts_limit' ] ) . ' times in a row and is temporarily locked. Any further wrong passwords will lead to your account being locked fully. You will be automatically unlocked in ' . ( ( $ policyObj [ 'illegal_attempts_penalty_seconds' ] ) / 60 ) . ' minutes or contact admin to unlock immediately' , \ USERCREDENTIAL_ACCOUNTPOLICY_ATTEMPTLIMIT1 ) ; } else { throw new UserCredentialException ( 'Login failed. Wrong username or password' , \ USERCREDENTIAL_ACCOUNTPOLICY_VALID ) ; } } $ currDateTimeObj = new \ DateTime ( ) ; $ passChangeDaysElapsedObj = $ currDateTimeObj -> diff ( $ this -> _userProfile [ 'policyinfo' ] [ 'password_last_changed_datetime' ] ) ; $ passChangeDaysElapsed = $ passChangeDaysElapsedObj -> format ( '%a' ) ; if ( $ passChangeDaysElapsed > $ policyObj [ 'password_reset_frequency' ] ) { throw new UserCredentialException ( 'The password has expired and must be changed' , \ USERCREDENTIAL_ACCOUNTPOLICY_EXPIRED ) ; } return true ; }
validate the password policy during authentication
21,371
final protected function _validatePolicyAtChange ( ) { if ( ! isset ( $ this -> _userProfile [ 'username' ] ) || ! isset ( $ this -> _userProfile [ 'password' ] ) || ! isset ( $ this -> _userProfile [ 'fullname' ] ) || ! isset ( $ this -> _userProfile [ 'passhist' ] ) ) { throw new UserCredentialException ( 'The username and password are not set' , 1016 ) ; } $ policyObj = $ this -> _udfPasswordPolicy ; $ passHistory = $ this -> _userProfile [ 'passhist' ] ; $ passHistoryRequired = array_slice ( $ passHistory , 0 , ( ( int ) $ policyObj [ 'password_repeat_minimum' ] ) ) ; foreach ( $ passHistoryRequired as $ passHistoryItem ) { if ( password_verify ( $ this -> _userProfile [ 'password' ] , $ passHistoryItem ) ) { throw new UserCredentialException ( 'User cannot repeat any of their ' . $ policyObj [ 'password_repeat_minimum' ] . ' last passwords' , \ USERCREDENTIAL_ACCOUNTPOLICY_REPEATERROR ) ; } } return true ; }
validate the password policy during process of making a password change
21,372
final protected function _canChangePassword ( ) { if ( ! isset ( $ this -> _userProfile [ 'username' ] ) || ! isset ( $ this -> _userProfile [ 'password' ] ) || ! isset ( $ this -> _userProfile [ 'fullname' ] ) || ! isset ( $ this -> _userProfile [ 'passhist' ] ) ) { throw new UserCredentialException ( 'The username and password are not set' , 1016 ) ; } $ currDateTimeObj = new \ DateTime ( ) ; if ( $ currDateTimeObj <= $ this -> _userProfile [ 'policyinfo' ] [ 'password_last_changed_datetime' ] ) { return false ; } else { return true ; } }
Check that a user can change password in case you want to implement limits on changing passwords only once in 24 hours
21,373
final protected function _validateTenancy ( ) { $ userProfile = $ this -> _userProfile ; $ currDateTimeObj = new \ DateTime ( ) ; if ( array_key_exists ( 'tenancy_expiry' , $ userProfile [ 'policyinfo' ] ) ) { $ tenancyExpiry = $ userProfile [ 'policyinfo' ] [ 'tenancy_expiry' ] ; if ( $ currDateTimeObj > $ tenancyExpiry ) { throw new UserCredentialException ( 'Tenancy problem with your account. Please contact your Administrator' ) ; } } return true ; }
validate the tenancy of an account . This can be preset by the system admin so that accounts that are past tenancy date are automatically not allowed to authenticate . Tenancy should be validated after other policies to avoid farming of accounts by testing which ones are still in tenancy
21,374
protected function doLoadAcl ( ObjectIdentityInterface $ objectIdentity ) { $ acl = null ; try { $ acl = $ this -> getAclProvider ( ) -> createAcl ( $ objectIdentity ) ; } catch ( AclAlreadyExistsException $ ex ) { $ acl = $ this -> getAclProvider ( ) -> findAcl ( $ objectIdentity ) ; } return $ acl ; }
Loads an ACL from the ACL provider first by attempting to create then finding if it already exists
21,375
public function connect ( $ timeout = 90 ) { $ host = $ this -> getAuthenticator ( ) -> getHost ( ) ; $ port = $ this -> getAuthenticator ( ) -> getPort ( ) ; $ this -> setConnection ( @ ftp_connect ( $ host , $ port , $ timeout ) ) ; if ( false === $ this -> getConnection ( ) ) { throw $ this -> newFTPException ( "connection failed" ) ; } return $ this ; }
Opens this FTP connection .
21,376
public function delete ( $ path ) { if ( false === @ ftp_delete ( $ this -> getConnection ( ) , $ path ) ) { throw $ this -> newFTPException ( sprintf ( "delete %s failed" , $ path ) ) ; } return $ this ; }
Deletes a file on the FTP server .
21,377
public function pasv ( $ pasv ) { if ( false === @ ftp_pasv ( $ this -> getConnection ( ) , $ pasv ) ) { throw $ this -> newFTPException ( sprintf ( "pasv from %d to %d failed" , ! $ pasv , $ pasv ) ) ; } return $ this ; }
Tuns passive mode on or off .
21,378
public function put ( $ localFile , $ remoteFile , $ mode = FTP_IMAGE , $ startPos = 0 ) { if ( false === @ ftp_put ( $ this -> getConnection ( ) , $ remoteFile , $ localFile , $ mode , $ startPos ) ) { throw $ this -> newFTPException ( sprintf ( "put %s into %s failed" , $ localFile , $ remoteFile ) ) ; } return $ this ; }
Uploads a file to The FTP server .
21,379
public function alwaysFrom ( string $ address , ? string $ name = null ) : void { $ this -> getMailer ( ) -> alwaysFrom ( $ address , $ name ) ; }
Set the global from address and name .
21,380
public function alwaysTo ( string $ address , ? string $ name = null ) : void { $ this -> getMailer ( ) -> alwaysTo ( $ address , $ name ) ; }
Set the global to address and name .
21,381
public function plain ( string $ view , array $ data , $ callback ) : Receipt { return $ this -> send ( [ 'text' => $ view ] , $ data , $ callback ) ; }
Send a new message when only a plain part .
21,382
public function setQueue ( QueueContract $ queue ) { if ( $ this -> mailer instanceof MailerContract ) { $ this -> mailer -> setQueue ( $ queue ) ; } $ this -> queue = $ queue ; return $ this ; }
Set the queue manager instance .
21,383
public function handleQueuedMessage ( Job $ job , $ data ) { $ this -> send ( $ data [ 'view' ] , $ data [ 'data' ] , $ this -> getQueuedCallable ( $ data ) ) ; $ job -> delete ( ) ; }
Handle a queued e - mail message job .
21,384
public function loadUndefinedConfigPaths ( ) { $ list = [ ] ; $ collection = $ this -> coreConfig -> getCollectionByPath ( SgCoreInterface :: PATH_UNDEFINED . '%' ) ; foreach ( $ collection as $ item ) { $ path = explode ( '/' , $ item -> getPath ( ) ) ; $ key = array_pop ( $ path ) ; $ list [ $ key ] = $ item -> getPath ( ) ; } return $ list ; }
Loads all core_config_data paths with undefined in them so that we can load up the configuration properly
21,385
public function getShopNumber ( ) { $ shopNumber = $ this -> request -> getParam ( 'shop_number' ) ; $ item = $ this -> sgCoreConfig -> getShopNumberCollection ( $ shopNumber ) -> getFirstItem ( ) ; return $ item -> getData ( 'value' ) ? $ shopNumber : '' ; }
The Gods will forever hate me for using request interface here
21,386
protected function registerMailer ( ) : void { $ this -> app -> singleton ( 'orchestra.mail' , function ( $ app ) { $ mailer = new Mailer ( $ app , $ transport = new TransportManager ( $ app ) ) ; if ( $ app -> bound ( 'orchestra.platform.memory' ) ) { $ mailer -> attach ( $ memory = $ app -> make ( 'orchestra.platform.memory' ) ) ; $ transport -> setMemoryProvider ( $ memory ) ; } if ( $ app -> bound ( 'queue' ) ) { $ mailer -> setQueue ( $ app -> make ( 'queue' ) ) ; } return $ mailer ; } ) ; }
Register the service provider for mail .
21,387
protected function registerIlluminateMailerResolver ( ) : void { $ this -> app -> afterResolving ( 'mailer' , function ( $ service ) { $ this -> app -> make ( 'orchestra.mail' ) -> configureIlluminateMailer ( $ service ) ; } ) ; }
Register the service provider for notifier .
21,388
public function delete ( $ id ) { $ params = $ this -> parseUrl ( $ id ) ; try { $ this -> getClient ( ) -> deleteObject ( array ( 'Bucket' => $ params [ 'bucket' ] , 'Key' => $ params [ 'key' ] ) ) ; } catch ( S3Exception $ e ) { return false ; } return true ; }
Delete a file from Amazon S3 by parsing a URL or using a direct key .
21,389
public function parseUrl ( $ url ) { $ region = $ this -> getConfig ( 'region' ) ; $ bucket = $ this -> getConfig ( 'bucket' ) ; $ key = $ url ; if ( strpos ( $ url , 'amazonaws.com' ) !== false ) { if ( preg_match ( '/^https?:\/\/s3(.+?)?\.amazonaws\.com\/(.+?)\/(.+?)$/i' , $ url , $ matches ) ) { $ region = $ matches [ 1 ] ? : $ region ; $ bucket = $ matches [ 2 ] ; $ key = $ matches [ 3 ] ; } else if ( preg_match ( '/^https?:\/\/(.+?)\.s3(.+?)?\.amazonaws\.com\/(.+?)$/i' , $ url , $ matches ) ) { $ bucket = $ matches [ 1 ] ; $ region = $ matches [ 2 ] ? : $ region ; $ key = $ matches [ 3 ] ; } } return array ( 'bucket' => $ bucket , 'key' => trim ( $ key , '/' ) , 'region' => trim ( $ region , '-' ) ) ; }
Parse an S3 URL and extract the bucket and key .
21,390
static function register ( $ protocol = 'sftp' ) { if ( in_array ( $ protocol , stream_get_wrappers ( ) , true ) ) { return false ; } $ class = function_exists ( 'get_called_class' ) ? get_called_class ( ) : __CLASS__ ; return stream_wrapper_register ( $ protocol , $ class ) ; }
Registers this class as a URL wrapper .
21,391
protected function checkToken ( ) { $ multiOtpWrapper = new MultiotpWrapper ( ) ; $ currentUserName = $ this -> getCurrentUsername ( ) ; if ( ! ( \ strlen ( ( string ) $ currentUserName ) ) ) { throw new UserCredentialException ( 'Cannot validate a TOTP token when username is not set!' , 2106 ) ; } $ tokenExists = $ multiOtpWrapper -> CheckTokenExists ( $ currentUserName ) ; if ( ! ( $ tokenExists ) ) { throw new UserCredentialException ( 'The TOTP token for the current user does not exist' , 2107 ) ; } $ multiOtpWrapper -> setToken ( $ currentUserName ) ; $ oneTimeToken = $ this -> getOneTimeToken ( ) ; $ tokenCheckResult = $ multiOtpWrapper -> CheckToken ( $ oneTimeToken ) ; if ( $ tokenCheckResult == 0 ) { return true ; } else { return false ; } }
Verify a user token if it exists as part of the multi factor login process
21,392
public function getIsoStateByMagentoRegion ( DataObject $ address ) { $ map = $ this -> getIsoToMagentoMapping ( ) ; $ sIsoCode = null ; if ( $ address -> getData ( 'country_id' ) && $ address -> getData ( 'region_code' ) ) { $ sIsoCode = $ address -> getData ( 'country_id' ) . "-" . $ address -> getData ( 'region_code' ) ; } if ( isset ( $ map [ $ address -> getData ( 'country_id' ) ] ) ) { foreach ( $ map [ $ address -> getData ( 'country_id' ) ] as $ isoCode => $ mageCode ) { if ( $ mageCode === $ address -> getData ( 'region_code' ) ) { $ sIsoCode = $ address -> getData ( 'country_id' ) . "-" . $ isoCode ; break ; } } } return $ sIsoCode ; }
Return ISO - Code for Magento address
21,393
public function serializeIteratorToStream ( StatementIterator $ statements , $ outputStream ) { if ( is_resource ( $ outputStream ) ) { } elseif ( is_string ( $ outputStream ) ) { $ outputStream = fopen ( $ outputStream , 'w' ) ; } else { throw new \ Exception ( 'Parameter $outputStream is neither a string nor resource.' ) ; } $ graph = new \ EasyRdf_Graph ( ) ; foreach ( $ statements as $ statement ) { $ stmtSubject = $ statement -> getSubject ( ) ; if ( $ stmtSubject -> isNamed ( ) ) { $ s = $ stmtSubject -> getUri ( ) ; } elseif ( $ stmtSubject -> isBlank ( ) ) { $ s = '_:' . $ stmtSubject -> getBlankId ( ) ; } else { throw new \ Exception ( 'Subject can either be a blank node or an URI.' ) ; } $ stmtPredicate = $ statement -> getPredicate ( ) ; if ( $ stmtPredicate -> isNamed ( ) ) { $ p = $ stmtPredicate -> getUri ( ) ; } else { throw new \ Exception ( 'Predicate can only be an URI.' ) ; } $ stmtObject = $ statement -> getObject ( ) ; if ( $ stmtObject -> isNamed ( ) ) { $ o = [ 'type' => 'uri' , 'value' => $ stmtObject -> getUri ( ) ] ; } elseif ( $ stmtObject -> isBlank ( ) ) { $ o = [ 'type' => 'bnode' , 'value' => '_:' . $ stmtObject -> getBlankId ( ) ] ; } elseif ( $ stmtObject -> isLiteral ( ) ) { $ o = [ 'type' => 'literal' , 'value' => $ stmtObject -> getValue ( ) , 'datatype' => $ stmtObject -> getDataType ( ) -> getUri ( ) , ] ; } else { throw new \ Exception ( 'Object can either be a blank node, an URI or literal.' ) ; } $ graph -> add ( $ s , $ p , $ o ) ; } fwrite ( $ outputStream , $ graph -> serialise ( $ this -> serialization ) . PHP_EOL ) ; }
Transforms the statements of a StatementIterator instance into a stream a file for instance .
21,394
public function set ( string $ name , $ value , int $ type = self :: TYPE_LOCAL ) : OptionList { if ( $ type == self :: TYPE_GLOBAL ) { self :: $ globalOptions [ $ name ] = $ value ; } else { $ this -> options [ $ name ] = $ value ; } return $ this ; }
Set option .
21,395
public function isset ( string $ name , int $ type = null ) : bool { if ( is_null ( $ type ) ) { return array_key_exists ( $ name , $ this -> options ) || array_key_exists ( $ name , self :: $ globalOptions ) ; } else { if ( $ type == self :: TYPE_GLOBAL ) { return array_key_exists ( $ name , self :: $ globalOptions ) ; } else { return array_key_exists ( $ name , $ this -> options ) ; } } }
Know if option exists .
21,396
public static function getGlobal ( string $ name ) { if ( isset ( self :: $ globalOptions [ $ name ] ) ) { return self :: $ globalOptions [ $ name ] ; } else { return null ; } }
Get global option value .
21,397
public function is_null ( string $ name , int $ type = null ) : bool { if ( isset ( self :: $ globalOptions [ $ name ] ) && ( is_null ( $ type ) || $ type == self :: TYPE_GLOBAL ) ) { return is_null ( self :: $ globalOptions [ $ name ] ) ; } else { if ( isset ( $ this -> options [ $ name ] ) && ( is_null ( $ type ) || $ type == self :: TYPE_LOCAL ) ) { return is_null ( $ this -> options [ $ name ] ) ; } else { return true ; } } }
Know if value of an option is null .
21,398
public static function getByIdentifier ( $ id ) { $ file = config ( 'filer.hash_routes' ) ? static :: whereHash ( $ id ) -> first ( ) : static :: find ( $ id ) ; if ( ! $ file ) { throw ( new ModelNotFoundException ) -> setModel ( static :: class ) ; } return $ file ; }
Get a model instance using a unique identifier according to filer . hash_routes .
21,399
public static function appendTo ( $ src , $ dest , $ newline = false ) { $ reader = @ fopen ( $ src , "r" ) ; if ( false === $ reader ) { throw new FileNotFoundException ( $ src ) ; } $ writer = @ fopen ( $ dest , "a" ) ; if ( false === $ writer ) { throw new IOException ( sprintf ( "Failed to open \"%s\"" , $ dest ) ) ; } if ( false === @ file_put_contents ( $ dest , $ reader , FILE_APPEND ) ) { throw new IOException ( sprintf ( "Failed to append \"%s\" into \"%s\"" , $ src , $ dest ) ) ; } if ( true === $ newline && false === @ file_put_contents ( $ dest , "\n" , FILE_APPEND ) ) { throw new IOException ( sprintf ( "Failed to append \"%s\" into \"%s\"" , $ src , $ dest ) ) ; } if ( false === @ fclose ( $ reader ) ) { throw new IOException ( sprintf ( "Failed to close \"%s\"" , $ src ) ) ; } if ( false === @ fclose ( $ writer ) ) { throw new IOException ( sprintf ( "Failed to close \"%s\"" , $ dest ) ) ; } }
Append to .