idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
42,600
public function validate ( $ attribute , $ value , array $ parameters , $ validator ) { $ data = $ validator -> getData ( ) ; list ( $ countries , $ types , $ detect , $ lenient ) = $ this -> extractParameters ( $ attribute , $ parameters , $ data ) ; if ( $ detect || ( $ lenient && empty ( $ countries ) ) ) { array_un...
Validates a phone number .
42,601
protected function extractParameters ( $ attribute , array $ parameters , array $ data ) { $ parameters = array_map ( 'strtolower' , $ parameters ) ; $ inputField = Collection :: make ( $ parameters ) -> intersect ( array_keys ( Arr :: dot ( $ data ) ) ) -> first ( ) ? : "${attribute}_country" ; if ( $ inputCountry = A...
Parse and extract parameters in the appropriate validation arguments .
42,602
protected static function parseFormat ( $ format ) { static :: loadFormats ( ) ; if ( in_array ( $ format , static :: $ formats , true ) ) { return $ format ; } return Arr :: get ( static :: $ formats , strtoupper ( $ format ) ) ; }
Parse a phone format .
42,603
public static function countryMismatch ( $ number , $ countries ) { $ countries = array_filter ( is_array ( $ countries ) ? $ countries : [ $ countries ] ) ; $ exception = new static ( libNumberParseException :: INVALID_COUNTRY_CODE , 'Number does not match the provided ' . Str :: plural ( 'country' , count ( $ countri...
Country mismatch static constructor .
42,604
protected static function parseTypes ( $ types ) { static :: loadTypes ( ) ; return Collection :: make ( is_array ( $ types ) ? $ types : func_get_args ( ) ) -> map ( function ( $ type ) { if ( is_numeric ( $ type ) && in_array ( $ type , static :: $ resolvedTypes ) ) { return ( int ) $ type ; } return Arr :: get ( sta...
Parse a phone type into constant s value .
42,605
public static function isValidCountryCode ( $ country ) { $ iso3166 = new ISO3166 ; try { $ iso3166 -> alpha2 ( $ country ) ; return true ; } catch ( \ Exception $ e ) { return false ; } }
Determine whether the given country code is valid .
42,606
protected function parseCountries ( $ countries ) { return Collection :: make ( is_array ( $ countries ) ? $ countries : func_get_args ( ) ) -> map ( function ( $ country ) { return strtoupper ( $ country ) ; } ) -> filter ( function ( $ value ) { return static :: isValidCountryCode ( $ value ) ; } ) -> toArray ( ) ; }
Parse the provided phone countries to a valid array .
42,607
public function country ( $ country ) { $ countries = is_array ( $ country ) ? $ country : func_get_args ( ) ; $ this -> countries = array_merge ( $ this -> countries , $ countries ) ; return $ this ; }
Set the phone countries .
42,608
public function type ( $ type ) { $ types = is_array ( $ type ) ? $ type : func_get_args ( ) ; $ this -> types = array_merge ( $ this -> types , $ types ) ; return $ this ; }
Set the phone types .
42,609
public function format ( $ format ) { $ parsedFormat = static :: parseFormat ( $ format ) ; if ( is_null ( $ parsedFormat ) ) { throw NumberFormatException :: invalid ( $ format ) ; } return $ this -> lib -> format ( $ this -> getPhoneNumberInstance ( ) , $ parsedFormat ) ; }
Format the phone number in a given format .
42,610
public function formatForCountry ( $ country ) { if ( ! static :: isValidCountryCode ( $ country ) ) { throw CountryCodeException :: invalid ( $ country ) ; } return $ this -> lib -> formatOutOfCountryCallingNumber ( $ this -> getPhoneNumberInstance ( ) , $ country ) ; }
Format the phone number in a way that it can be dialled from the provided country .
42,611
public function formatForMobileDialingInCountry ( $ country , $ removeFormatting = false ) { if ( ! static :: isValidCountryCode ( $ country ) ) { throw CountryCodeException :: invalid ( $ country ) ; } return $ this -> lib -> formatNumberForMobileDialing ( $ this -> getPhoneNumberInstance ( ) , $ country , $ removeFor...
Format the phone number in a way that it can be dialled from the provided country using a cellphone .
42,612
public function getCountry ( ) { if ( ! $ this -> country ) { $ this -> country = $ this -> filterValidCountry ( $ this -> countries ) ; } return $ this -> country ; }
Get the phone number s country .
42,613
protected function filterValidCountry ( $ countries ) { $ result = Collection :: make ( $ countries ) -> filter ( function ( $ country ) { try { $ instance = $ this -> lib -> parse ( $ this -> number , $ country ) ; return $ this -> lenient ? $ this -> lib -> isPossibleNumber ( $ instance , $ country ) : $ this -> lib ...
Filter the provided countries to the one that is valid for the number .
42,614
public function getType ( $ asConstant = false ) { $ type = $ this -> lib -> getNumberType ( $ this -> getPhoneNumberInstance ( ) ) ; if ( $ asConstant ) { return $ type ; } $ stringType = Arr :: get ( static :: parseTypesAsStrings ( $ type ) , 0 ) ; return $ stringType ? strtolower ( $ stringType ) : null ; }
Get the phone number s type .
42,615
public function unserialize ( $ serialized ) { $ this -> lib = PhoneNumberUtil :: getInstance ( ) ; $ this -> number = $ serialized ; $ this -> country = $ this -> lib -> getRegionCodeForNumber ( $ this -> getPhoneNumberInstance ( ) ) ; }
Reconstructs the phone instance from a string representation .
42,616
public function getWhereParameters ( ) { $ params = [ ] ; foreach ( $ this -> filters as $ filter ) { $ params = array_merge ( $ params , $ filter -> getParameters ( ) ) ; } return $ params ; }
Returns all the parameters for the query .
42,617
public function getWhereParametersFor ( $ fieldName ) { return array_intersect_key ( $ this -> getWhereParameters ( ) , array_flip ( preg_grep ( '/^' . $ fieldName . '_\d+$/' , array_keys ( $ this -> getWhereParameters ( ) ) ) ) ) ; }
Gets all the parameters for a specific field name .
42,618
public function setWhereParameter ( $ key , $ value ) { foreach ( $ this -> filters as $ filter ) { if ( $ filter -> hasParameter ( $ key ) ) { $ filter -> setParameter ( $ key , $ value ) ; } } }
Sets all the parameters for a specific field name .
42,619
public function build ( ) { $ query = $ this -> qb ; if ( $ this -> getWhereExpression ( ) ) { $ query -> where ( $ this -> getWhereExpression ( ) ) ; } foreach ( $ this -> getWhereParameters ( ) as $ key => $ param ) { $ query -> setParameter ( $ key , $ param , is_array ( $ param ) ? Connection :: PARAM_STR_ARRAY : n...
Part of the QueryInterface this turns all the input into a Doctrine QueryBuilder object and is usually run just before query execution . That allows modifications to be made to any of the parameters up until query execution time .
42,620
public function get ( $ class , $ mapping ) { if ( is_object ( $ class ) ) { $ class = get_class ( $ class ) ; } if ( array_key_exists ( $ class , $ this -> handlers ) ) { $ handler = $ this -> handlers [ $ class ] ; $ field = call_user_func ( $ handler , $ mapping , $ this -> em ) ; } else { $ field = new $ class ( $ ...
Gets the field instance for the supplied class .
42,621
public function getFieldFor ( $ type ) { if ( ! isset ( $ this -> typemap [ $ type ] ) ) { return false ; } $ class = $ this -> typemap [ $ type ] ; return $ this -> get ( $ class , [ 'type' => $ type ] ) ; }
Looks up a type from the typemap and returns a field class .
42,622
public function addFieldType ( $ name , Field \ FieldInterface $ field ) { $ this -> setHandler ( $ name , $ field ) ; $ this -> customHandlers [ ] = $ name ; $ this -> boltConfig -> getFields ( ) -> addField ( $ field ) ; }
Shorthand to add a field to both the new and legacy managers .
42,623
protected function getFields ( ) { $ fields = [ ] ; foreach ( $ this as $ k => $ v ) { if ( is_string ( $ k ) && strpos ( $ k , '_' ) !== 0 ) { $ fields [ ] = $ k ; } } foreach ( $ this -> _fields as $ k => $ v ) { if ( is_string ( $ k ) ) { $ fields [ ] = $ k ; } } return $ fields ; }
An internal method that builds a list of available fields depending on context .
42,624
protected function setFrameOptions ( Request $ request , Response $ response ) { if ( Zone :: isBackend ( $ request ) && $ this -> app [ 'config' ] -> get ( 'general/headers/x_frame_options' ) ) { $ response -> headers -> set ( 'X-Frame-Options' , 'SAMEORIGIN' ) ; $ response -> headers -> set ( 'Frame-Options' , 'SAMEO...
Set the X - Frame - Options headers to prevent click - jacking unless specifically disabled . Backend only!
42,625
private function getTemplateFieldTemplates ( ContentType $ contentType , Content $ content ) { $ templateFieldTemplates = [ ] ; $ templateFieldsConfig = $ this -> config -> get ( 'theme/templatefields' ) ; if ( $ templateFieldsConfig ) { $ templateFieldTemplates = array_keys ( $ templateFieldsConfig ) ; $ toRepair = [ ...
Determine which templates will result in templatefields .
42,626
private function createGroupTabs ( ContentType $ contentType , array $ has ) { $ groups = [ ] ; $ groupIds = [ ] ; $ addGroup = function ( $ group , $ label ) use ( & $ groups , & $ groupIds ) { $ nr = count ( $ groups ) + 1 ; $ id = rtrim ( 'tab-' . Slugify :: create ( ) -> slugify ( $ group ) , '-' ) ; if ( isset ( $...
Generate tab groups .
42,627
private function getUsedFieldtypes ( ContentType $ contentType , Content $ content , array $ has ) { $ fieldtypes = [ 'meta' => true , ] ; if ( $ content -> getTemplatefields ( ) instanceof TemplateFields ) { $ templateFields = $ content -> getTemplatefields ( ) -> getContenttype ( ) -> getFields ( ) ? : [ ] ; } else {...
Create a list of fields types used in regular template and virtual fields .
42,628
public function onRequestEarly ( GetResponseEvent $ event ) { $ validator = $ this -> app [ 'config.validator' ] ; $ response = $ validator -> checks ( ) ; if ( $ response instanceof Response ) { $ event -> setResponse ( $ response ) ; } }
Early functions .
42,629
public function onRequest ( GetResponseEvent $ event ) { if ( Zone :: isBackend ( $ event -> getRequest ( ) ) ) { $ this -> setVersionChangeNotice ( ) ; } $ this -> setGlobals ( ) ; if ( $ this -> app [ 'config' ] -> checkConfig ( ) === false ) { return ; } if ( ! $ this -> app [ 'config' ] -> get ( 'general/caching/co...
Normal functions .
42,630
private function setVersionChangeNotice ( ) { if ( ! $ this -> app [ 'config.environment' ] -> hasVersionChange ( ) ) { return ; } $ notice = Trans :: __ ( "Detected Bolt version change to <b>%VERSION%</b>, and the cache has been cleared. Please <a href=\"%URI%\">check the database</a>, if you haven't done so already."...
If required set a notification of version change for admin users .
42,631
private function setGlobals ( ) { $ twig = $ this -> app [ 'twig' ] ; $ config = $ this -> app [ 'config' ] ; $ users = $ this -> app [ 'users' ] ; $ zone = null ; $ requestStack = $ this -> app [ 'request_stack' ] ; if ( $ request = $ requestStack -> getCurrentRequest ( ) ) { $ zone = Zone :: get ( $ request ) ; } try...
Get the parameters that will be used to update Bolt s registered Twig globals .
42,632
protected function verifyCollection ( $ collection ) { if ( $ collection instanceof ControllerProviderInterface ) { $ connectedControllers = $ collection -> connect ( $ this -> app ) ; if ( ! $ connectedControllers instanceof ControllerCollection ) { throw new LogicException ( sprintf ( 'The method "%s::connect" must r...
Verifies collection is correct type and calls connect on providers .
42,633
public function getRelated ( $ contentType = null ) { if ( $ contentType !== null ) { return $ this -> getRelation ( $ contentType ) ; } return $ this -> getRelation ( ) -> all ( ) ; }
Gets all related content items
42,634
public function getValues ( ) { $ contentType = $ this -> getContenttype ( ) ; if ( ! isset ( $ contentType [ 'fields' ] ) ) { return [ ] ; } $ allValues = $ this -> toArray ( ) ; return array_intersect_key ( $ allValues , ( $ contentType [ 'fields' ] ) ) ; }
Helper to return an array of user - defined values from the Entity . This excludes meta fields set by Bolt .
42,635
public function getExcerpt ( $ length = 200 , $ includeTitle = false , $ focus = null , $ stripFields = null ) { $ excerpter = new Excerpt ( $ this ) ; $ excerpt = $ excerpter -> getExcerpt ( $ length , $ includeTitle , $ focus , $ stripFields ) ; return new Markup ( $ excerpt , 'UTF-8' ) ; }
Create an excerpt for the Entity .
42,636
public function getTitle ( ) { $ fields = $ this -> _fields ; if ( array_key_exists ( 'title' , $ fields ) ) { return ( string ) $ fields [ 'title' ] ; } $ fieldNames = $ this -> getTitleColumnNames ( $ this -> contenttype ) ; $ title = [ ] ; foreach ( $ fieldNames as $ fieldName ) { if ( array_key_exists ( $ fieldName...
Getter for a record s title field .
42,637
protected function getValidDateObject ( $ date ) { if ( empty ( $ date ) ) { return null ; } if ( is_string ( $ date ) ) { return new Carbon ( $ date ) ; } return $ date ; }
Get a valid date property to persist .
42,638
public function action ( array $ formValues , $ contentType , $ id , $ new , $ returnTo , $ editReferrer ) { $ contentTypeSlug = $ contentType [ 'slug' ] ; $ repo = $ this -> em -> getRepository ( $ contentTypeSlug ) ; if ( $ id ) { $ content = $ repo -> find ( $ id ) ; $ oldContent = clone $ content ; $ oldStatus = $ ...
Do the save for a POSTed record .
42,639
private function setTransitionStatus ( Entity \ Content $ content , $ contentTypeSlug , $ id , $ oldStatus ) { $ canTransition = $ this -> users -> isContentStatusTransitionAllowed ( $ oldStatus , $ content -> getStatus ( ) , $ contentTypeSlug , $ id ) ; if ( ! $ canTransition ) { $ content -> setStatus ( $ oldStatus )...
Check whether the status is allowed .
42,640
private function setPostedTaxonomies ( Entity \ Content $ content , $ formValues ) { $ taxonomies = $ this -> em -> createCollection ( Entity \ Taxonomy :: class ) ; $ taxonomies -> setFromPost ( $ formValues , $ content ) ; $ content -> setTaxonomy ( $ taxonomies ) ; }
Set valid POST taxonomies .
42,641
private function saveContentRecord ( Entity \ Content $ content , $ oldContent , $ contentType , $ new , $ comment , $ returnTo , $ editReferrer ) { $ repo = $ this -> em -> getRepository ( $ contentType [ 'slug' ] ) ; $ content -> setDatechanged ( 'now' ) ; $ repo -> save ( $ content ) ; $ id = $ content -> getId ( ) ...
Commit the record to the database .
42,642
private function setSuccessfulControlValues ( array $ formValues , $ fields ) { foreach ( $ fields as $ key => $ values ) { if ( isset ( $ formValues [ $ key ] ) ) { if ( $ values [ 'type' ] === 'float' ) { $ formValues [ $ key ] = str_replace ( ',' , '.' , $ formValues [ $ key ] ) ; } } else { if ( $ values [ 'type' ]...
Add successful control values to request values and do needed corrections .
42,643
private function logChange ( $ contentType , $ contentId , $ newContent = null , $ oldContent = null , $ comment = null ) { $ type = $ oldContent ? 'Update' : 'Insert' ; $ this -> loggerChange -> info ( $ type . ' record' , [ 'action' => strtoupper ( $ type ) , 'contenttype' => $ contentType , 'id' => $ contentId , 'ne...
Add a change log entry to track the change .
42,644
private function isEmptyArray ( $ input ) { if ( ! is_array ( $ input ) ) { return false ; } $ empty = true ; foreach ( new RecursiveIteratorIterator ( new RecursiveArrayIterator ( $ input ) , RecursiveIteratorIterator :: LEAVES_ONLY ) as $ key => $ value ) { $ empty = ( empty ( $ value ) && $ value !== '0' && $ value ...
Check wether an array is empty and if it is the value of the repeater is set to null .
42,645
public static function createRoot ( UrlGeneratorInterface $ urlGenerator , $ basePath ) { $ root = new static ( 'root' , $ basePath ) ; $ root -> urlGenerator = $ urlGenerator ; return $ root ; }
Create the root menu entry .
42,646
public function setRoute ( $ routeName , $ routeParams = [ ] ) { $ this -> routeName = $ routeName ; $ this -> routeParams = $ routeParams ; $ this -> routeGenerated = null ; return $ this ; }
Set the uri to be generated with given route name and params .
42,647
public function getUri ( ) { if ( $ this -> routeGenerated ) { return $ this -> routeGenerated ; } if ( $ this -> routeName !== null ) { return $ this -> routeGenerated = $ this -> urlGenerator -> generate ( $ this -> routeName , $ this -> routeParams ) ; } if ( strpos ( $ this -> uri , '/' ) === 0 || ! $ this -> paren...
Return the menu entry s URI relative to Bolt admin s .
42,648
public function add ( MenuEntry $ menu ) { $ menu -> parent = $ this ; $ menu -> urlGenerator = $ this -> urlGenerator ; $ this -> children [ $ menu -> getName ( ) ] = $ menu ; return $ menu ; }
Add child menu entry .
42,649
public function get ( $ name ) { if ( isset ( $ this -> children [ $ name ] ) ) { return $ this -> children [ $ name ] ; } throw new \ InvalidArgumentException ( sprintf ( 'Menu entry %s does not have a child named "%s"' , $ this -> name , $ name ) ) ; }
Return a menu entry s named child .
42,650
public function addDir ( DirectoryInterface $ dir , $ namespace = self :: MAIN_NAMESPACE ) { $ this -> cache = $ this -> errorCache = [ ] ; if ( ! $ dir -> exists ( ) ) { throw new LoaderError ( sprintf ( 'The "%s" directory does not exist.' , $ dir -> getFullPath ( ) ) ) ; } if ( ! $ dir -> isDir ( ) ) { throw new Loa...
Adds a directory where templates are stored .
42,651
public function prependDir ( DirectoryInterface $ dir , $ namespace = self :: MAIN_NAMESPACE ) { $ this -> cache = $ this -> errorCache = [ ] ; if ( ! $ dir -> exists ( ) ) { throw new LoaderError ( sprintf ( 'The "%s" directory does not exist.' , $ dir -> getFullPath ( ) ) ) ; } if ( ! $ dir -> isDir ( ) ) { throw new...
Prepends a directory where templates are stored .
42,652
protected function findTemplate ( $ name , $ throw = true ) { $ name = $ this -> normalizeName ( $ name ) ; if ( isset ( $ this -> cache [ $ name ] ) ) { return $ this -> cache [ $ name ] ; } if ( isset ( $ this -> errorCache [ $ name ] ) ) { if ( ! $ throw ) { return false ; } throw new LoaderError ( $ this -> errorCa...
Finds a file given the template name .
42,653
public function directoriesCheck ( Request $ request ) { $ options = [ ] ; $ results = $ this -> getCheck ( 'DirectoryAccess' ) -> setOptions ( $ options ) -> runCheck ( ) ; return $ this -> json ( $ results ) ; }
Check the needed directories are writeable .
42,654
public function emailCheck ( Request $ request ) { $ options = [ 'user' => $ this -> app [ 'users' ] -> getCurrentUser ( ) , 'host' => $ request -> getHost ( ) , 'ip' => $ request -> getClientIp ( ) , ] ; $ results = $ this -> getCheck ( 'EmailSetup' ) -> setOptions ( $ options ) -> runCheck ( ) ; return $ this -> json...
Send an e - mail ping test .
42,655
final protected function addMenuEntry ( $ label , $ path , $ icon = null , $ permission = null ) { Deprecated :: method ( null , 'registerMenuEntries' ) ; $ this -> menuEntries [ ] = ( new MenuEntry ( $ label , $ path ) ) -> setLabel ( $ label ) -> setIcon ( $ icon ) -> setPermission ( $ permission ) ; }
Add a menu option to backend menu .
42,656
public function initialize ( ) { if ( ! $ this -> checked ) { $ this -> config -> checkConfig ( ) ; $ this -> checked = true ; $ this -> data = $ this -> config -> get ( $ this -> path , $ this -> default ) ; } }
Initialize the configuration value .
42,657
protected function resolveBefore ( $ before ) { $ getBefore = $ this -> resolveMiddleware ( $ before ) ; return function ( Request $ request , Application $ app ) use ( $ getBefore ) { $ callback = $ getBefore ( $ request ) ; if ( ! is_callable ( $ callback ) ) { return null ; } return $ callback ( $ request , $ app ) ...
Returns a closure that will resolve the middleware callback to call on kernel request and call it .
42,658
protected function resolveAfter ( $ after ) { $ getAfter = $ this -> resolveMiddleware ( $ after ) ; return function ( Request $ request , Response $ response , Application $ app ) use ( $ getAfter ) { $ callback = $ getAfter ( $ request ) ; if ( ! is_callable ( $ callback ) ) { return null ; } return $ callback ( $ re...
Returns a closure that will resolve the middleware callback to call on kernel response and call it .
42,659
protected function resolveMiddleware ( $ callback ) { $ callbackResolver = $ this -> callbackResolver ; return function ( Request $ request ) use ( $ callback , $ callbackResolver ) { if ( ! is_string ( $ callback ) || substr ( $ callback , 0 , 2 ) !== '::' ) { return $ callbackResolver -> resolveCallback ( $ callback ...
Returns a closure that will resolve the class to use in middleware callback if one isn t specified .
42,660
protected function setupDefaults ( ) { $ this -> addTransformer ( 'html' , function ( $ value ) { return new Markup ( $ value , 'UTF-8' ) ; } ) ; $ this -> addTransformer ( 'text' , function ( $ value ) { return new Markup ( $ value , 'UTF-8' ) ; } ) ; $ this -> addTransformer ( 'textarea' , function ( $ value ) { retu...
Here we register some transformers that prepare the fields to be passed to twig . For repeaters and blocks this is recursive .
42,661
public function createView ( $ records ) { if ( $ records instanceof Content ) { $ this -> processSingleRecord ( $ records ) ; } elseif ( $ records instanceof QueryResultset ) { $ this -> processRecords ( $ records ) ; } return $ records ; }
This loads the relevant record or records and activates the class .
42,662
public function onStorageEventPostSave ( StorageEvent $ event ) { $ userEntity = $ event -> getContent ( ) ; if ( ! $ userEntity instanceof Entity \ Users ) { return ; } if ( ! $ userEntity -> isEnabled ( ) ) { $ this -> deleteAuthtokens ( $ userEntity ) ; $ this -> deleteSessions ( $ userEntity ) ; } }
Remove sessions & authtokens when a user is disabled .
42,663
public function onStorageEventPreDelete ( StorageEvent $ event ) { $ userEntity = $ event -> getContent ( ) ; if ( ! $ userEntity instanceof Entity \ Users ) { return ; } $ this -> deleteAuthtokens ( $ userEntity ) ; $ this -> deleteSessions ( $ userEntity ) ; }
Remove sessions & authtokens when a user is deleted .
42,664
private function deleteAuthtokens ( Entity \ Users $ user ) { $ repo = $ this -> em -> getRepository ( Entity \ Authtoken :: class ) ; $ repo -> deleteTokens ( $ user -> getId ( ) ) ; }
Delete any save authtokens for a user .
42,665
private function deleteSessions ( Entity \ Users $ user ) { $ savePath = $ this -> sessionStorage -> getOptions ( ) -> get ( 'save_path' ) ; try { $ sessionFiles = $ this -> filesystem -> find ( ) -> files ( ) -> in ( $ savePath ) ; } catch ( FileNotFoundException $ e ) { return ; } foreach ( $ sessionFiles as $ sessio...
Delete active session files for a user .
42,666
public function getLogin ( Request $ request ) { $ user = $ this -> getUser ( ) ; if ( $ user && $ user -> getEnabled ( ) == 1 ) { $ response = $ this -> redirectToRoute ( 'dashboard' ) ; $ token = $ this -> session ( ) -> get ( 'authentication' ) ; $ this -> setAuthenticationCookie ( $ request , $ response , $ token )...
Login page and Forgotten password page .
42,667
public function logout ( Request $ request ) { $ event = new AccessControlEvent ( $ request ) ; $ sessionAuth = $ this -> session ( ) -> get ( 'authentication' ) ; $ userId = $ sessionAuth ? $ sessionAuth -> getToken ( ) -> getUserId ( ) : false ; if ( $ userId && $ sessionAuth -> getUser ( ) ) { $ userName = $ session...
Logout page .
42,668
public function resetPassword ( Request $ request ) { $ event = new AccessControlEvent ( $ request ) ; $ this -> password ( ) -> resetPasswordConfirm ( $ request -> get ( 'token' ) , $ request -> getClientIp ( ) , $ event ) ; return $ this -> redirectToRoute ( 'login' , [ 'action' => 'login' ] ) ; }
Reset the password . This route is normally only reached when the user clicks a password reset link in the email .
42,669
private function handlePostLogin ( Request $ request , FormInterface $ form ) { $ event = new AccessControlEvent ( $ request ) ; $ username = $ form -> get ( 'username' ) -> getData ( ) ; $ password = $ form -> get ( 'password' ) -> getData ( ) ; if ( ! $ this -> login ( ) -> login ( $ username , $ password , $ event )...
Handle a login POST .
42,670
private function handlePostReset ( Request $ request , FormInterface $ form ) { $ event = new AccessControlEvent ( $ request ) ; $ username = $ form -> get ( 'username' ) -> getData ( ) ; if ( $ username === null || $ username === '' ) { $ this -> flashes ( ) -> error ( Trans :: __ ( 'general.phrase.please-provide-user...
Handle a password reset POST .
42,671
private function buildPath ( $ domain , $ locale ) { $ path = '/resources/translations/' . $ locale . '/' . $ domain . '.' . $ locale . '.yml' ; if ( strlen ( $ locale ) == 5 && ! is_dir ( $ this -> app [ 'path_resolver' ] -> resolve ( '%root%/app' . $ path ) ) ) { $ paths = $ this -> buildPath ( $ domain , substr ( $ ...
Get the path to a tranlsation resource .
42,672
private function addTranslatable ( $ text ) { if ( strlen ( $ text ) > 1 && ! isset ( $ this -> translatables [ $ text ] ) ) { $ this -> translatables [ $ text ] = '' ; } }
Adds a string to the internal list of translatable strings .
42,673
private function gatherTranslatableStrings ( ) { $ this -> translatables = [ ] ; $ this -> scanTwigFiles ( ) ; $ this -> scanPhpFiles ( ) ; ksort ( $ this -> translatables ) ; }
Find all twig templates and bolt php code extract translatables strings merge with existing translations .
42,674
private function readSavedTranslations ( ) { if ( ! is_file ( $ this -> absPath ) || ! is_readable ( $ this -> absPath ) ) { return null ; } try { $ savedTranslations = Yaml :: parse ( file_get_contents ( $ this -> absPath ) , true ) ; } catch ( ParseException $ e ) { $ this -> app [ 'logger.flash' ] -> danger ( 'Unabl...
Parses translations file and returns translations .
42,675
private function contentInfo ( ) { $ path = $ this -> absPath ; if ( ! file_exists ( $ path ) || filesize ( $ path ) < 10 ) { $ localeFallbacks = $ this -> app [ 'locale_fallbacks' ] ; list ( $ path ) = $ this -> buildPath ( 'infos' , reset ( $ localeFallbacks ) ) ; if ( ! file_exists ( $ path ) ) { $ this -> app [ 'lo...
Get the content of the info translation file or the fallback file .
42,676
private function contentMessages ( ) { $ savedTranslations = $ this -> readSavedTranslations ( ) ; if ( $ savedTranslations === null ) { return '' ; } $ this -> gatherTranslatableStrings ( ) ; $ newTranslations = [ ] ; foreach ( array_keys ( $ this -> translatables ) as $ key ) { $ newTranslations [ $ key ] = isset ( $...
Gets all translatable strings and returns a translationsfile for messages or contenttypes .
42,677
public function isWriteAllowed ( ) { $ msgRepl = [ '%s' => $ this -> relPath ] ; if ( ! file_exists ( $ this -> absPath ) && ( ! is_writable ( dirname ( $ this -> absPath ) ) && ! is_writable ( dirname ( dirname ( $ this -> absPath ) ) ) ) ) { $ msg = Trans :: __ ( "The translations file '%s' can't be created. You will...
Checks if translations file is allowed to write to .
42,678
public function login ( $ userName , $ password , AccessControlEvent $ event ) { $ authCookie = $ this -> requestStack -> getCurrentRequest ( ) -> cookies -> get ( $ this -> authTokenName ) ; $ this -> getRepositoryAuthtoken ( ) -> deleteExpiredTokens ( ) ; if ( $ userName !== null && $ password !== null ) { return $ t...
Attempt to login a user with the given password . Accepts username or email .
42,679
protected function loginCheckAuthtoken ( $ authCookie , AccessControlEvent $ event ) { if ( ! $ userTokenEntity = $ this -> getRepositoryAuthtoken ( ) -> getToken ( $ authCookie , $ this -> getClientIp ( ) , $ this -> getClientUserAgent ( ) ) ) { $ this -> flashLogger -> error ( Trans :: __ ( 'general.phrase.error-logi...
Attempt to login a user via the bolt_authtoken cookie .
42,680
protected function getUserEntity ( $ userName ) { if ( ! $ userEntity = $ this -> getRepositoryUsers ( ) -> getUser ( $ userName ) ) { $ this -> flashLogger -> error ( Trans :: __ ( 'general.phrase.error-user-name-password-incorrect' ) ) ; return null ; } if ( ! $ userEntity -> getEnabled ( ) ) { $ this -> systemLogger...
Get the user record entity if it exists .
42,681
protected function loginFailed ( Entity \ Users $ userEntity ) { $ this -> flashLogger -> error ( Trans :: __ ( 'general.phrase.error-user-name-password-incorrect' ) ) ; $ this -> systemLogger -> info ( "Failed login attempt for '" . $ userEntity -> getDisplayname ( ) . "'." , [ 'event' => 'authentication' ] ) ; $ user...
Add error messages to logs and update the user .
42,682
protected function updateUserLogin ( Entity \ Users $ userEntity ) { $ userEntity -> setLastseen ( Carbon :: now ( ) ) ; $ userEntity -> setLastip ( $ this -> getClientIp ( ) ) ; $ userEntity -> setFailedlogins ( 0 ) ; $ userEntity -> setThrottleduntil ( $ this -> throttleUntil ( 0 ) ) ; $ userEntity = $ this -> update...
Update the user record with latest login information .
42,683
protected function updateUserShadowLogin ( Entity \ Users $ userEntity ) { if ( Carbon :: now ( ) > $ userEntity -> getShadowvalidity ( ) ) { $ userEntity -> setShadowpassword ( null ) ; $ userEntity -> setShadowtoken ( null ) ; $ userEntity -> setShadowvalidity ( null ) ; } return $ userEntity ; }
Remove expired shadow login data .
42,684
protected function updateAuthToken ( Entity \ Users $ userEntity ) { $ userName = $ userEntity -> getUsername ( ) ; $ cookieLifetime = ( int ) $ this -> cookieOptions [ 'lifetime' ] ; $ repo = $ this -> getRepositoryAuthtoken ( ) ; try { $ tokenEntity = $ repo -> getUserToken ( $ userEntity -> getId ( ) , $ this -> get...
Set the Authtoken cookie and DB - entry . If it s already present update it .
42,685
private function throttleUntil ( $ attempts ) { if ( $ attempts < 5 ) { return null ; } $ wait = pow ( ( $ attempts - 4 ) , 2 ) ; return Carbon :: create ( ) -> addSeconds ( $ wait ) ; }
Calculate the amount of time until we should throttle login attempts for a user .
42,686
public function defaultFilterHandler ( $ key , $ value , $ expr ) { $ filter = new Filter ( ) ; $ filter -> setKey ( $ key ) ; if ( is_array ( $ value ) ) { $ count = 1 ; $ composite = $ expr -> andX ( ) ; foreach ( $ value as $ paramName => $ valueItem ) { $ val = $ this -> parseValue ( $ valueItem ) ; $ placeholder =...
The default handler is the last to be run and handler simple value parsing .
42,687
public function parseValue ( $ value ) { foreach ( $ this -> valueMatchers as $ matcher ) { $ regex = sprintf ( '/%s/u' , $ matcher [ 'token' ] ) ; $ values = $ matcher [ 'params' ] ; if ( preg_match ( $ regex , $ value ) ) { if ( is_callable ( $ values [ 'value' ] ) ) { preg_match ( $ regex , $ value , $ output ) ; $ ...
This method uses the defined value matchers to parse a passed in value .
42,688
public function addValueMatcher ( $ token , array $ params = [ ] , $ priority = null ) { if ( $ priority ) { array_unshift ( $ this -> valueMatchers , [ 'token' => $ token , 'params' => $ params ] ) ; } else { $ this -> valueMatchers [ ] = [ 'token' => $ token , 'params' => $ params ] ; } }
Adds an additional token to parse for value parameters .
42,689
public function get ( $ url ) { $ url = str_replace ( '__random__' , rand ( 100000 , 999999 ) , $ url ) ; return $ this -> client -> get ( $ url , [ 'timeout' => 10 ] ) -> getBody ( ) ; }
Fetches an image from a remote source .
42,690
protected function getConfig ( ) { if ( $ this -> config !== null ) { return $ this -> config ; } $ this -> config = $ this -> getDefaultConfig ( ) ; $ app = $ this -> getContainer ( ) ; $ file = $ app [ 'filesystem' ] -> getFile ( strtolower ( "extensions_config://{$this->getName()}.{$this->getVendor()}.yml" ) ) ; if ...
Returns the config for the extension .
42,691
private function addConfig ( ParsableInterface $ file ) { $ app = $ this -> getContainer ( ) ; try { $ newConfig = $ file -> parse ( ) ; } catch ( RuntimeException $ e ) { $ app [ 'logger.flash' ] -> danger ( $ e -> getMessage ( ) ) ; $ app [ 'logger.system' ] -> error ( $ e -> getMessage ( ) , [ 'event' => 'exception'...
Merge in a yaml file to the config .
42,692
private function copyDistFile ( FileInterface $ file ) { $ distFile = $ this -> getBaseDirectory ( ) -> getFile ( 'config/config.yml.dist' ) ; $ file -> write ( $ distFile -> read ( ) ) ; $ app = $ this -> getContainer ( ) ; $ app [ 'logger.system' ] -> info ( sprintf ( 'Copied %s to %s' , $ distFile -> getFullPath ( )...
Copy config . yml . dist to extension config dir .
42,693
public function trim ( $ log ) { $ period = new \ DateTime ( '-7 day' ) ; if ( $ log === 'change' ) { $ this -> changeRepository -> trimLog ( $ period ) ; } elseif ( $ log === 'system' ) { $ this -> systemRepository -> trimLog ( $ period ) ; } else { throw new \ UnexpectedValueException ( "Invalid log type requested: $...
Trim the log .
42,694
public function clear ( $ log ) { if ( $ log === 'change' ) { $ this -> changeRepository -> clearLog ( ) ; } elseif ( $ log === 'system' ) { $ this -> systemRepository -> clearLog ( ) ; } else { throw new \ UnexpectedValueException ( "Invalid log type requested: $log" ) ; } $ this -> app [ 'logger.system' ] -> info ( u...
Clear a log .
42,695
public function getActivity ( $ log , $ page = 1 , $ amount = 10 , $ options = [ ] ) { if ( $ log == 'change' ) { $ repo = $ this -> changeRepository ; } elseif ( $ log == 'system' ) { $ repo = $ this -> systemRepository ; } else { throw new \ UnexpectedValueException ( "Invalid log type requested: $log" ) ; } try { $ ...
Get a specific activity log .
42,696
public function getListingData ( array $ contenttype , $ contentId , array $ queryOptions ) { $ content = null ; if ( $ contentId ) { $ content = $ this -> app [ 'storage' ] -> getContent ( $ contenttype [ 'slug' ] , [ 'id' => $ contentId , 'hydrate' => false ] ) ; $ queryOptions [ 'contentid' ] = $ contentId ; } $ log...
Get the listing data such as title and count .
42,697
public static function addResources ( Application $ app , $ locale ) { $ transDirs = array_unique ( [ $ app [ 'path_resolver' ] -> resolve ( '%site%/app/translation/' ) , $ app [ 'path_resolver' ] -> resolve ( "%site%/app/translation/{$locale}" ) , $ app [ 'path_resolver' ] -> resolve ( "%bolt%/app/resources/translatio...
Adds all resources that belong to a locale .
42,698
protected function mergeGenericLocales ( array $ inputLocales ) { $ locales = [ ] ; foreach ( $ inputLocales as $ locale ) { $ locales [ ] = $ locale ; if ( strlen ( $ locale ) === 5 ) { $ locale = substr ( $ locale , 0 , 2 ) ; $ locales [ ] = $ locale ; } } $ locales = array_reverse ( array_unique ( array_reverse ( $ ...
Adds generic locales into a given list .
42,699
protected function mergeUtf8Locales ( array $ inputLocales ) { $ locales = [ ] ; foreach ( $ inputLocales as $ locale ) { $ locales [ ] = $ locale . '.UTF-8' ; $ locales [ ] = $ locale . '.utf8' ; $ locales [ ] = $ locale ; } return $ locales ; }
Adds UTF - 8 suffixes for each locale in given list .