idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
26,000
protected function _joinCondition ( $ options ) { $ conditions = [ ] ; $ tAlias = $ this -> _name ; $ sAlias = $ this -> getSource ( ) -> getAlias ( ) ; $ foreignKey = ( array ) $ options [ 'foreignKey' ] ; $ bindingKey = ( array ) $ this -> getBindingKey ( ) ; if ( count ( $ foreignKey ) !== count ( $ bindingKey ) ) {...
Returns a single or multiple conditions to be appended to the generated join clause for getting the results on the target table .
26,001
protected function _extractFinder ( $ finderData ) { $ finderData = ( array ) $ finderData ; if ( is_numeric ( key ( $ finderData ) ) ) { return [ current ( $ finderData ) , [ ] ] ; } return [ key ( $ finderData ) , current ( $ finderData ) ] ; }
Helper method to infer the requested finder and its options .
26,002
protected function _validateAndUnsetTokenField ( ServerRequest $ request ) { if ( in_array ( $ request -> getMethod ( ) , [ 'PUT' , 'POST' , 'DELETE' , 'PATCH' ] ) || $ request -> getData ( ) ) { $ this -> _validateToken ( $ request ) ; $ body = $ request -> getParsedBody ( ) ; if ( is_array ( $ body ) ) { unset ( $ bo...
Checks if the request is POST PUT DELETE or PATCH and validates the CSRF token
26,003
protected function _addTokenToRequest ( $ token , ServerRequest $ request ) { $ params = $ request -> getAttribute ( 'params' ) ; $ params [ '_csrfToken' ] = $ token ; return $ request -> withAttribute ( 'params' , $ params ) ; }
Add a CSRF token to the request parameters .
26,004
protected function _addTokenCookie ( $ token , ServerRequest $ request , Response $ response ) { $ expiry = new Time ( $ this -> _config [ 'expiry' ] ) ; $ cookie = new Cookie ( $ this -> _config [ 'cookieName' ] , $ token , $ expiry , $ request -> getAttribute ( 'webroot' ) , '' , ( bool ) $ this -> _config [ 'secure'...
Add a CSRF token to the response cookies .
26,005
public function getName ( ) { if ( ! static :: $ name ) { static :: $ name = str_replace ( 'Mailer' , '' , implode ( '' , array_slice ( explode ( '\\' , get_class ( $ this ) ) , - 1 ) ) ) ; } return static :: $ name ; }
Returns the mailer s name .
26,006
public function set ( $ key , $ value = null ) { $ this -> _email -> setViewVars ( is_string ( $ key ) ? [ $ key => $ value ] : $ key ) ; return $ this ; }
Sets email view vars .
26,007
public function send ( ) { deprecationWarning ( 'Response::send() will be removed in 4.0.0' ) ; if ( $ this -> hasHeader ( 'Location' ) && $ this -> _status === 200 ) { $ this -> statusCode ( 302 ) ; } $ this -> _setContent ( ) ; $ this -> sendHeaders ( ) ; if ( $ this -> _file ) { $ this -> _sendFile ( $ this -> _file...
Sends the complete response to the client including headers and message body . Will echo out the content in the response body .
26,008
public function sendHeaders ( ) { deprecationWarning ( 'Will be removed in 4.0.0' ) ; $ file = $ line = null ; if ( headers_sent ( $ file , $ line ) ) { Log :: warning ( "Headers already sent in {$file}:{$line}" ) ; return ; } $ codeMessage = $ this -> _statusCodes [ $ this -> _status ] ; $ this -> _setCookies ( ) ; $ ...
Sends the HTTP headers and cookies .
26,009
protected function _sendHeader ( $ name , $ value = null ) { deprecationWarning ( 'Will be removed in 4.0.0' ) ; if ( $ value === null ) { header ( $ name ) ; } else { header ( "{$name}: {$value}" ) ; } }
Sends a header to the client .
26,010
protected function _sendContent ( $ content ) { deprecationWarning ( 'Will be removed in 4.0.0' ) ; if ( ! is_string ( $ content ) && is_callable ( $ content ) ) { $ content = $ content ( ) ; } echo $ content ; }
Sends a content string to the client .
26,011
public function header ( $ header = null , $ value = null ) { deprecationWarning ( 'Response::header() is deprecated. ' . 'Use `withHeader()`, `getHeaderLine()` and `getHeaders()` instead.' ) ; if ( $ header === null ) { return $ this -> getSimpleHeaders ( ) ; } $ headers = is_array ( $ header ) ? $ header : [ $ header...
Buffers a header string to be sent Returns the complete list of buffered headers
26,012
protected function getSimpleHeaders ( ) { $ out = [ ] ; foreach ( $ this -> headers as $ key => $ values ) { $ header = $ this -> headerNames [ strtolower ( $ key ) ] ; if ( count ( $ values ) === 1 ) { $ values = $ values [ 0 ] ; } $ out [ $ header ] = $ values ; } return $ out ; }
Backwards compatibility helper for getting flattened headers .
26,013
public function location ( $ url = null ) { deprecationWarning ( 'Response::location() is deprecated. ' . 'Mutable responses are deprecated. Use `withLocation()` and `getHeaderLine()` instead.' ) ; if ( $ url === null ) { $ result = $ this -> getHeaderLine ( 'Location' ) ; if ( ! $ result ) { return null ; } return $ r...
Accessor for the location header .
26,014
protected function _handleCallableBody ( callable $ content ) { ob_start ( ) ; $ result1 = $ content ( ) ; $ result2 = ob_get_contents ( ) ; ob_get_clean ( ) ; if ( $ result1 ) { return $ result1 ; } return $ result2 ; }
Handles the callable body for backward compatibility reasons .
26,015
protected function _setStatus ( $ code , $ reasonPhrase = '' ) { if ( ! isset ( $ this -> _statusCodes [ $ code ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid status code: %s. Use a valid HTTP status code in range 1xx - 5xx.' , $ code ) ) ; } $ this -> _status = $ code ; if ( empty ( $ reasonPhrase ) )...
Modifier for response status
26,016
public function httpCodes ( $ code = null ) { deprecationWarning ( 'Response::httpCodes(). Will be removed in 4.0.0' ) ; if ( empty ( $ code ) ) { return $ this -> _statusCodes ; } if ( is_array ( $ code ) ) { $ codes = array_keys ( $ code ) ; $ min = min ( $ codes ) ; if ( ! is_int ( $ min ) || $ min < 100 || max ( $ ...
Queries & sets valid HTTP response codes & messages .
26,017
public function withType ( $ contentType ) { $ mappedType = $ this -> resolveType ( $ contentType ) ; $ new = clone $ this ; $ new -> _contentType = $ mappedType ; $ new -> _setContentType ( ) ; return $ new ; }
Get an updated response with the content type set .
26,018
protected function resolveType ( $ contentType ) { $ mapped = $ this -> getMimeType ( $ contentType ) ; if ( $ mapped ) { return is_array ( $ mapped ) ? current ( $ mapped ) : $ mapped ; } if ( strpos ( $ contentType , '/' ) === false ) { throw new InvalidArgumentException ( sprintf ( '"%s" is an invalid content type.'...
Translate and validate content - types .
26,019
public function getMimeType ( $ alias ) { if ( isset ( $ this -> _mimeTypes [ $ alias ] ) ) { return $ this -> _mimeTypes [ $ alias ] ; } return false ; }
Returns the mime type definition for an alias
26,020
public function mapType ( $ ctype ) { if ( is_array ( $ ctype ) ) { return array_map ( [ $ this , 'mapType' ] , $ ctype ) ; } foreach ( $ this -> _mimeTypes as $ alias => $ types ) { if ( in_array ( $ ctype , ( array ) $ types ) ) { return $ alias ; } } return null ; }
Maps a content - type back to an alias
26,021
public function cache ( $ since , $ time = '+1 day' ) { deprecationWarning ( 'Response::cache() is deprecated. ' . 'Use withCache() instead.' ) ; if ( ! is_int ( $ time ) ) { $ time = strtotime ( $ time ) ; } $ this -> _setHeader ( 'Date' , gmdate ( 'D, j M Y G:i:s ' , time ( ) ) . 'GMT' ) ; $ this -> modified ( $ sinc...
Sets the correct headers to instruct the client to cache the response .
26,022
public function withCache ( $ since , $ time = '+1 day' ) { if ( ! is_int ( $ time ) ) { $ time = strtotime ( $ time ) ; } return $ this -> withHeader ( 'Date' , gmdate ( 'D, j M Y G:i:s ' , time ( ) ) . 'GMT' ) -> withModified ( $ since ) -> withExpires ( $ time ) -> withSharable ( true ) -> withMaxAge ( $ time - time...
Create a new instance with the headers to enable client caching .
26,023
public function sharable ( $ public = null , $ time = null ) { deprecationWarning ( 'Response::sharable() is deprecated. ' . 'Use withSharable() instead.' ) ; if ( $ public === null ) { $ public = array_key_exists ( 'public' , $ this -> _cacheDirectives ) ; $ private = array_key_exists ( 'private' , $ this -> _cacheDir...
Sets whether a response is eligible to be cached by intermediate proxies This method controls the public or private directive in the Cache - Control header
26,024
public function sharedMaxAge ( $ seconds = null ) { deprecationWarning ( 'Response::sharedMaxAge() is deprecated. ' . 'Use withSharedMaxAge() instead.' ) ; if ( $ seconds !== null ) { $ this -> _cacheDirectives [ 's-maxage' ] = $ seconds ; $ this -> _setCacheControl ( ) ; } if ( isset ( $ this -> _cacheDirectives [ 's-...
Sets the Cache - Control s - maxage directive .
26,025
public function mustRevalidate ( $ enable = null ) { deprecationWarning ( 'Response::mustRevalidate() is deprecated. ' . 'Use withMustRevalidate() instead.' ) ; if ( $ enable !== null ) { if ( $ enable ) { $ this -> _cacheDirectives [ 'must-revalidate' ] = true ; } else { unset ( $ this -> _cacheDirectives [ 'must-reva...
Sets the Cache - Control must - revalidate directive . must - revalidate indicates that the response should not be served stale by a cache under any circumstance without first revalidating with the origin . If called with no parameters this function will return whether must - revalidate is present .
26,026
protected function _setCacheControl ( ) { $ control = '' ; foreach ( $ this -> _cacheDirectives as $ key => $ val ) { $ control .= $ val === true ? $ key : sprintf ( '%s=%s' , $ key , $ val ) ; $ control .= ', ' ; } $ control = rtrim ( $ control , ', ' ) ; $ this -> _setHeader ( 'Cache-Control' , $ control ) ; }
Helper method to generate a valid Cache - Control header from the options set in other methods
26,027
public function expires ( $ time = null ) { deprecationWarning ( 'Response::expires() is deprecated. ' . 'Use withExpires() instead.' ) ; if ( $ time !== null ) { $ date = $ this -> _getUTCDate ( $ time ) ; $ this -> _setHeader ( 'Expires' , $ date -> format ( 'D, j M Y H:i:s' ) . ' GMT' ) ; } if ( $ this -> hasHeader ...
Sets the Expires header for the response by taking an expiration time If called with no parameters it will return the current Expires value
26,028
public function withExpires ( $ time ) { $ date = $ this -> _getUTCDate ( $ time ) ; return $ this -> withHeader ( 'Expires' , $ date -> format ( 'D, j M Y H:i:s' ) . ' GMT' ) ; }
Create a new instance with the Expires header set .
26,029
public function withModified ( $ time ) { $ date = $ this -> _getUTCDate ( $ time ) ; return $ this -> withHeader ( 'Last-Modified' , $ date -> format ( 'D, j M Y H:i:s' ) . ' GMT' ) ; }
Create a new instance with the Last - Modified header set .
26,030
public function notModified ( ) { $ this -> _createStream ( ) ; $ this -> _setStatus ( 304 ) ; $ remove = [ 'Allow' , 'Content-Encoding' , 'Content-Language' , 'Content-Length' , 'Content-MD5' , 'Content-Type' , 'Last-Modified' ] ; foreach ( $ remove as $ header ) { $ this -> _clearHeader ( $ header ) ; } }
Sets the response as Not Modified by removing any body contents setting the status code to 304 Not Modified and removing all conflicting headers
26,031
public function withNotModified ( ) { $ new = $ this -> withStatus ( 304 ) ; $ new -> _createStream ( ) ; $ remove = [ 'Allow' , 'Content-Encoding' , 'Content-Language' , 'Content-Length' , 'Content-MD5' , 'Content-Type' , 'Last-Modified' ] ; foreach ( $ remove as $ header ) { $ new = $ new -> withoutHeader ( $ header ...
Create a new instance as not modified
26,032
public function vary ( $ cacheVariances = null ) { deprecationWarning ( 'Response::vary() is deprecated. ' . 'Use withVary() instead.' ) ; if ( $ cacheVariances !== null ) { $ cacheVariances = ( array ) $ cacheVariances ; $ this -> _setHeader ( 'Vary' , implode ( ', ' , $ cacheVariances ) ) ; } if ( $ this -> hasHeader...
Sets the Vary header for the response if an array is passed values will be imploded into a comma separated string . If no parameters are passed then an array with the current Vary header value is returned
26,033
public function etag ( $ hash = null , $ weak = false ) { deprecationWarning ( 'Response::etag() is deprecated. ' . 'Use withEtag() or getHeaderLine("Etag") instead.' ) ; if ( $ hash !== null ) { $ this -> _setHeader ( 'Etag' , sprintf ( '%s"%s"' , $ weak ? 'W/' : null , $ hash ) ) ; } if ( $ this -> hasHeader ( 'Etag'...
Sets the response Etag Etags are a strong indicative that a response can be cached by a HTTP client . A bad way of generating Etags is creating a hash of the response output instead generate a unique hash of the unique components that identifies a request such as a modification time a resource Id and anything else you ...
26,034
public function length ( $ bytes = null ) { deprecationWarning ( 'Response::length() is deprecated. ' . 'Use withLength() instead.' ) ; if ( $ bytes !== null ) { $ this -> _setHeader ( 'Content-Length' , $ bytes ) ; } if ( $ this -> hasHeader ( 'Content-Length' ) ) { return $ this -> getHeaderLine ( 'Content-Length' ) ...
Sets the Content - Length header for the response If called with no arguments returns the last Content - Length set
26,035
public function withAddedLink ( $ url , $ options = [ ] ) { $ params = [ ] ; foreach ( $ options as $ key => $ option ) { $ params [ ] = $ key . '="' . $ option . '"' ; } $ param = '' ; if ( $ params ) { $ param = '; ' . implode ( '; ' , $ params ) ; } return $ this -> withAddedHeader ( 'Link' , '<' . $ url . '>' . $ p...
Create a new response with the Link header set .
26,036
public function withCookie ( $ name , $ data = '' ) { if ( $ name instanceof Cookie ) { $ cookie = $ name ; } else { deprecationWarning ( get_called_class ( ) . '::withCookie(string $name, array $data) is deprecated. ' . 'Pass an instance of \Cake\Http\Cookie\Cookie instead.' ) ; if ( ! is_array ( $ data ) ) { $ data =...
Create a new response with a cookie set .
26,037
public function withExpiredCookie ( $ name , $ options = [ ] ) { if ( $ name instanceof CookieInterface ) { $ cookie = $ name -> withExpired ( ) ; } else { deprecationWarning ( get_called_class ( ) . '::withExpiredCookie(string $name, array $data) is deprecated. ' . 'Pass an instance of \Cake\Http\Cookie\Cookie instead...
Create a new response with an expired cookie set .
26,038
public function getCookie ( $ name ) { if ( ! $ this -> _cookies -> has ( $ name ) ) { return null ; } $ cookie = $ this -> _cookies -> get ( $ name ) ; return $ this -> convertCookieToArray ( $ cookie ) ; }
Read a single cookie from the response .
26,039
public function getCookies ( ) { $ out = [ ] ; foreach ( $ this -> _cookies as $ cookie ) { $ out [ $ cookie -> getName ( ) ] = $ this -> convertCookieToArray ( $ cookie ) ; } return $ out ; }
Get all cookies in the response .
26,040
public function cors ( ServerRequest $ request , $ allowedDomains = [ ] , $ allowedMethods = [ ] , $ allowedHeaders = [ ] ) { $ origin = $ request -> getHeaderLine ( 'Origin' ) ; $ ssl = $ request -> is ( 'ssl' ) ; $ builder = new CorsBuilder ( $ this , $ origin , $ ssl ) ; if ( ! $ origin ) { return $ builder ; } if (...
Setup access for origin and methods on cross origin requests
26,041
public function file ( $ path , array $ options = [ ] ) { deprecationWarning ( 'Response::file() is deprecated. ' . 'Use withFile() instead.' ) ; $ file = $ this -> validateFile ( $ path ) ; $ options += [ 'name' => null , 'download' => null ] ; $ extension = strtolower ( $ file -> ext ( ) ) ; $ download = $ options [ ...
Setup for display or download the given file .
26,042
public function withFile ( $ path , array $ options = [ ] ) { $ file = $ this -> validateFile ( $ path ) ; $ options += [ 'name' => null , 'download' => null ] ; $ extension = strtolower ( $ file -> ext ( ) ) ; $ mapped = $ this -> getMimeType ( $ extension ) ; if ( ( ! $ extension || ! $ mapped ) && $ options [ 'downl...
Create a new instance that is based on a file .
26,043
protected function validateFile ( $ path ) { if ( strpos ( $ path , '../' ) !== false || strpos ( $ path , '..\\' ) !== false ) { throw new NotFoundException ( __d ( 'cake' , 'The requested file contains `..` and will not be read.' ) ) ; } if ( ! is_file ( $ path ) ) { deprecationWarning ( 'Automatic prefixing of paths...
Validate a file path is a valid response body .
26,044
protected function _fileRange ( $ file , $ httpRange ) { $ fileSize = $ file -> size ( ) ; $ lastByte = $ fileSize - 1 ; $ start = 0 ; $ end = $ lastByte ; preg_match ( '/^bytes\s*=\s*(\d+)?\s*-\s*(\d+)?$/' , $ httpRange , $ matches ) ; if ( $ matches ) { $ start = $ matches [ 1 ] ; $ end = isset ( $ matches [ 2 ] ) ? ...
Apply a file range to a file and set the end offset .
26,045
protected function _sendFile ( $ file , $ range ) { deprecationWarning ( 'Will be removed in 4.0.0' ) ; ob_implicit_flush ( true ) ; $ file -> open ( 'rb' ) ; $ end = $ start = false ; if ( $ range ) { list ( $ start , $ end ) = $ range ; } if ( $ start !== false ) { $ file -> offset ( $ start ) ; } $ bufferSize = 8192...
Reads out a file and echos the content to the client .
26,046
protected function _extractFinder ( $ options ) { $ type = ! empty ( $ options [ 'finder' ] ) ? $ options [ 'finder' ] : 'all' ; unset ( $ options [ 'finder' ] , $ options [ 'maxLimit' ] ) ; if ( is_array ( $ type ) ) { $ options = ( array ) current ( $ type ) + $ options ; $ type = key ( $ type ) ; } return [ $ type ,...
Extracts the finder name and options out of the provided pagination options .
26,047
protected function _prefix ( RepositoryInterface $ object , $ order , $ whitelisted = false ) { $ tableAlias = $ object -> getAlias ( ) ; $ tableOrder = [ ] ; foreach ( $ order as $ key => $ value ) { if ( is_numeric ( $ key ) ) { $ tableOrder [ ] = $ value ; continue ; } $ field = $ key ; $ alias = $ tableAlias ; if (...
Prefixes the field with the table alias if possible .
26,048
public function checkLimit ( array $ options ) { $ options [ 'limit' ] = ( int ) $ options [ 'limit' ] ; if ( empty ( $ options [ 'limit' ] ) || $ options [ 'limit' ] < 1 ) { $ options [ 'limit' ] = 1 ; } $ options [ 'limit' ] = max ( min ( $ options [ 'limit' ] , $ options [ 'maxLimit' ] ) , 1 ) ; return $ options ; }
Check the limit parameter and ensure it s within the maxLimit bounds .
26,049
public function execute ( Arguments $ args , ConsoleIo $ io ) { if ( ! $ args -> getOption ( 'xml' ) ) { $ io -> out ( '<info>Current Paths:</info>' , 2 ) ; $ io -> out ( '* app: ' . APP_DIR . DIRECTORY_SEPARATOR ) ; $ io -> out ( '* root: ' . ROOT . DIRECTORY_SEPARATOR ) ; $ io -> out ( '* core: ' . CORE_PATH ) ; $ i...
Main function Prints out the list of commands .
26,050
public function checkRules ( EntityInterface $ entity , $ operation = RulesChecker :: CREATE , $ options = null ) { $ rules = $ this -> rulesChecker ( ) ; $ options = $ options ? : new ArrayObject ( ) ; $ options = is_array ( $ options ) ? new ArrayObject ( $ options ) : $ options ; $ hasEvents = ( $ this instanceof Ev...
Returns whether or not the passed entity complies with all the rules stored in the rules checker .
26,051
public function rulesChecker ( ) { if ( $ this -> _rulesChecker !== null ) { return $ this -> _rulesChecker ; } $ class = defined ( 'static::RULES_CLASS' ) ? static :: RULES_CLASS : 'Cake\Datasource\RulesChecker' ; $ this -> _rulesChecker = $ this -> buildRules ( new $ class ( [ 'repository' => $ this ] ) ) ; $ this ->...
Returns the RulesChecker for this instance .
26,052
public function loadModel ( $ modelClass = null , $ modelType = null ) { if ( $ modelClass === null ) { $ modelClass = $ this -> modelClass ; } if ( $ modelType === null ) { $ modelType = $ this -> getModelType ( ) ; if ( $ modelType === null ) { throw new UnexpectedValueException ( 'No model type has been defined' ) ;...
Loads and constructs repository objects required by this object
26,053
public function modelType ( $ modelType = null ) { deprecationWarning ( get_called_class ( ) . '::modelType() is deprecated. ' . 'Use setModelType()/getModelType() instead.' ) ; if ( $ modelType === null ) { return $ this -> _modelType ; } $ this -> _modelType = $ modelType ; return $ this ; }
Set or get the model type to be used by this class
26,054
protected function _propertyName ( ) { list ( , $ name ) = pluginSplit ( $ this -> _name ) ; return Inflector :: underscore ( Inflector :: singularize ( $ name ) ) ; }
Returns default property name based on association name .
26,055
public static function lengthBetween ( $ check , $ min , $ max ) { if ( ! is_string ( $ check ) ) { return false ; } $ length = mb_strlen ( $ check ) ; return ( $ length >= $ min && $ length <= $ max ) ; }
Checks that a string length is within specified range . Spaces are included in the character count . Returns true if string matches value min max or between min and max
26,056
public static function numElements ( $ check , $ operator , $ expectedCount ) { if ( ! is_array ( $ check ) && ! $ check instanceof \ Countable ) { return false ; } return self :: comparison ( count ( $ check ) , $ operator , $ expectedCount ) ; }
Used to check the count of a given value of type array or Countable .
26,057
public static function comparison ( $ check1 , $ operator , $ check2 ) { if ( ( float ) $ check1 != $ check1 ) { return false ; } $ message = 'Operator `%s` is deprecated, use constant `Validation::%s` instead.' ; $ operator = str_replace ( [ ' ' , "\t" , "\n" , "\r" , "\0" , "\x0B" ] , '' , strtolower ( $ operator ) )...
Used to compare 2 numeric values .
26,058
public static function containsNonAlphaNumeric ( $ check , $ count = 1 ) { if ( ! is_scalar ( $ check ) ) { return false ; } $ matches = preg_match_all ( '/[^a-zA-Z0-9]/' , $ check ) ; return $ matches >= $ count ; }
Checks if a string contains one or more non - alphanumeric characters .
26,059
public static function custom ( $ check , $ regex = null ) { if ( $ regex === null ) { static :: $ errors [ ] = 'You must define a regular expression for Validation::custom()' ; return false ; } return static :: _check ( $ check , $ regex ) ; }
Used when a custom regular expression is needed .
26,060
public static function date ( $ check , $ format = 'ymd' , $ regex = null ) { if ( $ check instanceof DateTimeInterface ) { return true ; } if ( is_object ( $ check ) ) { return false ; } if ( is_array ( $ check ) ) { $ check = static :: _getDateString ( $ check ) ; $ format = 'ymd' ; } if ( $ regex !== null ) { return...
Date validation determines if the string passed is a valid date . keys that expect full month day and year will validate leap years .
26,061
public static function datetime ( $ check , $ dateFormat = 'ymd' , $ regex = null ) { if ( $ check instanceof DateTimeInterface ) { return true ; } if ( is_object ( $ check ) ) { return false ; } $ valid = false ; if ( is_array ( $ check ) ) { $ check = static :: _getDateString ( $ check ) ; $ dateFormat = 'ymd' ; } $ ...
Validates a datetime value
26,062
public static function boolean ( $ check , array $ booleanValues = [ ] ) { if ( ! $ booleanValues ) { $ booleanValues = [ true , false , 0 , 1 , '0' , '1' ] ; } return in_array ( $ check , $ booleanValues , true ) ; }
Validates if passed value is boolean - like .
26,063
public static function truthy ( $ check , array $ truthyValues = [ ] ) { if ( ! $ truthyValues ) { $ truthyValues = [ true , 1 , '1' ] ; } return in_array ( $ check , $ truthyValues , true ) ; }
Validates if given value is truthy .
26,064
public static function falsey ( $ check , array $ falseyValues = [ ] ) { if ( ! $ falseyValues ) { $ falseyValues = [ false , 0 , '0' ] ; } return in_array ( $ check , $ falseyValues , true ) ; }
Validates if given value is falsey .
26,065
public static function decimal ( $ check , $ places = null , $ regex = null ) { if ( $ regex === null ) { $ lnum = '[0-9]+' ; $ dnum = "[0-9]*[\.]{$lnum}" ; $ sign = '[+-]?' ; $ exp = "(?:[eE]{$sign}{$lnum})?" ; if ( $ places === null ) { $ regex = "/^{$sign}(?:{$lnum}|{$dnum}){$exp}$/" ; } elseif ( $ places === true )...
Checks that a value is a valid decimal . Both the sign and exponent are optional .
26,066
public static function extension ( $ check , $ extensions = [ 'gif' , 'jpeg' , 'png' , 'jpg' ] ) { if ( $ check instanceof UploadedFileInterface ) { return static :: extension ( $ check -> getClientFilename ( ) , $ extensions ) ; } if ( is_array ( $ check ) ) { $ check = isset ( $ check [ 'name' ] ) ? $ check [ 'name' ...
Checks that value has a valid file extension .
26,067
public static function ip ( $ check , $ type = 'both' ) { $ type = strtolower ( $ type ) ; $ flags = 0 ; if ( $ type === 'ipv4' ) { $ flags = FILTER_FLAG_IPV4 ; } if ( $ type === 'ipv6' ) { $ flags = FILTER_FLAG_IPV6 ; } return ( bool ) filter_var ( $ check , FILTER_VALIDATE_IP , [ 'flags' => $ flags ] ) ; }
Validation of an IP address .
26,068
public static function money ( $ check , $ symbolPosition = 'left' ) { $ money = '(?!0,?\d)(?:\d{1,3}(?:([, .])\d{3})?(?:\1\d{3})*|(?:\d+))((?!\1)[,.]\d{1,2})?' ; if ( $ symbolPosition === 'right' ) { $ regex = '/^' . $ money . '(?<!\x{00a2})\p{Sc}?$/u' ; } else { $ regex = '/^(?!\x{00a2})\p{Sc}?' . $ money . '$/u' ; }...
Checks that a value is a monetary amount .
26,069
public static function multiple ( $ check , array $ options = [ ] , $ caseInsensitive = false ) { $ defaults = [ 'in' => null , 'max' => null , 'min' => null ] ; $ options += $ defaults ; $ check = array_filter ( ( array ) $ check , function ( $ value ) { return ( $ value || is_numeric ( $ value ) ) ; } ) ; if ( empty ...
Validates a multiple select . Comparison is case sensitive by default .
26,070
public static function inList ( $ check , array $ list , $ caseInsensitive = false ) { if ( $ caseInsensitive ) { $ list = array_map ( 'mb_strtolower' , $ list ) ; $ check = mb_strtolower ( $ check ) ; } else { $ list = array_map ( 'strval' , $ list ) ; } return in_array ( ( string ) $ check , $ list , true ) ; }
Checks if a value is in a given list . Comparison is case sensitive by default .
26,071
public static function userDefined ( $ check , $ object , $ method , $ args = null ) { deprecationWarning ( 'Validation::userDefined() is deprecated. ' . 'You can just set a callable for `rule` key when adding validators.' ) ; return $ object -> $ method ( $ check , $ args ) ; }
Runs an user - defined validation .
26,072
public static function mimeType ( $ check , $ mimeTypes = [ ] ) { $ file = static :: getFilename ( $ check ) ; if ( $ file === false ) { return false ; } if ( ! function_exists ( 'finfo_open' ) ) { throw new LogicException ( 'ext/fileinfo is required for validating file mime types' ) ; } if ( ! is_file ( $ file ) ) { t...
Checks the mime type of a file .
26,073
protected static function getFilename ( $ check ) { if ( $ check instanceof UploadedFileInterface ) { try { return $ check -> getStream ( ) -> getMetadata ( 'uri' ) ; } catch ( RuntimeException $ e ) { return false ; } } if ( is_array ( $ check ) && isset ( $ check [ 'tmp_name' ] ) ) { return $ check [ 'tmp_name' ] ; }...
Helper for reading the file out of the various file implementations we accept .
26,074
public static function fileSize ( $ check , $ operator = null , $ size = null ) { $ file = static :: getFilename ( $ check ) ; if ( $ file === false ) { return false ; } if ( is_string ( $ size ) ) { $ size = Text :: parseFileSize ( $ size ) ; } $ filesize = filesize ( $ file ) ; return static :: comparison ( $ filesiz...
Checks the filesize
26,075
public static function uploadError ( $ check , $ allowNoFile = false ) { if ( $ check instanceof UploadedFileInterface ) { $ code = $ check -> getError ( ) ; } elseif ( is_array ( $ check ) && isset ( $ check [ 'error' ] ) ) { $ code = $ check [ 'error' ] ; } else { $ code = $ check ; } if ( $ allowNoFile ) { return in...
Checking for upload errors
26,076
public static function uploadedFile ( $ file , array $ options = [ ] ) { $ options += [ 'minSize' => null , 'maxSize' => null , 'types' => null , 'optional' => false , ] ; if ( ! is_array ( $ file ) && ! ( $ file instanceof UploadedFileInterface ) ) { return false ; } $ error = $ isUploaded = false ; if ( $ file instan...
Validate an uploaded file .
26,077
public static function imageSize ( $ file , $ options ) { if ( ! isset ( $ options [ 'height' ] ) && ! isset ( $ options [ 'width' ] ) ) { throw new InvalidArgumentException ( 'Invalid image size validation parameters! Missing `width` and / or `height`.' ) ; } $ filename = static :: getFilename ( $ file ) ; list ( $ wi...
Validates the size of an uploaded image .
26,078
public static function geoCoordinate ( $ value , array $ options = [ ] ) { $ options += [ 'format' => 'both' , 'type' => 'latLong' ] ; if ( $ options [ 'type' ] !== 'latLong' ) { throw new RuntimeException ( sprintf ( 'Unsupported coordinate type "%s". Use "latLong" instead.' , $ options [ 'type' ] ) ) ; } $ pattern = ...
Validates a geographic coordinate .
26,079
public static function utf8 ( $ value , array $ options = [ ] ) { if ( ! is_string ( $ value ) ) { return false ; } $ options += [ 'extended' => false ] ; if ( $ options [ 'extended' ] ) { return true ; } return preg_match ( '/[\x{10000}-\x{10FFFF}]/u' , $ value ) === 0 ; }
Check that the input value is a utf8 string .
26,080
public static function isInteger ( $ value ) { if ( ! is_scalar ( $ value ) || is_float ( $ value ) ) { return false ; } if ( is_int ( $ value ) ) { return true ; } return ( bool ) preg_match ( '/^-?[0-9]+$/' , $ value ) ; }
Check that the input value is an integer
26,081
public static function iban ( $ check ) { if ( ! preg_match ( '/^[A-Z]{2}[0-9]{2}[A-Z0-9]{1,30}$/' , $ check ) ) { return false ; } $ country = substr ( $ check , 0 , 2 ) ; $ checkInt = intval ( substr ( $ check , 2 , 2 ) ) ; $ account = substr ( $ check , 4 ) ; $ search = range ( 'A' , 'Z' ) ; $ replace = [ ] ; foreac...
Check that the input value has a valid International Bank Account Number IBAN syntax Requirements are uppercase no whitespaces max length 34 country code and checksum exist at right spots body matches against checksum via Mod97 - 10 algorithm
26,082
protected static function _getDateString ( $ value ) { $ formatted = '' ; if ( isset ( $ value [ 'year' ] , $ value [ 'month' ] , $ value [ 'day' ] ) && ( is_numeric ( $ value [ 'year' ] ) && is_numeric ( $ value [ 'month' ] ) && is_numeric ( $ value [ 'day' ] ) ) ) { $ formatted .= sprintf ( '%d-%02d-%02d ' , $ value ...
Converts an array representing a date or datetime into a ISO string . The arrays are typically sent for validation from a form generated by the CakePHP FormHelper .
26,083
protected static function _populateIp ( ) { if ( ! isset ( static :: $ _pattern [ 'IPv6' ] ) ) { $ pattern = '((([0-9A-Fa-f]{1,4}:){7}(([0-9A-Fa-f]{1,4})|:))|(([0-9A-Fa-f]{1,4}:){6}' ; $ pattern .= '(:|((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})' ; $ pattern .= '|(:[0-9A-Fa-f]{1,4})))|(([0-9...
Lazily populate the IP address patterns used for validations
26,084
public function addCookie ( CookieInterface $ cookie ) { if ( ! $ cookie -> getDomain ( ) || ! $ cookie -> getPath ( ) ) { throw new InvalidArgumentException ( 'Cookie must have a domain and a path set.' ) ; } $ this -> _cookies = $ this -> _cookies -> add ( $ cookie ) ; return $ this ; }
Adds a cookie to the Client collection .
26,085
public function get ( $ url , $ data = [ ] , array $ options = [ ] ) { $ options = $ this -> _mergeOptions ( $ options ) ; $ body = null ; if ( isset ( $ data [ '_content' ] ) ) { $ body = $ data [ '_content' ] ; unset ( $ data [ '_content' ] ) ; } $ url = $ this -> buildUrl ( $ url , $ data , $ options ) ; return $ th...
Do a GET request .
26,086
public function post ( $ url , $ data = [ ] , array $ options = [ ] ) { $ options = $ this -> _mergeOptions ( $ options ) ; $ url = $ this -> buildUrl ( $ url , [ ] , $ options ) ; return $ this -> _doRequest ( Request :: METHOD_POST , $ url , $ data , $ options ) ; }
Do a POST request .
26,087
public function put ( $ url , $ data = [ ] , array $ options = [ ] ) { $ options = $ this -> _mergeOptions ( $ options ) ; $ url = $ this -> buildUrl ( $ url , [ ] , $ options ) ; return $ this -> _doRequest ( Request :: METHOD_PUT , $ url , $ data , $ options ) ; }
Do a PUT request .
26,088
public function patch ( $ url , $ data = [ ] , array $ options = [ ] ) { $ options = $ this -> _mergeOptions ( $ options ) ; $ url = $ this -> buildUrl ( $ url , [ ] , $ options ) ; return $ this -> _doRequest ( Request :: METHOD_PATCH , $ url , $ data , $ options ) ; }
Do a PATCH request .
26,089
public function options ( $ url , $ data = [ ] , array $ options = [ ] ) { $ options = $ this -> _mergeOptions ( $ options ) ; $ url = $ this -> buildUrl ( $ url , [ ] , $ options ) ; return $ this -> _doRequest ( Request :: METHOD_OPTIONS , $ url , $ data , $ options ) ; }
Do an OPTIONS request .
26,090
public function trace ( $ url , $ data = [ ] , array $ options = [ ] ) { $ options = $ this -> _mergeOptions ( $ options ) ; $ url = $ this -> buildUrl ( $ url , [ ] , $ options ) ; return $ this -> _doRequest ( Request :: METHOD_TRACE , $ url , $ data , $ options ) ; }
Do a TRACE request .
26,091
public function delete ( $ url , $ data = [ ] , array $ options = [ ] ) { $ options = $ this -> _mergeOptions ( $ options ) ; $ url = $ this -> buildUrl ( $ url , [ ] , $ options ) ; return $ this -> _doRequest ( Request :: METHOD_DELETE , $ url , $ data , $ options ) ; }
Do a DELETE request .
26,092
public function head ( $ url , array $ data = [ ] , array $ options = [ ] ) { $ options = $ this -> _mergeOptions ( $ options ) ; $ url = $ this -> buildUrl ( $ url , $ data , $ options ) ; return $ this -> _doRequest ( Request :: METHOD_HEAD , $ url , '' , $ options ) ; }
Do a HEAD request .
26,093
protected function _doRequest ( $ method , $ url , $ data , $ options ) { $ request = $ this -> _createRequest ( $ method , $ url , $ data , $ options ) ; return $ this -> send ( $ request , $ options ) ; }
Helper method for doing non - GET requests .
26,094
protected function _sendRequest ( Request $ request , $ options ) { $ responses = $ this -> _adapter -> send ( $ request , $ options ) ; $ url = $ request -> getUri ( ) ; foreach ( $ responses as $ response ) { $ this -> _cookies = $ this -> _cookies -> addFromResponse ( $ response , $ request ) ; } return array_pop ( ...
Send a request without redirection .
26,095
public function buildUrl ( $ url , $ query = [ ] , $ options = [ ] ) { if ( empty ( $ options ) && empty ( $ query ) ) { return $ url ; } if ( $ query ) { $ q = ( strpos ( $ url , '?' ) === false ) ? '?' : '&' ; $ url .= $ q ; $ url .= is_string ( $ query ) ? $ query : http_build_query ( $ query ) ; } $ defaults = [ 'h...
Generate a URL based on the scoped client options .
26,096
protected function _createRequest ( $ method , $ url , $ data , $ options ) { $ headers = isset ( $ options [ 'headers' ] ) ? ( array ) $ options [ 'headers' ] : [ ] ; if ( isset ( $ options [ 'type' ] ) ) { $ headers = array_merge ( $ headers , $ this -> _typeHeaders ( $ options [ 'type' ] ) ) ; } if ( is_string ( $ d...
Creates a new request object based on the parameters .
26,097
protected function _addAuthentication ( Request $ request , $ options ) { $ auth = $ options [ 'auth' ] ; $ adapter = $ this -> _createAuth ( $ auth , $ options ) ; $ result = $ adapter -> authentication ( $ request , $ options [ 'auth' ] ) ; return $ result ? : $ request ; }
Add authentication headers to the request .
26,098
protected function _addProxy ( Request $ request , $ options ) { $ auth = $ options [ 'proxy' ] ; $ adapter = $ this -> _createAuth ( $ auth , $ options ) ; $ result = $ adapter -> proxyAuthentication ( $ request , $ options [ 'proxy' ] ) ; return $ result ? : $ request ; }
Add proxy authentication headers .
26,099
protected function _createAuth ( $ auth , $ options ) { if ( empty ( $ auth [ 'type' ] ) ) { $ auth [ 'type' ] = 'basic' ; } $ name = ucfirst ( $ auth [ 'type' ] ) ; $ class = App :: className ( $ name , 'Http/Client/Auth' ) ; if ( ! $ class ) { throw new Exception ( sprintf ( 'Invalid authentication type %s' , $ name ...
Create the authentication strategy .