idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
43,800
public static function getRealRelationFields ( string $ module ) : array { $ relation = [ ] ; $ table = TableRegistry :: getTableLocator ( ) -> get ( $ module ) ; foreach ( $ table -> associations ( ) as $ association ) { $ relation [ ] = $ association -> getName ( ) ; } return $ relation ; }
Returns a list of relation fields .
43,801
public static function getVirtualModuleFields ( string $ module , bool $ validate = true ) : array { $ fields = [ ] ; $ mc = new ModuleConfig ( ConfigType :: MODULE ( ) , $ module , null , [ 'cacheSkip' => true ] ) ; $ mc -> setParser ( new Parser ( $ mc -> createSchema ( ) , [ 'validate' => $ validate ] ) ) ; $ virtua...
Returns a list of virtual fields in config . json .
43,802
public static function isVirtualModuleField ( string $ module , string $ field ) : bool { $ config = self :: getVirtualModuleFields ( $ module ) ; if ( empty ( $ config ) || ! is_array ( $ config ) ) { return false ; } return in_array ( $ field , array_keys ( $ config ) ) ; }
Check if the field is defined in the module s virtual fields
43,803
public static function isValidModuleField ( string $ module , string $ field ) : bool { return static :: isRealModuleField ( $ module , $ field ) || static :: isVirtualModuleField ( $ module , $ field ) || static :: isRealRelationField ( $ module , $ field ) ; }
Check if the given field is valid for given module
43,804
public static function isValidFieldType ( string $ type ) : bool { try { $ config = ConfigFactory :: getByType ( $ type , 'dummy_field' ) ; } catch ( InvalidArgumentException $ e ) { return false ; } return true ; }
Check if the field type is valid
43,805
private function selection ( string $ path ) : array { $ modules = $ this -> getModules ( $ path ) ; if ( empty ( $ modules ) ) { $ this -> abort ( 'Aborting, system modules not found.' ) ; } $ result [ ] = $ this -> in ( 'Please select first related module:' , $ modules ) ; $ result [ ] = $ this -> in ( 'Please select...
Interactive shell for modules selection .
43,806
private function isModule ( string $ module ) : bool { $ config = ( new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ module , null , [ 'cacheSkip' => true ] ) ) -> parse ( ) ; $ config = json_encode ( $ config ) ; if ( false === $ config ) { return false ; } $ config = json_decode ( $ config , true ) ; if ( empty ( $...
Checks module validity .
43,807
private function normalize ( array $ selection ) : array { $ result = [ ] ; foreach ( $ selection as $ module ) { $ result [ ] = $ this -> _camelize ( strtolower ( trim ( $ module ) ) ) ; } $ result = array_unique ( $ result ) ; asort ( $ result ) ; return $ result ; }
Interactive input normalization .
43,808
private function validate ( string $ name , string $ path ) : void { if ( ! ctype_alpha ( $ name ) ) { $ this -> abort ( sprintf ( 'Invalid Relation name provided: %s' , $ name ) ) ; } if ( in_array ( $ name , Utility :: findDirs ( $ path ) ) ) { $ this -> abort ( sprintf ( 'Relation %s already exists' , $ name ) ) ; }...
Validates relation name parameter .
43,809
private function bakeModuleConfig ( array $ selection , string $ path ) : bool { reset ( $ selection ) ; $ this -> BakeTemplate -> set ( [ 'display_field' => $ this -> _modelKey ( current ( $ selection ) ) ] ) ; return $ this -> createFile ( $ path . implode ( '' , $ selection ) . DS . 'config' . DS . 'config.dist.json...
Bake Relation configuration files .
43,810
protected function getRemindersToModules ( RepositoryInterface $ table ) : array { $ config = ( new ModuleConfig ( ConfigType :: MODULE ( ) , $ table -> getRegistryAlias ( ) ) ) -> parseToArray ( ) ; if ( empty ( $ config [ 'table' ] [ 'allow_reminders' ] ) ) { return [ ] ; } return $ config [ 'table' ] [ 'allow_remind...
Get a list of reminder modules
43,811
protected function getReminderField ( RepositoryInterface $ table ) : string { $ config = ( new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ table -> getRegistryAlias ( ) ) ) -> parse ( ) ; $ fields = array_filter ( ( array ) $ config , function ( $ field ) { if ( 'reminder' === $ field -> type ) { return $ field ; }...
Get the fist reminder field of the given table
43,812
protected function getAttendeesFields ( Table $ table , array $ modules ) : array { $ associations = [ ] ; foreach ( $ table -> associations ( ) as $ association ) { if ( in_array ( Inflector :: humanize ( $ association -> getTarget ( ) -> getTable ( ) ) , $ modules ) ) { $ associations [ ] = $ association ; } } if ( e...
Retrieve attendees fields from current Table s associations .
43,813
protected function isRequiredModified ( EntityInterface $ entity , array $ requiredFields ) : bool { foreach ( $ requiredFields as $ field ) { if ( $ entity -> isDirty ( $ field ) ) { return true ; } } return false ; }
Check that required entity fields are modified
43,814
protected function getEventOptions ( CsvTable $ table , EntityInterface $ entity , string $ startField ) : array { $ eventTimes = $ this -> getEventTime ( $ entity , $ startField ) ; $ mailer = new IcEmail ( $ table , $ entity ) ; $ result = [ 'id' => $ entity -> get ( 'id' ) , 'sequence' => $ entity -> isNew ( ) ? 0 :...
Get options for the new event
43,815
public function validate ( ) : bool { $ table = $ this -> getConfig ( ) -> getTable ( ) ; foreach ( [ $ this -> config -> getField ( ) , $ this -> config -> getDisplayField ( ) ] as $ field ) { if ( $ table -> getSchema ( ) -> hasColumn ( $ field ) ) { continue ; } $ this -> errors [ ] = sprintf ( 'Unknown column "%s" ...
Validator method .
43,816
public static function toDateTime ( $ value , DateTimeZone $ dtz ) : DateTime { $ format = 'Y-m-d H:i:s' ; if ( is_string ( $ value ) ) { $ val = strtotime ( $ value ) ; if ( false === $ val ) { throw new InvalidArgumentException ( sprintf ( 'Unsupported datetime string provided: %s' , $ value ) ) ; } return new DateTi...
Convert a given value to DateTime instance
43,817
public static function offsetToUtc ( DateTime $ value ) : DateTime { $ result = $ value ; $ dtz = $ value -> getTimezone ( ) ; if ( $ dtz -> getName ( ) === 'UTC' ) { return $ result ; } $ epoch = time ( ) ; $ transitions = $ dtz -> getTransitions ( $ epoch , $ epoch ) ; $ offset = $ transitions [ 0 ] [ 'offset' ] ; $ ...
Offset DateTime value to UTC
43,818
protected function _extractType ( string $ type ) : string { if ( preg_match ( static :: PATTERN_TYPE , $ type , $ matches ) ) { if ( ! empty ( $ matches [ 1 ] ) ) { return $ matches [ 1 ] ; } } return $ type ; }
Extract field type from type value
43,819
protected function _extractLimit ( string $ type ) { if ( preg_match ( static :: PATTERN_TYPE , $ type , $ matches ) ) { if ( ! empty ( $ matches [ 2 ] ) ) { return $ matches [ 2 ] ; } } return static :: DEFAULT_FIELD_LIMIT ; }
Extract field limit from type value
43,820
public function setName ( string $ name ) : void { if ( empty ( $ name ) ) { throw new InvalidArgumentException ( 'Empty field name is not allowed' ) ; } $ this -> _name = $ name ; }
Set field name
43,821
public function setType ( string $ type ) : void { if ( empty ( $ type ) ) { throw new InvalidArgumentException ( 'Empty field type is not allowed: ' . $ this -> getName ( ) ) ; } $ this -> _type = $ this -> _extractType ( $ type ) ; }
Set field type
43,822
public function setLimit ( $ limit ) : void { if ( $ limit === null ) { $ this -> _limit = $ limit ; return ; } if ( is_int ( $ limit ) || is_numeric ( $ limit ) ) { $ limit = abs ( intval ( $ limit ) ) ; $ this -> _limit = $ limit === 0 ? null : $ limit ; return ; } if ( empty ( $ limit ) ) { throw new InvalidArgument...
Set field limit
43,823
public function getProvider ( string $ name ) : string { $ providers = $ this -> getProviders ( ) ; if ( ! in_array ( $ name , array_keys ( $ providers ) ) ) { throw new InvalidArgumentException ( "Provider for [$name] is not configured" ) ; } return $ providers [ $ name ] ; }
Get provider by name
43,824
protected function getSearchOperators ( $ data = null , array $ options = [ ] ) : array { $ result = $ this -> config -> getProvider ( 'searchOperators' ) ; $ result = new $ result ( $ this -> config ) ; $ result = $ result -> provide ( $ data , $ options ) ; return $ result ; }
Helper method to get search operators
43,825
protected function getDefaultOptions ( $ data = null , array $ options = [ ] ) : array { $ result = [ 'type' => $ options [ 'fieldDefinitions' ] -> getType ( ) , 'label' => $ options [ 'label' ] , 'operators' => $ this -> getSearchOperators ( $ data , $ options ) , 'input' => [ 'content' => '' , ] , ] ; return $ result...
Get default search options
43,826
protected function getBasicTemplate ( string $ type ) : string { $ view = $ this -> config -> getView ( ) ; $ result = $ view -> Form -> control ( '{{name}}' , [ 'value' => '{{value}}' , 'type' => $ type , 'label' => false ] ) ; return $ result ; }
Get basic template for a given type
43,827
public function getOptions ( string $ listName ) : array { try { $ entity = $ this -> find ( 'all' ) -> enableHydration ( true ) -> where ( [ 'name' => $ listName ] ) -> firstOrFail ( ) ; } catch ( RecordNotFoundException $ e ) { return [ ] ; } $ treeOptions = [ 'keyPath' => 'value' , 'valuePath' => 'name' , 'spacer' =...
Reusable query options .
43,828
protected function checkParent ( string $ module , array $ options = [ ] , array $ config = [ ] ) : void { if ( empty ( $ config [ 'parent' ] ) ) { return ; } if ( ! empty ( $ config [ 'parent' ] [ 'redirect' ] ) ) { if ( in_array ( $ config [ 'parent' ] [ 'redirect' ] , [ 'parent' ] ) ) { if ( empty ( $ config [ 'pare...
Check parent section of the configuration
43,829
public static function get ( AggregatorInterface $ aggregator ) { $ config = $ aggregator -> getConfig ( ) ; $ query = $ config -> getTable ( ) -> find ( 'all' ) ; $ query = $ aggregator -> applyConditions ( $ query ) ; $ query = static :: join ( $ aggregator , $ query ) ; $ entity = $ query -> first ( ) ; if ( null ==...
Aggregator execution method .
43,830
private static function join ( AggregatorInterface $ aggregator , QueryInterface $ query ) : QueryInterface { $ config = $ aggregator -> getConfig ( ) ; if ( ! $ config -> joinMode ( ) ) { return $ query ; } Assert :: isInstanceOf ( $ query , Query :: class ) ; $ association = static :: findAssociation ( $ aggregator )...
Aggregator query is joined whenever the entity instance is set meaning that the results will be limited to the entity s associated records .
43,831
private static function findAssociation ( AggregatorInterface $ aggregator ) : Association { $ config = $ aggregator -> getConfig ( ) ; $ table = $ config -> getTable ( ) ; $ joinTable = $ config -> getJoinTable ( ) ; foreach ( $ table -> associations ( ) as $ association ) { if ( ! in_array ( $ association -> type ( )...
Association instance finder .
43,832
public function setName ( string $ name = '' ) : void { if ( empty ( $ name ) ) { throw new RuntimeException ( 'Panel name not found therefore the object cannot be created' ) ; } $ this -> name = $ name ; }
Setter of panel name .
43,833
public function getExpression ( bool $ clean = false ) : string { return $ clean ? str_replace ( self :: EXP_TOKEN , '' , $ this -> expression ) : $ this -> expression ; }
Getter of expression
43,834
public function setExpression ( array $ config ) : void { $ panels = Hash :: get ( $ config , self :: PANELS ) ; $ exp = Hash :: get ( $ panels , $ this -> getName ( ) ) ; $ this -> expression = $ exp ; }
Setter of expression .
43,835
public function setFields ( ) : void { preg_match_all ( '#' . self :: EXP_TOKEN . '(.*?)' . self :: EXP_TOKEN . '#' , $ this -> getExpression ( ) , $ matches ) ; if ( empty ( $ matches [ 1 ] ) ) { throw new InvalidArgumentException ( "No tokens found in expression" ) ; } $ this -> fields = $ matches [ 1 ] ; }
Setter of fields .
43,836
public function getFieldValues ( array $ data ) : array { $ result = [ ] ; foreach ( $ this -> getFields ( ) as $ field ) { $ result [ $ field ] = array_key_exists ( $ field , $ data ) ? $ data [ $ field ] : null ; } return $ result ; }
Returns field values from the given entity .
43,837
public function evalExpression ( array $ data ) : bool { $ language = new ExpressionLanguage ( ) ; $ values = $ this -> getFieldValues ( $ data ) ; $ eval = $ language -> evaluate ( $ this -> getExpression ( true ) , $ values ) ; return $ eval ; }
Evaluate the expression .
43,838
public static function getPanelNames ( array $ config ) : array { if ( empty ( $ config [ self :: PANELS ] ) ) { return [ ] ; } return array_keys ( $ config [ self :: PANELS ] ) ; }
Returns panel names .
43,839
public static function getLookup ( RepositoryInterface $ table ) : array { $ moduleName = App :: shortName ( get_class ( $ table ) , 'Model/Table' , 'Table' ) ; $ config = new ModuleConfig ( ConfigType :: MODULE ( ) , $ moduleName ) ; $ parsed = $ config -> parse ( ) ; if ( ! property_exists ( $ parsed , 'table' ) ) { ...
Get Table s lookup fields .
43,840
public static function getCsv ( RepositoryInterface $ table ) : array { $ moduleName = App :: shortName ( get_class ( $ table ) , 'Model/Table' , 'Table' ) ; $ config = new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ moduleName ) ; $ parsed = json_encode ( $ config -> parse ( ) ) ; if ( false === $ parsed ) { return...
Get Table s csv fields .
43,841
public static function getCsvField ( RepositoryInterface $ table , string $ field ) : ? CsvField { if ( '' === $ field ) { return null ; } $ moduleName = App :: shortName ( get_class ( $ table ) , 'Model/Table' , 'Table' ) ; $ config = new ModuleConfig ( ConfigType :: MIGRATION ( ) , $ moduleName ) ; $ parsed = $ confi...
CSV field instance getter .
43,842
public static function getVirtual ( RepositoryInterface $ table ) : array { $ moduleName = App :: shortName ( get_class ( $ table ) , 'Model/Table' , 'Table' ) ; $ config = ( new ModuleConfig ( ConfigType :: MODULE ( ) , $ moduleName ) ) -> parse ( ) ; return property_exists ( $ config , 'virtualFields' ) ? ( array ) $...
Module virtual fields getter .
43,843
public static function getCsvView ( RepositoryInterface $ table , string $ action , bool $ includeModel = false , bool $ panels = false ) : array { $ tableName = App :: shortName ( get_class ( $ table ) , 'Model/Table' , 'Table' ) ; $ config = ( new ModuleConfig ( ConfigType :: VIEW ( ) , $ tableName , $ action ) ) -> ...
Get View s csv fields .
43,844
public static function getList ( string $ listName , bool $ flat = false ) : array { $ moduleName = '' ; if ( false !== strpos ( $ listName , '.' ) ) { list ( $ moduleName , $ listName ) = explode ( '.' , $ listName , 2 ) ; } $ config = new ModuleConfig ( ConfigType :: LISTS ( ) , $ moduleName , $ listName , [ 'flatten...
Get list s options .
43,845
protected static function arrangePanels ( array $ fields ) : array { $ result = [ ] ; foreach ( $ fields as $ row ) { $ panelName = array_shift ( $ row ) ; $ result [ $ panelName ] [ ] = $ row ; } return $ result ; }
Method that arranges csv fields into panels .
43,846
protected static function setFieldPluginAndModel ( string $ tableName , array $ fields ) : array { list ( $ plugin , $ model ) = pluginSplit ( $ tableName ) ; $ callback = function ( & $ value , $ key ) use ( $ plugin , $ model ) { $ value = [ 'plugin' => $ plugin , 'model' => $ model , 'name' => $ value ] ; return $ v...
Add plugin and model name for each of the csv fields .
43,847
public function findImported ( QueryInterface $ query , array $ options ) : QueryInterface { $ query -> where ( [ 'import_id' => $ options [ 'import' ] -> id , 'status' => static :: STATUS_SUCCESS ] ) ; return $ query ; }
Find import results by import id and success status .
43,848
public function findPending ( QueryInterface $ query , array $ options ) : QueryInterface { $ query -> where ( [ 'import_id' => $ options [ 'import' ] -> id , 'status' => static :: STATUS_PENDING ] ) ; return $ query ; }
Find import results by import id and pending status .
43,849
public function findFailed ( QueryInterface $ query , array $ options ) : QueryInterface { $ query -> where ( [ 'import_id' => $ options [ 'import' ] -> id , 'status' => static :: STATUS_FAIL ] ) ; return $ query ; }
Find import results by import id and fail status .
43,850
protected function validateEmbedded ( string $ embeddedValue , string $ module , string $ view ) : void { list ( $ embeddedModule , $ embeddedModuleField ) = false !== strpos ( $ embeddedValue , '.' ) ? explode ( '.' , $ embeddedValue ) : [ null , $ embeddedValue ] ; if ( empty ( $ embeddedModule ) ) { $ this -> errors...
Validates values enclosed in EMBEDDED
43,851
protected function validateAssociation ( string $ associationValue , string $ module , string $ view ) : void { $ table = TableRegistry :: getTableLocator ( ) -> get ( $ module ) ; if ( ! $ table -> hasAssociation ( $ associationValue ) ) { $ this -> errors [ ] = sprintf ( '%s module [%s] view reference ASSOCIATION col...
Validates values enclosed in ASSOCIATION
43,852
protected function _getRelatedParentProperties ( array $ relatedProperties ) : array { if ( empty ( $ relatedProperties [ 'entity' ] ) || empty ( $ relatedProperties [ 'controller' ] ) || empty ( $ relatedProperties [ 'config' ] [ 'parent' ] [ 'module' ] ) ) { return [ ] ; } $ foreignKey = $ this -> _getForeignKey ( Ta...
Get related model s parent model properties .
43,853
protected function _getRelatedProperties ( string $ tableName , string $ data ) : array { $ table = TableRegistry :: get ( $ tableName ) ; $ config = ( new ModuleConfig ( ConfigType :: MODULE ( ) , $ tableName ) ) -> parseToArray ( ) ; $ displayField = $ table -> getDisplayField ( ) ; $ displayFieldValue = '' ; try { $...
Get related model s properties .
43,854
protected function _getForeignKey ( Table $ table , string $ modelName ) : string { foreach ( $ table -> associations ( ) as $ association ) { if ( $ modelName !== $ association -> className ( ) ) { continue ; } $ primaryKey = $ association -> getForeignKey ( ) ; if ( ! is_string ( $ primaryKey ) ) { throw new RuntimeE...
Get parent model association s foreign key .
43,855
protected function _getAssociatedRecord ( Table $ table , string $ value ) : EntityInterface { $ primaryKey = $ table -> getPrimaryKey ( ) ; if ( ! is_string ( $ primaryKey ) ) { throw new UnsupportedPrimaryKeyException ( ) ; } $ finderMethod = $ table -> hasBehavior ( 'Trash' ) ? 'withTrashed' : 'all' ; $ entity = $ t...
Retrieve and return associated record Entity by primary key value . If the record has been trashed - query will return NULL .
43,856
protected function _getInputHelp ( array $ properties ) : string { $ config = ( new ModuleConfig ( ConfigType :: MODULE ( ) , $ properties [ 'controller' ] ) ) -> parseToArray ( ) ; $ typeaheadFields = ! empty ( $ config [ 'table' ] [ 'typeahead_fields' ] ) ? $ config [ 'table' ] [ 'typeahead_fields' ] : [ ] ; if ( emp...
Generate input help string
43,857
protected function _getInputIcon ( array $ properties ) : string { $ config = ( new ModuleConfig ( ConfigType :: MODULE ( ) , $ properties [ 'controller' ] ) ) -> parseToArray ( ) ; if ( ! isset ( $ config [ 'table' ] ) ) { return Configure :: read ( 'CsvMigrations.default_icon' ) ; } if ( ! isset ( $ config [ 'table' ...
Get input field associated icon
43,858
public static function getParallelLimit ( $ tokenData ) { if ( ! empty ( $ tokenData [ 'owner' ] [ 'limits' ] [ self :: PARALLEL_LIMIT_NAME ] [ 'value' ] ) ) { return ( int ) $ tokenData [ 'owner' ] [ 'limits' ] [ self :: PARALLEL_LIMIT_NAME ] [ 'value' ] ; } return null ; }
Parallel jobs limit of KBC project null if unlimited
43,859
protected function getPostJson ( Request $ request , $ assoc = true ) { $ return = array ( ) ; $ body = $ request -> getContent ( ) ; if ( ! empty ( $ body ) && ! is_null ( $ body ) && $ body != 'null' ) { $ return = json_decode ( $ body , $ assoc ) ; if ( json_last_error ( ) != JSON_ERROR_NONE ) { throw new UserExcept...
Extracts POST data in JSON from request
43,860
public function autoload ( $ class ) { $ parent = explode ( '\\' , get_class ( $ this ) ) ; $ class_array = explode ( '\\' , $ class ) ; $ intersect = array_intersect_assoc ( $ parent , $ class_array ) ; $ intersect_depth = count ( $ intersect ) ; $ autoload_match_depth = static :: $ autoload_ns_match_depth ; if ( $ in...
Auto - load classes on demand to reduce memory consumption . Classes must have a namespace so as to resolve performance issues around auto - loading classes unrelated to current plugin .
43,861
protected function configure_defaults ( ) { $ this -> modules = new \ stdClass ( ) ; $ this -> modules -> count = 0 ; $ this -> installed_dir = static :: dirname ( static :: $ current_file , 1 ) ; $ this -> plugin_basedir = static :: dirname ( static :: $ current_file , 2 ) ; $ assumed_plugin_name = basename ( $ this -...
Setup plugins global params .
43,862
public static function filepath_to_classname ( $ file , $ installed_dir , $ namespace ) { $ path_info = str_ireplace ( $ installed_dir , '' , $ file ) ; $ path_info = pathinfo ( $ path_info ) ; $ converted_dir = str_replace ( '/' , '\\' , $ path_info [ 'dirname' ] ) ; $ converted_dir = ucwords ( $ converted_dir , '_\\'...
Utility function to get class name from filename if you follow this abstract plugin s naming standards
43,863
public static function get ( ) { global $ wp_plugins ; $ plugin_name = strtolower ( get_called_class ( ) ) ; if ( isset ( $ wp_plugins ) && isset ( $ wp_plugins -> $ plugin_name ) ) { return $ wp_plugins -> $ plugin_name ; } else { return false ; } }
Used to get the instance of the class as an unforced singleton model
43,864
private function get_file_name_from_class ( $ class ) { if ( 'classmap' === static :: $ autoload_type ) { $ filtered_class_name = explode ( '\\' , $ class ) ; $ class_filename = end ( $ filtered_class_name ) ; $ class_filename = str_replace ( '_' , '-' , $ class_filename ) ; return static :: $ filename_prefix . $ class...
Take a class name and turn it into a file name .
43,865
private function load_file ( $ path ) { if ( $ path && is_readable ( $ path ) ) { include_once ( $ path ) ; $ success = true ; } return ! ( empty ( $ success ) ) ? true : false ; }
Include a class file .
43,866
private function psr4_get_file_name_from_class ( $ class ) { $ class = strtolower ( $ class ) ; if ( stristr ( $ class , '\\' ) ) { $ class = str_ireplace ( static :: $ autoload_class_prefix , '' , $ class ) ; $ class = str_replace ( [ '_' , '\\' ] , [ '-' , '/' ] , $ class ) ; $ class = explode ( '/' , $ class ) ; $ f...
Take a namespaced class name and turn it into a file name .
43,867
public static function run ( $ file ) { if ( did_action ( 'plugins_loaded' ) ) { add_action ( 'init' , [ get_called_class ( ) , 'load' ] , 1 ) ; } else { add_action ( 'plugins_loaded' , [ get_called_class ( ) , 'load' ] ) ; } register_activation_hook ( $ file , [ get_called_class ( ) , 'activate' ] ) ; register_deactiv...
Setup special hooks that don t run after plugins_loaded action
43,868
private static function set ( $ instance = false ) { global $ wp_plugins ; if ( ! isset ( $ wp_plugins ) ) { $ wp_plugins = new \ stdClass ( ) ; } $ called_class = get_called_class ( ) ; $ plugin_name = strtolower ( $ called_class ) ; if ( empty ( $ instance ) || ! is_a ( $ instance , $ called_class ) ) { $ wp_plugins ...
Used to setup the instance of the class and place in wp_plugins collection .
43,869
public function getMapping ( ) { $ params [ 'index' ] = $ this -> getLastIndexName ( ) ; $ params [ 'type' ] = 'jobs' ; return $ this -> client -> indices ( ) -> getMapping ( $ params ) ; }
Return mapping from latest index
43,870
public function onBeforeWrite ( ) { if ( ! $ this -> owner -> isChanged ( 'CurrentVersionID' ) ) { return ; } if ( $ this -> owner -> hasMethod ( 'regenerateFormattedImages' ) ) { $ this -> owner -> regenerateFormattedImages ( ) ; return ; } if ( $ this -> owner -> ParentID ) { $ base = $ this -> owner -> Parent ( ) ->...
Regenerates all cached images if the version number has been changed .
43,871
public function onAfterWrite ( ) { $ changed = $ this -> owner -> getChangedFields ( true , 2 ) ; if ( ! $ this -> owner instanceof Folder && ! $ this -> owner -> CurrentVersionID ) { $ this -> createVersion ( ) ; } if ( array_key_exists ( 'Filename' , $ changed ) ) { if ( $ changed [ 'Filename' ] [ 'before' ] == null ...
Creates the initial version when the file is created as well as updating the version records when the parent file is moved .
43,872
public function onBeforeDelete ( ) { $ currentVersion = $ this -> owner -> CurrentVersion ( ) ; if ( $ currentVersion && $ currentVersion -> ID > 0 ) { $ folder = dirname ( $ this -> owner -> CurrentVersion ( ) -> getFullPath ( ) ) ; if ( $ versions = $ this -> owner -> Versions ( ) ) { foreach ( $ versions as $ versio...
Deletes all saved version of the file as well as the file itself .
43,873
public function savePreviousVersion ( $ version ) { if ( ! is_numeric ( $ version ) ) { return ; } try { $ this -> setVersionNumber ( $ version ) ; $ this -> owner -> write ( ) ; } catch ( Exception $ e ) { throw new ValidationException ( new ValidationResult ( false , "Could not replace file #{$this->owner->ID} with v...
Handles rolling back to a selected version on save .
43,874
public function createVersion ( ) { if ( ! file_exists ( $ this -> owner -> getFullPath ( ) ) ) { return false ; } $ version = new FileVersion ( ) ; $ version -> FileID = $ this -> owner -> ID ; $ version -> write ( ) ; $ this -> owner -> CurrentVersionID = $ version -> ID ; return ( bool ) $ this -> owner -> write ( )...
Creates a new file version and sets it as the current version .
43,875
public function indexAction ( ) { $ rootPath = str_replace ( 'web/../' , '' , ROOT_PATH ) ; $ filepath = $ rootPath . '/../../composer/installed.json' ; if ( ! file_exists ( $ filepath ) ) { $ filepath = $ rootPath . '/vendor/composer/installed.json' ; } $ installedJson = file_get_contents ( $ filepath ) ; $ jsonDecode...
Displays Syrup components with their recent version
43,876
public function onBeforeWrite ( ) { if ( ! $ this -> isInDB ( ) ) { $ this -> CreatorID = Member :: currentUserID ( ) ; } if ( ! $ this -> VersionNumber ) { $ versions = DataObject :: get ( 'FileVersion' , sprintf ( '"FileID" = %d' , $ this -> FileID ) ) ; if ( $ versions ) { $ this -> VersionNumber = $ versions -> Cou...
Saves version meta - data and generates the saved file version on first write .
43,877
protected function saveCurrentVersion ( ) { $ file = File :: get ( ) -> byID ( $ this -> FileID ) ; if ( $ file -> ParentID ) { $ base = Controller :: join_links ( $ file -> Parent ( ) -> getFullPath ( ) , self :: VERSION_FOLDER , $ this -> FileID ) ; } else { $ base = Controller :: join_links ( Director :: baseFolder ...
Saves the current version of the linked File object in a versions directory then returns the relative path to where it is stored .
43,878
protected function enqueue ( $ jobId , $ queueName = 'default' , $ otherData = [ ] ) { $ queue = $ this -> container -> get ( 'syrup.queue_factory' ) -> get ( $ queueName ) ; return $ queue -> enqueue ( $ jobId , $ otherData ) ; }
Add JobId to queue
43,879
public function setStatus ( $ status ) { $ allowedStatuses = array ( Job :: STATUS_ERROR , Job :: STATUS_SUCCESS , Job :: STATUS_WARNING , Job :: STATUS_TERMINATED ) ; if ( ! in_array ( $ status , $ allowedStatuses ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Status "%s" is not allowed in JobException' , $ s...
Set job status
43,880
protected function _checkSignature ( ) { if ( ! $ this -> getConfig ( 'security.secureUrls' ) ) { return ; } $ signKey = $ this -> getConfig ( 'security.signKey' ) ? : Security :: getSalt ( ) ; try { SignatureFactory :: create ( $ signKey ) -> validateRequest ( $ this -> _path , $ this -> _params ) ; } catch ( Exceptio...
Check signature token if secure URLs are enabled .
43,881
protected function _checkModified ( $ request , $ response , $ server ) { $ modifiedTime = false ; try { $ modifiedTime = $ server -> getSource ( ) -> getTimestamp ( $ server -> getSourcePath ( $ this -> _path ) ) ; } catch ( Exception $ exception ) { return $ this -> _handleException ( $ request , $ response , $ excep...
Get file s modified time .
43,882
protected function _getResponse ( $ request , $ response , $ server ) { if ( ( empty ( $ this -> _params ) || ( count ( $ this -> _params ) === 1 && isset ( $ this -> _params [ 's' ] ) ) ) && $ this -> getConfig ( 'originalPassThrough' ) ) { try { $ response = $ this -> _passThrough ( $ request , $ response , $ server ...
Get response instance which contains image to render .
43,883
protected function _passThrough ( $ request , $ response , $ server ) { $ source = $ server -> getSource ( ) ; $ path = $ server -> getSourcePath ( $ this -> _path ) ; $ resource = $ source -> readStream ( $ path ) ; if ( $ resource === false ) { throw new ResponseException ( ) ; } $ stream = new Stream ( $ resource ) ...
Generate response using original image .
43,884
protected function _isNotModified ( $ request , $ modifiedTime ) { $ modifiedSince = $ request -> getHeaderLine ( 'If-Modified-Since' ) ; if ( ! $ modifiedSince ) { return false ; } return strtotime ( $ modifiedSince ) === ( int ) $ modifiedTime ; }
Compare file s modfied time with If - Modified - Since header .
43,885
protected function _withCacheHeaders ( $ response , $ cacheTime , $ modifiedTime ) { $ expire = strtotime ( $ cacheTime ) ; $ maxAge = $ expire - time ( ) ; return $ response -> withHeader ( 'Cache-Control' , 'public,max-age=' . $ maxAge ) -> withHeader ( 'Date' , gmdate ( 'D, j M Y G:i:s \G\M\T' , time ( ) ) ) -> with...
Return response instance with caching headers .
43,886
protected function _withCustomHeaders ( $ response ) { foreach ( ( array ) $ this -> getConfig ( 'headers' ) as $ key => $ value ) { $ response = $ response -> withHeader ( $ key , $ value ) ; } return $ response ; }
Return response instance with headers specified in config .
43,887
public function url ( $ path , array $ params = [ ] ) { $ base = true ; if ( isset ( $ params [ '_base' ] ) ) { $ base = $ params [ '_base' ] ; unset ( $ params [ '_base' ] ) ; } $ url = $ this -> urlBuilder ( ) -> getUrl ( $ path , $ params ) ; if ( $ base && strpos ( $ url , 'http' ) !== 0 ) { $ url = $ this -> reque...
URL with query string based on resizing params .
43,888
public function urlBuilder ( $ urlBuilder = null ) { if ( $ urlBuilder !== null ) { return $ this -> _urlBuilder = $ urlBuilder ; } if ( ! isset ( $ this -> _urlBuilder ) ) { $ config = $ this -> getConfig ( ) ; $ this -> _urlBuilder = UrlBuilderFactory :: create ( $ config [ 'baseUrl' ] , $ config [ 'secureUrls' ] ? (...
Get URL builder instance .
43,889
public static function getInstance ( ) { if ( ! self :: $ _instance ) { self :: $ _instance = new Environment ( ) ; Configure :: write ( 'Environment.initialized' , true ) ; } return self :: $ _instance ; }
Retrieves the current instance of an environment
43,890
public static function configure ( $ name , $ params , $ config = null , $ callable = null ) { $ _this = Environment :: getInstance ( ) ; $ _this -> environments [ $ name ] = compact ( 'name' , 'params' , 'config' , 'callable' ) ; }
Configures a given environment with certain instructions
43,891
public static function is ( $ environment = null ) { $ current = Configure :: read ( 'Environment.name' ) ; if ( ! $ environment ) { return $ current ; } return $ current === $ environment ; }
Checks if the current environment matches the passed environment
43,892
public function setup ( $ environment = null , $ default = 'development' ) { if ( Configure :: read ( 'Environment.setup' ) ) { return false ; } $ current = $ this -> currentEnvironment ( $ environment , $ default ) ; if ( ! isset ( $ this -> environments [ $ current ] ) ) { throw new Exception ( sprintf ( 'Environment...
Configures the current environment
43,893
protected function currentEnvironment ( $ environment = null , $ default = 'development' ) { $ current = ( $ environment === null ) ? $ default : $ environment ; if ( empty ( $ environment ) ) { foreach ( $ this -> environments as $ name => $ config ) { if ( $ this -> _match ( $ name , $ config [ 'params' ] ) ) { $ cur...
Gets the current environment
43,894
protected function _match ( $ environment , $ params ) { $ cakeEnv = env ( 'CAKE_ENV' ) ; if ( ! empty ( $ cakeEnv ) ) { return env ( 'CAKE_ENV' ) == $ environment ; } if ( is_bool ( $ params ) ) { return $ params ; } if ( is_callable ( $ params ) || ( is_string ( $ params ) && function_exists ( $ params ) ) ) { return...
Matches the current setup to a given environment
43,895
public function setLimit ( $ limit ) { if ( is_numeric ( $ limit ) ) $ this -> items_per_page = $ limit ; $ this -> setCurrent ( self :: findCurrentPage ( $ this -> routeKey ) ) ; }
set maximum items shown on one page
43,896
public function setCurrent ( $ current ) { if ( ! $ this -> routeKeyPrefix ) $ current = str_replace ( $ this -> routeKeyPrefix , '' , $ current ) ; if ( ! is_numeric ( $ current ) ) return ; if ( $ current <= $ this -> getMax ( ) ) $ this -> current_page = $ current ; else $ this -> current_page = $ this -> getMax ( )...
set the current page number
43,897
public function setLinkPath ( $ linkPath ) { $ this -> linkPath = ( substr ( $ linkPath , 0 , 1 ) != '/' ) ? '/' . $ linkPath : $ linkPath ; if ( substr ( $ this -> linkPath , - 1 ) != '/' ) $ this -> linkPath .= '/' ; }
set path to current routing for link building
43,898
static public function findCurrentPage ( $ key = 'page' ) { $ f3 = \ Base :: instance ( ) ; return $ f3 -> exists ( 'PARAMS.' . $ key ) ? preg_replace ( "/[^0-9]/" , "" , $ f3 -> get ( 'PARAMS.' . $ key ) ) : 1 ; }
extract the current page number from the route parameter token
43,899
public function getLast ( ) { return ( $ this -> current_page < $ this -> getMax ( ) - $ this -> range ) ? $ this -> getMax ( ) : false ; }
return last page number if current page is not in range