idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
4,700
|
public function getFormatter ( $ dateLength = IntlDateFormatter :: MEDIUM , $ timeLength = IntlDateFormatter :: NONE ) { return $ this -> getCustomFormatter ( null , null , $ dateLength , $ timeLength ) ; }
|
Get date formatter
|
4,701
|
public function FormatFromSettings ( $ member = null ) { if ( ! $ member ) { $ member = Security :: getCurrentUser ( ) ; } if ( ! $ member ) { return $ this -> Nice ( ) ; } return $ this -> Format ( $ member -> getDateFormat ( ) , $ member -> getLocale ( ) ) ; }
|
Return a date formatted as per a CMS user s settings .
|
4,702
|
public function RangeString ( $ otherDateObj , $ includeOrdinals = false ) { $ d1 = $ this -> DayOfMonth ( $ includeOrdinals ) ; $ d2 = $ otherDateObj -> DayOfMonth ( $ includeOrdinals ) ; $ m1 = $ this -> ShortMonth ( ) ; $ m2 = $ otherDateObj -> ShortMonth ( ) ; $ y1 = $ this -> Year ( ) ; $ y2 = $ otherDateObj -> Year ( ) ; if ( $ y1 != $ y2 ) { return "$d1 $m1 $y1 - $d2 $m2 $y2" ; } elseif ( $ m1 != $ m2 ) { return "$d1 $m1 - $d2 $m2 $y1" ; } else { return "$d1 - $d2 $m1 $y1" ; } }
|
Return a string in the form 12 - 16 Sept or 12 Aug - 16 Sept
|
4,703
|
public function Rfc2822 ( ) { $ formatter = $ this -> getInternalFormatter ( ) ; $ formatter -> setPattern ( 'y-MM-dd HH:mm:ss' ) ; return $ formatter -> format ( $ this -> getTimestamp ( ) ) ; }
|
Return date in RFC2822 format
|
4,704
|
public function TimeDiffIn ( $ format ) { if ( ! $ this -> value ) { return null ; } $ now = DBDatetime :: now ( ) -> getTimestamp ( ) ; $ time = $ this -> getTimestamp ( ) ; $ ago = abs ( $ time - $ now ) ; switch ( $ format ) { case "seconds" : $ span = $ ago ; return _t ( __CLASS__ . '.SECONDS_SHORT_PLURALS' , '{count} sec|{count} secs' , [ 'count' => $ span ] ) ; case "minutes" : $ span = round ( $ ago / 60 ) ; return _t ( __CLASS__ . '.MINUTES_SHORT_PLURALS' , '{count} min|{count} mins' , [ 'count' => $ span ] ) ; case "hours" : $ span = round ( $ ago / 3600 ) ; return _t ( __CLASS__ . '.HOURS_SHORT_PLURALS' , '{count} hour|{count} hours' , [ 'count' => $ span ] ) ; case "days" : $ span = round ( $ ago / 86400 ) ; return _t ( __CLASS__ . '.DAYS_SHORT_PLURALS' , '{count} day|{count} days' , [ 'count' => $ span ] ) ; case "months" : $ span = round ( $ ago / 86400 / 30 ) ; return _t ( __CLASS__ . '.MONTHS_SHORT_PLURALS' , '{count} month|{count} months' , [ 'count' => $ span ] ) ; case "years" : $ span = round ( $ ago / 86400 / 365 ) ; return _t ( __CLASS__ . '.YEARS_SHORT_PLURALS' , '{count} year|{count} years' , [ 'count' => $ span ] ) ; default : throw new \ InvalidArgumentException ( "Invalid format $format" ) ; } }
|
Gets the time difference but always returns it in a certain format
|
4,705
|
public function IsToday ( ) { return $ this -> Format ( self :: ISO_DATE ) === DBDatetime :: now ( ) -> Format ( self :: ISO_DATE ) ; }
|
Returns true if date is today .
|
4,706
|
protected function fixInputDate ( $ value ) { list ( $ year , $ month , $ day , $ time ) = $ this -> explodeDateString ( $ value ) ; if ( ( int ) $ year === 0 && ( int ) $ month === 0 && ( int ) $ day === 0 ) { return null ; } if ( ! checkdate ( $ month , $ day , $ year ) ) { throw new InvalidArgumentException ( "Invalid date: '$value'. Use " . self :: ISO_DATE . " to prevent this error." ) ; } return sprintf ( '%d-%02d-%02d%s' , $ year , $ month , $ day , $ time ) ; }
|
Fix non - iso dates
|
4,707
|
protected function explodeDateString ( $ value ) { if ( ! preg_match ( '#^(?<first>\\d+)[-/\\.](?<second>\\d+)[-/\\.](?<third>\\d+)(?<time>.*)$#' , $ value , $ matches ) ) { throw new InvalidArgumentException ( "Invalid date: '$value'. Use " . self :: ISO_DATE . " to prevent this error." ) ; } $ parts = [ $ matches [ 'first' ] , $ matches [ 'second' ] , $ matches [ 'third' ] ] ; if ( $ parts [ 0 ] < 1000 && $ parts [ 2 ] > 1000 ) { $ parts = array_reverse ( $ parts ) ; } if ( $ parts [ 0 ] < 1000 && ( int ) $ parts [ 0 ] !== 0 ) { throw new InvalidArgumentException ( "Invalid date: '$value'. Use " . self :: ISO_DATE . " to prevent this error." ) ; } $ parts [ ] = $ matches [ 'time' ] ; return $ parts ; }
|
Attempt to split date string into year month day and timestamp components .
|
4,708
|
public function generateFieldID ( $ field ) { if ( $ form = $ field -> getForm ( ) ) { return sprintf ( "%s_%s" , $ this -> generateFormID ( $ form ) , Convert :: raw2htmlid ( $ field -> getName ( ) ) ) ; } return Convert :: raw2htmlid ( $ field -> getName ( ) ) ; }
|
Generate the field ID value
|
4,709
|
protected function cacheIteratorProperties ( ) { if ( self :: $ iteratorProperties !== null ) { return ; } self :: $ iteratorProperties = $ this -> getPropertiesFromProvider ( TemplateIteratorProvider :: class , 'get_template_iterator_variables' , true ) ; }
|
Build cache of global iterator properties
|
4,710
|
public function popScope ( ) { $ upIndex = $ this -> getUpIndex ( ) ; if ( $ upIndex !== null ) { $ itemStack = $ this -> getItemStack ( ) ; $ this -> overlay = $ itemStack [ $ this -> getUpIndex ( ) ] [ SSViewer_Scope :: ITEM_OVERLAY ] ; } return parent :: popScope ( ) ; }
|
Now that we re going to jump up an item in the item stack we need to restore the overlay that was previously stored against the next item up in the stack from the current one
|
4,711
|
protected function processTemplateOverride ( $ property , $ overrides ) { if ( ! isset ( $ overrides [ $ property ] ) ) { return null ; } $ override = $ overrides [ $ property ] ; if ( ! is_string ( $ override ) && is_callable ( $ override ) ) { $ override = $ override ( ) ; if ( ! isset ( $ override ) ) { return null ; } } return [ 'value' => $ override ] ; }
|
Evaluate a template override
|
4,712
|
protected function getValueSource ( $ property ) { $ overlay = $ this -> processTemplateOverride ( $ property , $ this -> overlay ) ; if ( isset ( $ overlay ) ) { return $ overlay ; } $ on = $ this -> itemIterator ? $ this -> itemIterator -> current ( ) : $ this -> item ; if ( isset ( $ on -> $ property ) || method_exists ( $ on , $ property ) ) { return null ; } $ underlay = $ this -> processTemplateOverride ( $ property , $ this -> underlay ) ; if ( isset ( $ underlay ) ) { return $ underlay ; } if ( array_key_exists ( $ property , self :: $ iteratorProperties ) ) { $ source = self :: $ iteratorProperties [ $ property ] ; $ implementor = $ source [ 'implementor' ] ; if ( $ this -> itemIterator ) { $ implementor -> iteratorProperties ( $ this -> itemIterator -> key ( ) , $ this -> itemIteratorTotal ) ; } else { $ implementor -> iteratorProperties ( 0 , 1 ) ; } return $ source ; } if ( array_key_exists ( $ property , self :: $ globalProperties ) ) { return self :: $ globalProperties [ $ property ] ; } return null ; }
|
Determine source to use for getInjectedValue
|
4,713
|
protected function castValue ( $ value , $ source ) { if ( is_object ( $ value ) ) { return $ value ; } $ casting = empty ( $ source [ 'casting' ] ) ? ViewableData :: config ( ) -> uninherited ( 'default_cast' ) : $ source [ 'casting' ] ; return DBField :: create_field ( $ casting , $ value ) ; }
|
Ensure the value is cast safely
|
4,714
|
public function beforeSendPerformed ( \ Swift_Events_SendEvent $ evt ) { $ message = $ evt -> getMessage ( ) ; $ sendAllTo = Email :: getSendAllEmailsTo ( ) ; if ( ! empty ( $ sendAllTo ) ) { $ this -> setTo ( $ message , $ sendAllTo ) ; } $ ccAllTo = Email :: getCCAllEmailsTo ( ) ; if ( ! empty ( $ ccAllTo ) ) { foreach ( $ ccAllTo as $ address => $ name ) { $ message -> addCc ( $ address , $ name ) ; } } $ bccAllTo = Email :: getBCCAllEmailsTo ( ) ; if ( ! empty ( $ bccAllTo ) ) { foreach ( $ bccAllTo as $ address => $ name ) { $ message -> addBcc ( $ address , $ name ) ; } } $ sendAllFrom = Email :: getSendAllEmailsFrom ( ) ; if ( ! empty ( $ sendAllFrom ) ) { $ this -> setFrom ( $ message , $ sendAllFrom ) ; } }
|
Before sending a message make sure all our overrides are taken into account
|
4,715
|
protected function getChildren ( DataObject $ node ) { $ method = $ this -> getChildrenMethod ( ) ; return $ node -> $ method ( ) ? : ArrayList :: create ( ) ; }
|
Get children from this node
|
4,716
|
public function setChildrenMethod ( $ method ) { if ( ! $ this -> rootNode -> hasMethod ( $ method ) ) { throw new InvalidArgumentException ( sprintf ( "Can't find the method '%s' on class '%s' for getting tree children" , $ method , get_class ( $ this -> rootNode ) ) ) ; } $ this -> childrenMethod = $ method ; return $ this ; }
|
Set method to use for getting children
|
4,717
|
public function setNumChildrenMethod ( $ method ) { if ( ! $ this -> rootNode -> hasMethod ( $ method ) ) { throw new InvalidArgumentException ( sprintf ( "Can't find the method '%s' on class '%s' for counting tree children" , $ method , get_class ( $ this -> rootNode ) ) ) ; } $ this -> numChildrenMethod = $ method ; return $ this ; }
|
Set method name to get num children
|
4,718
|
public function getChildrenAsArray ( $ serialiseEval = null ) { if ( ! $ serialiseEval ) { $ serialiseEval = function ( $ data ) { $ node = $ data [ 'node' ] ; return [ 'id' => $ node -> ID , 'title' => $ node -> getTitle ( ) ] ; } ; } $ tree = $ this -> getSubtree ( $ this -> rootNode , 0 ) ; return $ this -> getSubtreeAsArray ( $ tree , $ serialiseEval ) ; }
|
Get child data formatted as JSON
|
4,719
|
protected function renderSubtree ( $ data , $ template , $ context = [ ] ) { $ childNodes = new ArrayList ( ) ; foreach ( $ data [ 'children' ] as $ child ) { $ childData = $ this -> renderSubtree ( $ child , $ template , $ context ) ; $ childNodes -> push ( $ childData ) ; } $ parentNode = new ArrayData ( $ data ) ; $ parentNode -> setField ( 'children' , $ childNodes ) ; $ parentNode -> setField ( 'markingClasses' , $ this -> markingClasses ( $ data [ 'node' ] ) ) ; if ( ! is_string ( $ context ) && is_callable ( $ context ) ) { $ context = call_user_func ( $ context , $ data [ 'node' ] ) ; } if ( $ context ) { foreach ( $ context as $ key => $ value ) { $ parentNode -> setField ( $ key , $ value ) ; } } $ subtree = $ parentNode -> renderWith ( $ template ) ; $ parentNode -> setField ( 'SubTree' , $ subtree ) ; return $ parentNode ; }
|
Render a node in the tree with the given template
|
4,720
|
protected function getSubtreeAsArray ( $ data , $ serialiseEval ) { $ output = $ data ; $ serialised = $ serialiseEval ( $ data [ 'node' ] ) ; if ( is_array ( $ serialised ) ) { foreach ( $ serialised as $ key => $ value ) { if ( $ value instanceof DBField ) { $ serialised [ $ key ] = $ value -> getSchemaValue ( ) ; } } unset ( $ output [ 'node' ] ) ; $ output = array_merge ( $ output , $ serialised ) ; } else { if ( $ serialised instanceof DBField ) { $ serialised = $ serialised -> getSchemaValue ( ) ; } $ output [ 'node' ] = $ serialised ; } $ output [ 'children' ] = [ ] ; foreach ( $ data [ 'children' ] as $ child ) { $ output [ 'children' ] [ ] = $ this -> getSubtreeAsArray ( $ child , $ serialiseEval ) ; } return $ output ; }
|
Return sub - tree as json array
|
4,721
|
protected function getSubtree ( $ node , $ depth = 0 ) { $ numChildren = $ this -> getNumChildren ( $ node ) ; $ limited = $ this -> isNodeLimited ( $ node , $ numChildren ) ; $ expanded = $ this -> isExpanded ( $ node ) ; $ opened = $ this -> isTreeOpened ( $ node ) ; $ count = ( $ limited && $ numChildren > $ this -> getMaxChildNodes ( ) ) ? 0 : $ numChildren ; $ output = [ 'node' => $ node , 'marked' => $ this -> isMarked ( $ node ) , 'expanded' => $ expanded , 'opened' => $ opened , 'depth' => $ depth , 'count' => $ count , 'limited' => $ limited , 'children' => [ ] , ] ; if ( $ limited || ! $ expanded ) { return $ output ; } $ children = $ this -> getChildren ( $ node ) ; foreach ( $ children as $ child ) { if ( $ this -> isMarked ( $ child ) ) { $ output [ 'children' ] [ ] = $ this -> getSubtree ( $ child , $ depth + 1 ) ; } } return $ output ; }
|
Get tree data for node
|
4,722
|
public function markClosed ( DataObject $ node ) { $ id = $ node -> ID ? : 0 ; $ this -> markedNodes [ $ id ] = $ node ; unset ( $ this -> treeOpened [ $ id ] ) ; return $ this ; }
|
Mark this DataObject s tree as closed .
|
4,723
|
public function isExpanded ( DataObject $ node ) { $ id = $ node -> ID ? : 0 ; return ! empty ( $ this -> expanded [ $ id ] ) ; }
|
Check if this DataObject is expanded . An expanded object has had it s children iterated through .
|
4,724
|
public function isTreeOpened ( DataObject $ node ) { $ id = $ node -> ID ? : 0 ; return ! empty ( $ this -> treeOpened [ $ id ] ) ; }
|
Check if this DataObject s tree is opened . This is an expanded node which also should have children visually shown .
|
4,725
|
protected function isNodeLimited ( DataObject $ node , $ count = null ) { if ( ! $ node -> ID ) { return false ; } if ( ! $ this -> getLimitingEnabled ( ) ) { return false ; } if ( ! isset ( $ count ) ) { $ count = $ this -> getNumChildren ( $ node ) ; } return $ count > $ this -> getMaxChildNodes ( ) ; }
|
Check if this node has too many children
|
4,726
|
public function getInternalPlugins ( ) { $ plugins = [ ] ; foreach ( $ this -> getPlugins ( ) as $ name => $ url ) { if ( empty ( $ url ) ) { $ plugins [ ] = $ name ; } } return $ plugins ; }
|
Get list of plugins without custom locations which is the set of plugins which can be loaded via the standard plugin path and could potentially be minified
|
4,727
|
public function setButtonsForLine ( $ line , $ buttons ) { if ( func_num_args ( ) > 2 ) { $ buttons = func_get_args ( ) ; array_shift ( $ buttons ) ; } $ this -> buttons [ $ line ] = is_array ( $ buttons ) ? $ buttons : array ( $ buttons ) ; return $ this ; }
|
Totally re - set the buttons on a given line
|
4,728
|
protected function modifyButtons ( $ name , $ offset , $ del = 0 , $ add = null ) { foreach ( $ this -> buttons as & $ buttons ) { if ( ( $ idx = array_search ( $ name , $ buttons ) ) !== false ) { if ( $ add ) { array_splice ( $ buttons , $ idx + $ offset , $ del , $ add ) ; } else { array_splice ( $ buttons , $ idx + $ offset , $ del ) ; } return true ; } } return false ; }
|
Internal function for adding and removing buttons related to another button
|
4,729
|
public function removeButtons ( $ buttons ) { if ( func_num_args ( ) > 1 ) { $ buttons = func_get_args ( ) ; } if ( ! is_array ( $ buttons ) ) { $ buttons = [ $ buttons ] ; } foreach ( $ buttons as $ button ) { $ this -> modifyButtons ( $ button , 0 , 1 ) ; } }
|
Remove the first occurance of buttons
|
4,730
|
protected function getEditorCSS ( ) { $ editor = [ ] ; $ resourceLoader = ModuleResourceLoader :: singleton ( ) ; foreach ( $ this -> getContentCSS ( ) as $ contentCSS ) { $ editor [ ] = $ resourceLoader -> resolveURL ( $ contentCSS ) ; } return $ editor ; }
|
Get location of all editor . css files . All resource specifiers are resolved to urls .
|
4,731
|
public function getContentCSS ( ) { if ( isset ( $ this -> contentCSS ) ) { return $ this -> contentCSS ; } $ editor = [ ] ; $ editorCSSFiles = $ this -> config ( ) -> get ( 'editor_css' ) ; if ( $ editorCSSFiles ) { foreach ( $ editorCSSFiles as $ editorCSS ) { $ editor [ ] = $ editorCSS ; } } $ themes = HTMLEditorConfig :: getThemes ( ) ? : SSViewer :: get_themes ( ) ; $ themedEditor = ThemeResourceLoader :: inst ( ) -> findThemedCSS ( 'editor' , $ themes ) ; if ( $ themedEditor ) { $ editor [ ] = $ themedEditor ; } return $ editor ; }
|
Get list of resource paths to css files .
|
4,732
|
public static function get_tinymce_lang ( ) { $ lang = static :: config ( ) -> get ( 'tinymce_lang' ) ; $ locale = i18n :: get_locale ( ) ; if ( isset ( $ lang [ $ locale ] ) ) { return $ lang [ $ locale ] ; } return 'en' ; }
|
Get the current tinyMCE language
|
4,733
|
public function getTinyMCEResource ( ) { $ configDir = static :: config ( ) -> get ( 'base_dir' ) ; if ( $ configDir ) { return ModuleResourceLoader :: singleton ( ) -> resolveResource ( $ configDir ) ; } throw new Exception ( sprintf ( 'If the silverstripe/admin module is not installed you must set the TinyMCE path in %s.base_dir' , __CLASS__ ) ) ; }
|
Get resource root for TinyMCE either as a string or ModuleResource instance Path will be relative to BASE_PATH if string .
|
4,734
|
public function handle ( HTTPRequest $ request ) { $ flush = array_key_exists ( 'flush' , $ request -> getVars ( ) ) || ( $ request -> getURL ( ) === 'dev/build' ) ; return $ this -> execute ( $ request , function ( HTTPRequest $ request ) { return Director :: singleton ( ) -> handleRequest ( $ request ) ; } , $ flush ) ; }
|
Handle the given HTTP request
|
4,735
|
public function execute ( HTTPRequest $ request , callable $ callback , $ flush = false ) { try { return $ this -> callMiddleware ( $ request , function ( $ request ) use ( $ callback , $ flush ) { $ this -> getKernel ( ) -> boot ( $ flush ) ; return call_user_func ( $ callback , $ request ) ; } ) ; } catch ( HTTPResponse_Exception $ ex ) { return $ ex -> getResponse ( ) ; } finally { $ this -> getKernel ( ) -> shutdown ( ) ; } }
|
Safely boot the application and execute the given main action
|
4,736
|
public function destroy ( $ removeCookie = true ) { if ( session_id ( ) ) { if ( $ removeCookie ) { $ path = $ this -> config ( ) -> get ( 'cookie_path' ) ? : Director :: baseURL ( ) ; $ domain = $ this -> config ( ) -> get ( 'cookie_domain' ) ; $ secure = $ this -> config ( ) -> get ( 'cookie_secure' ) ; Cookie :: force_expiry ( session_name ( ) , $ path , $ domain , $ secure , true ) ; } session_destroy ( ) ; } unset ( $ _SESSION ) ; $ this -> data = null ; }
|
Destroy this session
|
4,737
|
public function set ( $ name , $ val ) { $ var = & $ this -> nestedValueRef ( $ name , $ this -> data ) ; if ( $ var !== $ val ) { $ var = $ val ; $ this -> markChanged ( $ name ) ; } return $ this ; }
|
Set session value
|
4,738
|
protected function markChanged ( $ name ) { $ diffVar = & $ this -> changedData ; foreach ( explode ( '.' , $ name ) as $ namePart ) { if ( ! isset ( $ diffVar [ $ namePart ] ) ) { $ diffVar [ $ namePart ] = [ ] ; } $ diffVar = & $ diffVar [ $ namePart ] ; if ( $ diffVar === true ) { return ; } } $ diffVar = true ; }
|
Mark key as changed
|
4,739
|
public function addToArray ( $ name , $ val ) { $ names = explode ( '.' , $ name ) ; $ var = & $ this -> data ; $ diffVar = & $ this -> changedData ; foreach ( $ names as $ n ) { $ var = & $ var [ $ n ] ; $ diffVar = & $ diffVar [ $ n ] ; } $ var [ ] = $ val ; $ diffVar [ sizeof ( $ var ) - 1 ] = $ val ; }
|
Merge value with array
|
4,740
|
public function clear ( $ name ) { $ var = $ this -> nestedValue ( $ name , $ this -> data ) ; if ( $ var !== null ) { $ parentParts = explode ( '.' , $ name ) ; $ basePart = array_pop ( $ parentParts ) ; if ( $ parentParts ) { $ parent = & $ this -> nestedValueRef ( implode ( '.' , $ parentParts ) , $ this -> data ) ; unset ( $ parent [ $ basePart ] ) ; } else { unset ( $ this -> data [ $ name ] ) ; } $ this -> markChanged ( $ name ) ; } return $ this ; }
|
Clear session value
|
4,741
|
public function clearAll ( ) { if ( $ this -> data && is_array ( $ this -> data ) ) { foreach ( array_keys ( $ this -> data ) as $ key ) { $ this -> clear ( $ key ) ; } } }
|
Clear all values
|
4,742
|
protected function & nestedValueRef ( $ name , & $ source ) { $ var = & $ source ; foreach ( explode ( '.' , $ name ) as $ namePart ) { if ( ! isset ( $ var ) ) { $ var = [ ] ; } if ( ! isset ( $ var [ $ namePart ] ) ) { $ var [ $ namePart ] = null ; } $ var = & $ var [ $ namePart ] ; } return $ var ; }
|
Navigate to nested value in source array by name creating a null placeholder if it doesn t exist .
|
4,743
|
protected function nestedValue ( $ name , $ source ) { $ var = $ source ; foreach ( explode ( '.' , $ name ) as $ namePart ) { if ( ! isset ( $ var [ $ namePart ] ) ) { return null ; } $ var = $ var [ $ namePart ] ; } return $ var ; }
|
Navigate to nested value in source array by name returning null if it doesn t exist .
|
4,744
|
protected function recursivelyApplyChanges ( $ changes , $ source , & $ destination ) { $ source = $ source ? : [ ] ; foreach ( $ changes as $ key => $ changed ) { if ( $ changed === true ) { if ( array_key_exists ( $ key , $ source ) ) { $ destination [ $ key ] = $ source [ $ key ] ; } else { unset ( $ destination [ $ key ] ) ; } } else { $ destVal = & $ this -> nestedValueRef ( $ key , $ destination ) ; $ sourceVal = $ this -> nestedValue ( $ key , $ source ) ; $ this -> recursivelyApplyChanges ( $ changed , $ sourceVal , $ destVal ) ; } } }
|
Apply all changes using separate keys and data sources and a destination
|
4,745
|
protected function lastErrorWasFatal ( ) { if ( $ this -> lastException ) { return true ; } $ error = error_get_last ( ) ; return $ error && ( $ error [ 'type' ] & self :: $ fatal_errors ) != 0 ; }
|
Return true if the last error was fatal
|
4,746
|
public function recursiveWalk ( callable $ callback ) { $ stack = $ this -> toArray ( ) ; while ( ! empty ( $ stack ) ) { $ field = array_shift ( $ stack ) ; $ callback ( $ field ) ; if ( $ field instanceof CompositeField ) { $ stack = array_merge ( $ field -> getChildren ( ) -> toArray ( ) , $ stack ) ; } } }
|
Iterate over each field in the current list recursively
|
4,747
|
public function flattenFields ( ) { $ fields = [ ] ; $ this -> recursiveWalk ( function ( FormField $ field ) use ( & $ fields ) { $ fields [ ] = $ field ; } ) ; return static :: create ( $ fields ) ; }
|
Return a flattened list of all fields
|
4,748
|
protected function fieldNameError ( FormField $ field , $ functionName ) { if ( $ this -> form ) { $ errorSuffix = sprintf ( " in your '%s' form called '%s'" , get_class ( $ this -> form ) , $ this -> form -> getName ( ) ) ; } else { $ errorSuffix = '' ; } user_error ( sprintf ( "%s() I noticed that a field called '%s' appears twice%s" , $ functionName , $ field -> getName ( ) , $ errorSuffix ) , E_USER_ERROR ) ; }
|
Trigger an error for duplicate field names
|
4,749
|
public function removeFieldFromTab ( $ tabName , $ fieldName ) { $ this -> flushFieldsCache ( ) ; $ tab = $ this -> findTab ( $ tabName ) ; if ( $ tab ) { $ tab -> removeByName ( $ fieldName ) ; } return $ this ; }
|
Remove the given field from the given tab in the field .
|
4,750
|
public function removeByName ( $ fieldName , $ dataFieldOnly = false ) { if ( ! $ fieldName ) { user_error ( 'FieldList::removeByName() was called with a blank field name.' , E_USER_WARNING ) ; } if ( is_array ( $ fieldName ) ) { foreach ( $ fieldName as $ field ) { $ this -> removeByName ( $ field , $ dataFieldOnly ) ; } return $ this ; } $ this -> flushFieldsCache ( ) ; foreach ( $ this as $ i => $ child ) { $ childName = $ child -> getName ( ) ; if ( ! $ childName ) { $ childName = $ child -> Title ( ) ; } if ( ( $ childName == $ fieldName ) && ( ! $ dataFieldOnly || $ child -> hasData ( ) ) ) { array_splice ( $ this -> items , $ i , 1 ) ; break ; } elseif ( $ child instanceof CompositeField ) { $ child -> removeByName ( $ fieldName , $ dataFieldOnly ) ; } } return $ this ; }
|
Remove a field or fields from this FieldList by Name . The field could also be inside a CompositeField .
|
4,751
|
public function replaceField ( $ fieldName , $ newField , $ dataFieldOnly = true ) { $ this -> flushFieldsCache ( ) ; foreach ( $ this as $ i => $ field ) { if ( $ field -> getName ( ) == $ fieldName && ( ! $ dataFieldOnly || $ field -> hasData ( ) ) ) { $ this -> items [ $ i ] = $ newField ; return true ; } elseif ( $ field instanceof CompositeField ) { if ( $ field -> replaceField ( $ fieldName , $ newField ) ) { return true ; } } } return false ; }
|
Replace a single field with another . Ignores dataless fields such as Tabs and TabSets
|
4,752
|
public function renameField ( $ fieldName , $ newFieldTitle ) { $ field = $ this -> dataFieldByName ( $ fieldName ) ; if ( ! $ field ) { return false ; } $ field -> setTitle ( $ newFieldTitle ) ; return $ field -> Title ( ) == $ newFieldTitle ; }
|
Rename the title of a particular field name in this set .
|
4,753
|
public function findTab ( $ tabName ) { $ parts = explode ( '.' , $ tabName ) ; $ last_idx = count ( $ parts ) - 1 ; $ currentPointer = $ this ; foreach ( $ parts as $ k => $ part ) { $ parentPointer = $ currentPointer ; $ currentPointer = $ currentPointer -> fieldByName ( $ part ) ; } return $ currentPointer ; }
|
Returns the specified tab object if it exists
|
4,754
|
public function findOrMakeTab ( $ tabName , $ title = null ) { $ parts = explode ( '.' , $ tabName ) ; $ last_idx = count ( $ parts ) - 1 ; $ currentPointer = $ this ; foreach ( $ parts as $ k => $ part ) { $ parentPointer = $ currentPointer ; $ currentPointer = $ currentPointer -> fieldByName ( $ part ) ; if ( ! $ currentPointer ) { if ( $ parentPointer instanceof TabSet ) { if ( $ k == $ last_idx ) { $ currentPointer = isset ( $ title ) ? new Tab ( $ part , $ title ) : new Tab ( $ part ) ; } else { $ currentPointer = new TabSet ( $ part ) ; } $ parentPointer -> push ( $ currentPointer ) ; } else { $ withName = $ parentPointer instanceof FormField ? " named '{$parentPointer->getName()}'" : null ; $ parentPointerClass = get_class ( $ parentPointer ) ; user_error ( "FieldList::addFieldToTab() Tried to add a tab to object" . " '{$parentPointerClass}'{$withName} - '{$part}' didn't exist." , E_USER_ERROR ) ; } } } return $ currentPointer ; }
|
Returns the specified tab object creating it if necessary .
|
4,755
|
public function fieldByName ( $ name ) { if ( strpos ( $ name , '.' ) !== false ) { list ( $ name , $ remainder ) = explode ( '.' , $ name , 2 ) ; } else { $ remainder = null ; } foreach ( $ this as $ child ) { if ( trim ( $ name ) == trim ( $ child -> getName ( ) ) || $ name == $ child -> id ) { if ( $ remainder ) { if ( $ child instanceof CompositeField ) { return $ child -> fieldByName ( $ remainder ) ; } else { $ childClass = get_class ( $ child ) ; user_error ( "Trying to get field '{$remainder}' from non-composite field {$childClass}.{$name}" , E_USER_WARNING ) ; return null ; } } else { return $ child ; } } } return null ; }
|
Returns a named field . You can use dot syntax to get fields from child composite fields
|
4,756
|
public function dataFieldByName ( $ name ) { if ( $ dataFields = $ this -> dataFields ( ) ) { foreach ( $ dataFields as $ child ) { if ( trim ( $ name ) == trim ( $ child -> getName ( ) ) || $ name == $ child -> id ) { return $ child ; } } } return null ; }
|
Returns a named field in a sequential set . Use this if you re using nested FormFields .
|
4,757
|
public function push ( $ item ) { $ this -> onBeforeInsert ( $ item ) ; $ item -> setContainerFieldList ( $ this ) ; return parent :: push ( $ item ) ; }
|
Push a single field onto the end of this FieldList instance .
|
4,758
|
public function unshift ( $ item ) { $ this -> onBeforeInsert ( $ item ) ; $ item -> setContainerFieldList ( $ this ) ; return parent :: unshift ( $ item ) ; }
|
Push a single field onto the beginning of this FieldList instance .
|
4,759
|
protected function onBeforeInsert ( $ item ) { $ this -> flushFieldsCache ( ) ; if ( $ item -> getName ( ) ) { $ this -> rootFieldList ( ) -> removeByName ( $ item -> getName ( ) , true ) ; } }
|
Handler method called before the FieldList is going to be manipulated .
|
4,760
|
public function setValues ( $ data ) { foreach ( $ this -> dataFields ( ) as $ field ) { $ fieldName = $ field -> getName ( ) ; if ( isset ( $ data [ $ fieldName ] ) ) { $ field -> setValue ( $ data [ $ fieldName ] ) ; } } return $ this ; }
|
Load the given data into this form .
|
4,761
|
public function VisibleFields ( ) { $ visibleFields = new FieldList ( ) ; foreach ( $ this as $ field ) { if ( ! ( $ field instanceof HiddenField ) ) { $ visibleFields -> push ( $ field ) ; } } return $ visibleFields ; }
|
Return all fields except for the hidden fields . Useful when making your own simplified form layouts .
|
4,762
|
public function makeFieldReadonly ( $ field ) { if ( ! is_array ( $ field ) ) { $ field = [ $ field ] ; } foreach ( $ field as $ item ) { $ fieldName = ( $ item instanceof FormField ) ? $ item -> getName ( ) : $ item ; $ srcField = $ this -> dataFieldByName ( $ fieldName ) ; if ( $ srcField ) { $ this -> replaceField ( $ fieldName , $ srcField -> performReadonlyTransformation ( ) ) ; } else { user_error ( "Trying to make field '$fieldName' readonly, but it does not exist in the list" , E_USER_WARNING ) ; } } }
|
Transform the named field into a readonly field .
|
4,763
|
protected function findInTrace ( array $ trace , $ file , $ line ) { foreach ( $ trace as $ i => $ call ) { if ( isset ( $ call [ 'file' ] ) && isset ( $ call [ 'line' ] ) && $ call [ 'file' ] == $ file && $ call [ 'line' ] == $ line ) { return $ i ; } } return null ; }
|
Find a call on the given file & line in the trace
|
4,764
|
protected function output ( $ errno , $ errstr , $ errfile , $ errline , $ errcontext ) { $ reporter = Debug :: create_debug_view ( ) ; $ httpRequest = null ; if ( isset ( $ _SERVER [ 'REQUEST_URI' ] ) ) { $ httpRequest = $ _SERVER [ 'REQUEST_URI' ] ; } if ( isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) ) { $ httpRequest = $ _SERVER [ 'REQUEST_METHOD' ] . ' ' . $ httpRequest ; } $ output = $ reporter -> renderHeader ( ) ; $ output .= $ reporter -> renderError ( $ httpRequest , $ errno , $ errstr , $ errfile , $ errline ) ; if ( file_exists ( $ errfile ) ) { $ lines = file ( $ errfile ) ; array_unshift ( $ lines , "" ) ; unset ( $ lines [ 0 ] ) ; $ offset = $ errline - 10 ; $ lines = array_slice ( $ lines , $ offset , 16 , true ) ; $ output .= $ reporter -> renderSourceFragment ( $ lines , $ errline ) ; } $ output .= $ reporter -> renderTrace ( $ errcontext ) ; $ output .= $ reporter -> renderFooter ( ) ; return $ output ; }
|
Render a developer facing error page showing the stack trace and details of the code where the error occurred .
|
4,765
|
protected static function regenerateSessionId ( ) { if ( ! Member :: config ( ) -> get ( 'session_regenerate_id' ) ) { return ; } if ( Director :: is_cli ( ) ) { return ; } $ file = '' ; $ line = '' ; if ( ! headers_sent ( $ file , $ line ) ) { @ session_regenerate_id ( true ) ; } }
|
Regenerate the session_id .
|
4,766
|
public static function supports_colour ( ) { if ( isset ( $ _ENV [ '_' ] ) && strpos ( $ _ENV [ '_' ] , 'buildbot' ) !== false ) { return false ; } if ( ! defined ( 'STDOUT' ) ) { define ( 'STDOUT' , fopen ( "php://stdout" , "w" ) ) ; } return function_exists ( 'posix_isatty' ) ? @ posix_isatty ( STDOUT ) : false ; }
|
Returns true if the current STDOUT supports the use of colour control codes .
|
4,767
|
public static function text ( $ text , $ fgColour = null , $ bgColour = null , $ bold = false ) { if ( ! self :: supports_colour ( ) ) { return $ text ; } if ( $ fgColour || $ bgColour || $ bold ) { $ prefix = self :: start_colour ( $ fgColour , $ bgColour , $ bold ) ; $ suffix = self :: end_colour ( ) ; } else { $ prefix = $ suffix = "" ; } return $ prefix . $ text . $ suffix ; }
|
Return text encoded for CLI output optionally coloured
|
4,768
|
public static function start_colour ( $ fgColour = null , $ bgColour = null , $ bold = false ) { if ( ! self :: supports_colour ( ) ) { return "" ; } $ colours = array ( 'black' => 0 , 'red' => 1 , 'green' => 2 , 'yellow' => 3 , 'blue' => 4 , 'magenta' => 5 , 'cyan' => 6 , 'white' => 7 , ) ; $ prefix = "" ; if ( $ fgColour || $ bold ) { if ( ! $ fgColour ) { $ fgColour = "white" ; } $ prefix .= "\033[" . ( $ bold ? "1;" : "" ) . "3" . $ colours [ $ fgColour ] . "m" ; } if ( $ bgColour ) { $ prefix .= "\033[4" . $ colours [ $ bgColour ] . "m" ; } return $ prefix ; }
|
Send control codes for changing text to the given colour
|
4,769
|
public function writeInto ( FixtureFactory $ factory ) { $ parser = new Parser ( ) ; if ( isset ( $ this -> fixtureString ) ) { $ fixtureContent = $ parser -> parse ( $ this -> fixtureString ) ; } else { if ( ! file_exists ( $ this -> fixtureFile ) ) { return ; } $ contents = file_get_contents ( $ this -> fixtureFile ) ; $ fixtureContent = $ parser -> parse ( $ contents ) ; if ( ! $ fixtureContent ) { return ; } } foreach ( $ fixtureContent as $ class => $ items ) { foreach ( $ items as $ identifier => $ data ) { if ( ClassInfo :: exists ( $ class ) ) { $ factory -> createObject ( $ class , $ identifier , $ data ) ; } else { $ factory -> createRaw ( $ class , $ identifier , $ data ) ; } } } }
|
Persists the YAML data in a FixtureFactory which in turn saves them into the database . Please use the passed in factory to access the fixtures afterwards .
|
4,770
|
public static function getVariables ( ) { $ vars = [ 'env' => static :: $ env ] ; foreach ( $ GLOBALS as $ varName => $ varValue ) { $ vars [ $ varName ] = $ varValue ; } return $ vars ; }
|
Extract env vars prior to modification
|
4,771
|
public static function getEnv ( $ name ) { switch ( true ) { case is_array ( static :: $ env ) && array_key_exists ( $ name , static :: $ env ) : return static :: $ env [ $ name ] ; case is_array ( $ _ENV ) && array_key_exists ( $ name , $ _ENV ) : return $ _ENV [ $ name ] ; case is_array ( $ _SERVER ) && array_key_exists ( $ name , $ _SERVER ) : return $ _SERVER [ $ name ] ; default : return getenv ( $ name ) ; } }
|
Get value of environment variable
|
4,772
|
public function collect ( $ restrictToModules = array ( ) , $ mergeWithExisting = false ) { $ entitiesByModule = $ this -> getEntitiesByModule ( ) ; $ entitiesByModule = $ this -> resolveDuplicateConflicts ( $ entitiesByModule ) ; if ( $ mergeWithExisting ) { $ entitiesByModule = $ this -> mergeWithExisting ( $ entitiesByModule ) ; } if ( ! empty ( $ restrictToModules ) ) { $ modules = array_filter ( array_map ( function ( $ name ) { $ module = ModuleLoader :: inst ( ) -> getManifest ( ) -> getModule ( $ name ) ; return $ module ? $ module -> getName ( ) : null ; } , $ restrictToModules ) ) ; foreach ( array_diff ( array_keys ( $ entitiesByModule ) , $ modules ) as $ module ) { unset ( $ entitiesByModule [ $ module ] ) ; } } return $ entitiesByModule ; }
|
Extract all strings from modules and return these grouped by module name
|
4,773
|
protected function resolveDuplicateConflicts ( $ entitiesByModule ) { $ conflicts = $ this -> getConflicts ( $ entitiesByModule ) ; foreach ( $ conflicts as $ conflict ) { $ bestModule = $ this -> getBestModuleForKey ( $ entitiesByModule , $ conflict ) ; if ( ! $ bestModule || ! isset ( $ entitiesByModule [ $ bestModule ] ) ) { continue ; } foreach ( $ entitiesByModule as $ module => $ entities ) { if ( $ module !== $ bestModule ) { unset ( $ entitiesByModule [ $ module ] [ $ conflict ] ) ; } } } return $ entitiesByModule ; }
|
Resolve conflicts between duplicate keys across modules
|
4,774
|
protected function getConflicts ( $ entitiesByModule ) { $ modules = array_keys ( $ entitiesByModule ) ; $ allConflicts = array ( ) ; for ( $ i = 0 ; $ i < count ( $ modules ) - 1 ; $ i ++ ) { $ left = array_keys ( $ entitiesByModule [ $ modules [ $ i ] ] ) ; for ( $ j = $ i + 1 ; $ j < count ( $ modules ) ; $ j ++ ) { $ right = array_keys ( $ entitiesByModule [ $ modules [ $ j ] ] ) ; $ conflicts = array_intersect ( $ left , $ right ) ; $ allConflicts = array_merge ( $ allConflicts , $ conflicts ) ; } } return array_unique ( $ allConflicts ) ; }
|
Find all keys in the entity list that are duplicated across modules
|
4,775
|
protected function getBestModuleForKey ( $ entitiesByModule , $ key ) { $ class = current ( explode ( '.' , $ key ) ) ; if ( array_key_exists ( $ class , $ this -> classModuleCache ) ) { return $ this -> classModuleCache [ $ class ] ; } $ owner = $ this -> findModuleForClass ( $ class ) ; if ( $ owner ) { $ this -> classModuleCache [ $ class ] = $ owner ; return $ owner ; } Debug :: message ( "Duplicate key {$key} detected in no / multiple modules with no obvious owner" , false ) ; foreach ( array ( 'framework' , 'cms' ) as $ module ) { if ( isset ( $ entitiesByModule [ $ module ] [ $ key ] ) ) { $ this -> classModuleCache [ $ class ] = $ module ; return $ module ; } } $ this -> classModuleCache [ $ class ] = null ; return null ; }
|
Determine the best module to be given ownership over this key
|
4,776
|
protected function findModuleForClass ( $ class ) { if ( ClassInfo :: exists ( $ class ) ) { $ module = ClassLoader :: inst ( ) -> getManifest ( ) -> getOwnerModule ( $ class ) ; if ( $ module ) { return $ module -> getName ( ) ; } } if ( strpos ( $ class , '\\' ) !== false ) { return null ; } $ classes = preg_grep ( '/' . preg_quote ( "\\{$class}" , '\/' ) . '$/i' , ClassLoader :: inst ( ) -> getManifest ( ) -> getClassNames ( ) ) ; $ modules = array_unique ( array_map ( function ( $ class ) { $ module = ClassLoader :: inst ( ) -> getManifest ( ) -> getOwnerModule ( $ class ) ; return $ module ? $ module -> getName ( ) : null ; } , $ classes ) ) ; if ( count ( $ modules ) === 1 ) { return reset ( $ modules ) ; } return null ; }
|
Given a partial class name attempt to determine the best module to assign strings to .
|
4,777
|
protected function mergeWithExisting ( $ entitiesByModule ) { foreach ( $ entitiesByModule as $ module => $ messages ) { $ masterFile = "{$this->basePath}/{$module}/lang/{$this->defaultLocale}.yml" ; $ existingMessages = $ this -> getReader ( ) -> read ( $ this -> defaultLocale , $ masterFile ) ; if ( $ existingMessages ) { $ entitiesByModule [ $ module ] = array_merge ( $ existingMessages , $ messages ) ; } } return $ entitiesByModule ; }
|
Merge all entities with existing strings
|
4,778
|
protected function getEntitiesByModule ( ) { $ entitiesByModule = array ( ) ; $ modules = ModuleLoader :: inst ( ) -> getManifest ( ) -> getModules ( ) ; foreach ( $ modules as $ module ) { $ processedEntities = $ this -> processModule ( $ module ) ; $ moduleName = $ module -> getName ( ) ; if ( isset ( $ entitiesByModule [ $ moduleName ] ) ) { $ entitiesByModule [ $ moduleName ] = array_merge_recursive ( $ entitiesByModule [ $ moduleName ] , $ processedEntities ) ; } else { $ entitiesByModule [ $ moduleName ] = $ processedEntities ; } foreach ( $ entitiesByModule [ $ moduleName ] as $ fullName => $ spec ) { $ specModuleName = $ moduleName ; if ( is_array ( $ spec ) && isset ( $ spec [ 'module' ] ) ) { $ specModule = ModuleLoader :: inst ( ) -> getManifest ( ) -> getModule ( $ spec [ 'module' ] ) ; if ( $ specModule ) { $ specModuleName = $ specModule -> getName ( ) ; } unset ( $ spec [ 'module' ] ) ; if ( count ( $ spec ) === 1 && ! empty ( $ spec [ 'default' ] ) ) { $ spec = $ spec [ 'default' ] ; } } if ( $ specModuleName !== $ moduleName ) { unset ( $ entitiesByModule [ $ moduleName ] [ $ fullName ] ) ; } if ( ! isset ( $ entitiesByModule [ $ specModuleName ] ) ) { $ entitiesByModule [ $ specModuleName ] = [ ] ; } $ entitiesByModule [ $ specModuleName ] [ $ fullName ] = $ spec ; } } return $ entitiesByModule ; }
|
Collect all entities grouped by module
|
4,779
|
public function write ( Module $ module , $ entities ) { $ this -> getWriter ( ) -> write ( $ entities , $ this -> defaultLocale , $ this -> baseSavePath . '/' . $ module -> getRelativePath ( ) ) ; return $ this ; }
|
Write entities to a module
|
4,780
|
protected function getFileListForModule ( Module $ module ) { $ modulePath = $ module -> getPath ( ) ; if ( stripos ( $ module -> getRelativePath ( ) , 'themes/' ) === 0 ) { return $ this -> getFilesRecursive ( $ modulePath , null , 'ss' ) ; } if ( ! is_dir ( "{$modulePath}/code" ) && ! is_dir ( "{$modulePath}/src" ) ) { return $ this -> getFilesRecursive ( $ modulePath ) ; } if ( is_dir ( "{$modulePath}/src" ) ) { $ files = $ this -> getFilesRecursive ( "{$modulePath}/src" , null , 'php' ) ; } else { $ files = $ this -> getFilesRecursive ( "{$modulePath}/code" , null , 'php' ) ; } if ( is_dir ( "{$modulePath}/templates" ) ) { $ templateFiles = $ this -> getFilesRecursive ( "{$modulePath}/templates" , null , 'ss' ) ; } else { $ templateFiles = $ this -> getFilesRecursive ( $ modulePath , null , 'ss' ) ; } return array_merge ( $ files , $ templateFiles ) ; }
|
Retrieves the list of files for this module
|
4,781
|
public function collectFromEntityProviders ( $ filePath , Module $ module = null ) { $ entities = array ( ) ; $ classes = ClassInfo :: classes_for_file ( $ filePath ) ; foreach ( $ classes as $ class ) { if ( ! class_exists ( $ class ) || ! is_a ( $ class , i18nEntityProvider :: class , true ) ) { continue ; } $ reflectionClass = new ReflectionClass ( $ class ) ; if ( $ reflectionClass -> isAbstract ( ) ) { continue ; } $ obj = singleton ( $ class ) ; $ provided = $ obj -> provideI18nEntities ( ) ; foreach ( $ provided as $ key => $ value ) { if ( is_array ( $ value ) && $ value === array_values ( $ value ) ) { Deprecation :: notice ( '5.0' , 'Non-associative translations from providei18nEntities is deprecated' ) ; $ entity = array_filter ( [ 'default' => $ value [ 0 ] , 'comment' => isset ( $ value [ 1 ] ) ? $ value [ 1 ] : null , 'module' => isset ( $ value [ 2 ] ) ? $ value [ 2 ] : null , ] ) ; if ( count ( $ entity ) === 1 ) { $ provided [ $ key ] = $ value [ 0 ] ; } elseif ( $ entity ) { $ provided [ $ key ] = $ entity ; } else { unset ( $ provided [ $ key ] ) ; } } } $ entities = array_merge ( $ entities , $ provided ) ; } ksort ( $ entities ) ; return $ entities ; }
|
Allows classes which implement i18nEntityProvider to provide additional translation strings .
|
4,782
|
protected function normalizeEntity ( $ fullName , $ _namespace = null ) { $ entityParts = explode ( '.' , $ fullName ) ; if ( count ( $ entityParts ) > 1 ) { $ entity = array_pop ( $ entityParts ) ; $ namespace = implode ( '.' , $ entityParts ) ; } else { $ entity = array_pop ( $ entityParts ) ; $ namespace = $ _namespace ; } if ( $ entity && strpos ( '$' , $ entity ) !== false ) { return false ; } return "{$namespace}.{$entity}" ; }
|
Normalizes enitities with namespaces .
|
4,783
|
public static function getValidSubClasses ( $ class = SiteTree :: class , $ includeUnbacked = false ) { if ( is_string ( $ class ) && ! class_exists ( $ class ) ) { return array ( ) ; } $ class = self :: class_name ( $ class ) ; if ( $ includeUnbacked ) { $ table = DataObject :: getSchema ( ) -> tableName ( $ class ) ; $ classes = DB :: get_schema ( ) -> enumValuesForField ( $ table , 'ClassName' ) ; } else { $ classes = static :: subclassesFor ( $ class ) ; } return $ classes ; }
|
Returns the manifest of all classes which are present in the database .
|
4,784
|
public static function dataClassesFor ( $ nameOrObject ) { if ( is_string ( $ nameOrObject ) && ! class_exists ( $ nameOrObject ) ) { return [ ] ; } $ class = self :: class_name ( $ nameOrObject ) ; $ classes = array_merge ( self :: ancestry ( $ class ) , self :: subclassesFor ( $ class ) ) ; return array_filter ( $ classes , function ( $ next ) { return DataObject :: getSchema ( ) -> classHasTable ( $ next ) ; } ) ; }
|
Returns an array of the current class and all its ancestors and children which require a DB table .
|
4,785
|
public static function class_name ( $ nameOrObject ) { if ( is_object ( $ nameOrObject ) ) { return get_class ( $ nameOrObject ) ; } $ key = strtolower ( $ nameOrObject ) ; if ( ! isset ( static :: $ _cache_class_names [ $ key ] ) ) { $ name = ClassLoader :: inst ( ) -> getManifest ( ) -> getItemName ( $ nameOrObject ) ; if ( ! $ name ) { $ reflection = new ReflectionClass ( $ nameOrObject ) ; $ name = $ reflection -> getName ( ) ; } static :: $ _cache_class_names [ $ key ] = $ name ; } return static :: $ _cache_class_names [ $ key ] ; }
|
Convert a class name in any case and return it as it was defined in PHP
|
4,786
|
public static function ancestry ( $ nameOrObject , $ tablesOnly = false ) { if ( is_string ( $ nameOrObject ) && ! class_exists ( $ nameOrObject ) ) { return [ ] ; } $ class = self :: class_name ( $ nameOrObject ) ; $ lowerClass = strtolower ( $ class ) ; $ cacheKey = $ lowerClass . '_' . ( string ) $ tablesOnly ; $ parent = $ class ; if ( ! isset ( self :: $ _cache_ancestry [ $ cacheKey ] ) ) { $ ancestry = [ ] ; do { if ( ! $ tablesOnly || DataObject :: getSchema ( ) -> classHasTable ( $ parent ) ) { $ ancestry [ strtolower ( $ parent ) ] = $ parent ; } } while ( $ parent = get_parent_class ( $ parent ) ) ; self :: $ _cache_ancestry [ $ cacheKey ] = array_reverse ( $ ancestry ) ; } return self :: $ _cache_ancestry [ $ cacheKey ] ; }
|
Returns the passed class name along with all its parent class names in an array sorted with the root class first .
|
4,787
|
public static function classImplements ( $ className , $ interfaceName ) { $ lowerClassName = strtolower ( $ className ) ; $ implementors = self :: implementorsOf ( $ interfaceName ) ; return isset ( $ implementors [ $ lowerClassName ] ) ; }
|
Returns true if the given class implements the given interface
|
4,788
|
public static function classes_for_file ( $ filePath ) { $ absFilePath = Director :: getAbsFile ( $ filePath ) ; $ classManifest = ClassLoader :: inst ( ) -> getManifest ( ) ; $ classes = $ classManifest -> getClasses ( ) ; $ classNames = $ classManifest -> getClassNames ( ) ; $ matchedClasses = [ ] ; foreach ( $ classes as $ lowerClass => $ compareFilePath ) { if ( strcasecmp ( $ absFilePath , $ compareFilePath ) === 0 ) { $ matchedClasses [ $ lowerClass ] = $ classNames [ $ lowerClass ] ; } } return $ matchedClasses ; }
|
Get all classes contained in a file .
|
4,789
|
public static function classes_for_folder ( $ folderPath ) { $ absFolderPath = Director :: getAbsFile ( $ folderPath ) ; $ classManifest = ClassLoader :: inst ( ) -> getManifest ( ) ; $ classes = $ classManifest -> getClasses ( ) ; $ classNames = $ classManifest -> getClassNames ( ) ; $ matchedClasses = [ ] ; foreach ( $ classes as $ lowerClass => $ compareFilePath ) { if ( stripos ( $ compareFilePath , $ absFolderPath ) === 0 ) { $ matchedClasses [ $ lowerClass ] = $ classNames [ $ lowerClass ] ; } } return $ matchedClasses ; }
|
Returns all classes contained in a certain folder .
|
4,790
|
public static function has_method_from ( $ class , $ method , $ compclass ) { $ lClass = strtolower ( $ class ) ; $ lMethod = strtolower ( $ method ) ; $ lCompclass = strtolower ( $ compclass ) ; if ( ! isset ( self :: $ _cache_methods [ $ lClass ] ) ) { self :: $ _cache_methods [ $ lClass ] = array ( ) ; } if ( ! array_key_exists ( $ lMethod , self :: $ _cache_methods [ $ lClass ] ) ) { self :: $ _cache_methods [ $ lClass ] [ $ lMethod ] = false ; $ classRef = new ReflectionClass ( $ class ) ; if ( $ classRef -> hasMethod ( $ method ) ) { $ methodRef = $ classRef -> getMethod ( $ method ) ; self :: $ _cache_methods [ $ lClass ] [ $ lMethod ] = $ methodRef -> getDeclaringClass ( ) -> getName ( ) ; } } return strtolower ( self :: $ _cache_methods [ $ lClass ] [ $ lMethod ] ) === $ lCompclass ; }
|
Determine if the given class method is implemented at the given comparison class
|
4,791
|
public static function shortName ( $ nameOrObject ) { $ name = static :: class_name ( $ nameOrObject ) ; $ parts = explode ( '\\' , $ name ) ; return end ( $ parts ) ; }
|
Strip namespace from class
|
4,792
|
public static function hasMethod ( $ object , $ method ) { if ( empty ( $ object ) ) { return false ; } if ( method_exists ( $ object , $ method ) ) { return true ; } return method_exists ( $ object , 'hasMethod' ) && $ object -> hasMethod ( $ method ) ; }
|
Helper to determine if the given object has a method
|
4,793
|
public function isLockedOut ( ) { $ lockedOutUntilObj = $ this -> dbObject ( 'LockedOutUntil' ) ; if ( $ lockedOutUntilObj -> InFuture ( ) ) { return true ; } $ maxAttempts = $ this -> config ( ) -> get ( 'lock_out_after_incorrect_logins' ) ; if ( $ maxAttempts <= 0 ) { return false ; } $ idField = static :: config ( ) -> get ( 'unique_identifier_field' ) ; $ attempts = LoginAttempt :: getByEmail ( $ this -> { $ idField } ) -> sort ( 'Created' , 'DESC' ) -> limit ( $ maxAttempts ) ; if ( $ attempts -> count ( ) < $ maxAttempts ) { return false ; } foreach ( $ attempts as $ attempt ) { if ( $ attempt -> Status === 'Success' ) { return false ; } } $ firstFailureDate = $ attempts -> first ( ) -> dbObject ( 'Created' ) ; $ maxAgeSeconds = $ this -> config ( ) -> get ( 'lock_out_delay_mins' ) * 60 ; $ lockedOutUntil = $ firstFailureDate -> getTimestamp ( ) + $ maxAgeSeconds ; $ now = DBDatetime :: now ( ) -> getTimestamp ( ) ; if ( $ now < $ lockedOutUntil ) { return true ; } return false ; }
|
Returns true if this user is locked out
|
4,794
|
public function regenerateTempID ( ) { $ generator = new RandomGenerator ( ) ; $ lifetime = self :: config ( ) -> get ( 'temp_id_lifetime' ) ; $ this -> TempIDHash = $ generator -> randomToken ( 'sha1' ) ; $ this -> TempIDExpired = $ lifetime ? date ( 'Y-m-d H:i:s' , strtotime ( DBDatetime :: now ( ) -> getValue ( ) ) + $ lifetime ) : null ; $ this -> write ( ) ; }
|
Trigger regeneration of TempID .
|
4,795
|
public static function logged_in_session_exists ( ) { Deprecation :: notice ( '5.0.0' , 'This method is deprecated and now does not add value. Please use Security::getCurrentUser()' ) ; $ member = Security :: getCurrentUser ( ) ; if ( $ member && $ member -> exists ( ) ) { return true ; } return false ; }
|
Check if the member ID logged in session actually has a database record of the same ID . If there is no logged in user FALSE is returned anyway .
|
4,796
|
public function encryptWithUserSettings ( $ string ) { if ( ! $ string ) { return null ; } if ( ! $ this -> PasswordEncryption ) { return $ string ; } $ e = PasswordEncryptor :: create_for_algorithm ( $ this -> PasswordEncryption ) ; return $ e -> encrypt ( $ string , $ this -> Salt ) ; }
|
Utility for generating secure password hashes for this member .
|
4,797
|
public function generateAutologinTokenAndStoreHash ( $ lifetime = null ) { if ( $ lifetime !== null ) { Deprecation :: notice ( '5.0' , 'Passing a $lifetime to Member::generateAutologinTokenAndStoreHash() is deprecated, use the Member.auto_login_token_lifetime config setting instead' , Deprecation :: SCOPE_GLOBAL ) ; $ lifetime = ( 86400 * $ lifetime ) ; } else { $ lifetime = $ this -> config ( ) -> auto_login_token_lifetime ; } do { $ generator = new RandomGenerator ( ) ; $ token = $ generator -> randomToken ( ) ; $ hash = $ this -> encryptWithUserSettings ( $ token ) ; } while ( DataObject :: get_one ( Member :: class , array ( '"Member"."AutoLoginHash"' => $ hash ) ) ) ; $ this -> AutoLoginHash = $ hash ; $ this -> AutoLoginExpired = date ( 'Y-m-d H:i:s' , time ( ) + $ lifetime ) ; $ this -> write ( ) ; return $ token ; }
|
Generate an auto login token which can be used to reset the password at the same time hashing it and storing in the database .
|
4,798
|
public function validateAutoLoginToken ( $ autologinToken ) { $ hash = $ this -> encryptWithUserSettings ( $ autologinToken ) ; $ member = self :: member_from_autologinhash ( $ hash , false ) ; return ( bool ) $ member ; }
|
Check the token against the member .
|
4,799
|
public static function member_from_autologinhash ( $ hash , $ login = false ) { $ member = static :: get ( ) -> filter ( [ 'AutoLoginHash' => $ hash , 'AutoLoginExpired:GreaterThan' => DBDatetime :: now ( ) -> getValue ( ) , ] ) -> first ( ) ; if ( $ login && $ member ) { Injector :: inst ( ) -> get ( IdentityStore :: class ) -> logIn ( $ member ) ; } return $ member ; }
|
Return the member for the auto login hash
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.