idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
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 ( ) ) ; $ this -> query -> setDistinct ( true ) ; if ( $ sort = singleton ( $ this -> dataClass ) -> config ( ) -> get ( 'default_sort' ) ) { $ this -> sort ( $ sort ) ; } $ baseTable = DataObject :: getSchema ( ) -> tableName ( $ baseClass ) ; $ this -> query -> setFrom ( "\"{$baseTable}\"" ) ; $ obj = Injector :: inst ( ) -> get ( $ baseClass ) ; $ obj -> extend ( 'augmentDataQueryCreation' , $ this -> query , $ this ) ; }
|
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_replace ( '"' , '' , trim ( $ k ) ) ; $ parts = explode ( '.' , $ col ) ; if ( preg_match ( '/_SortColumn/' , $ col ) ) { if ( isset ( $ originalSelect [ $ col ] ) ) { $ query -> selectField ( $ originalSelect [ $ col ] , $ col ) ; } continue ; } if ( count ( $ parts ) == 1 ) { $ qualCol = "\"{$parts[0]}\"" ; $ table = DataObject :: getSchema ( ) -> tableForField ( $ this -> dataClass ( ) , $ parts [ 0 ] ) ; if ( $ table ) { $ qualCol = "\"{$table}\".{$qualCol}" ; } unset ( $ newOrderby [ $ k ] ) ; $ newOrderby [ $ qualCol ] = $ dir ; $ selects = $ query -> getSelect ( ) ; if ( ! isset ( $ selects [ $ col ] ) && ! in_array ( $ qualCol , $ selects ) ) { $ query -> selectField ( $ qualCol ) ; } } else { $ qualCol = '"' . implode ( '"."' , $ parts ) . '"' ; if ( ! in_array ( $ qualCol , $ query -> getSelect ( ) ) ) { unset ( $ newOrderby [ $ k ] ) ; $ newOrderby [ "\"_SortColumn$i\"" ] = $ dir ; $ query -> selectField ( $ qualCol , "_SortColumn$i" ) ; $ i ++ ; } } } $ query -> setOrderBy ( $ newOrderby ) ; } }
|
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 [ 'ID' ] ) ; foreach ( $ databaseFields as $ k => $ v ) { if ( ( is_null ( $ columns ) || in_array ( $ k , $ columns ) ) && ! isset ( $ compositeFields [ $ k ] ) ) { $ expressionForField = $ query -> expressionForField ( $ k ) ; $ quotedField = $ schema -> sqlColumnForField ( $ tableClass , $ k ) ; if ( $ expressionForField ) { if ( ! isset ( $ this -> collidingFields [ $ k ] ) ) { $ this -> collidingFields [ $ k ] = array ( $ expressionForField ) ; } $ this -> collidingFields [ $ k ] [ ] = $ quotedField ; } else { $ query -> selectField ( $ quotedField , $ k ) ; } } } foreach ( $ compositeFields as $ k => $ v ) { if ( ( is_null ( $ columns ) || in_array ( $ k , $ columns ) ) && $ v ) { $ tableName = $ schema -> tableName ( $ tableClass ) ; $ dbO = Injector :: inst ( ) -> create ( $ v , $ k ) ; $ dbO -> setTable ( $ tableName ) ; $ dbO -> addToQuery ( $ query ) ; } } }
|
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} on {$localClass}" ) ; } $ schema = DataObject :: getSchema ( ) ; $ foreignTable = $ schema -> tableName ( $ foreignClass ) ; $ foreignTableAliased = $ foreignPrefix . $ foreignTable ; if ( $ this -> query -> isJoinedTo ( $ foreignTableAliased ) ) { return ; } $ foreignKey = $ schema -> getRemoteJoinField ( $ localClass , $ localField , $ type , $ polymorphic ) ; $ localIDColumn = $ schema -> sqlColumnForField ( $ localClass , 'ID' , $ localPrefix ) ; if ( $ polymorphic ) { $ foreignKeyIDColumn = $ schema -> sqlColumnForField ( $ foreignClass , "{$foreignKey}ID" , $ foreignPrefix ) ; $ foreignKeyClassColumn = $ schema -> sqlColumnForField ( $ foreignClass , "{$foreignKey}Class" , $ foreignPrefix ) ; $ localClassColumn = $ schema -> sqlColumnForField ( $ localClass , 'ClassName' , $ localPrefix ) ; $ joinExpression = "{$foreignKeyIDColumn} = {$localIDColumn} AND {$foreignKeyClassColumn} = {$localClassColumn}" ; } else { $ foreignKeyIDColumn = $ schema -> sqlColumnForField ( $ foreignClass , $ foreignKey , $ foreignPrefix ) ; $ joinExpression = "{$foreignKeyIDColumn} = {$localIDColumn}" ; } $ this -> query -> addLeftJoin ( $ foreignTable , $ joinExpression , $ foreignTableAliased ) ; $ ancestry = ClassInfo :: ancestry ( $ foreignClass , true ) ; $ ancestry = array_reverse ( $ ancestry ) ; foreach ( $ ancestry as $ ancestor ) { $ ancestorTable = $ schema -> tableName ( $ ancestor ) ; if ( $ ancestorTable !== $ foreignTable ) { $ ancestorTableAliased = $ foreignPrefix . $ ancestorTable ; $ this -> query -> addLeftJoin ( $ ancestorTable , "\"{$foreignTableAliased}\".\"ID\" = \"{$ancestorTableAliased}\".\"ID\"" , $ ancestorTableAliased ) ; } } }
|
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 ) { throw new InvalidArgumentException ( "Could not join polymorphic has_one relationship {$localField} on {$localClass}" ) ; } $ schema = DataObject :: getSchema ( ) ; $ foreignBaseClass = $ schema -> baseDataClass ( $ foreignClass ) ; $ foreignBaseTable = $ schema -> tableName ( $ foreignBaseClass ) ; if ( $ this -> query -> isJoinedTo ( $ foreignPrefix . $ foreignBaseTable ) ) { return ; } $ foreignIDColumn = $ schema -> sqlColumnForField ( $ foreignBaseClass , 'ID' , $ foreignPrefix ) ; $ localColumn = $ schema -> sqlColumnForField ( $ localClass , "{$localField}ID" , $ localPrefix ) ; $ this -> query -> addLeftJoin ( $ foreignBaseTable , "{$foreignIDColumn} = {$localColumn}" , $ foreignPrefix . $ foreignBaseTable ) ; $ ancestry = ClassInfo :: ancestry ( $ foreignClass , true ) ; if ( ! empty ( $ ancestry ) ) { $ ancestry = array_reverse ( $ ancestry ) ; foreach ( $ ancestry as $ ancestor ) { $ ancestorTable = $ schema -> tableName ( $ ancestor ) ; if ( $ ancestorTable !== $ foreignBaseTable ) { $ ancestorTableAliased = $ foreignPrefix . $ ancestorTable ; $ this -> query -> addLeftJoin ( $ ancestorTable , "{$foreignIDColumn} = \"{$ancestorTableAliased}\".\"ID\"" , $ ancestorTableAliased ) ; } } } }
|
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 ) ) { $ relationClassOrTable = $ schema -> tableName ( $ relationClassOrTable ) ; } $ componentBaseClass = $ schema -> baseDataClass ( $ componentClass ) ; $ componentBaseTable = $ schema -> tableName ( $ componentBaseClass ) ; $ componentAliasedTable = $ componentPrefix . $ componentBaseTable ; if ( $ this -> query -> isJoinedTo ( $ componentAliasedTable ) ) { return ; } $ relationAliasedTable = $ componentPrefix . $ relationClassOrTable ; $ parentIDColumn = $ schema -> sqlColumnForField ( $ parentClass , 'ID' , $ parentPrefix ) ; $ this -> query -> addLeftJoin ( $ relationClassOrTable , "\"{$relationAliasedTable}\".\"{$parentField}\" = {$parentIDColumn}" , $ relationAliasedTable ) ; $ componentIDColumn = $ schema -> sqlColumnForField ( $ componentBaseClass , 'ID' , $ componentPrefix ) ; $ this -> query -> addLeftJoin ( $ componentBaseTable , "\"{$relationAliasedTable}\".\"{$componentField}\" = {$componentIDColumn}" , $ componentAliasedTable ) ; $ ancestry = ClassInfo :: ancestry ( $ componentClass , true ) ; $ ancestry = array_reverse ( $ ancestry ) ; foreach ( $ ancestry as $ ancestor ) { $ ancestorTable = $ schema -> tableName ( $ ancestor ) ; if ( $ ancestorTable !== $ componentBaseTable ) { $ ancestorTableAliased = $ componentPrefix . $ ancestorTable ; $ this -> query -> addLeftJoin ( $ ancestorTable , "{$componentIDColumn} = \"{$ancestorTableAliased}\".\"ID\"" , $ ancestorTableAliased ) ; } } }
|
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 -> setOrderBy ( null ) ; $ subSelectSQL = $ subSelect -> sql ( $ subSelectParameters ) ; $ this -> where ( array ( $ this -> expressionForField ( $ field ) . " NOT IN ($subSelectSQL)" => $ subSelectParameters ) ) ; return $ this ; }
|
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 -> ensureSelectContainsOrderbyColumns ( $ query , $ originalSelect ) ; return $ query -> execute ( ) -> column ( $ field ) ; }
|
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." , E_USER_WARNING ) ; } $ this -> extend ( 'onAfterInit' ) ; }
|
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 , '_' ) . '_' . $ action ; if ( SSViewer :: hasTemplate ( $ templateName ) ) { return $ class ; } $ class = get_parent_class ( $ class ) ; } return null ; }
|
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 ( $ parentClass ) ; } return SSViewer :: hasTemplate ( $ templates ) ; }
|
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 = 'can' . $ perm ) ) { return $ this -> $ methodName ( $ member ) ; } else { return true ; } }
|
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 , $ confirmationTokenChain , $ this -> getApplication ( ) -> getKernel ( ) ) ; if ( $ result ) { return $ result ; } $ params = array_merge ( $ request -> getVars ( ) , $ confirmationTokenChain -> params ( false ) ) ; $ backURL = $ confirmationTokenChain -> getRedirectUrlBase ( ) . '?' . http_build_query ( $ params ) ; $ loginPage = Director :: absoluteURL ( Security :: config ( ) -> get ( 'login_url' ) ) ; $ loginPage .= "?BackURL=" . urlencode ( $ backURL ) ; $ result = new HTTPResponse ( ) ; $ result -> redirect ( $ loginPage ) ; return $ result ; }
|
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 ( $ controller -> Link ( ) , $ this -> form -> getName ( ) ) ; } $ link = Controller :: join_links ( $ base , $ action , '/' ) ; $ this -> extend ( 'updateLink' , $ link , $ action ) ; return $ link ; }
|
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-Type' , 'application/json' ) ; return $ response ; } $ this -> form -> loadMessagesFrom ( $ result ) ; $ response = new HTTPResponse ( $ this -> form -> forTemplate ( ) ) ; $ response -> addHeader ( 'Content-Type' , 'text/html' ) ; return $ response ; }
|
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 $ fieldOrAction instanceof FormAction ; } ) ; return $ actions ; }
|
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 = true ; return $ callback ( $ stream ) ; }
|
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_get ( 'post_max_size' ) ) ; $ this -> getValidator ( ) -> setAllowedMaxFileSize ( min ( $ maxUpload , $ maxPost ) ) ; }
|
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 ] [ 0 ] ; } else { return $ this -> extractValue ( $ this -> items -> current ( ) , $ this -> keyField ) ; } } }
|
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 ) ; } return self :: $ configs [ $ identifier ] ; }
|
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 < ; 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 ( ) ; if ( $ otherPath !== $ path ) { throw new LogicException ( "Module {$name} is in two places - {$path} and {$otherPath}" ) ; } }
|
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 -> setVariable ( self :: PROJECT_KEY , $ project ) ; } $ this -> modules = $ sorter -> getSortedList ( ) ; }
|
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 ) { continue ; } if ( empty ( $ module -> getRelativePath ( ) ) ) { $ rootModule = $ module ; } else { return $ module ; } } return $ rootModule ; }
|
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 ] ) ) { return $ dirs [ $ lang ] ; } return 'ltr' ; }
|
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 [ $ code ] = $ this -> localeName ( $ code ) ; } static :: $ cache_locales [ $ locale ] = $ localised ; return $ localised ; }
|
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 ) { $ localised [ $ code ] = $ this -> languageName ( $ code ) ; } static :: $ cache_languages [ $ locale ] = $ localised ; return $ localised ; }
|
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 ) { $ localised [ $ code ] = $ this -> countryName ( $ code ) ; } $ collator = new Collator ( i18n :: get_locale ( ) ) ; $ collator -> asort ( $ localised ) ; static :: $ cache_countries [ $ locale ] = $ localised ; return $ localised ; }
|
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_string ( $ specId ) ) { $ class = $ specId ; } if ( empty ( $ class ) ) { throw new InvalidArgumentException ( 'Missing spec class' ) ; } $ spec [ 'class' ] = $ class ; $ id = is_string ( $ specId ) ? $ specId : ( isset ( $ spec [ 'id' ] ) ? $ spec [ 'id' ] : $ class ) ; $ priority = isset ( $ spec [ 'priority' ] ) ? $ spec [ 'priority' ] : 1 ; if ( isset ( $ this -> specs [ $ id ] ) && isset ( $ this -> specs [ $ id ] [ 'priority' ] ) ) { if ( $ this -> specs [ $ id ] [ 'priority' ] > $ priority ) { return $ this ; } } if ( file_exists ( $ file ) ) { require_once $ file ; } $ spec [ 'id' ] = $ id ; $ this -> specs [ $ id ] = $ spec ; if ( isset ( $ this -> serviceCache [ $ id ] ) ) { $ this -> updateSpecConstructor ( $ spec ) ; $ this -> instantiate ( $ spec , $ id ) ; } } return $ this ; }
|
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 -> specs [ $ id ] [ 'properties' ] [ $ property ] = $ value ; } if ( isset ( $ this -> serviceCache [ $ id ] ) ) { $ this -> instantiate ( array ( 'class' => $ id ) , $ id ) ; } } }
|
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 ) ; return $ this -> get ( $ id ) ; } if ( preg_match ( '/^`(?<name>[^`]+)`$/' , $ value , $ matches ) ) { $ envValue = Environment :: getEnv ( $ matches [ 'name' ] ) ; if ( $ envValue !== false ) { $ value = $ envValue ; } elseif ( defined ( $ matches [ 'name' ] ) ) { $ value = constant ( $ matches [ 'name' ] ) ; } else { $ value = null ; } } return $ value ; }
|
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 = $ spec [ 'constructor' ] ; } if ( ( ! $ type || $ type !== self :: PROTOTYPE ) && empty ( $ constructorParams ) && is_subclass_of ( $ class , DataObject :: class ) ) { $ constructorParams = array ( null , true ) ; } $ factory = isset ( $ spec [ 'factory' ] ) ? $ this -> get ( $ spec [ 'factory' ] ) : $ this -> getObjectCreator ( ) ; $ object = $ factory -> create ( $ class , $ constructorParams ) ; if ( ! $ object ) { return null ; } if ( ! $ id ) { $ id = isset ( $ spec [ 'id' ] ) ? $ spec [ 'id' ] : null ; } if ( ! $ type ) { $ type = isset ( $ spec [ 'type' ] ) ? $ spec [ 'type' ] : null ; } if ( $ id && ( ! $ type || $ type !== self :: PROTOTYPE ) ) { $ this -> serviceCache [ $ id ] = $ object ; } $ this -> inject ( $ object , $ id ) ; return $ object ; }
|
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 not allowed" ) ; } if ( $ object instanceof $ filterClass ) { $ this -> unregisterNamedObject ( $ key ) ; break ; } } } return $ this ; }
|
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 ] ) ) { return $ this -> specs [ $ name ] ; } } if ( ! $ inherit || ! strpos ( $ name , '.' ) ) { return null ; } return $ this -> getServiceSpec ( substr ( $ name , 0 , strrpos ( $ 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 $ query -> where ( $ where ) ; } $ where = DB :: get_conn ( ) -> comparisonClause ( $ field , null , true , ! $ inclusive , $ this -> getCaseSensitive ( ) , true ) ; if ( ! $ inclusive ) { $ nullClause = DB :: get_conn ( ) -> nullCheckClause ( $ field , true ) ; $ where .= " OR {$nullClause}" ; } $ clause = [ $ where => $ value ] ; return $ this -> aggregate ? $ this -> applyAggregate ( $ query , $ clause ) : $ query -> where ( $ clause ) ; }
|
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 \ InvalidArgumentException ( "Cannot filter {$field} against an empty set" ) ; } $ hasNull = in_array ( null , $ values , true ) ; if ( $ hasNull ) { $ values = array_filter ( $ values , function ( $ value ) { return $ value !== null ; } ) ; } $ connective = '' ; if ( empty ( $ values ) ) { $ predicate = '' ; } elseif ( $ caseSensitive === null ) { $ column = $ this -> getDbName ( ) ; $ placeholders = DB :: placeholders ( $ values ) ; if ( $ inclusive ) { $ predicate = "$column IN ($placeholders)" ; } else { $ predicate = "$column NOT IN ($placeholders)" ; } } else { $ comparisonClause = DB :: get_conn ( ) -> comparisonClause ( $ this -> getDbName ( ) , null , true , ! $ inclusive , $ this -> getCaseSensitive ( ) , true ) ; $ count = count ( $ values ) ; if ( $ count > 1 ) { $ connective = $ inclusive ? ' OR ' : ' AND ' ; $ conditions = array_fill ( 0 , $ count , $ comparisonClause ) ; $ predicate = implode ( $ connective , $ conditions ) ; } else { $ predicate = $ comparisonClause ; } } if ( $ hasNull || ! $ inclusive ) { $ isNull = ! $ hasNull || $ inclusive ; $ nullCondition = DB :: get_conn ( ) -> nullCheckClause ( $ field , $ isNull ) ; if ( empty ( $ predicate ) ) { $ predicate = $ nullCondition ; } else { if ( $ isNull ) { $ nullCondition = " OR {$nullCondition}" ; } else { $ nullCondition = " AND {$nullCondition}" ; } if ( $ connective && ( ( $ connective === ' OR ' ) !== $ isNull ) ) { $ predicate = "({$predicate})" ; } $ predicate .= $ nullCondition ; } } $ clause = [ $ predicate => $ values ] ; return $ this -> aggregate ? $ this -> applyAggregate ( $ query , $ clause ) : $ query -> where ( $ clause ) ; }
|
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 ( stripos ( $ relativePath , ManifestFileFinder :: VENDOR_DIR . DIRECTORY_SEPARATOR ) === 0 ) { $ relativePath = Path :: join ( RESOURCES_DIR , substr ( $ relativePath , strlen ( ManifestFileFinder :: VENDOR_DIR ) ) ) ; } return [ $ exists , $ absolutePath , $ relativePath ] ; }
|
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 = ( $ this -> getRequireExistingPassword ( ) && isset ( $ value [ '_CurrentPassword' ] ) ) ? $ value [ '_CurrentPassword' ] : null ; if ( $ this -> showOnClick && isset ( $ value [ '_PasswordFieldVisible' ] ) ) { $ this -> getChildren ( ) -> fieldByName ( $ this -> getName ( ) . '[_PasswordFieldVisible]' ) -> setValue ( $ value [ '_PasswordFieldVisible' ] ) ; } } else { if ( $ value || ( ! $ value && $ this -> canBeEmpty ) ) { $ this -> value = $ value ; $ this -> confirmValue = $ value ; } } if ( $ oldValue != $ this -> value ) { $ this -> getChildren ( ) -> fieldByName ( $ this -> getName ( ) . '[_Password]' ) -> setValue ( $ this -> value ) ; $ this -> getChildren ( ) -> fieldByName ( $ this -> getName ( ) . '[_ConfirmPassword]' ) -> setValue ( $ this -> confirmValue ) ; } return $ this ; }
|
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 ( $ name ) ; return $ this ; }
|
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 ( $ currentName , _t ( 'SilverStripe\\Security\\Member.CURRENT_PASSWORD' , 'Current Password' ) ) ; $ this -> getChildren ( ) -> unshift ( $ confirmField ) ; } else { $ this -> getChildren ( ) -> removeByName ( $ currentName , true ) ; } return $ this ; }
|
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() encountered a non array argument' , E_USER_WARNING ) ; return [ ] ; } if ( ! $ array ) { continue ; } foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) && array_key_exists ( $ key , $ merged ) && is_array ( $ merged [ $ key ] ) ) { $ merged [ $ key ] = ArrayLib :: array_merge_recursive ( $ merged [ $ key ] , $ value ) ; } else { $ merged [ $ key ] = $ value ; } } } return $ merged ; }
|
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 ; } } ) ; return $ out ; }
|
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 ( $ this -> failover ) . " object has neither an AbsoluteLink nor a Link method." . " Can't put a link in the RSS feed" , E_USER_WARNING ) ; }
|
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 .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.