idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
25,400
public static function normalize ( $ url = '/' ) { if ( is_array ( $ url ) ) { $ url = static :: url ( $ url ) ; } if ( preg_match ( '/^[a-z\-]+:\/\//' , $ url ) ) { return $ url ; } $ request = static :: getRequest ( ) ; if ( $ request ) { $ base = $ request -> getAttribute ( 'base' ) ; if ( strlen ( $ base ) && stris...
Normalizes a URL for purposes of comparison .
25,401
public static function extensions ( $ extensions = null , $ merge = true ) { $ collection = static :: $ _collection ; if ( $ extensions === null ) { if ( ! static :: $ initialized ) { static :: _loadRoutes ( ) ; } return array_unique ( array_merge ( static :: $ _defaultExtensions , $ collection -> getExtensions ( ) ) )...
Get or set valid extensions for all routes connected later .
25,402
public static function parseNamedParams ( ServerRequest $ request , array $ options = [ ] ) { deprecationWarning ( 'Router::parseNamedParams() is deprecated. ' . '2.x backwards compatible named parameter support will be removed in 4.0' ) ; $ options += [ 'separator' => ':' ] ; if ( ! $ request -> getParam ( 'pass' ) ) ...
Provides legacy support for named parameters on incoming URLs .
25,403
public static function createRouteBuilder ( $ path , array $ options = [ ] ) { $ defaults = [ 'routeClass' => static :: defaultRouteClass ( ) , 'extensions' => static :: $ _defaultExtensions , ] ; $ options += $ defaults ; return new RouteBuilder ( static :: $ _collection , $ path , [ ] , [ 'routeClass' => $ options [ ...
Create a RouteBuilder for the provided path .
25,404
public static function scope ( $ path , $ params = [ ] , $ callback = null ) { $ options = [ ] ; if ( is_array ( $ params ) ) { $ options = $ params ; unset ( $ params [ 'routeClass' ] , $ params [ 'extensions' ] ) ; } $ builder = static :: createRouteBuilder ( '/' , $ options ) ; $ builder -> scope ( $ path , $ params...
Create a routing scope .
25,405
public static function prefix ( $ name , $ params = [ ] , $ callback = null ) { if ( $ callback === null ) { $ callback = $ params ; $ params = [ ] ; } $ name = Inflector :: underscore ( $ name ) ; if ( empty ( $ params [ 'path' ] ) ) { $ path = '/' . $ name ; } else { $ path = $ params [ 'path' ] ; unset ( $ params [ ...
Create prefixed routes .
25,406
protected function _prepare ( ) { $ table = $ this -> _context [ 'table' ] ; $ entity = $ this -> _context [ 'entity' ] ; if ( empty ( $ table ) ) { if ( is_array ( $ entity ) || $ entity instanceof Traversable ) { foreach ( $ entity as $ e ) { $ entity = $ e ; break ; } } $ isEntity = $ entity instanceof EntityInterfa...
Prepare some additional data from the context .
25,407
public function isCreate ( ) { $ entity = $ this -> _context [ 'entity' ] ; if ( is_array ( $ entity ) || $ entity instanceof Traversable ) { foreach ( $ entity as $ e ) { $ entity = $ e ; break ; } } if ( $ entity instanceof EntityInterface ) { return $ entity -> isNew ( ) !== false ; } return true ; }
Check whether or not this form is a create or update .
25,408
protected function _schemaDefault ( $ parts ) { $ table = $ this -> _getTable ( $ parts ) ; if ( $ table === false ) { return null ; } $ field = end ( $ parts ) ; $ defaults = $ table -> getSchema ( ) -> defaultValues ( ) ; if ( ! array_key_exists ( $ field , $ defaults ) ) { return null ; } return $ defaults [ $ field...
Get default value from table schema for given entity field .
25,409
public function entity ( $ path = null ) { if ( $ path === null ) { return $ this -> _context [ 'entity' ] ; } $ oneElement = count ( $ path ) === 1 ; if ( $ oneElement && $ this -> _isCollection ) { return false ; } $ entity = $ this -> _context [ 'entity' ] ; if ( $ oneElement ) { return $ entity ; } if ( $ path [ 0 ...
Fetch the leaf entity for the given path .
25,410
public function isRequired ( $ field ) { $ parts = explode ( '.' , $ field ) ; $ entity = $ this -> entity ( $ parts ) ; $ isNew = true ; if ( $ entity instanceof EntityInterface ) { $ isNew = $ entity -> isNew ( ) ; } $ validator = $ this -> _getValidator ( $ parts ) ; $ fieldName = array_pop ( $ parts ) ; if ( ! $ va...
Check if a field should be marked as required .
25,411
protected function _getValidator ( $ parts ) { $ keyParts = array_filter ( array_slice ( $ parts , 0 , - 1 ) , function ( $ part ) { return ! is_numeric ( $ part ) ; } ) ; $ key = implode ( '.' , $ keyParts ) ; $ entity = $ this -> entity ( $ parts ) ? : null ; if ( isset ( $ this -> _validator [ $ key ] ) ) { $ this -...
Get the validator associated to an entity based on naming conventions .
25,412
protected function _getTable ( $ parts , $ fallback = true ) { if ( ! is_array ( $ parts ) || count ( $ parts ) === 1 ) { return $ this -> _tables [ $ this -> _rootName ] ; } $ normalized = array_slice ( array_filter ( $ parts , function ( $ part ) { return ! is_numeric ( $ part ) ; } ) , 0 , - 1 ) ; $ path = implode (...
Get the table instance from a property path
25,413
public function shouldRetry ( Exception $ exception , $ retryCount ) { $ message = $ exception -> getMessage ( ) ; foreach ( static :: $ causes as $ cause ) { if ( strstr ( $ message , $ cause ) !== false ) { return $ this -> reconnect ( ) ; } } return false ; }
Checks whether or not the exception was caused by a lost connection and returns true if it was able to successfully reconnect .
25,414
protected function reconnect ( ) { if ( $ this -> connection -> inTransaction ( ) ) { return false ; } try { $ this -> connection -> disconnect ( ) ; } catch ( Exception $ e ) { } try { $ this -> connection -> connect ( ) ; $ this -> connection -> log ( '[RECONNECT]' ) ; return true ; } catch ( Exception $ e ) { return...
Tries to re - establish the connection to the server if it is safe to do so
25,415
public function startup ( ) { if ( $ this -> param ( 'host' ) ) { $ this -> _host = $ this -> param ( 'host' ) ; } if ( $ this -> param ( 'port' ) ) { $ this -> _port = ( int ) $ this -> param ( 'port' ) ; } if ( $ this -> param ( 'document_root' ) ) { $ this -> _documentRoot = $ this -> param ( 'document_root' ) ; } i...
Starts up the Shell and displays the welcome message . Allows for checking and configuring prior to command or main execution
25,416
public function handleException ( $ exception , $ request , $ response ) { $ renderer = $ this -> getRenderer ( $ exception , $ request ) ; try { $ res = $ renderer -> render ( ) ; $ this -> logException ( $ request , $ exception ) ; return $ res ; } catch ( Throwable $ exception ) { $ this -> logException ( $ request ...
Handle an exception and generate an error response
25,417
protected function getRenderer ( $ exception , $ request ) { if ( ! $ this -> exceptionRenderer ) { $ this -> exceptionRenderer = $ this -> getConfig ( 'exceptionRenderer' ) ? : ExceptionRenderer :: class ; } if ( $ exception instanceof Error ) { $ exception = new PHP7ErrorException ( $ exception ) ; } if ( is_string (...
Get a renderer instance
25,418
public function getConfig ( $ key = null , $ default = null ) { if ( ! $ this -> _configInitialized ) { $ this -> _config = $ this -> _defaultConfig ; $ this -> _configInitialized = true ; } $ return = $ this -> _configRead ( $ key ) ; return $ return === null ? $ default : $ return ; }
Returns the config .
25,419
protected function _configRead ( $ key ) { if ( $ key === null ) { return $ this -> _config ; } if ( strpos ( $ key , '.' ) === false ) { return isset ( $ this -> _config [ $ key ] ) ? $ this -> _config [ $ key ] : null ; } $ return = $ this -> _config ; foreach ( explode ( '.' , $ key ) as $ k ) { if ( ! is_array ( $ ...
Reads a config key .
25,420
protected function _configWrite ( $ key , $ value , $ merge = false ) { if ( is_string ( $ key ) && $ value === null ) { $ this -> _configDelete ( $ key ) ; return ; } if ( $ merge ) { $ update = is_array ( $ key ) ? $ key : [ $ key => $ value ] ; if ( $ merge === 'shallow' ) { $ this -> _config = array_merge ( $ this ...
Writes a config key .
25,421
protected function _configDelete ( $ key ) { if ( strpos ( $ key , '.' ) === false ) { unset ( $ this -> _config [ $ key ] ) ; return ; } $ update = & $ this -> _config ; $ stack = explode ( '.' , $ key ) ; $ length = count ( $ stack ) ; foreach ( $ stack as $ i => $ k ) { if ( ! is_array ( $ update ) ) { throw new Exc...
Deletes a single config key .
25,422
protected function _displayException ( $ exception ) { $ rendererClassName = App :: className ( $ this -> _options [ 'exceptionRenderer' ] , 'Error' ) ; try { if ( ! $ rendererClassName ) { throw new Exception ( "$rendererClassName is an invalid class." ) ; } $ renderer = new $ rendererClassName ( $ exception ) ; $ res...
Displays an exception response body .
25,423
protected function _logInternalError ( $ exception ) { $ this -> _options [ 'trace' ] = false ; $ message = sprintf ( "[%s] %s\n%s" , get_class ( $ exception ) , $ exception -> getMessage ( ) , $ exception -> getTraceAsString ( ) ) ; trigger_error ( $ message , E_USER_ERROR ) ; }
Logs both PHP5 and PHP7 errors .
25,424
protected function _sendResponse ( $ response ) { if ( is_string ( $ response ) ) { echo $ response ; return ; } $ emitter = new ResponseEmitter ( ) ; $ emitter -> emit ( $ response ) ; }
Method that can be easily stubbed in testing .
25,425
protected function _decodeGzipBody ( $ body ) { if ( ! function_exists ( 'gzinflate' ) ) { throw new RuntimeException ( 'Cannot decompress gzip response body without gzinflate()' ) ; } $ offset = 0 ; if ( substr ( $ body , 0 , 2 ) === "\x1f\x8b" ) { $ offset = 2 ; } if ( substr ( $ body , $ offset , 1 ) === "\x08" ) { ...
Uncompress a gzip response .
25,426
protected function _parseHeaders ( $ headers ) { foreach ( $ headers as $ key => $ value ) { if ( substr ( $ value , 0 , 5 ) === 'HTTP/' ) { preg_match ( '/HTTP\/([\d.]+) ([0-9]+)(.*)/i' , $ value , $ matches ) ; $ this -> protocol = $ matches [ 1 ] ; $ this -> code = ( int ) $ matches [ 2 ] ; $ this -> reasonPhrase = ...
Parses headers if necessary .
25,427
public function isOk ( ) { $ codes = [ static :: STATUS_OK , static :: STATUS_CREATED , static :: STATUS_ACCEPTED , static :: STATUS_NON_AUTHORITATIVE_INFORMATION , static :: STATUS_NO_CONTENT ] ; return in_array ( $ this -> code , $ codes ) ; }
Check if the response was OK
25,428
public function isRedirect ( ) { $ codes = [ static :: STATUS_MOVED_PERMANENTLY , static :: STATUS_FOUND , static :: STATUS_SEE_OTHER , static :: STATUS_TEMPORARY_REDIRECT , ] ; return ( in_array ( $ this -> code , $ codes ) && $ this -> getHeaderLine ( 'Location' ) ) ; }
Check if the response had a redirect status code .
25,429
public function getEncoding ( ) { $ content = $ this -> getHeaderLine ( 'content-type' ) ; if ( ! $ content ) { return null ; } preg_match ( '/charset\s?=\s?[\'"]?([a-z0-9-_]+)[\'"]?/i' , $ content , $ matches ) ; if ( empty ( $ matches [ 1 ] ) ) { return null ; } return $ matches [ 1 ] ; }
Get the encoding if it was set .
25,430
public function getCookie ( $ name ) { $ this -> buildCookieCollection ( ) ; if ( ! $ this -> cookies -> has ( $ name ) ) { return null ; } return $ this -> cookies -> get ( $ name ) -> getValue ( ) ; }
Get the value of a single cookie .
25,431
public function getCookieData ( $ name ) { $ this -> buildCookieCollection ( ) ; if ( ! $ this -> cookies -> has ( $ name ) ) { return null ; } $ cookie = $ this -> cookies -> get ( $ name ) ; return $ this -> convertCookieToArray ( $ cookie ) ; }
Get the full data for a single cookie .
25,432
protected function convertCookieToArray ( CookieInterface $ cookie ) { return [ 'name' => $ cookie -> getName ( ) , 'value' => $ cookie -> getValue ( ) , 'path' => $ cookie -> getPath ( ) , 'domain' => $ cookie -> getDomain ( ) , 'secure' => $ cookie -> isSecure ( ) , 'httponly' => $ cookie -> isHttpOnly ( ) , 'expires...
Convert the cookie into an array of its properties .
25,433
public function body ( $ parser = null ) { deprecationWarning ( 'Response::body() is deprecated. Use getStringBody()/getJson()/getXml() instead.' ) ; $ stream = $ this -> stream ; $ stream -> rewind ( ) ; if ( $ parser ) { return $ parser ( $ stream -> getContents ( ) ) ; } return $ stream -> getContents ( ) ; }
Get the response body .
25,434
protected function _getJson ( ) { if ( $ this -> _json ) { return $ this -> _json ; } return $ this -> _json = json_decode ( $ this -> _getBody ( ) , true ) ; }
Get the response body as JSON decoded data .
25,435
protected function _getXml ( ) { if ( $ this -> _xml ) { return $ this -> _xml ; } libxml_use_internal_errors ( ) ; $ data = simplexml_load_string ( $ this -> _getBody ( ) ) ; if ( $ data ) { $ this -> _xml = $ data ; return $ this -> _xml ; } return null ; }
Get the response body as XML decoded data .
25,436
public function fetch ( $ type = parent :: FETCH_TYPE_NUM ) { $ callback = $ this -> _callback ; $ row = $ this -> _statement -> fetch ( $ type ) ; return $ row === false ? $ row : $ callback ( $ row ) ; }
Fetch a row from the statement .
25,437
public function fetchAll ( $ type = parent :: FETCH_TYPE_NUM ) { return array_map ( $ this -> _callback , $ this -> _statement -> fetchAll ( $ type ) ) ; }
Fetch all rows from the statement .
25,438
public function connection ( $ connection = null ) { if ( $ connection !== null ) { $ this -> _connection = $ connection ; } return $ this -> _connection ; }
Returns correct connection resource or object that is internally used If first argument is passed it will set internal connection object or result to the value passed
25,439
public function isConnected ( ) { if ( $ this -> _connection === null ) { $ connected = false ; } else { try { $ connected = $ this -> _connection -> query ( 'SELECT 1' ) ; } catch ( PDOException $ e ) { $ connected = false ; } } return ( bool ) $ connected ; }
Checks whether or not the driver is connected .
25,440
public function beginTransaction ( ) { $ this -> connect ( ) ; if ( $ this -> _connection -> inTransaction ( ) ) { return true ; } return $ this -> _connection -> beginTransaction ( ) ; }
Starts a transaction
25,441
public function quote ( $ value , $ type ) { $ this -> connect ( ) ; return $ this -> _connection -> quote ( $ value , $ type ) ; }
Returns a value in a safe representation to be used in a query string
25,442
public function lastInsertId ( $ table = null , $ column = null ) { $ this -> connect ( ) ; return $ this -> _connection -> lastInsertId ( $ table ) ; }
Returns last id generated for a table or sequence in database
25,443
protected static function _loadConfig ( ) { foreach ( static :: $ _config as $ name => $ properties ) { if ( isset ( $ properties [ 'engine' ] ) ) { $ properties [ 'className' ] = $ properties [ 'engine' ] ; } if ( ! static :: $ _registry -> has ( $ name ) ) { static :: $ _registry -> load ( $ name , $ properties ) ; }...
Load the defined configuration and create all the defined logging adapters .
25,444
public function log ( LoggedQuery $ query ) { if ( ! empty ( $ query -> params ) ) { $ query -> query = $ this -> _interpolate ( $ query ) ; } $ this -> _log ( $ query ) ; }
Writes a LoggedQuery into a log
25,445
protected function _interpolate ( $ query ) { $ params = array_map ( function ( $ p ) { if ( $ p === null ) { return 'NULL' ; } if ( is_bool ( $ p ) ) { return $ p ? '1' : '0' ; } if ( is_string ( $ p ) ) { $ replacements = [ '$' => '\\$' , '\\' => '\\\\\\\\' , "'" => "''" , ] ; $ p = strtr ( $ p , $ replacements ) ; r...
Helper function used to replace query placeholders by the real params used to execute the query
25,446
public function templater ( ) { if ( $ this -> _templater === null ) { $ class = $ this -> getConfig ( 'templateClass' ) ? : 'Cake\View\StringTemplate' ; $ this -> _templater = new $ class ( ) ; $ templates = $ this -> getConfig ( 'templates' ) ; if ( $ templates ) { if ( is_string ( $ templates ) ) { $ this -> _templa...
Returns the templater instance .
25,447
public function clear ( $ check ) { if ( $ check ) { return true ; } $ info = wincache_ucache_info ( ) ; $ cacheKeys = $ info [ 'ucache_entries' ] ; unset ( $ info ) ; foreach ( $ cacheKeys as $ key ) { if ( strpos ( $ key [ 'key_name' ] , $ this -> _config [ 'prefix' ] ) === 0 ) { wincache_ucache_delete ( $ key [ 'key...
Delete all keys from the cache . This will clear every item in the cache matching the cache config prefix .
25,448
public function add ( $ data ) { if ( ( count ( $ this -> _values ) && $ data instanceof Query ) || ( $ this -> _query && is_array ( $ data ) ) ) { throw new Exception ( 'You cannot mix subqueries and array data in inserts.' ) ; } if ( $ data instanceof Query ) { $ this -> setQuery ( $ data ) ; return ; } $ this -> _va...
Add a row of data to be inserted .
25,449
public function columns ( $ cols = null ) { deprecationWarning ( 'ValuesExpression::columns() is deprecated. ' . 'Use ValuesExpression::setColumns()/getColumns() instead.' ) ; if ( $ cols !== null ) { return $ this -> setColumns ( $ cols ) ; } return $ this -> getColumns ( ) ; }
Sets the columns to be inserted . If no params are passed then it returns the currently stored columns .
25,450
protected function _columnNames ( ) { $ columns = [ ] ; foreach ( $ this -> _columns as $ col ) { if ( is_string ( $ col ) ) { $ col = trim ( $ col , '`[]"' ) ; } $ columns [ ] = $ col ; } return $ columns ; }
Get the bare column names .
25,451
public function values ( $ values = null ) { deprecationWarning ( 'ValuesExpression::values() is deprecated. ' . 'Use ValuesExpression::setValues()/getValues() instead.' ) ; if ( $ values !== null ) { return $ this -> setValues ( $ values ) ; } return $ this -> getValues ( ) ; }
Sets the values to be inserted . If no params are passed then it returns the currently stored values
25,452
public function query ( Query $ query = null ) { deprecationWarning ( 'ValuesExpression::query() is deprecated. ' . 'Use ValuesExpression::setQuery()/getQuery() instead.' ) ; if ( $ query !== null ) { return $ this -> setQuery ( $ query ) ; } return $ this -> getQuery ( ) ; }
Sets the query object to be used as the values expression to be evaluated to insert records in the table . If no params are passed then it returns the currently stored query
25,453
public function sql ( ValueBinder $ generator ) { if ( empty ( $ this -> _values ) && empty ( $ this -> _query ) ) { return '' ; } if ( ! $ this -> _castedExpressions ) { $ this -> _processExpressions ( ) ; } $ columns = $ this -> _columnNames ( ) ; $ defaults = array_fill_keys ( $ columns , null ) ; $ placeholders = [...
Convert the values into a SQL string with placeholders .
25,454
public function traverse ( callable $ visitor ) { if ( $ this -> _query ) { return ; } if ( ! $ this -> _castedExpressions ) { $ this -> _processExpressions ( ) ; } foreach ( $ this -> _values as $ v ) { if ( $ v instanceof ExpressionInterface ) { $ v -> traverse ( $ visitor ) ; } if ( ! is_array ( $ v ) ) { continue ;...
Traverse the values expression .
25,455
protected function _processExpressions ( ) { $ types = [ ] ; $ typeMap = $ this -> getTypeMap ( ) ; $ columns = $ this -> _columnNames ( ) ; foreach ( $ columns as $ c ) { if ( ! is_scalar ( $ c ) ) { continue ; } $ types [ $ c ] = $ typeMap -> type ( $ c ) ; } $ types = $ this -> _requiresToExpressionCasting ( $ types...
Converts values that need to be casted to expressions
25,456
protected function _options ( $ options , $ class ) { $ options += [ 'from' => $ class :: now ( ) , 'timezone' => null , 'format' => $ class :: $ wordFormat , 'accuracy' => $ class :: $ wordAccuracy , 'end' => $ class :: $ wordEnd , 'relativeString' => __d ( 'cake' , '%s ago' ) , 'absoluteString' => __d ( 'cake' , 'on ...
Build the options for relative date formatting .
25,457
protected function _id ( $ name , $ val ) { $ name = $ this -> _domId ( $ name ) ; $ idSuffix = mb_strtolower ( str_replace ( [ '/' , '@' , '<' , '>' , ' ' , '"' , '\'' ] , '-' , $ val ) ) ; $ count = 1 ; $ check = $ idSuffix ; while ( in_array ( $ check , $ this -> _idSuffixes ) ) { $ check = $ idSuffix . $ count ++ ;...
Generate an ID attribute for an element .
25,458
protected function _domId ( $ value ) { $ domId = mb_strtolower ( Text :: slug ( $ value , '-' ) ) ; if ( $ this -> _idPrefix ) { $ domId = $ this -> _idPrefix . '-' . $ domId ; } return $ domId ; }
Generate an ID suitable for use in an ID attribute .
25,459
public function load ( $ file ) { $ loader = new PhpConfig ( ) ; $ widgets = $ loader -> read ( $ file ) ; $ this -> add ( $ widgets ) ; }
Load a config file containing widgets .
25,460
protected function _resolveWidget ( $ widget ) { $ type = gettype ( $ widget ) ; if ( $ type === 'object' ) { return $ widget ; } if ( $ type === 'string' ) { $ widget = [ $ widget ] ; } $ class = array_shift ( $ widget ) ; $ className = App :: className ( $ class , 'View/Widget' , 'Widget' ) ; if ( $ className === fal...
Resolves a widget spec into an instance .
25,461
protected static function _buildTransport ( $ name ) { if ( ! isset ( static :: $ _config [ $ name ] ) ) { throw new InvalidArgumentException ( sprintf ( 'The "%s" transport configuration does not exist' , $ name ) ) ; } if ( is_array ( static :: $ _config [ $ name ] ) && empty ( static :: $ _config [ $ name ] [ 'class...
Finds and builds the instance of the required tranport class .
25,462
public static function get ( $ name ) { $ registry = static :: getRegistry ( ) ; if ( isset ( $ registry -> { $ name } ) ) { return $ registry -> { $ name } ; } static :: _buildTransport ( $ name ) ; return $ registry -> { $ name } ; }
Get transport instance .
25,463
public function parseAuthData ( $ digest ) { if ( substr ( $ digest , 0 , 7 ) === 'Digest ' ) { $ digest = substr ( $ digest , 7 ) ; } $ keys = $ match = [ ] ; $ req = [ 'nonce' => 1 , 'nc' => 1 , 'cnonce' => 1 , 'qop' => 1 , 'username' => 1 , 'uri' => 1 , 'response' => 1 ] ; preg_match_all ( '/(\w+)=([\'"]?)([a-zA-Z0-...
Parse the digest authentication headers and split them up .
25,464
public function generateResponseHash ( $ digest , $ password , $ method ) { return md5 ( $ password . ':' . $ digest [ 'nonce' ] . ':' . $ digest [ 'nc' ] . ':' . $ digest [ 'cnonce' ] . ':' . $ digest [ 'qop' ] . ':' . md5 ( $ method . ':' . $ digest [ 'uri' ] ) ) ; }
Generate the response hash for a given digest array .
25,465
public function pop ( ) { if ( empty ( $ this -> _configStack ) ) { return ; } list ( $ this -> _config , $ this -> _compiled ) = array_pop ( $ this -> _configStack ) ; }
Restore the most recently pushed set of templates .
25,466
public function add ( array $ templates ) { $ this -> setConfig ( $ templates ) ; $ this -> _compileTemplates ( array_keys ( $ templates ) ) ; return $ this ; }
Registers a list of templates by name
25,467
public function load ( $ file ) { $ loader = new PhpConfig ( ) ; $ templates = $ loader -> read ( $ file ) ; $ this -> add ( $ templates ) ; }
Load a config file containing templates .
25,468
protected function _formatAttribute ( $ key , $ value , $ escape = true ) { if ( is_array ( $ value ) ) { $ value = implode ( ' ' , $ value ) ; } if ( is_numeric ( $ key ) ) { return "$value=\"$value\"" ; } $ truthy = [ 1 , '1' , true , 'true' , $ key ] ; $ isMinimized = isset ( $ this -> _compactAttributes [ $ key ] )...
Formats an individual attribute and returns the string value of the composed attribute . Works with minimized attributes that have the same value as their name such as disabled and checked
25,469
public static function build ( $ input , array $ options = [ ] ) { $ defaults = [ 'return' => 'simplexml' , 'loadEntities' => false , 'readFile' => true , 'parseHuge' => false , ] ; $ options += $ defaults ; if ( is_array ( $ input ) || is_object ( $ input ) ) { return static :: fromArray ( $ input , $ options ) ; } if...
Initialize SimpleXMLElement or DOMDocument from a given XML string file path URL or array .
25,470
protected static function _loadXml ( $ input , $ options ) { $ hasDisable = function_exists ( 'libxml_disable_entity_loader' ) ; $ internalErrors = libxml_use_internal_errors ( true ) ; if ( $ hasDisable && ! $ options [ 'loadEntities' ] ) { libxml_disable_entity_loader ( true ) ; } $ flags = 0 ; if ( ! empty ( $ optio...
Parse the input data and create either a SimpleXmlElement object or a DOMDocument .
25,471
public static function loadHtml ( $ input , $ options = [ ] ) { $ defaults = [ 'return' => 'simplexml' , 'loadEntities' => false , ] ; $ options += $ defaults ; $ hasDisable = function_exists ( 'libxml_disable_entity_loader' ) ; $ internalErrors = libxml_use_internal_errors ( true ) ; if ( $ hasDisable && ! $ options [...
Parse the input html string and create either a SimpleXmlElement object or a DOMDocument .
25,472
public static function fromArray ( $ input , $ options = [ ] ) { if ( is_object ( $ input ) && method_exists ( $ input , 'toArray' ) && is_callable ( [ $ input , 'toArray' ] ) ) { $ input = call_user_func ( [ $ input , 'toArray' ] ) ; } if ( ! is_array ( $ input ) || count ( $ input ) !== 1 ) { throw new XmlException (...
Transform an array into a SimpleXMLElement
25,473
protected static function _fromArray ( $ dom , $ node , & $ data , $ format ) { if ( empty ( $ data ) || ! is_array ( $ data ) ) { return ; } foreach ( $ data as $ key => $ value ) { if ( is_string ( $ key ) ) { if ( is_object ( $ value ) && method_exists ( $ value , 'toArray' ) && is_callable ( [ $ value , 'toArray' ]...
Recursive method to create childs from array
25,474
public static function toArray ( $ obj ) { if ( $ obj instanceof DOMNode ) { $ obj = simplexml_import_dom ( $ obj ) ; } if ( ! ( $ obj instanceof SimpleXMLElement ) ) { throw new XmlException ( 'The input is not instance of SimpleXMLElement, DOMDocument or DOMNode.' ) ; } $ result = [ ] ; $ namespaces = array_merge ( [...
Returns this XML structure as an array .
25,475
protected static function _toArray ( $ xml , & $ parentData , $ ns , $ namespaces ) { $ data = [ ] ; foreach ( $ namespaces as $ namespace ) { foreach ( $ xml -> attributes ( $ namespace , true ) as $ key => $ value ) { if ( ! empty ( $ namespace ) ) { $ key = $ namespace . ':' . $ key ; } $ data [ '@' . $ key ] = ( st...
Recursive method to toArray
25,476
public function printer ( $ valuePath , $ keyPath = null , $ spacer = '__' ) { if ( ! $ keyPath ) { $ counter = 0 ; $ keyPath = function ( ) use ( & $ counter ) { return $ counter ++ ; } ; } return new TreePrinter ( $ this -> getInnerIterator ( ) , $ valuePath , $ keyPath , $ spacer , $ this -> _mode ) ; }
Returns another iterator which will return the values ready to be displayed to a user . It does so by extracting one property from each of the elements and prefixing it with a spacer so that the relative position in the tree can be visualized .
25,477
public function errors ( array $ data , $ newRecord = true ) { $ errors = [ ] ; foreach ( $ this -> _fields as $ name => $ field ) { $ keyPresent = array_key_exists ( $ name , $ data ) ; $ providers = $ this -> _providers ; $ context = compact ( 'data' , 'newRecord' , 'field' , 'providers' ) ; if ( ! $ keyPresent && ! ...
Returns an array of fields that have failed validation . On the current model . This method will actually run validation rules over data not just return the messages .
25,478
public function field ( $ name , ValidationSet $ set = null ) { if ( empty ( $ this -> _fields [ $ name ] ) ) { $ set = $ set ? : new ValidationSet ( ) ; $ this -> _fields [ $ name ] = $ set ; } return $ this -> _fields [ $ name ] ; }
Returns a ValidationSet object containing all validation rules for a field if passed a ValidationSet as second argument it will replace any other rule set defined before
25,479
public function getProvider ( $ name ) { if ( isset ( $ this -> _providers [ $ name ] ) ) { return $ this -> _providers [ $ name ] ; } if ( $ name !== 'default' ) { return null ; } $ this -> _providers [ $ name ] = new RulesProvider ( ) ; return $ this -> _providers [ $ name ] ; }
Returns the provider stored under that name if it exists .
25,480
public static function getDefaultProvider ( $ name ) { if ( ! isset ( self :: $ _defaultProviders [ $ name ] ) ) { return null ; } return self :: $ _defaultProviders [ $ name ] ; }
Returns the default provider stored under that name if it exists .
25,481
public function provider ( $ name , $ object = null ) { deprecationWarning ( 'Validator::provider() is deprecated. ' . 'Use Validator::setProvider()/getProvider() instead.' ) ; if ( $ object !== null ) { return $ this -> setProvider ( $ name , $ object ) ; } return $ this -> getProvider ( $ name ) ; }
Associates an object to a name so it can be used as a provider . Providers are objects or class names that can contain methods used during validation of for deciding whether a validation rule can be applied . All validation methods when called will receive the full list of providers stored in this validator .
25,482
public function offsetSet ( $ field , $ rules ) { if ( ! $ rules instanceof ValidationSet ) { $ set = new ValidationSet ( ) ; foreach ( ( array ) $ rules as $ name => $ rule ) { $ set -> add ( $ name , $ rule ) ; } } $ this -> _fields [ $ field ] = $ rules ; }
Sets the rule set for a field
25,483
public function add ( $ field , $ name , $ rule = [ ] ) { $ validationSet = $ this -> field ( $ field ) ; if ( ! is_array ( $ name ) ) { $ rules = [ $ name => $ rule ] ; } else { $ rules = $ name ; } foreach ( $ rules as $ name => $ rule ) { if ( is_array ( $ rule ) ) { $ rule += [ 'rule' => $ name ] ; } $ validationSe...
Adds a new rule to a field s rule set . If second argument is an array then rules list for the field will be replaced with second argument and third argument will be ignored .
25,484
public function addNested ( $ field , Validator $ validator , $ message = null , $ when = null ) { $ extra = array_filter ( [ 'message' => $ message , 'on' => $ when ] ) ; $ validationSet = $ this -> field ( $ field ) ; $ validationSet -> add ( static :: NESTED , $ extra + [ 'rule' => function ( $ value , $ context ) u...
Adds a nested validator .
25,485
public function remove ( $ field , $ rule = null ) { if ( $ rule === null ) { unset ( $ this -> _fields [ $ field ] ) ; } else { $ this -> field ( $ field ) -> remove ( $ rule ) ; } return $ this ; }
Removes a rule from the set by its name
25,486
public function allowEmptyFor ( $ field , $ flags , $ when = true , $ message = null ) { $ this -> field ( $ field ) -> allowEmpty ( $ when ) ; if ( $ message ) { $ this -> _allowEmptyMessages [ $ field ] = $ message ; } if ( $ flags !== null ) { $ this -> _allowEmptyFlags [ $ field ] = $ flags ; } return $ this ; }
Indicate that a field can be empty .
25,487
public function allowEmptyString ( $ field , $ when = true , $ message = null ) { return $ this -> allowEmptyFor ( $ field , self :: EMPTY_STRING , $ when , $ message ) ; }
Allows a field to be an empty string .
25,488
public function allowEmptyArray ( $ field , $ when = true , $ message = null ) { return $ this -> allowEmptyFor ( $ field , self :: EMPTY_STRING | self :: EMPTY_ARRAY , $ when , $ message ) ; }
Allows a field to be an empty array .
25,489
public function allowEmptyFile ( $ field , $ when = true , $ message = null ) { return $ this -> allowEmptyFor ( $ field , self :: EMPTY_FILE , $ when , $ message ) ; }
Allows a field to be an empty file .
25,490
public function allowEmptyDate ( $ field , $ when = true , $ message = null ) { return $ this -> allowEmptyFor ( $ field , self :: EMPTY_STRING | self :: EMPTY_DATE , $ when , $ message ) ; }
Allows a field to be an empty date .
25,491
public function allowEmptyTime ( $ field , $ when = true , $ message = null ) { return $ this -> allowEmptyFor ( $ field , self :: EMPTY_STRING | self :: EMPTY_TIME , $ when , $ message ) ; }
Allows a field to be an empty time .
25,492
public function lengthBetween ( $ field , array $ range , $ message = null , $ when = null ) { if ( count ( $ range ) !== 2 ) { throw new InvalidArgumentException ( 'The $range argument requires 2 numbers' ) ; } $ extra = array_filter ( [ 'on' => $ when , 'message' => $ message ] ) ; return $ this -> add ( $ field , 'l...
Add an rule that ensures a string length is within a range .
25,493
public function creditCard ( $ field , $ type = 'all' , $ message = null , $ when = null ) { $ extra = array_filter ( [ 'on' => $ when , 'message' => $ message ] ) ; return $ this -> add ( $ field , 'creditCard' , $ extra + [ 'rule' => [ 'creditCard' , $ type , true ] , ] ) ; }
Add a credit card rule to a field .
25,494
public function greaterThan ( $ field , $ value , $ message = null , $ when = null ) { $ extra = array_filter ( [ 'on' => $ when , 'message' => $ message ] ) ; return $ this -> add ( $ field , 'greaterThan' , $ extra + [ 'rule' => [ 'comparison' , Validation :: COMPARE_GREATER , $ value ] ] ) ; }
Add a greater than comparison rule to a field .
25,495
public function greaterThanOrEqual ( $ field , $ value , $ message = null , $ when = null ) { $ extra = array_filter ( [ 'on' => $ when , 'message' => $ message ] ) ; return $ this -> add ( $ field , 'greaterThanOrEqual' , $ extra + [ 'rule' => [ 'comparison' , Validation :: COMPARE_GREATER_OR_EQUAL , $ value ] ] ) ; }
Add a greater than or equal to comparison rule to a field .
25,496
public function lessThan ( $ field , $ value , $ message = null , $ when = null ) { $ extra = array_filter ( [ 'on' => $ when , 'message' => $ message ] ) ; return $ this -> add ( $ field , 'lessThan' , $ extra + [ 'rule' => [ 'comparison' , Validation :: COMPARE_LESS , $ value ] ] ) ; }
Add a less than comparison rule to a field .
25,497
public function lessThanOrEqual ( $ field , $ value , $ message = null , $ when = null ) { $ extra = array_filter ( [ 'on' => $ when , 'message' => $ message ] ) ; return $ this -> add ( $ field , 'lessThanOrEqual' , $ extra + [ 'rule' => [ 'comparison' , Validation :: COMPARE_LESS_OR_EQUAL , $ value ] ] ) ; }
Add a less than or equal comparison rule to a field .
25,498
public function equals ( $ field , $ value , $ message = null , $ when = null ) { $ extra = array_filter ( [ 'on' => $ when , 'message' => $ message ] ) ; return $ this -> add ( $ field , 'equals' , $ extra + [ 'rule' => [ 'comparison' , Validation :: COMPARE_EQUAL , $ value ] ] ) ; }
Add a equal to comparison rule to a field .
25,499
public function notEquals ( $ field , $ value , $ message = null , $ when = null ) { $ extra = array_filter ( [ 'on' => $ when , 'message' => $ message ] ) ; return $ this -> add ( $ field , 'notEquals' , $ extra + [ 'rule' => [ 'comparison' , Validation :: COMPARE_NOT_EQUAL , $ value ] ] ) ; }
Add a not equal to comparison rule to a field .