idx
int64
0
241k
question
stringlengths
64
6.21k
target
stringlengths
5
803
5,000
protected function initialiseQuery ( ) { $ baseClass = DataObject :: getSchema ( ) -> baseDataClass ( $ this -> dataClass ( ) ) ; if ( ! $ baseClass ) { throw new InvalidArgumentException ( "DataQuery::create() Can't find data classes for '{$this->dataClass}'" ) ; } $ this -> query = new SQLSelect ( array ( ) ) ; $ thi...
Set up the simplest initial query
5,001
protected function ensureSelectContainsOrderbyColumns ( $ query , $ originalSelect = array ( ) ) { if ( $ orderby = $ query -> getOrderBy ( ) ) { $ newOrderby = array ( ) ; $ i = 0 ; foreach ( $ orderby as $ k => $ dir ) { $ newOrderby [ $ k ] = $ dir ; if ( strpos ( $ k , '(' ) !== false ) { continue ; } $ col = str_r...
Ensure that if a query has an order by clause those columns are present in the select .
5,002
public function max ( $ field ) { $ table = DataObject :: getSchema ( ) -> tableForField ( $ this -> dataClass , $ field ) ; if ( ! $ table ) { return $ this -> aggregate ( "MAX(\"$field\")" ) ; } return $ this -> aggregate ( "MAX(\"$table\".\"$field\")" ) ; }
Return the maximum value of the given field in this DataList
5,003
protected function selectColumnsFromTable ( SQLSelect & $ query , $ tableClass , $ columns = null ) { $ schema = DataObject :: getSchema ( ) ; $ databaseFields = $ schema -> databaseFields ( $ tableClass , false ) ; $ compositeFields = $ schema -> compositeFields ( $ tableClass , false ) ; unset ( $ databaseFields [ 'I...
Update the SELECT clause of the query with the columns from the given table
5,004
public function sort ( $ sort = null , $ direction = null , $ clear = true ) { if ( $ clear ) { $ this -> query -> setOrderBy ( $ sort , $ direction ) ; } else { $ this -> query -> addOrderBy ( $ sort , $ direction ) ; } return $ this ; }
Set the ORDER BY clause of this query
5,005
public function innerJoin ( $ table , $ onClause , $ alias = null , $ order = 20 , $ parameters = array ( ) ) { if ( $ table ) { $ this -> query -> addInnerJoin ( $ table , $ onClause , $ alias , $ order , $ parameters ) ; } return $ this ; }
Add an INNER JOIN clause to this query .
5,006
public function leftJoin ( $ table , $ onClause , $ alias = null , $ order = 20 , $ parameters = array ( ) ) { if ( $ table ) { $ this -> query -> addLeftJoin ( $ table , $ onClause , $ alias , $ order , $ parameters ) ; } return $ this ; }
Add a LEFT JOIN clause to this query .
5,007
protected function joinHasManyRelation ( $ localClass , $ localField , $ foreignClass , $ localPrefix = null , $ foreignPrefix = null , $ type = 'has_many' ) { if ( ! $ foreignClass || $ foreignClass === DataObject :: class ) { throw new InvalidArgumentException ( "Could not find a has_many relationship {$localField} o...
Join the given has_many relation to this query . Also works with belongs_to
5,008
protected function joinHasOneRelation ( $ localClass , $ localField , $ foreignClass , $ localPrefix = null , $ foreignPrefix = null ) { if ( ! $ foreignClass ) { throw new InvalidArgumentException ( "Could not find a has_one relationship {$localField} on {$localClass}" ) ; } if ( $ foreignClass === DataObject :: class...
Join the given class to this query with the given key
5,009
protected function joinManyManyRelationship ( $ relationClass , $ parentClass , $ componentClass , $ parentField , $ componentField , $ relationClassOrTable , $ parentPrefix = null , $ componentPrefix = null ) { $ schema = DataObject :: getSchema ( ) ; if ( class_exists ( $ relationClassOrTable ) ) { $ relationClassOrT...
Join table via many_many relationship
5,010
public function subtract ( DataQuery $ subtractQuery , $ field = 'ID' ) { $ fieldExpression = $ subtractQuery -> expressionForField ( $ field ) ; $ subSelect = $ subtractQuery -> getFinalisedQuery ( ) ; $ subSelect -> setSelect ( array ( ) ) ; $ subSelect -> selectField ( $ fieldExpression , $ field ) ; $ subSelect -> ...
Removes the result of query from this query .
5,011
public function selectFromTable ( $ table , $ fields ) { $ fieldExpressions = array_map ( function ( $ item ) use ( $ table ) { return Convert :: symbol2sql ( "{$table}.{$item}" ) ; } , $ fields ) ; $ this -> query -> setSelect ( $ fieldExpressions ) ; return $ this ; }
Select the only given fields from the given table .
5,012
public function addSelectFromTable ( $ table , $ fields ) { $ fieldExpressions = array_map ( function ( $ item ) use ( $ table ) { return Convert :: symbol2sql ( "{$table}.{$item}" ) ; } , $ fields ) ; $ this -> query -> addSelect ( $ fieldExpressions ) ; return $ this ; }
Add the given fields from the given table to the select statement .
5,013
public function column ( $ field = 'ID' ) { $ fieldExpression = $ this -> expressionForField ( $ field ) ; $ query = $ this -> getFinalisedQuery ( array ( $ field ) ) ; $ originalSelect = $ query -> getSelect ( ) ; $ query -> setSelect ( array ( ) ) ; $ query -> selectField ( $ fieldExpression , $ field ) ; $ this -> e...
Query the given field column from the database and return as an array .
5,014
public function getQueryParam ( $ key ) { if ( isset ( $ this -> queryParams [ $ key ] ) ) { return $ this -> queryParams [ $ key ] ; } return null ; }
Set an arbitrary query parameter that can be used by decorators to add additional meta - data to the query .
5,015
public function doInit ( ) { $ this -> extend ( 'onBeforeInit' ) ; $ this -> baseInitCalled = false ; $ this -> init ( ) ; if ( ! $ this -> baseInitCalled ) { $ class = static :: class ; user_error ( "init() method on class '{$class}' doesn't call Controller::init()." . "Make sure that you have parent::init() included....
A stand in function to protect the init function from failing to be called as well as providing before and after hooks for the init function itself
5,016
protected function beforeHandleRequest ( HTTPRequest $ request ) { $ this -> setRequest ( $ request ) ; $ this -> pushCurrent ( ) ; $ this -> setResponse ( new HTTPResponse ( ) ) ; $ this -> doInit ( ) ; }
A bootstrap for the handleRequest method
5,017
public function removeAction ( $ fullURL , $ action = null ) { if ( ! $ action ) { $ action = $ this -> getAction ( ) ; } $ returnURL = $ fullURL ; if ( ( $ pos = strpos ( $ fullURL , $ action ) ) !== false ) { $ returnURL = substr ( $ fullURL , 0 , $ pos ) ; } return $ returnURL ; }
Removes all the action part of the current URL and returns the result . If no action parameter is present returns the full URL .
5,018
protected function definingClassForAction ( $ action ) { $ definingClass = parent :: definingClassForAction ( $ action ) ; if ( $ definingClass ) { return $ definingClass ; } $ class = static :: class ; while ( $ class != 'SilverStripe\\Control\\RequestHandler' ) { $ templateName = strtok ( $ class , '_' ) . '_' . $ ac...
Return the class that defines the given action so that we know where to check allowed_actions . Overrides RequestHandler to also look at defined templates .
5,019
public function hasActionTemplate ( $ action ) { if ( isset ( $ this -> templates [ $ action ] ) ) { return true ; } $ parentClass = static :: class ; $ templates = array ( ) ; while ( $ parentClass != __CLASS__ ) { $ templates [ ] = strtok ( $ parentClass , '_' ) . '_' . $ action ; $ parentClass = get_parent_class ( $...
Returns TRUE if this controller has a template that is specifically designed to handle a specific action .
5,020
public function can ( $ perm , $ member = null ) { if ( ! $ member ) { $ member = Security :: getCurrentUser ( ) ; } if ( is_array ( $ perm ) ) { $ perm = array_map ( array ( $ this , 'can' ) , $ perm , array_fill ( 0 , count ( $ perm ) , $ member ) ) ; return min ( $ perm ) ; } if ( $ this -> hasMethod ( $ methodName ...
Returns true if the member is allowed to do the given action . Defaults to the currently logged in user .
5,021
public function combineAnd ( ValidationResult $ other ) { $ this -> isValid = $ this -> isValid && $ other -> isValid ( ) ; $ this -> messages = array_merge ( $ this -> messages , $ other -> getMessages ( ) ) ; return $ this ; }
Combine this Validation Result with the ValidationResult given in other . It will be valid if both this and the other result are valid . This object will be modified to contain the new validation information .
5,022
protected function safeReloadWithTokens ( HTTPRequest $ request , ConfirmationTokenChain $ confirmationTokenChain ) { $ this -> getApplication ( ) -> getKernel ( ) -> boot ( false ) ; $ request -> getSession ( ) -> init ( $ request ) ; $ result = ErrorDirector :: singleton ( ) -> handleRequestWithTokenChain ( $ request...
Reload application with the given token but only if either the user is authenticated or authentication is impossible .
5,023
protected function getOptionClass ( $ value , $ odd ) { $ oddClass = $ odd ? 'odd' : 'even' ; $ valueClass = ' val' . Convert :: raw2htmlid ( $ value ) ; return $ oddClass . $ valueClass ; }
Get extra classes for each item in the list
5,024
public function Link ( $ action = null ) { $ controller = $ this -> form -> getController ( ) ; if ( empty ( $ controller ) ) { return null ; } if ( $ controller -> hasMethod ( "FormObjectLink" ) ) { $ base = $ controller -> FormObjectLink ( $ this -> form -> getName ( ) ) ; } else { $ base = Controller :: join_links (...
Get link for this form
5,025
protected function getAjaxErrorResponse ( ValidationResult $ result ) { $ acceptType = $ this -> getRequest ( ) -> getHeader ( 'Accept' ) ; if ( strpos ( $ acceptType , 'application/json' ) !== false ) { $ response = new HTTPResponse ( json_encode ( $ result -> getMessages ( ) ) ) ; $ response -> addHeader ( 'Content-T...
Build HTTP error response for ajax requests
5,026
public function buttonClicked ( ) { $ actions = $ this -> getAllActions ( ) ; foreach ( $ actions as $ action ) { if ( $ this -> buttonClickedFunc === $ action -> actionName ( ) ) { return $ action ; } } return null ; }
Get instance of button which was clicked for this request
5,027
protected function getAllActions ( ) { $ fields = $ this -> form -> Fields ( ) -> dataFields ( ) ; $ actions = $ this -> form -> Actions ( ) -> dataFields ( ) ; $ fieldsAndActions = array_merge ( $ fields , $ actions ) ; $ actions = array_filter ( $ fieldsAndActions , function ( $ fieldOrAction ) { return $ fieldOrActi...
Get a list of all actions including those in the main fields FieldList
5,028
public function getData ( $ name , $ default = null ) { if ( ! isset ( $ this -> data [ $ name ] ) ) { $ this -> data [ $ name ] = $ default ; } else { if ( is_array ( $ this -> data [ $ name ] ) ) { $ this -> data [ $ name ] = new GridState_Data ( $ this -> data [ $ name ] ) ; } } return $ this -> data [ $ name ] ; }
Retrieve the value for the given key
5,029
protected function isSeekable ( ) { $ stream = $ this -> getStream ( ) ; if ( ! $ stream ) { return false ; } $ metadata = stream_get_meta_data ( $ stream ) ; return $ metadata [ 'seekable' ] ; }
Determine if a stream is seekable
5,030
protected function consumeStream ( $ callback ) { $ stream = $ this -> getStream ( ) ; if ( ! $ stream ) { return null ; } if ( $ this -> consumed ) { if ( ! $ this -> isSeekable ( ) ) { throw new BadMethodCallException ( "Unseekable stream has already been consumed" ) ; } rewind ( $ stream ) ; } $ this -> consumed = t...
Safely consume the stream
5,031
protected function constructUploadReceiver ( ) { $ this -> setUpload ( Upload :: create ( ) ) ; $ this -> getValidator ( ) -> setAllowedExtensions ( array_filter ( File :: config ( ) -> allowed_extensions ) ) ; $ maxUpload = File :: ini2bytes ( ini_get ( 'upload_max_filesize' ) ) ; $ maxPost = File :: ini2bytes ( ini_g...
Bootstrap Uploadable field
5,032
protected function extractValue ( $ item , $ key ) { if ( is_object ( $ item ) ) { if ( method_exists ( $ item , 'hasMethod' ) && $ item -> hasMethod ( $ key ) ) { return $ item -> { $ key } ( ) ; } return $ item -> { $ key } ; } else { if ( array_key_exists ( $ key , $ item ) ) { return $ item [ $ key ] ; } } }
Extracts a value from an item in the list where the item is either an object or array .
5,033
public function key ( ) { if ( ( $ this -> endItemIdx !== null ) && isset ( $ this -> lastItems [ $ this -> endItemIdx ] ) ) { return $ this -> lastItems [ $ this -> endItemIdx ] [ 0 ] ; } else { if ( isset ( $ this -> firstItems [ $ this -> firstItemIdx ] ) ) { return $ this -> firstItems [ $ this -> firstItemIdx ] [ ...
Return the key of the current element .
5,034
public static function get ( $ identifier = null ) { if ( ! $ identifier ) { return static :: get_active ( ) ; } if ( ! isset ( self :: $ configs [ $ identifier ] ) ) { self :: $ configs [ $ identifier ] = static :: create ( ) ; self :: $ configs [ $ identifier ] -> setOption ( 'editorIdentifier' , $ identifier ) ; } r...
Get the HTMLEditorConfig object for the given identifier . This is a correct way to get an HTMLEditorConfig instance - do not call new
5,035
public static function set_config ( $ identifier , HTMLEditorConfig $ config = null ) { if ( $ config ) { self :: $ configs [ $ identifier ] = $ config ; self :: $ configs [ $ identifier ] -> setOption ( 'editorIdentifier' , $ identifier ) ; } else { unset ( self :: $ configs [ $ identifier ] ) ; } return $ config ; }
Assign a new config or clear existing for the given identifier
5,036
public static function get_available_configs_map ( ) { $ configs = array ( ) ; foreach ( self :: $ configs as $ identifier => $ config ) { $ configs [ $ identifier ] = $ config -> getOption ( 'friendly_name' ) ; } return $ configs ; }
Get the available configurations as a map of friendly_name to configuration name .
5,037
public function FieldHolder ( $ properties = array ( ) ) { $ obj = $ properties ? $ this -> customise ( $ properties ) : $ this ; return $ obj -> renderWith ( $ this -> getTemplates ( ) ) ; }
Returns a tab - strip and the associated tabs . The HTML is a standardised format containing a &lt ; ul ;
5,038
public function push ( FormField $ field ) { if ( $ field instanceof Tab || $ field instanceof TabSet ) { $ field -> setTabSet ( $ this ) ; } parent :: push ( $ field ) ; }
Add a new child field to the end of the set .
5,039
public function unshift ( FormField $ field ) { if ( $ field instanceof Tab || $ field instanceof TabSet ) { $ field -> setTabSet ( $ this ) ; } parent :: unshift ( $ field ) ; }
Add a new child field to the beginning of the set .
5,040
public function insertBefore ( $ insertBefore , $ field , $ appendIfMissing = true ) { if ( $ field instanceof Tab || $ field instanceof TabSet ) { $ field -> setTabSet ( $ this ) ; } return parent :: insertBefore ( $ insertBefore , $ field , $ appendIfMissing ) ; }
Inserts a field before a particular field in a FieldList .
5,041
public function insertAfter ( $ insertAfter , $ field , $ appendIfMissing = true ) { if ( $ field instanceof Tab || $ field instanceof TabSet ) { $ field -> setTabSet ( $ this ) ; } return parent :: insertAfter ( $ insertAfter , $ field , $ appendIfMissing ) ; }
Inserts a field after a particular field in a FieldList .
5,042
public function addModule ( $ path ) { $ module = new Module ( $ path , $ this -> base ) ; $ name = $ module -> getName ( ) ; if ( empty ( $ this -> modules [ $ name ] ) ) { $ this -> modules [ $ name ] = $ module ; return ; } $ path = $ module -> getPath ( ) ; $ otherPath = $ this -> modules [ $ name ] -> getPath ( ) ...
Adds a path as a module
5,043
public function activateConfig ( ) { $ modules = $ this -> getModules ( ) ; foreach ( array_reverse ( $ modules ) as $ module ) { $ module -> activate ( ) ; } }
Includes all of the php _config . php files found by this manifest .
5,044
public function getModule ( $ name ) { if ( isset ( $ this -> modules [ $ name ] ) ) { return $ this -> modules [ $ name ] ; } if ( ! strstr ( $ name , '/' ) ) { foreach ( $ this -> modules as $ module ) { if ( strcasecmp ( $ module -> getShortName ( ) , $ name ) === 0 ) { return $ module ; } } } return null ; }
Get module by name
5,045
public function sort ( ) { $ order = static :: config ( ) -> uninherited ( 'module_priority' ) ; $ project = static :: config ( ) -> get ( 'project' ) ; $ sorter = Injector :: inst ( ) -> createWithArgs ( PrioritySorter :: class . '.modulesorter' , [ $ this -> modules , $ order ? : [ ] ] ) ; if ( $ project ) { $ sorter...
Sort modules sorted by priority
5,046
public function getModuleByPath ( $ path ) { $ path = realpath ( $ path ) ; if ( ! $ path ) { return null ; } $ rootModule = null ; $ modules = ModuleLoader :: inst ( ) -> getManifest ( ) -> getModules ( ) ; foreach ( $ modules as $ module ) { if ( stripos ( $ path , realpath ( $ module -> getPath ( ) ) ) !== 0 ) { con...
Get module that contains the given path
5,047
public function scriptDirection ( $ locale = null ) { $ dirs = static :: config ( ) -> get ( 'text_direction' ) ; if ( ! $ locale ) { $ locale = i18n :: get_locale ( ) ; } if ( isset ( $ dirs [ $ locale ] ) ) { return $ dirs [ $ locale ] ; } $ lang = $ this -> langFromLocale ( $ locale ) ; if ( isset ( $ dirs [ $ lang ...
Returns the script direction in format compatible with the HTML dir attribute .
5,048
public function getLocales ( ) { $ locale = i18n :: get_locale ( ) ; if ( ! empty ( static :: $ cache_locales [ $ locale ] ) ) { return static :: $ cache_locales [ $ locale ] ; } $ locales = $ this -> config ( ) -> get ( 'locales' ) ; $ localised = [ ] ; foreach ( $ locales as $ code => $ default ) { $ localised [ $ co...
Get all locale codes and names
5,049
public function getLanguages ( ) { $ locale = i18n :: get_locale ( ) ; if ( ! empty ( static :: $ cache_languages [ $ locale ] ) ) { return static :: $ cache_languages [ $ locale ] ; } $ languages = $ this -> config ( ) -> get ( 'languages' ) ; $ localised = [ ] ; foreach ( $ languages as $ code => $ default ) { $ loca...
Get all language codes and names
5,050
public function getCountries ( ) { $ locale = i18n :: get_locale ( ) ; if ( ! empty ( static :: $ cache_countries [ $ locale ] ) ) { return static :: $ cache_countries [ $ locale ] ; } $ countries = $ this -> config ( ) -> get ( 'countries' ) ; $ localised = [ ] ; foreach ( $ countries as $ code => $ default ) { $ loca...
Get all country codes and names
5,051
public function nest ( ) { $ manifest = clone $ this -> getManifest ( ) ; $ newLoader = new static ; $ newLoader -> pushManifest ( $ manifest ) ; return $ newLoader -> activate ( ) ; }
Nest the config loader and activates it
5,052
protected function getPluralForm ( $ value ) { if ( is_array ( $ value ) ) { $ forms = i18n :: config ( ) -> uninherited ( 'plurals' ) ; $ forms = array_combine ( $ forms , $ forms ) ; return array_intersect_key ( $ value , $ forms ) ; } return i18n :: parse_plurals ( $ value ) ; }
Get array - plural form for any value
5,053
public function getYaml ( $ messages , $ locale ) { $ entities = $ this -> denormaliseMessages ( $ messages ) ; $ content = $ this -> getDumper ( ) -> dump ( [ $ locale => $ entities ] , 99 ) ; return $ content ; }
Convert messages to yml ready to write
5,054
protected function getClassKey ( $ entity ) { $ parts = explode ( '.' , $ entity ) ; $ class = array_shift ( $ parts ) ; if ( count ( $ parts ) > 1 && reset ( $ parts ) === 'ss' ) { $ class .= '.ss' ; array_shift ( $ parts ) ; } $ key = implode ( '.' , $ parts ) ; return array ( $ class , $ key ) ; }
Determine class and key for a localisation entity
5,055
public static function unnest ( ) { $ loader = InjectorLoader :: inst ( ) ; if ( $ loader -> countManifests ( ) <= 1 ) { user_error ( "Unable to unnest root Injector, please make sure you don't have mis-matched nest/unnest" , E_USER_WARNING ) ; } else { $ loader -> popManifest ( ) ; } return static :: inst ( ) ; }
Change the active Injector back to the Injector instance the current active Injector object was copied from .
5,056
public function load ( $ config = array ( ) ) { foreach ( $ config as $ specId => $ spec ) { if ( is_string ( $ spec ) ) { $ spec = array ( 'class' => $ spec ) ; } $ file = isset ( $ spec [ 'src' ] ) ? $ spec [ 'src' ] : null ; $ class = isset ( $ spec [ 'class' ] ) ? $ spec [ 'class' ] : null ; if ( ! $ class && is_st...
Load services using the passed in configuration for those services
5,057
public function updateSpec ( $ id , $ property , $ value , $ append = true ) { if ( isset ( $ this -> specs [ $ id ] [ 'properties' ] [ $ property ] ) ) { $ current = & $ this -> specs [ $ id ] [ 'properties' ] [ $ property ] ; if ( is_array ( $ current ) && $ append ) { $ current [ ] = $ value ; } else { $ this -> spe...
Update the configuration of an already defined service
5,058
public function convertServiceProperty ( $ value ) { if ( is_array ( $ value ) ) { $ newVal = array ( ) ; foreach ( $ value as $ k => $ v ) { $ newVal [ $ k ] = $ this -> convertServiceProperty ( $ v ) ; } return $ newVal ; } if ( is_string ( $ value ) && strpos ( $ value , '%$' ) === 0 ) { $ id = substr ( $ value , 2 ...
Recursively convert a value into its proper representation with service references resolved to actual objects
5,059
protected function instantiate ( $ spec , $ id = null , $ type = null ) { if ( is_string ( $ spec ) ) { $ spec = array ( 'class' => $ spec ) ; } $ class = $ spec [ 'class' ] ; $ constructorParams = array ( ) ; if ( isset ( $ spec [ 'constructor' ] ) && is_array ( $ spec [ 'constructor' ] ) ) { $ constructorParams = $ s...
Instantiate a managed object
5,060
protected function setObjectProperty ( $ object , $ name , $ value ) { if ( ClassInfo :: hasMethod ( $ object , 'set' . $ name ) ) { $ object -> { 'set' . $ name } ( $ value ) ; } else { $ object -> $ name = $ value ; } }
Helper to set a property s value
5,061
public function getServiceName ( $ name ) { if ( $ this -> getServiceSpec ( $ name , false ) ) { return $ name ; } if ( ! strpos ( $ name , '.' ) ) { return null ; } return $ this -> getServiceName ( substr ( $ name , 0 , strrpos ( $ name , '.' ) ) ) ; }
Does the given service exist and if so what s the stored name for it?
5,062
public function registerService ( $ service , $ replace = null ) { $ registerAt = get_class ( $ service ) ; if ( $ replace !== null ) { $ registerAt = $ replace ; } $ this -> specs [ $ registerAt ] = array ( 'class' => get_class ( $ service ) ) ; $ this -> serviceCache [ $ registerAt ] = $ service ; return $ this ; }
Register a service object with an optional name to register it as the service for
5,063
public function unregisterObjects ( $ types ) { if ( ! is_array ( $ types ) ) { $ types = [ $ types ] ; } foreach ( $ this -> serviceCache as $ key => $ object ) { foreach ( $ types as $ filterClass ) { if ( strcasecmp ( $ filterClass , 'object' ) === 0 ) { throw new InvalidArgumentException ( "Global unregistration is...
Clear out objects of one or more types that are managed by the injetor .
5,064
public function get ( $ name , $ asSingleton = true , $ constructorArgs = [ ] ) { $ object = $ this -> getNamedService ( $ name , $ asSingleton , $ constructorArgs ) ; if ( ! $ object ) { throw new InjectorNotFoundException ( "The '{$name}' service could not be found" ) ; } return $ object ; }
Get a named managed object
5,065
protected function getServiceNamedSpec ( $ name , $ constructorArgs = [ ] ) { $ spec = $ this -> getServiceSpec ( $ name ) ; if ( $ spec ) { $ name = $ this -> getServiceName ( $ name ) ; } else { $ spec = [ 'class' => $ name , 'constructor' => $ constructorArgs , ] ; } return [ $ name , $ spec ] ; }
Get or build a named service and specification
5,066
public function getServiceSpec ( $ name , $ inherit = true ) { if ( isset ( $ this -> specs [ $ name ] ) ) { return $ this -> specs [ $ name ] ; } $ config = $ this -> configLocator -> locateConfigFor ( $ name ) ; if ( $ config ) { $ this -> load ( [ $ name => $ config ] ) ; if ( isset ( $ this -> specs [ $ name ] ) ) ...
Search for spec lazy - loading in from config locator . Falls back to parent service name if unloaded
5,067
private function getDefaultOptions ( $ start = null , $ end = null ) { if ( ! $ start ) { $ start = ( int ) date ( 'Y' ) ; } if ( ! $ end ) { $ end = 1900 ; } $ years = array ( ) ; for ( $ i = $ start ; $ i >= $ end ; $ i -- ) { $ years [ $ i ] = $ i ; } return $ years ; }
Returns a list of default options that can be used to populate a select box or compare against input values . Starts by default at the current year and counts back to 1900 .
5,068
protected function oneFilter ( DataQuery $ query , $ inclusive ) { $ this -> model = $ query -> applyRelation ( $ this -> relation ) ; $ field = $ this -> getDbName ( ) ; $ value = $ this -> getValue ( ) ; if ( $ value === null ) { $ where = DB :: get_conn ( ) -> nullCheckClause ( $ field , $ inclusive ) ; return $ que...
Applies a single match either as inclusive or exclusive
5,069
protected function manyFilter ( DataQuery $ query , $ inclusive ) { $ this -> model = $ query -> applyRelation ( $ this -> relation ) ; $ caseSensitive = $ this -> getCaseSensitive ( ) ; $ field = $ this -> getDbName ( ) ; $ values = $ this -> getValue ( ) ; if ( empty ( $ values ) ) { throw new \ InvalidArgumentExcept...
Applies matches for several values either as inclusive or exclusive
5,070
public function getVary ( ) { if ( isset ( $ this -> vary ) ) { return $ this -> vary ; } $ defaultVary = $ this -> config ( ) -> get ( 'defaultVary' ) ; return array_keys ( array_filter ( $ defaultVary ) ) ; }
Get current vary keys
5,071
public function addVary ( $ vary ) { $ combied = $ this -> combineVary ( $ this -> getVary ( ) , $ vary ) ; $ this -> setVary ( $ combied ) ; return $ this ; }
Add a vary
5,072
public function registerModificationDate ( $ date ) { $ timestamp = is_numeric ( $ date ) ? $ date : strtotime ( $ date ) ; if ( $ timestamp > $ this -> modificationDate ) { $ this -> modificationDate = $ timestamp ; } return $ this ; }
Register a modification date . Used to calculate the Last - Modified HTTP header . Can be called multiple times and will automatically retain the most recent date .
5,073
protected function setState ( $ state ) { if ( ! array_key_exists ( $ state , $ this -> stateDirectives ) ) { throw new InvalidArgumentException ( "Invalid state {$state}" ) ; } $ this -> state = $ state ; return $ this ; }
Set current state . Should only be invoked internally after processing precedence rules .
5,074
protected function applyChangeLevel ( $ level , $ force ) { $ forcingLevel = $ level + ( $ force ? self :: LEVEL_FORCED : 0 ) ; if ( $ forcingLevel < $ this -> getForcingLevel ( ) ) { return false ; } $ this -> forcingLevel = $ forcingLevel ; return true ; }
Instruct the cache to apply a change with a given level optionally modifying it with a force flag to increase priority of this action .
5,075
public function setStateDirectivesFromArray ( $ states , $ directives ) { foreach ( $ directives as $ directive => $ value ) { $ this -> setStateDirective ( $ states , $ directive , $ value ) ; } return $ this ; }
Low level method to set directives from an associative array
5,076
public function hasStateDirective ( $ state , $ directive ) { $ directive = strtolower ( $ directive ) ; return isset ( $ this -> stateDirectives [ $ state ] [ $ directive ] ) ; }
Low level method to check if a directive is currently set
5,077
public function getStateDirective ( $ state , $ directive ) { $ directive = strtolower ( $ directive ) ; if ( isset ( $ this -> stateDirectives [ $ state ] [ $ directive ] ) ) { return $ this -> stateDirectives [ $ state ] [ $ directive ] ; } return false ; }
Low level method to get the value of a directive for a state . Returns false if there is no directive . True means the flag is set otherwise the value of the directive .
5,078
public function applyToResponse ( $ response ) { $ headers = $ this -> generateHeadersFor ( $ response ) ; foreach ( $ headers as $ name => $ value ) { if ( ! $ response -> getHeader ( $ name ) ) { $ response -> addHeader ( $ name , $ value ) ; } } return $ this ; }
Generate all headers to add to this object
5,079
protected function generateCacheHeader ( ) { $ cacheControl = [ ] ; foreach ( $ this -> getDirectives ( ) as $ directive => $ value ) { if ( $ value === true ) { $ cacheControl [ ] = $ directive ; } else { $ cacheControl [ ] = $ directive . '=' . $ value ; } } return implode ( ', ' , $ cacheControl ) ; }
Generate the cache header
5,080
public function generateHeadersFor ( HTTPResponse $ response ) { return array_filter ( [ 'Last-Modified' => $ this -> generateLastModifiedHeader ( ) , 'Vary' => $ this -> generateVaryHeader ( $ response ) , 'Cache-Control' => $ this -> generateCacheHeader ( ) , 'Expires' => $ this -> generateExpiresHeader ( ) , ] ) ; }
Generate all headers to output
5,081
protected function generateVaryHeader ( HTTPResponse $ response ) { $ vary = $ this -> getVary ( ) ; if ( $ response -> getHeader ( 'Vary' ) ) { $ vary = $ this -> combineVary ( $ vary , $ response -> getHeader ( 'Vary' ) ) ; } if ( $ vary ) { return implode ( ', ' , $ vary ) ; } return null ; }
Generate vary http header
5,082
protected function generateExpiresHeader ( ) { $ maxAge = $ this -> getDirective ( 'max-age' ) ; if ( $ maxAge === false ) { return null ; } $ expires = DBDatetime :: now ( ) -> getTimestamp ( ) + $ maxAge ; return gmdate ( 'D, d M Y H:i:s' , $ expires ) . ' GMT' ; }
Generate Expires http header
5,083
protected function augmentState ( HTTPRequest $ request , HTTPResponse $ response ) { if ( $ response -> isError ( ) || $ response -> isRedirect ( ) ) { $ this -> disableCache ( true ) ; } elseif ( $ request -> getSession ( ) -> getAll ( ) ) { $ this -> privateCache ( ) ; } }
Update state based on current request and response objects
5,084
protected function resolveModuleResource ( ModuleResource $ resource ) { $ relativePath = $ resource -> getRelativePath ( ) ; $ exists = $ resource -> exists ( ) ; $ absolutePath = $ resource -> getPath ( ) ; if ( Director :: publicDir ( ) ) { $ relativePath = Path :: join ( RESOURCES_DIR , $ relativePath ) ; } elseif ...
Update relative path for a module resource
5,085
public function setValue ( $ value , $ data = null ) { if ( $ data && $ data instanceof DataObject ) { $ value = '' ; } $ oldValue = $ this -> value ; if ( is_array ( $ value ) ) { $ this -> value = $ value [ '_Password' ] ; $ this -> confirmValue = $ value [ '_ConfirmPassword' ] ; $ this -> currentPasswordValue = ( $ ...
Value is sometimes an array and sometimes a single value so we need to handle both cases .
5,086
public function setName ( $ name ) { $ this -> getPasswordField ( ) -> setName ( $ name . '[_Password]' ) ; $ this -> getConfirmPasswordField ( ) -> setName ( $ name . '[_ConfirmPassword]' ) ; if ( $ this -> hiddenField ) { $ this -> hiddenField -> setName ( $ name . '[_PasswordFieldVisible]' ) ; } parent :: setName ( ...
Update the names of the child fields when updating name of field .
5,087
public function isSaveable ( ) { return ! $ this -> showOnClick || ( $ this -> showOnClick && $ this -> hiddenField && $ this -> hiddenField -> Value ( ) ) ; }
Determines if the field was actually shown on the client side - if not we don t validate or save it .
5,088
public function saveInto ( DataObjectInterface $ record ) { if ( ! $ this -> isSaveable ( ) ) { return ; } if ( ! ( $ this -> canBeEmpty && ! $ this -> value ) ) { parent :: saveInto ( $ record ) ; } }
Only save if field was shown on the client and is not empty .
5,089
public function performReadonlyTransformation ( ) { $ field = $ this -> castedCopy ( ReadonlyField :: class ) -> setTitle ( $ this -> title ? $ this -> title : _t ( 'SilverStripe\\Security\\Member.PASSWORD' , 'Password' ) ) -> setValue ( '*****' ) ; return $ field ; }
Makes a read only field with some stars in it to replace the password
5,090
public function setRequireExistingPassword ( $ show ) { if ( ( bool ) $ show === $ this -> requireExistingPassword ) { return $ this ; } $ this -> requireExistingPassword = $ show ; $ name = $ this -> getName ( ) ; $ currentName = "{$name}[_CurrentPassword]" ; if ( $ show ) { $ confirmField = PasswordField :: create ( ...
Set if the existing password should be required
5,091
protected function filteredTokens ( ) { foreach ( $ this -> tokens as $ token ) { if ( $ token -> reloadRequired ( ) || $ token -> reloadRequiredIfError ( ) ) { yield $ token ; } } }
Collect all tokens that require a redirect
5,092
public function getRedirectUrlParams ( ) { $ params = $ _GET ; unset ( $ params [ 'url' ] ) ; foreach ( $ this -> filteredTokens ( ) as $ token ) { $ params = array_merge ( $ params , $ token -> params ( ) ) ; } return $ params ; }
Collate GET vars from all token providers that need to apply a token
5,093
public static function invert ( $ arr ) { if ( ! $ arr ) { return [ ] ; } $ result = array ( ) ; foreach ( $ arr as $ columnName => $ column ) { foreach ( $ column as $ rowName => $ cell ) { $ result [ $ rowName ] [ $ columnName ] = $ cell ; } } return $ result ; }
Inverses the first and second level keys of an associative array keying the result by the second level and combines all first level entries within them .
5,094
public static function array_map_recursive ( $ f , $ array ) { $ applyOrRecurse = function ( $ v ) use ( $ f ) { return is_array ( $ v ) ? ArrayLib :: array_map_recursive ( $ f , $ v ) : call_user_func ( $ f , $ v ) ; } ; return array_map ( $ applyOrRecurse , $ array ) ; }
Similar to array_map but recurses when arrays are encountered .
5,095
public static function array_merge_recursive ( $ array ) { $ arrays = func_get_args ( ) ; $ merged = array ( ) ; if ( count ( $ arrays ) == 1 ) { return $ array ; } while ( $ arrays ) { $ array = array_shift ( $ arrays ) ; if ( ! is_array ( $ array ) ) { trigger_error ( 'SilverStripe\ORM\ArrayLib::array_merge_recursive...
Recursively merges two or more arrays .
5,096
public static function flatten ( $ array , $ preserveKeys = true , & $ out = array ( ) ) { array_walk_recursive ( $ array , function ( $ value , $ key ) use ( & $ out , $ preserveKeys ) { if ( ! is_scalar ( $ value ) ) { } elseif ( $ preserveKeys ) { $ out [ $ key ] = $ value ; } else { $ out [ ] = $ value ; } } ) ; re...
Takes an multi dimension array and returns the flattened version .
5,097
public function Description ( ) { $ description = $ this -> rssField ( $ this -> descriptionField ) ; if ( $ description instanceof DBHTMLText ) { return $ description -> obj ( 'AbsoluteLinks' ) ; } return $ description ; }
Get the description of this entry
5,098
public function AbsoluteLink ( ) { if ( $ this -> failover -> hasMethod ( 'AbsoluteLink' ) ) { return $ this -> failover -> AbsoluteLink ( ) ; } else { if ( $ this -> failover -> hasMethod ( 'Link' ) ) { return Director :: absoluteURL ( $ this -> failover -> Link ( ) ) ; } } throw new BadMethodCallException ( get_class...
Get a link to this entry
5,099
public function set ( $ key , $ value ) { $ setting = SettingModel :: create ( [ 'key' => $ key , 'value' => $ value , ] ) ; return $ setting ? $ value : false ; }
Set value against a key .