idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
26,100 | protected function _setPagingParams ( ) { $ controller = $ this -> getController ( ) ; $ request = $ controller -> getRequest ( ) ; $ paging = $ this -> _paginator -> getPagingParams ( ) + ( array ) $ request -> getParam ( 'paging' , [ ] ) ; $ controller -> setRequest ( $ request -> withParam ( 'paging' , $ paging ) ) ... | Set paging params to request instance . |
26,101 | public function setTable ( Table $ table ) { $ this -> _table = $ table ; $ eventManager = $ table -> getEventManager ( ) ; if ( $ eventManager !== null ) { $ this -> setEventManager ( $ eventManager ) ; } } | Attaches a table instance to this registry . |
26,102 | public static function className ( $ class ) { $ result = App :: className ( $ class , 'Model/Behavior' , 'Behavior' ) ; if ( ! $ result ) { $ result = App :: className ( $ class , 'ORM/Behavior' , 'Behavior' ) ; } return $ result ? : null ; } | Resolve a behavior classname . |
26,103 | protected function _create ( $ class , $ alias , $ config ) { $ instance = new $ class ( $ this -> _table , $ config ) ; $ enable = isset ( $ config [ 'enabled' ] ) ? $ config [ 'enabled' ] : true ; if ( $ enable ) { $ this -> getEventManager ( ) -> on ( $ instance ) ; } $ methods = $ this -> _getMethods ( $ instance ,... | Create the behavior instance . |
26,104 | protected function _getMethods ( Behavior $ instance , $ class , $ alias ) { $ finders = array_change_key_case ( $ instance -> implementedFinders ( ) ) ; $ methods = array_change_key_case ( $ instance -> implementedMethods ( ) ) ; foreach ( $ finders as $ finder => $ methodName ) { if ( isset ( $ this -> _finderMap [ $... | Get the behavior methods and ensure there are no duplicates . |
26,105 | public function call ( $ method , array $ args = [ ] ) { $ method = strtolower ( $ method ) ; if ( $ this -> hasMethod ( $ method ) && $ this -> has ( $ this -> _methodMap [ $ method ] [ 0 ] ) ) { list ( $ behavior , $ callMethod ) = $ this -> _methodMap [ $ method ] ; return call_user_func_array ( [ $ this -> _loaded ... | Invoke a method on a behavior . |
26,106 | public function callFinder ( $ type , array $ args = [ ] ) { $ type = strtolower ( $ type ) ; if ( $ this -> hasFinder ( $ type ) && $ this -> has ( $ this -> _finderMap [ $ type ] [ 0 ] ) ) { list ( $ behavior , $ callMethod ) = $ this -> _finderMap [ $ type ] ; return call_user_func_array ( [ $ this -> _loaded [ $ be... | Invoke a finder on a behavior . |
26,107 | public function emit ( $ val , $ key = null ) { $ this -> _result [ $ key === null ? $ this -> _counter : $ key ] = $ val ; $ this -> _counter ++ ; } | Appends a new record to the final list of results and optionally assign a key for this record . |
26,108 | protected function _execute ( ) { $ mapper = $ this -> _mapper ; foreach ( $ this -> _data as $ key => $ val ) { $ mapper ( $ val , $ key , $ this ) ; } $ this -> _data = null ; if ( ! empty ( $ this -> _intermediate ) && empty ( $ this -> _reducer ) ) { throw new LogicException ( 'No reducer function was provided' ) ;... | Runs the actual Map - Reduce algorithm . This is iterate the original data and call the mapper function for each then for each intermediate bucket created during the Map phase call the reduce function . |
26,109 | public function unauthenticated ( ServerRequest $ request , Response $ response ) { $ Exception = new UnauthorizedException ( ) ; $ Exception -> responseHeader ( $ this -> loginHeaders ( $ request ) ) ; throw $ Exception ; } | Handles an unauthenticated access attempt by sending appropriate login headers |
26,110 | public function targetForeignKey ( $ key = null ) { deprecationWarning ( 'BelongToMany::targetForeignKey() is deprecated. ' . 'Use setTargetForeignKey()/getTargetForeignKey() instead.' ) ; if ( $ key !== null ) { $ this -> setTargetForeignKey ( $ key ) ; } return $ this -> getTargetForeignKey ( ) ; } | Sets the name of the field representing the foreign key to the target table . If no parameters are passed current field is returned |
26,111 | public function getForeignKey ( ) { if ( $ this -> _foreignKey === null ) { $ this -> _foreignKey = $ this -> _modelKey ( $ this -> getSource ( ) -> getTable ( ) ) ; } return $ this -> _foreignKey ; } | Gets the name of the field representing the foreign key to the source table . |
26,112 | public function sort ( $ sort = null ) { deprecationWarning ( 'BelongToMany::sort() is deprecated. ' . 'Use setSort()/getSort() instead.' ) ; if ( $ sort !== null ) { $ this -> setSort ( $ sort ) ; } return $ this -> getSort ( ) ; } | Sets the sort order in which target records should be returned . If no arguments are passed the currently configured value is returned |
26,113 | public function junction ( $ table = null ) { if ( $ table === null && $ this -> _junctionTable ) { return $ this -> _junctionTable ; } $ tableLocator = $ this -> getTableLocator ( ) ; if ( $ table === null && $ this -> _through ) { $ table = $ this -> _through ; } elseif ( $ table === null ) { $ tableName = $ this -> ... | Sets the table instance for the junction relation . If no arguments are passed the current configured table instance is returned |
26,114 | protected function _generateTargetAssociations ( $ junction , $ source , $ target ) { $ junctionAlias = $ junction -> getAlias ( ) ; $ sAlias = $ source -> getAlias ( ) ; if ( ! $ target -> hasAssociation ( $ junctionAlias ) ) { $ target -> hasMany ( $ junctionAlias , [ 'targetTable' => $ junction , 'foreignKey' => $ t... | Generate reciprocal associations as necessary . |
26,115 | protected function _generateSourceAssociations ( $ junction , $ source ) { $ junctionAlias = $ junction -> getAlias ( ) ; if ( ! $ source -> hasAssociation ( $ junctionAlias ) ) { $ source -> hasMany ( $ junctionAlias , [ 'targetTable' => $ junction , 'foreignKey' => $ this -> getForeignKey ( ) , 'strategy' => $ this -... | Generate additional source table associations as necessary . |
26,116 | protected function _generateJunctionAssociations ( $ junction , $ source , $ target ) { $ tAlias = $ target -> getAlias ( ) ; $ sAlias = $ source -> getAlias ( ) ; if ( ! $ junction -> hasAssociation ( $ tAlias ) ) { $ junction -> belongsTo ( $ tAlias , [ 'foreignKey' => $ this -> getTargetForeignKey ( ) , 'targetTable... | Generate associations on the junction table as necessary |
26,117 | public function cascadeDelete ( EntityInterface $ entity , array $ options = [ ] ) { if ( ! $ this -> getDependent ( ) ) { return true ; } $ foreignKey = ( array ) $ this -> getForeignKey ( ) ; $ bindingKey = ( array ) $ this -> getBindingKey ( ) ; $ conditions = [ ] ; if ( ! empty ( $ bindingKey ) ) { $ conditions = a... | Clear out the data in the junction table for a given entity . |
26,118 | public function setSaveStrategy ( $ strategy ) { if ( ! in_array ( $ strategy , [ self :: SAVE_APPEND , self :: SAVE_REPLACE ] ) ) { $ msg = sprintf ( 'Invalid save strategy "%s"' , $ strategy ) ; throw new InvalidArgumentException ( $ msg ) ; } $ this -> _saveStrategy = $ strategy ; return $ this ; } | Sets the strategy that should be used for saving . |
26,119 | public function saveStrategy ( $ strategy = null ) { deprecationWarning ( 'BelongsToMany::saveStrategy() is deprecated. ' . 'Use setSaveStrategy()/getSaveStrategy() instead.' ) ; if ( $ strategy !== null ) { $ this -> setSaveStrategy ( $ strategy ) ; } return $ this -> getSaveStrategy ( ) ; } | Sets the strategy that should be used for saving . If called with no arguments it will return the currently configured strategy |
26,120 | protected function _saveLinks ( EntityInterface $ sourceEntity , $ targetEntities , $ options ) { $ target = $ this -> getTarget ( ) ; $ junction = $ this -> junction ( ) ; $ entityClass = $ junction -> getEntityClass ( ) ; $ belongsTo = $ junction -> getAssociation ( $ target -> getAlias ( ) ) ; $ foreignKey = ( array... | Creates links between the source entity and each of the passed target entities |
26,121 | public function link ( EntityInterface $ sourceEntity , array $ targetEntities , array $ options = [ ] ) { $ this -> _checkPersistenceStatus ( $ sourceEntity , $ targetEntities ) ; $ property = $ this -> getProperty ( ) ; $ links = $ sourceEntity -> get ( $ property ) ? : [ ] ; $ links = array_merge ( $ links , $ targe... | Associates the source entity to each of the target entities provided by creating links in the junction table . Both the source entity and each of the target entities are assumed to be already persisted if they are marked as new or their status is unknown then an exception will be thrown . |
26,122 | protected function targetConditions ( ) { if ( $ this -> _targetConditions !== null ) { return $ this -> _targetConditions ; } $ conditions = $ this -> getConditions ( ) ; if ( ! is_array ( $ conditions ) ) { return $ conditions ; } $ matching = [ ] ; $ alias = $ this -> getAlias ( ) . '.' ; foreach ( $ conditions as $... | Returns filtered conditions that reference the target table . |
26,123 | protected function junctionConditions ( ) { if ( $ this -> _junctionConditions !== null ) { return $ this -> _junctionConditions ; } $ matching = [ ] ; $ conditions = $ this -> getConditions ( ) ; if ( ! is_array ( $ conditions ) ) { return $ matching ; } $ alias = $ this -> _junctionAssociationName ( ) . '.' ; foreach... | Returns filtered conditions that specifically reference the junction table . |
26,124 | public function find ( $ type = null , array $ options = [ ] ) { $ type = $ type ? : $ this -> getFinder ( ) ; list ( $ type , $ opts ) = $ this -> _extractFinder ( $ type ) ; $ query = $ this -> getTarget ( ) -> find ( $ type , $ options + $ opts ) -> where ( $ this -> targetConditions ( ) ) -> addDefaultTypes ( $ thi... | Proxies the finding operation to the target table s find method and modifies the query accordingly based of this association configuration . |
26,125 | protected function _appendJunctionJoin ( $ query , $ conditions ) { $ name = $ this -> _junctionAssociationName ( ) ; $ joins = $ query -> clause ( 'join' ) ; $ matching = [ $ name => [ 'table' => $ this -> junction ( ) -> getTable ( ) , 'conditions' => $ conditions , 'type' => QueryInterface :: JOIN_TYPE_INNER ] ] ; $... | Append a join to the junction table . |
26,126 | protected function _checkPersistenceStatus ( $ sourceEntity , array $ targetEntities ) { if ( $ sourceEntity -> isNew ( ) ) { $ error = 'Source entity needs to be persisted before links can be created or removed.' ; throw new InvalidArgumentException ( $ error ) ; } foreach ( $ targetEntities as $ entity ) { if ( $ ent... | Throws an exception should any of the passed entities is not persisted . |
26,127 | protected function _collectJointEntities ( $ sourceEntity , $ targetEntities ) { $ target = $ this -> getTarget ( ) ; $ source = $ this -> getSource ( ) ; $ junction = $ this -> junction ( ) ; $ jointProperty = $ this -> _junctionProperty ; $ primary = ( array ) $ target -> getPrimaryKey ( ) ; $ result = [ ] ; $ missin... | Returns the list of joint entities that exist between the source entity and each of the passed target entities |
26,128 | protected function _junctionAssociationName ( ) { if ( ! $ this -> _junctionAssociationName ) { $ this -> _junctionAssociationName = $ this -> getTarget ( ) -> getAssociation ( $ this -> junction ( ) -> getAlias ( ) ) -> getName ( ) ; } return $ this -> _junctionAssociationName ; } | Returns the name of the association from the target table to the junction table this name is used to generate alias in the query and to later on retrieve the results . |
26,129 | protected function _junctionTableName ( $ name = null ) { if ( $ name === null ) { if ( empty ( $ this -> _junctionTableName ) ) { $ tablesNames = array_map ( 'Cake\Utility\Inflector::underscore' , [ $ this -> getSource ( ) -> getTable ( ) , $ this -> getTarget ( ) -> getTable ( ) ] ) ; sort ( $ tablesNames ) ; $ this ... | Sets the name of the junction table . If no arguments are passed the current configured name is returned . A default name based of the associated tables will be generated if none found . |
26,130 | protected function _pagingSubquery ( $ original , $ limit , $ offset ) { $ field = '_cake_paging_._cake_page_rownum_' ; if ( $ original -> clause ( 'order' ) ) { $ select = $ original -> clause ( 'select' ) ; $ order = new OrderByExpression ( ) ; $ original -> clause ( 'order' ) -> iterateParts ( function ( $ direction... | Generate a paging subquery for older versions of SQLserver . |
26,131 | public function parse ( $ url , $ method = '' ) { $ params = parent :: parse ( $ url , $ method ) ; if ( ! $ params ) { return false ; } if ( ! empty ( $ params [ 'controller' ] ) ) { $ params [ 'controller' ] = Inflector :: camelize ( $ params [ 'controller' ] ) ; } if ( ! empty ( $ params [ 'plugin' ] ) ) { if ( strp... | Parses a string URL into an array . If it matches it will convert the prefix controller and plugin keys to their camelized form . |
26,132 | protected function _underscore ( $ url ) { if ( ! empty ( $ url [ 'controller' ] ) ) { $ url [ 'controller' ] = Inflector :: underscore ( $ url [ 'controller' ] ) ; } if ( ! empty ( $ url [ 'plugin' ] ) ) { $ url [ 'plugin' ] = Inflector :: underscore ( $ url [ 'plugin' ] ) ; } return $ url ; } | Helper method for underscoring keys in a URL array . |
26,133 | public function tieWith ( $ conjunction = null ) { deprecationWarning ( 'QueryExpression::tieWith() is deprecated. ' . 'Use QueryExpression::setConjunction()/getConjunction() instead.' ) ; if ( $ conjunction !== null ) { return $ this -> setConjunction ( $ conjunction ) ; } return $ this -> getConjunction ( ) ; } | Changes the conjunction for the conditions at this level of the expression tree . If called with no arguments it will return the currently configured value . |
26,134 | public function add ( $ conditions , $ types = [ ] ) { if ( is_string ( $ conditions ) ) { $ this -> _conditions [ ] = $ conditions ; return $ this ; } if ( $ conditions instanceof ExpressionInterface ) { $ this -> _conditions [ ] = $ conditions ; return $ this ; } $ this -> _addConditions ( $ conditions , $ types ) ; ... | Adds one or more conditions to this expression object . Conditions can be expressed in a one dimensional array that will cause all conditions to be added directly at this level of the tree or they can be nested arbitrarily making it create more expression objects that will be nested inside and configured to use the spe... |
26,135 | public function gt ( $ field , $ value , $ type = null ) { if ( $ type === null ) { $ type = $ this -> _calculateType ( $ field ) ; } return $ this -> add ( new Comparison ( $ field , $ value , $ type , '>' ) ) ; } | Adds a new condition to the expression object in the form field > value . |
26,136 | public function isNull ( $ field ) { if ( ! ( $ field instanceof ExpressionInterface ) ) { $ field = new IdentifierExpression ( $ field ) ; } return $ this -> add ( new UnaryExpression ( 'IS NULL' , $ field , UnaryExpression :: POSTFIX ) ) ; } | Adds a new condition to the expression object in the form field IS NULL . |
26,137 | public function isNotNull ( $ field ) { if ( ! ( $ field instanceof ExpressionInterface ) ) { $ field = new IdentifierExpression ( $ field ) ; } return $ this -> add ( new UnaryExpression ( 'IS NOT NULL' , $ field , UnaryExpression :: POSTFIX ) ) ; } | Adds a new condition to the expression object in the form field IS NOT NULL . |
26,138 | public function addCase ( $ conditions , $ values = [ ] , $ types = [ ] ) { return $ this -> add ( new CaseExpression ( $ conditions , $ values , $ types ) ) ; } | Adds a new case expression to the expression object |
26,139 | public function between ( $ field , $ from , $ to , $ type = null ) { if ( $ type === null ) { $ type = $ this -> _calculateType ( $ field ) ; } return $ this -> add ( new BetweenExpression ( $ field , $ from , $ to , $ type ) ) ; } | Adds a new condition to the expression object in the form field BETWEEN from AND to . |
26,140 | public function and_ ( $ conditions , $ types = [ ] ) { if ( $ this -> isCallable ( $ conditions ) ) { return $ conditions ( new static ( [ ] , $ this -> getTypeMap ( ) -> setTypes ( $ types ) ) ) ; } return new static ( $ conditions , $ this -> getTypeMap ( ) -> setTypes ( $ types ) ) ; } | Returns a new QueryExpression object containing all the conditions passed and set up the conjunction to be AND |
26,141 | public function or_ ( $ conditions , $ types = [ ] ) { if ( $ this -> isCallable ( $ conditions ) ) { return $ conditions ( new static ( [ ] , $ this -> getTypeMap ( ) -> setTypes ( $ types ) , 'OR' ) ) ; } return new static ( $ conditions , $ this -> getTypeMap ( ) -> setTypes ( $ types ) , 'OR' ) ; } | Returns a new QueryExpression object containing all the conditions passed and set up the conjunction to be OR |
26,142 | public function equalFields ( $ left , $ right ) { $ wrapIdentifier = function ( $ field ) { if ( $ field instanceof ExpressionInterface ) { return $ field ; } return new IdentifierExpression ( $ field ) ; } ; return $ this -> eq ( $ wrapIdentifier ( $ left ) , $ wrapIdentifier ( $ right ) ) ; } | Builds equal condition or assignment with identifier wrapping . |
26,143 | public function traverse ( callable $ callable ) { foreach ( $ this -> _conditions as $ c ) { if ( $ c instanceof ExpressionInterface ) { $ callable ( $ c ) ; $ c -> traverse ( $ callable ) ; } } } | Traverses the tree structure of this query expression by executing a callback function for each of the conditions that are included in this object . Useful for compiling the final expression or doing introspection in the structure . |
26,144 | public function iterateParts ( callable $ callable ) { $ parts = [ ] ; foreach ( $ this -> _conditions as $ k => $ c ) { $ key = & $ k ; $ part = $ callable ( $ c , $ key ) ; if ( $ part !== null ) { $ parts [ $ key ] = $ part ; } } $ this -> _conditions = $ parts ; return $ this ; } | Executes a callable function for each of the parts that form this expression . |
26,145 | public function isCallable ( $ c ) { if ( is_string ( $ c ) ) { return false ; } if ( is_object ( $ c ) && is_callable ( $ c ) ) { return true ; } return is_array ( $ c ) && isset ( $ c [ 0 ] ) && is_object ( $ c [ 0 ] ) && is_callable ( $ c ) ; } | Check whether or not a callable is acceptable . |
26,146 | protected function _addConditions ( array $ conditions , array $ types ) { $ operators = [ 'and' , 'or' , 'xor' ] ; $ typeMap = $ this -> getTypeMap ( ) -> setTypes ( $ types ) ; foreach ( $ conditions as $ k => $ c ) { $ numericKey = is_numeric ( $ k ) ; if ( $ this -> isCallable ( $ c ) ) { $ expr = new static ( [ ] ... | Auxiliary function used for decomposing a nested array of conditions and build a tree structure inside this object to represent the full SQL expression . String conditions are stored directly in the conditions while any other representation is wrapped around an adequate instance or of this class . |
26,147 | protected function _parseCondition ( $ field , $ value ) { $ operator = '=' ; $ expression = $ field ; $ parts = explode ( ' ' , trim ( $ field ) , 2 ) ; if ( count ( $ parts ) > 1 ) { list ( $ expression , $ operator ) = $ parts ; } $ type = $ this -> getTypeMap ( ) -> type ( $ expression ) ; $ operator = strtolower (... | Parses a string conditions by trying to extract the operator inside it if any and finally returning either an adequate QueryExpression object or a plain string representation of the condition . This function is responsible for generating the placeholders and replacing the values by them while storing the value elsewher... |
26,148 | protected function _calculateType ( $ field ) { $ field = $ field instanceof IdentifierExpression ? $ field -> getIdentifier ( ) : $ field ; if ( is_string ( $ field ) ) { return $ this -> getTypeMap ( ) -> type ( $ field ) ; } return null ; } | Returns the type name for the passed field if it was stored in the typeMap |
26,149 | public function boundary ( ) { if ( $ this -> _boundary ) { return $ this -> _boundary ; } $ this -> _boundary = md5 ( uniqid ( time ( ) ) ) ; return $ this -> _boundary ; } | Get the boundary marker |
26,150 | public function add ( $ name , $ value = null ) { if ( is_array ( $ value ) ) { $ this -> addRecursive ( $ name , $ value ) ; } elseif ( is_resource ( $ value ) ) { $ this -> addFile ( $ name , $ value ) ; } elseif ( $ name instanceof FormDataPart && $ value === null ) { $ this -> _hasComplexPart = true ; $ this -> _pa... | Add a new part to the data . |
26,151 | public function addMany ( array $ data ) { foreach ( $ data as $ name => $ value ) { $ this -> add ( $ name , $ value ) ; } return $ this ; } | Add multiple parts at once . |
26,152 | public function addRecursive ( $ name , $ value ) { foreach ( $ value as $ key => $ value ) { $ key = $ name . '[' . $ key . ']' ; $ this -> add ( $ key , $ value ) ; } } | Recursively add data . |
26,153 | protected function _calculateWidths ( $ rows ) { $ widths = [ ] ; foreach ( $ rows as $ line ) { foreach ( array_values ( $ line ) as $ k => $ v ) { $ columnLength = $ this -> _cellWidth ( $ v ) ; if ( $ columnLength >= ( isset ( $ widths [ $ k ] ) ? $ widths [ $ k ] : 0 ) ) { $ widths [ $ k ] = $ columnLength ; } } } ... | Calculate the column widths |
26,154 | protected function _cellWidth ( $ text ) { if ( strpos ( $ text , '<' ) === false && strpos ( $ text , '>' ) === false ) { return mb_strwidth ( $ text ) ; } $ styles = array_keys ( $ this -> _io -> styles ( ) ) ; $ tags = implode ( '|' , $ styles ) ; $ text = preg_replace ( '#</?(?:' . $ tags . ')>#' , '' , $ text ) ; ... | Get the width of a cell exclusive of style tags . |
26,155 | protected function _rowSeparator ( $ widths ) { $ out = '' ; foreach ( $ widths as $ column ) { $ out .= '+' . str_repeat ( '-' , $ column + 2 ) ; } $ out .= '+' ; $ this -> _io -> out ( $ out ) ; } | Output a row separator . |
26,156 | protected function _render ( array $ row , $ widths , $ options = [ ] ) { if ( count ( $ row ) === 0 ) { return ; } $ out = '' ; foreach ( array_values ( $ row ) as $ i => $ column ) { $ pad = $ widths [ $ i ] - $ this -> _cellWidth ( $ column ) ; if ( ! empty ( $ options [ 'style' ] ) ) { $ column = $ this -> _addStyl... | Output a row . |
26,157 | public function output ( $ rows ) { if ( ! is_array ( $ rows ) || count ( $ rows ) === 0 ) { return ; } $ config = $ this -> getConfig ( ) ; $ widths = $ this -> _calculateWidths ( $ rows ) ; $ this -> _rowSeparator ( $ widths ) ; if ( $ config [ 'headers' ] === true ) { $ this -> _render ( array_shift ( $ rows ) , $ w... | Output a table . |
26,158 | public static function instance ( $ manager = null ) { if ( $ manager instanceof EventManager ) { static :: $ _generalManager = $ manager ; } if ( empty ( static :: $ _generalManager ) ) { static :: $ _generalManager = new static ( ) ; } static :: $ _generalManager -> _isGlobal = true ; return static :: $ _generalManag... | Returns the globally available instance of a Cake \ Event \ EventManager this is used for dispatching events attached from outside the scope other managers were created . Usually for creating hook systems or inter - class communication |
26,159 | public function attach ( $ callable , $ eventKey = null , array $ options = [ ] ) { deprecationWarning ( 'EventManager::attach() is deprecated. Use EventManager::on() instead.' ) ; if ( $ eventKey === null ) { $ this -> on ( $ callable ) ; return ; } if ( $ options ) { $ this -> on ( $ eventKey , $ options , $ callable... | Adds a new listener to an event . |
26,160 | protected function _attachSubscriber ( EventListenerInterface $ subscriber ) { foreach ( ( array ) $ subscriber -> implementedEvents ( ) as $ eventKey => $ function ) { $ options = [ ] ; $ method = $ function ; if ( is_array ( $ function ) && isset ( $ function [ 'callable' ] ) ) { list ( $ method , $ options ) = $ thi... | Auxiliary function to attach all implemented callbacks of a Cake \ Event \ EventListenerInterface class instance as individual methods on this manager |
26,161 | protected function _extractCallable ( $ function , $ object ) { $ method = $ function [ 'callable' ] ; $ options = $ function ; unset ( $ options [ 'callable' ] ) ; if ( is_string ( $ method ) ) { $ method = [ $ object , $ method ] ; } return [ $ method , $ options ] ; } | Auxiliary function to extract and return a PHP callback type out of the callable definition from the return value of the implementedEvents method on a Cake \ Event \ EventListenerInterface |
26,162 | public function detach ( $ callable , $ eventKey = null ) { deprecationWarning ( 'EventManager::detach() is deprecated. Use EventManager::off() instead.' ) ; if ( $ eventKey === null ) { $ this -> off ( $ callable ) ; return ; } $ this -> off ( $ eventKey , $ callable ) ; } | Removes a listener from the active listeners . |
26,163 | protected function _detachSubscriber ( EventListenerInterface $ subscriber , $ eventKey = null ) { $ events = ( array ) $ subscriber -> implementedEvents ( ) ; if ( ! empty ( $ eventKey ) && empty ( $ events [ $ eventKey ] ) ) { return ; } if ( ! empty ( $ eventKey ) ) { $ events = [ $ eventKey => $ events [ $ eventKey... | Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface |
26,164 | public function matchingListeners ( $ eventKeyPattern ) { $ matchPattern = '/' . preg_quote ( $ eventKeyPattern , '/' ) . '/' ; $ matches = array_intersect_key ( $ this -> _listeners , array_flip ( preg_grep ( $ matchPattern , array_keys ( $ this -> _listeners ) , 0 ) ) ) ; return $ matches ; } | Returns the listeners matching a specified pattern |
26,165 | public function addEventToList ( Event $ event ) { if ( $ this -> _eventList ) { $ this -> _eventList -> add ( $ event ) ; } return $ this ; } | Adds an event to the list if the event list object is present . |
26,166 | public function setEventList ( EventList $ eventList ) { $ this -> _eventList = $ eventList ; $ this -> _trackEvents = true ; return $ this ; } | Enables the listing of dispatched events . |
26,167 | public static function precision ( $ value , $ precision = 3 , array $ options = [ ] ) { $ formatter = static :: formatter ( [ 'precision' => $ precision , 'places' => $ precision ] + $ options ) ; return $ formatter -> format ( $ value ) ; } | Formats a number with a level of precision . |
26,168 | public static function parseFloat ( $ value , array $ options = [ ] ) { $ formatter = static :: formatter ( $ options ) ; return ( float ) $ formatter -> parse ( $ value , NumberFormatter :: TYPE_DOUBLE ) ; } | Parse a localized numeric string and transform it in a float point |
26,169 | public static function formatter ( $ options = [ ] ) { $ locale = isset ( $ options [ 'locale' ] ) ? $ options [ 'locale' ] : ini_get ( 'intl.default_locale' ) ; if ( ! $ locale ) { $ locale = static :: DEFAULT_LOCALE ; } $ type = NumberFormatter :: DECIMAL ; if ( ! empty ( $ options [ 'type' ] ) ) { $ type = $ options... | Returns a formatter object that can be reused for similar formatting task under the same locale and options . This is often a speedier alternative to using other methods in this class as only one formatter object needs to be constructed . |
26,170 | public static function config ( $ locale , $ type = NumberFormatter :: DECIMAL , array $ options = [ ] ) { static :: $ _formatters [ $ locale ] [ $ type ] = static :: _setAttributes ( new NumberFormatter ( $ locale , $ type ) , $ options ) ; } | Configure formatters . |
26,171 | public function startup ( Event $ event ) { $ controller = $ event -> getSubject ( ) ; $ request = $ controller -> request ; $ this -> session = $ request -> getSession ( ) ; $ this -> _action = $ request -> getParam ( 'action' ) ; $ hasData = ( $ request -> getData ( ) || $ request -> is ( [ 'put' , 'post' , 'delete' ... | Component startup . All security checking happens here . |
26,172 | protected function _throwException ( $ exception = null ) { if ( $ exception !== null ) { if ( ! Configure :: read ( 'debug' ) && $ exception instanceof SecurityException ) { $ exception -> setReason ( $ exception -> getMessage ( ) ) ; $ exception -> setMessage ( self :: DEFAULT_EXCEPTION_MESSAGE ) ; } throw $ exceptio... | Check debug status and throw an Exception based on the existing one |
26,173 | protected function _secureRequired ( Controller $ controller ) { if ( is_array ( $ this -> _config [ 'requireSecure' ] ) && ! empty ( $ this -> _config [ 'requireSecure' ] ) ) { $ requireSecure = $ this -> _config [ 'requireSecure' ] ; if ( in_array ( $ this -> _action , $ requireSecure ) || $ requireSecure === [ '*' ]... | Check if access requires secure connection |
26,174 | protected function _authRequired ( Controller $ controller ) { $ request = $ controller -> getRequest ( ) ; if ( is_array ( $ this -> _config [ 'requireAuth' ] ) && ! empty ( $ this -> _config [ 'requireAuth' ] ) && $ request -> getData ( ) ) { deprecationWarning ( 'SecurityComponent::requireAuth() will be removed in 4... | Check if authentication is required |
26,175 | protected function _validatePost ( Controller $ controller ) { $ token = $ this -> _validToken ( $ controller ) ; $ hashParts = $ this -> _hashParts ( $ controller ) ; $ check = hash_hmac ( 'sha1' , implode ( '' , $ hashParts ) , Security :: getSalt ( ) ) ; if ( hash_equals ( $ check , $ token ) ) { return true ; } $ m... | Validate submitted form |
26,176 | protected function _hashParts ( Controller $ controller ) { $ request = $ controller -> getRequest ( ) ; $ session = $ request -> getSession ( ) ; $ session -> start ( ) ; $ data = $ request -> getData ( ) ; $ fieldList = $ this -> _fieldsList ( $ data ) ; $ unlocked = $ this -> _sortedUnlocked ( $ data ) ; return [ Ro... | Return hash parts for the Token generation |
26,177 | protected function _fieldsList ( array $ check ) { $ locked = '' ; $ token = urldecode ( $ check [ '_Token' ] [ 'fields' ] ) ; $ unlocked = $ this -> _unlocked ( $ check ) ; if ( strpos ( $ token , ':' ) ) { list ( $ token , $ locked ) = explode ( ':' , $ token , 2 ) ; } unset ( $ check [ '_Token' ] , $ check [ '_csrfT... | Return the fields list for the hash calculation |
26,178 | protected function _sortedUnlocked ( $ data ) { $ unlocked = $ this -> _unlocked ( $ data ) ; $ unlocked = explode ( '|' , $ unlocked ) ; sort ( $ unlocked , SORT_STRING ) ; return implode ( '|' , $ unlocked ) ; } | Get the sorted unlocked string |
26,179 | protected function _debugPostTokenNotMatching ( Controller $ controller , $ hashParts ) { $ messages = [ ] ; $ expectedParts = json_decode ( urldecode ( $ controller -> getRequest ( ) -> getData ( '_Token.debug' ) ) , true ) ; if ( ! is_array ( $ expectedParts ) || count ( $ expectedParts ) !== 3 ) { return 'Invalid se... | Create a message for humans to understand why Security token is not matching |
26,180 | protected function _debugCheckFields ( $ dataFields , $ expectedFields = [ ] , $ intKeyMessage = '' , $ stringKeyMessage = '' , $ missingMessage = '' ) { $ messages = $ this -> _matchExistingFields ( $ dataFields , $ expectedFields , $ intKeyMessage , $ stringKeyMessage ) ; $ expectedFieldsMessage = $ this -> _debugExp... | Iterates data array to check against expected |
26,181 | public function generateToken ( ServerRequest $ request ) { if ( $ request -> is ( 'requested' ) ) { if ( $ this -> session -> check ( '_Token' ) ) { $ request = $ request -> withParam ( '_Token' , $ this -> session -> read ( '_Token' ) ) ; } return $ request ; } $ token = [ 'allowedControllers' => $ this -> _config [ ... | Manually add form tampering prevention token information into the provided request object . |
26,182 | protected function _callback ( Controller $ controller , $ method , $ params = [ ] ) { if ( ! is_callable ( [ $ controller , $ method ] ) ) { throw new BadRequestException ( 'The request has been black-holed' ) ; } return call_user_func_array ( [ & $ controller , $ method ] , empty ( $ params ) ? null : $ params ) ; } | Calls a controller callback method |
26,183 | protected function _debugExpectedFields ( $ expectedFields = [ ] , $ missingMessage = '' ) { if ( count ( $ expectedFields ) === 0 ) { return null ; } $ expectedFieldNames = [ ] ; foreach ( ( array ) $ expectedFields as $ key => $ expectedField ) { if ( is_int ( $ key ) ) { $ expectedFieldNames [ ] = $ expectedField ; ... | Generate debug message for the expected fields |
26,184 | protected function _processPost ( $ data ) { $ method = $ this -> getEnv ( 'REQUEST_METHOD' ) ; $ override = false ; if ( in_array ( $ method , [ 'PUT' , 'DELETE' , 'PATCH' ] ) && strpos ( $ this -> contentType ( ) , 'application/x-www-form-urlencoded' ) === 0 ) { $ data = $ this -> input ( ) ; parse_str ( $ data , $ d... | Sets the REQUEST_METHOD environment variable based on the simulated _method HTTP override value . The ORIGINAL_REQUEST_METHOD is also preserved if you want the read the non - simulated HTTP method the client used . |
26,185 | protected function _processGet ( $ query , $ queryString = '' ) { $ unsetUrl = '/' . str_replace ( [ '.' , ' ' ] , '_' , urldecode ( $ this -> url ) ) ; unset ( $ query [ $ unsetUrl ] , $ query [ $ this -> base . $ unsetUrl ] ) ; if ( strlen ( $ queryString ) ) { parse_str ( $ queryString , $ queryArgs ) ; $ query += $... | Process the GET parameters and move things into the object . |
26,186 | protected function _processFiles ( $ post , $ files ) { if ( ! is_array ( $ files ) ) { return $ post ; } $ fileData = [ ] ; foreach ( $ files as $ key => $ value ) { if ( $ value instanceof UploadedFileInterface ) { $ fileData [ $ key ] = $ value ; continue ; } if ( is_array ( $ value ) && isset ( $ value [ 'tmp_name'... | Process uploaded files and move things onto the post data . |
26,187 | public function session ( Session $ session = null ) { deprecationWarning ( 'ServerRequest::session() is deprecated. ' . 'Use getSession() instead. The setter part will be removed.' ) ; if ( $ session === null ) { return $ this -> session ; } return $ this -> session = $ session ; } | Returns the instance of the Session object for this request |
26,188 | public function clientIp ( ) { if ( $ this -> trustProxy && $ this -> getEnv ( 'HTTP_X_FORWARDED_FOR' ) ) { $ addresses = array_map ( 'trim' , explode ( ',' , $ this -> getEnv ( 'HTTP_X_FORWARDED_FOR' ) ) ) ; $ trusted = ( count ( $ this -> trustedProxies ) > 0 ) ; $ n = count ( $ addresses ) ; if ( $ trusted ) { $ tru... | Get the IP the client is using or says they are using . |
26,189 | public function referer ( $ local = false ) { $ ref = $ this -> getEnv ( 'HTTP_REFERER' ) ; $ base = Configure :: read ( 'App.fullBaseUrl' ) . $ this -> webroot ; if ( ! empty ( $ ref ) && ! empty ( $ base ) ) { if ( $ local && strpos ( $ ref , $ base ) === 0 ) { $ ref = substr ( $ ref , strlen ( $ base ) ) ; if ( ! st... | Returns the referer that referred this request . |
26,190 | public function & __get ( $ name ) { if ( isset ( $ this -> deprecatedProperties [ $ name ] ) ) { $ method = $ this -> deprecatedProperties [ $ name ] [ 'get' ] ; deprecationWarning ( "Accessing `{$name}` as a property will be removed in 4.0.0. " . "Use request->{$method} instead." ) ; return $ this -> { $ name } ; } d... | Magic get method allows access to parsed routing parameters directly on the object . |
26,191 | public function is ( $ type , ... $ args ) { if ( is_array ( $ type ) ) { $ result = array_map ( [ $ this , 'is' ] , $ type ) ; return count ( array_filter ( $ result ) ) > 0 ; } $ type = strtolower ( $ type ) ; if ( ! isset ( static :: $ _detectors [ $ type ] ) ) { return false ; } if ( $ args ) { return $ this -> _is... | Check whether or not a Request is a certain type . |
26,192 | protected function _headerDetector ( $ detect ) { foreach ( $ detect [ 'header' ] as $ header => $ value ) { $ header = $ this -> getEnv ( 'http_' . $ header ) ; if ( $ header !== null ) { if ( ! is_string ( $ value ) && ! is_bool ( $ value ) && is_callable ( $ value ) ) { return call_user_func ( $ value , $ header ) ;... | Detects if a specific header is present . |
26,193 | protected function _paramDetector ( $ detect ) { $ key = $ detect [ 'param' ] ; if ( isset ( $ detect [ 'value' ] ) ) { $ value = $ detect [ 'value' ] ; return isset ( $ this -> params [ $ key ] ) ? $ this -> params [ $ key ] == $ value : false ; } if ( isset ( $ detect [ 'options' ] ) ) { return isset ( $ this -> para... | Detects if a specific request parameter is present . |
26,194 | protected function _environmentDetector ( $ detect ) { if ( isset ( $ detect [ 'env' ] ) ) { if ( isset ( $ detect [ 'value' ] ) ) { return $ this -> getEnv ( $ detect [ 'env' ] ) == $ detect [ 'value' ] ; } if ( isset ( $ detect [ 'pattern' ] ) ) { return ( bool ) preg_match ( $ detect [ 'pattern' ] , $ this -> getEnv... | Detects if a specific environment variable is present . |
26,195 | public function isAll ( array $ types ) { $ result = array_filter ( array_map ( [ $ this , 'is' ] , $ types ) ) ; return count ( $ result ) === count ( $ types ) ; } | Check that a request matches all the given types . |
26,196 | public static function addDetector ( $ name , $ callable ) { $ name = strtolower ( $ name ) ; if ( is_callable ( $ callable ) ) { static :: $ _detectors [ $ name ] = $ callable ; return ; } if ( isset ( static :: $ _detectors [ $ name ] , $ callable [ 'options' ] ) ) { $ callable = Hash :: merge ( static :: $ _detector... | Add a new detector to the list of detectors that a request can use . There are several different formats and types of detectors that can be set . |
26,197 | public function addPaths ( array $ paths ) { deprecationWarning ( 'ServerRequest::addPaths() is deprecated. ' . 'Use `withAttribute($key, $value)` instead.' ) ; foreach ( [ 'webroot' , 'here' , 'base' ] as $ element ) { if ( isset ( $ paths [ $ element ] ) ) { $ this -> { $ element } = $ paths [ $ element ] ; } } retur... | Add paths to the requests paths vars . This will overwrite any existing paths . Provides an easy way to modify here webroot and base . |
26,198 | public function here ( $ base = true ) { deprecationWarning ( 'ServerRequest::here() will be removed in 4.0.0. You should use getRequestTarget() instead.' ) ; $ url = $ this -> here ; if ( ! empty ( $ this -> query ) ) { $ url .= '?' . http_build_query ( $ this -> query , null , '&' ) ; } if ( ! $ base ) { $ url = preg... | Get the value of the current requests URL . Will include the query string arguments . |
26,199 | protected function normalizeHeaderName ( $ name ) { $ name = str_replace ( '-' , '_' , strtoupper ( $ name ) ) ; if ( ! in_array ( $ name , [ 'CONTENT_LENGTH' , 'CONTENT_TYPE' ] ) ) { $ name = 'HTTP_' . $ name ; } return $ name ; } | Normalize a header name into the SERVER version . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.