idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
26,400
public function belongsTo ( $ associated , array $ options = [ ] ) { $ options += [ 'sourceTable' => $ this ] ; $ association = $ this -> _associations -> load ( BelongsTo :: class , $ associated , $ options ) ; return $ association ; }
Creates a new BelongsTo association between this table and a target table . A belongs to association is a N - 1 relationship where this table is the N side and where there is a single associated record in the target table for each one in this table .
26,401
public function hasOne ( $ associated , array $ options = [ ] ) { $ options += [ 'sourceTable' => $ this ] ; $ association = $ this -> _associations -> load ( HasOne :: class , $ associated , $ options ) ; return $ association ; }
Creates a new HasOne association between this table and a target table . A has one association is a 1 - 1 relationship .
26,402
public function hasMany ( $ associated , array $ options = [ ] ) { $ options += [ 'sourceTable' => $ this ] ; $ association = $ this -> _associations -> load ( HasMany :: class , $ associated , $ options ) ; return $ association ; }
Creates a new HasMany association between this table and a target table . A has many association is a 1 - N relationship .
26,403
public function belongsToMany ( $ associated , array $ options = [ ] ) { $ options += [ 'sourceTable' => $ this ] ; $ association = $ this -> _associations -> load ( BelongsToMany :: class , $ associated , $ options ) ; return $ association ; }
Creates a new BelongsToMany association between this table and a target table . A belongs to many association is a M - N relationship .
26,404
public function findThreaded ( Query $ query , array $ options ) { $ options += [ 'keyField' => $ this -> getPrimaryKey ( ) , 'parentField' => 'parent_id' , 'nestingKey' => 'children' ] ; if ( isset ( $ options [ 'idField' ] ) ) { $ options [ 'keyField' ] = $ options [ 'idField' ] ; unset ( $ options [ 'idField' ] ) ; ...
Results for this finder will be a nested array and is appropriate if you want to use the parent_id field of your model data to build nested results .
26,405
protected function _executeTransaction ( callable $ worker , $ atomic = true ) { if ( $ atomic ) { return $ this -> getConnection ( ) -> transactional ( function ( ) use ( $ worker ) { return $ worker ( ) ; } ) ; } return $ worker ( ) ; }
Handles the logic executing of a worker inside a transaction .
26,406
public function saveOrFail ( EntityInterface $ entity , $ options = [ ] ) { $ saved = $ this -> save ( $ entity , $ options ) ; if ( $ saved === false ) { throw new PersistenceFailedException ( $ entity , [ 'save' ] ) ; } return $ saved ; }
Try to save an entity or throw a PersistenceFailedException if the application rules checks failed the entity contains errors or the save was aborted by a callback .
26,407
protected function _processSave ( $ entity , $ options ) { $ primaryColumns = ( array ) $ this -> getPrimaryKey ( ) ; if ( $ options [ 'checkExisting' ] && $ primaryColumns && $ entity -> isNew ( ) && $ entity -> has ( $ primaryColumns ) ) { $ alias = $ this -> getAlias ( ) ; $ conditions = [ ] ; foreach ( $ entity -> ...
Performs the actual saving of an entity based on the passed options .
26,408
protected function _onSaveSuccess ( $ entity , $ options ) { $ success = $ this -> _associations -> saveChildren ( $ this , $ entity , $ options [ 'associated' ] , [ '_primary' => false ] + $ options -> getArrayCopy ( ) ) ; if ( ! $ success && $ options [ 'atomic' ] ) { return false ; } $ this -> dispatchEvent ( 'Model...
Handles the saving of children associations and executing the afterSave logic once the entity for this table has been saved successfully .
26,409
protected function _insert ( $ entity , $ data ) { $ primary = ( array ) $ this -> getPrimaryKey ( ) ; if ( empty ( $ primary ) ) { $ msg = sprintf ( 'Cannot insert row in "%s" table, it has no primary key.' , $ this -> getTable ( ) ) ; throw new RuntimeException ( $ msg ) ; } $ keys = array_fill ( 0 , count ( $ primar...
Auxiliary function to handle the insert of an entity s data in the table
26,410
protected function _newId ( $ primary ) { if ( ! $ primary || count ( ( array ) $ primary ) > 1 ) { return null ; } $ typeName = $ this -> getSchema ( ) -> getColumnType ( $ primary [ 0 ] ) ; $ type = Type :: build ( $ typeName ) ; return $ type -> newId ( ) ; }
Generate a primary key value for a new record .
26,411
protected function _update ( $ entity , $ data ) { $ primaryColumns = ( array ) $ this -> getPrimaryKey ( ) ; $ primaryKey = $ entity -> extract ( $ primaryColumns ) ; $ data = array_diff_key ( $ data , $ primaryKey ) ; if ( empty ( $ data ) ) { return $ entity ; } if ( count ( $ primaryColumns ) === 0 ) { $ entityClas...
Auxiliary function to handle the update of an entity s data in the table
26,412
public function saveMany ( $ entities , $ options = [ ] ) { $ isNew = [ ] ; $ cleanup = function ( $ entities ) use ( & $ isNew ) { foreach ( $ entities as $ key => $ entity ) { if ( isset ( $ isNew [ $ key ] ) && $ isNew [ $ key ] ) { $ entity -> unsetProperty ( $ this -> getPrimaryKey ( ) ) ; $ entity -> isNew ( true...
Persists multiple entities of a table .
26,413
public function deleteOrFail ( EntityInterface $ entity , $ options = [ ] ) { $ deleted = $ this -> delete ( $ entity , $ options ) ; if ( $ deleted === false ) { throw new PersistenceFailedException ( $ entity , [ 'delete' ] ) ; } return $ deleted ; }
Try to delete an entity or throw a PersistenceFailedException if the entity is new has no primary key value application rules checks failed or the delete was aborted by a callback .
26,414
protected function _processDelete ( $ entity , $ options ) { if ( $ entity -> isNew ( ) ) { return false ; } $ primaryKey = ( array ) $ this -> getPrimaryKey ( ) ; if ( ! $ entity -> has ( $ primaryKey ) ) { $ msg = 'Deleting requires all primary key values.' ; throw new InvalidArgumentException ( $ msg ) ; } if ( $ op...
Perform the delete operation .
26,415
public function hasFinder ( $ type ) { $ finder = 'find' . $ type ; return method_exists ( $ this , $ finder ) || ( $ this -> _behaviors && $ this -> _behaviors -> hasFinder ( $ type ) ) ; }
Returns true if the finder exists for the table
26,416
protected function _dynamicFinder ( $ method , $ args ) { $ method = Inflector :: underscore ( $ method ) ; preg_match ( '/^find_([\w]+)_by_/' , $ method , $ matches ) ; if ( empty ( $ matches ) ) { $ fields = substr ( $ method , 8 ) ; $ findType = 'all' ; } else { $ fields = substr ( $ method , strlen ( $ matches [ 0 ...
Provides the dynamic findBy and findByAll methods .
26,417
public function implementedEvents ( ) { $ eventMap = [ 'Model.beforeMarshal' => 'beforeMarshal' , 'Model.buildValidator' => 'buildValidator' , 'Model.beforeFind' => 'beforeFind' , 'Model.beforeSave' => 'beforeSave' , 'Model.afterSave' => 'afterSave' , 'Model.afterSaveCommit' => 'afterSaveCommit' , 'Model.beforeDelete' ...
Get the Model callbacks this table is interested in .
26,418
protected function _buildFieldToken ( $ url , $ fields , $ unlockedFields = [ ] ) { $ locked = [ ] ; foreach ( $ fields as $ key => $ value ) { if ( is_numeric ( $ value ) ) { $ value = ( string ) $ value ; } if ( ! is_int ( $ key ) ) { $ locked [ $ key ] = $ value ; unset ( $ fields [ $ key ] ) ; } } sort ( $ unlocked...
Generate the token data for the provided inputs .
26,419
public static function get ( $ type ) { if ( ! isset ( static :: $ _modelFactories [ 'Table' ] ) ) { static :: $ _modelFactories [ 'Table' ] = [ TableRegistry :: getTableLocator ( ) , 'get' ] ; } if ( ! isset ( static :: $ _modelFactories [ $ type ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown reposito...
Get the factory for the specified repository type .
26,420
public static function hash ( $ string , $ algorithm = null , $ salt = false ) { if ( empty ( $ algorithm ) ) { $ algorithm = static :: $ hashType ; } $ algorithm = strtolower ( $ algorithm ) ; $ availableAlgorithms = hash_algos ( ) ; if ( ! in_array ( $ algorithm , $ availableAlgorithms ) ) { throw new RuntimeExceptio...
Create a hash from string using given method .
26,421
public static function randomBytes ( $ length ) { if ( function_exists ( 'random_bytes' ) ) { return random_bytes ( $ length ) ; } if ( ! function_exists ( 'openssl_random_pseudo_bytes' ) ) { throw new RuntimeException ( 'You do not have a safe source of random data available. ' . 'Install either the openssl extension,...
Get random bytes from a secure source .
26,422
public static function engine ( $ instance = null ) { if ( $ instance === null && static :: $ _instance === null ) { if ( extension_loaded ( 'openssl' ) ) { $ instance = new OpenSsl ( ) ; } elseif ( extension_loaded ( 'mcrypt' ) ) { $ instance = new Mcrypt ( ) ; } } if ( $ instance ) { static :: $ _instance = $ instanc...
Get the crypto implementation based on the loaded extensions .
26,423
public static function constantEquals ( $ original , $ compare ) { if ( ! is_string ( $ original ) || ! is_string ( $ compare ) ) { return false ; } if ( function_exists ( 'hash_equals' ) ) { return hash_equals ( $ original , $ compare ) ; } $ originalLength = mb_strlen ( $ original , '8bit' ) ; $ compareLength = mb_st...
A timing attack resistant comparison that prefers native PHP implementations .
26,424
protected function _foreignKeyAcceptsNull ( Table $ table , array $ properties ) { return ! in_array ( false , array_map ( function ( $ prop ) use ( $ table ) { return $ table -> getSchema ( ) -> isNullable ( $ prop ) ; } , $ properties ) ) ; }
Checks the nullable flag of the foreign key
26,425
public function tableLocator ( LocatorInterface $ tableLocator = null ) { deprecationWarning ( get_called_class ( ) . '::tableLocator() is deprecated. ' . 'Use getTableLocator()/setTableLocator() instead.' ) ; if ( $ tableLocator !== null ) { $ this -> setTableLocator ( $ tableLocator ) ; } return $ this -> getTableLoc...
Sets the table locator . If no parameters are passed it will return the currently used locator .
26,426
public function translate ( $ key , array $ tokensValues = [ ] ) { if ( isset ( $ tokensValues [ '_count' ] ) ) { $ message = $ this -> getMessage ( static :: PLURAL_PREFIX . $ key ) ; if ( ! $ message ) { $ message = $ this -> getMessage ( $ key ) ; } } else { $ message = $ this -> getMessage ( $ key ) ; if ( ! $ mess...
Translates the message formatting any placeholders
26,427
protected function resolveContext ( $ key , $ message , array $ vars ) { $ context = isset ( $ vars [ '_context' ] ) ? $ vars [ '_context' ] : null ; if ( $ context === null ) { if ( isset ( $ message [ '_context' ] [ '' ] ) ) { return $ message [ '_context' ] [ '' ] === '' ? $ key : $ message [ '_context' ] [ '' ] ; }...
Resolve a message s context structure .
26,428
public function routeClass ( $ routeClass = null ) { deprecationWarning ( 'RouteBuilder::routeClass() is deprecated. ' . 'Use RouteBuilder::setRouteClass()/getRouteClass() instead.' ) ; if ( $ routeClass === null ) { return $ this -> getRouteClass ( ) ; } $ this -> setRouteClass ( $ routeClass ) ; }
Get or set default route class .
26,429
public function extensions ( $ extensions = null ) { deprecationWarning ( 'RouteBuilder::extensions() is deprecated. ' . 'Use RouteBuilder::setExtensions()/getExtensions() instead.' ) ; if ( $ extensions === null ) { return $ this -> getExtensions ( ) ; } $ this -> setExtensions ( $ extensions ) ; }
Get or set the extensions in this route builder s scope .
26,430
public function addExtensions ( $ extensions ) { $ extensions = array_merge ( $ this -> _extensions , ( array ) $ extensions ) ; $ this -> _extensions = array_unique ( $ extensions ) ; }
Add additional extensions to what is already in current scope
26,431
public function path ( ) { $ routeKey = strpos ( $ this -> _path , ':' ) ; if ( $ routeKey !== false ) { return substr ( $ this -> _path , 0 , $ routeKey ) ; } return $ this -> _path ; }
Get the path this scope is for .
26,432
public function get ( $ template , $ target , $ name = null ) { return $ this -> _methodRoute ( 'GET' , $ template , $ target , $ name ) ; }
Create a route that only responds to GET requests .
26,433
public function post ( $ template , $ target , $ name = null ) { return $ this -> _methodRoute ( 'POST' , $ template , $ target , $ name ) ; }
Create a route that only responds to POST requests .
26,434
public function put ( $ template , $ target , $ name = null ) { return $ this -> _methodRoute ( 'PUT' , $ template , $ target , $ name ) ; }
Create a route that only responds to PUT requests .
26,435
public function patch ( $ template , $ target , $ name = null ) { return $ this -> _methodRoute ( 'PATCH' , $ template , $ target , $ name ) ; }
Create a route that only responds to PATCH requests .
26,436
public function delete ( $ template , $ target , $ name = null ) { return $ this -> _methodRoute ( 'DELETE' , $ template , $ target , $ name ) ; }
Create a route that only responds to DELETE requests .
26,437
public function head ( $ template , $ target , $ name = null ) { return $ this -> _methodRoute ( 'HEAD' , $ template , $ target , $ name ) ; }
Create a route that only responds to HEAD requests .
26,438
public function options ( $ template , $ target , $ name = null ) { return $ this -> _methodRoute ( 'OPTIONS' , $ template , $ target , $ name ) ; }
Create a route that only responds to OPTIONS requests .
26,439
protected function _methodRoute ( $ method , $ template , $ target , $ name ) { if ( $ name !== null ) { $ name = $ this -> _namePrefix . $ name ; } $ options = [ '_name' => $ name , '_ext' => $ this -> _extensions , '_middleware' => $ this -> middleware , 'routeClass' => $ this -> _routeClass , ] ; $ target = $ this -...
Helper to create routes that only respond to a single HTTP method .
26,440
public function loadPlugin ( $ name , $ file = 'routes.php' ) { $ plugins = Plugin :: getCollection ( ) ; if ( ! $ plugins -> has ( $ name ) ) { throw new MissingPluginException ( [ 'plugin' => $ name ] ) ; } $ plugin = $ plugins -> get ( $ name ) ; if ( $ file !== 'routes.php' ) { deprecationWarning ( 'Loading plugin ...
Load routes from a plugin .
26,441
public function connect ( $ route , $ defaults = [ ] , array $ options = [ ] ) { $ defaults = $ this -> parseDefaults ( $ defaults ) ; if ( empty ( $ options [ '_ext' ] ) ) { $ options [ '_ext' ] = $ this -> _extensions ; } if ( empty ( $ options [ 'routeClass' ] ) ) { $ options [ 'routeClass' ] = $ this -> _routeClass...
Connects a new Route .
26,442
protected static function parseDefaults ( $ defaults ) { if ( ! is_string ( $ defaults ) ) { return $ defaults ; } $ regex = '/(?:(?<plugin>[a-zA-Z0-9\/]*)\.)?(?<prefix>[a-zA-Z0-9\/]*?)' . '(?:\/)?(?<controller>[a-zA-Z0-9]*):{2}(?<action>[a-zA-Z0-9_]*)/i' ; if ( preg_match ( $ regex , $ defaults , $ matches ) ) { forea...
Parse the defaults if they re a string
26,443
protected function _makeRoute ( $ route , $ defaults , $ options ) { if ( is_string ( $ route ) ) { $ routeClass = App :: className ( $ options [ 'routeClass' ] , 'Routing/Route' ) ; if ( $ routeClass === false ) { throw new InvalidArgumentException ( sprintf ( 'Cannot find route class %s' , $ options [ 'routeClass' ] ...
Create a route object or return the provided object .
26,444
public function prefix ( $ name , $ params = [ ] , callable $ callback = null ) { if ( $ callback === null ) { if ( ! is_callable ( $ params ) ) { throw new InvalidArgumentException ( 'A valid callback is expected' ) ; } $ callback = $ params ; $ params = [ ] ; } $ name = Inflector :: underscore ( $ name ) ; $ path = '...
Add prefixed routes .
26,445
public function scope ( $ path , $ params , $ callback = null ) { if ( is_callable ( $ params ) ) { $ callback = $ params ; $ params = [ ] ; } if ( ! is_callable ( $ callback ) ) { $ msg = 'Need a callable function/object to connect routes.' ; throw new InvalidArgumentException ( $ msg ) ; } if ( $ this -> _path !== '/...
Create a new routing scope .
26,446
public function applyMiddleware ( ... $ names ) { foreach ( $ names as $ name ) { if ( ! $ this -> _collection -> middlewareExists ( $ name ) ) { $ message = "Cannot apply '$name' middleware or middleware group. " . 'Use registerMiddleware() to register middleware.' ; throw new RuntimeException ( $ message ) ; } } $ th...
Apply a middleware to the current route scope .
26,447
public function defaultFormatter ( $ name = null ) { if ( $ name === null ) { return $ this -> _defaultFormatter ; } return $ this -> _defaultFormatter = $ name ; }
Sets the name of the default messages formatter to use for future translator instances .
26,448
protected function _getFromLoader ( $ name , $ locale ) { $ loader = $ this -> _loaders [ $ name ] ( $ name , $ locale ) ; $ package = $ loader ; if ( ! is_callable ( $ loader ) ) { $ loader = function ( ) use ( $ package ) { return $ package ; } ; } $ loader = $ this -> setLoaderFallback ( $ name , $ loader ) ; $ this...
Registers a new package by passing the register loaded function for the package name .
26,449
public function setLoaderFallback ( $ name , callable $ loader ) { $ fallbackDomain = 'default' ; if ( ! $ this -> _useFallback || $ name === $ fallbackDomain ) { return $ loader ; } $ loader = function ( ) use ( $ loader , $ fallbackDomain ) { $ package = $ loader ( ) ; if ( ! $ package -> getFallback ( ) ) { $ packag...
Set domain fallback for loader .
26,450
public static function uuid ( ) { $ random = function_exists ( 'random_int' ) ? 'random_int' : 'mt_rand' ; return sprintf ( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' , $ random ( 0 , 65535 ) , $ random ( 0 , 65535 ) , $ random ( 0 , 65535 ) , $ random ( 0 , 4095 ) | 0x4000 , $ random ( 0 , 0x3fff ) | 0x8000 , $ random ( 0...
Generate a random UUID version 4
26,451
public static function wrapBlock ( $ text , $ options = [ ] ) { if ( is_numeric ( $ options ) ) { $ options = [ 'width' => $ options ] ; } $ options += [ 'width' => 72 , 'wordWrap' => true , 'indent' => null , 'indentAt' => 0 ] ; if ( ! empty ( $ options [ 'indentAt' ] ) && $ options [ 'indentAt' ] === 0 ) { $ indentLe...
Wraps a complete block of text to a specific width can optionally wrap at word breaks .
26,452
public static function wordWrap ( $ text , $ width = 72 , $ break = "\n" , $ cut = false ) { $ paragraphs = explode ( $ break , $ text ) ; foreach ( $ paragraphs as & $ paragraph ) { $ paragraph = static :: _wordWrap ( $ paragraph , $ width , $ break , $ cut ) ; } return implode ( $ break , $ paragraphs ) ; }
Unicode and newline aware version of wordwrap .
26,453
protected static function _strlen ( $ text , array $ options ) { if ( empty ( $ options [ 'trimWidth' ] ) ) { $ strlen = 'mb_strlen' ; } else { $ strlen = 'mb_strwidth' ; } if ( empty ( $ options [ 'html' ] ) ) { return $ strlen ( $ text ) ; } $ pattern = '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i' ; $ replace...
Get string length .
26,454
protected static function _substr ( $ text , $ start , $ length , array $ options ) { if ( empty ( $ options [ 'trimWidth' ] ) ) { $ substr = 'mb_substr' ; } else { $ substr = 'mb_strimwidth' ; } $ maxPosition = self :: _strlen ( $ text , [ 'trimWidth' => false ] + $ options ) ; if ( $ start < 0 ) { $ start += $ maxPos...
Return part of a string .
26,455
protected static function _removeLastWord ( $ text ) { $ spacepos = mb_strrpos ( $ text , ' ' ) ; if ( $ spacepos !== false ) { $ lastWord = mb_strrpos ( $ text , $ spacepos ) ; if ( mb_strwidth ( $ lastWord ) === mb_strlen ( $ lastWord ) ) { $ text = mb_substr ( $ text , 0 , $ spacepos ) ; } return $ text ; } return '...
Removes the last word from the input text .
26,456
public static function toList ( array $ list , $ and = null , $ separator = ', ' ) { if ( $ and === null ) { $ and = __d ( 'cake' , 'and' ) ; } if ( count ( $ list ) > 1 ) { return implode ( $ separator , array_slice ( $ list , null , - 1 ) ) . ' ' . $ and . ' ' . array_pop ( $ list ) ; } return array_pop ( $ list ) ; ...
Creates a comma separated list where the last two items are joined with and forming natural language .
26,457
public static function isMultibyte ( $ string ) { $ length = strlen ( $ string ) ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ value = ord ( $ string [ $ i ] ) ; if ( $ value > 128 ) { return true ; } } return false ; }
Check if the string contain multibyte characters
26,458
public static function transliterate ( $ string , $ transliterator = null ) { if ( ! $ transliterator ) { $ transliterator = static :: $ _defaultTransliterator ? : static :: $ _defaultTransliteratorId ; } return transliterator_transliterate ( $ transliterator , $ string ) ; }
Transliterate string .
26,459
public function check ( $ url ) { try { $ request = new ServerRequest ( [ 'url' => $ url ] ) ; $ route = Router :: parseRequest ( $ request ) ; $ name = null ; foreach ( Router :: routes ( ) as $ r ) { if ( $ r -> match ( $ route ) ) { $ name = isset ( $ r -> options [ '_name' ] ) ? $ r -> options [ '_name' ] : $ r -> ...
Checks a url for the route that will be applied .
26,460
public function generate ( ) { try { $ args = $ this -> _splitArgs ( $ this -> args ) ; $ url = Router :: url ( $ args ) ; $ this -> out ( "> $url" ) ; $ this -> out ( ) ; } catch ( MissingRouteException $ e ) { $ this -> err ( '<warning>The provided parameters do not match any routes.</warning>' ) ; $ this -> out ( ) ...
Generate a URL based on a set of parameters
26,461
protected function _splitArgs ( $ args ) { $ out = [ ] ; foreach ( $ args as $ arg ) { if ( strpos ( $ arg , ':' ) !== false ) { list ( $ key , $ value ) = explode ( ':' , $ arg ) ; if ( in_array ( $ value , [ 'true' , 'false' ] ) ) { $ value = $ value === 'true' ; } $ out [ $ key ] = $ value ; } else { $ out [ ] = $ a...
Split the CLI arguments into a hash .
26,462
public static function build ( $ name ) { if ( isset ( static :: $ _builtTypes [ $ name ] ) ) { return static :: $ _builtTypes [ $ name ] ; } if ( ! isset ( static :: $ _types [ $ name ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Unknown type "%s"' , $ name ) ) ; } if ( is_string ( static :: $ _types [ $ nam...
Returns a Type object capable of converting a type identified by name .
26,463
public static function buildAll ( ) { $ result = [ ] ; foreach ( static :: $ _types as $ name => $ type ) { $ result [ $ name ] = isset ( static :: $ _builtTypes [ $ name ] ) ? static :: $ _builtTypes [ $ name ] : static :: build ( $ name ) ; } return $ result ; }
Returns an arrays with all the mapped type objects indexed by name .
26,464
protected function _basicTypeCast ( $ value ) { deprecationWarning ( 'Using Type::_basicTypeCast() is deprecated. ' . "The '{$this->_name}' type needs to be updated to implement `TypeInterface`." ) ; if ( $ value === null ) { return null ; } if ( ! empty ( static :: $ _basicTypes [ $ this -> _name ] ) ) { $ typeInfo = ...
Checks whether this type is a basic one and can be converted using a callback If it is returns converted value
26,465
public static function boolval ( $ value ) { deprecationWarning ( 'Type::boolval() is deprecated.' ) ; if ( is_string ( $ value ) && ! is_numeric ( $ value ) ) { return strtolower ( $ value ) === 'true' ; } return ! empty ( $ value ) ; }
Type converter for boolean values .
26,466
public function toDatabase ( $ value , Driver $ driver ) { if ( $ value === null || is_string ( $ value ) ) { return $ value ; } if ( is_int ( $ value ) ) { $ class = $ this -> _className ; $ value = new $ class ( '@' . $ value ) ; } $ format = ( array ) $ this -> _format ; if ( $ this -> dbTimezone !== null && $ this ...
Convert DateTime instance into strings .
26,467
public function setTimezone ( $ timezone ) { if ( is_string ( $ timezone ) ) { $ timezone = new DateTimeZone ( $ timezone ) ; } $ this -> dbTimezone = $ timezone ; return $ this ; }
Set database timezone .
26,468
public function toPHP ( $ value , Driver $ driver ) { if ( $ value === null || strpos ( $ value , '0000-00-00' ) === 0 ) { return null ; } $ instance = clone $ this -> _datetimeInstance ; $ instance = $ instance -> modify ( $ value ) ; if ( $ this -> setToDateStart ) { $ instance = $ instance -> setTime ( 0 , 0 , 0 ) ;...
Convert strings into DateTime instances .
26,469
protected function _setClassName ( $ class , $ fallback ) { if ( ! class_exists ( $ class ) ) { $ class = $ fallback ; } $ this -> _className = $ class ; $ this -> _datetimeInstance = new $ this -> _className ; }
Set the classname to use when building objects .
26,470
public function build ( ) { $ response = $ this -> _response ; if ( empty ( $ this -> _origin ) ) { return $ response ; } if ( isset ( $ this -> _headers [ 'Access-Control-Allow-Origin' ] ) ) { foreach ( $ this -> _headers as $ key => $ value ) { $ response = $ response -> withHeader ( $ key , $ value ) ; } } return $ ...
Apply the queued headers to the response .
26,471
public function allowOrigin ( $ domain ) { $ allowed = $ this -> _normalizeDomains ( ( array ) $ domain ) ; foreach ( $ allowed as $ domain ) { if ( ! preg_match ( $ domain [ 'preg' ] , $ this -> _origin ) ) { continue ; } $ value = $ domain [ 'original' ] === '*' ? '*' : $ this -> _origin ; $ this -> _headers [ 'Acces...
Set the list of allowed domains .
26,472
protected function _normalizeDomains ( $ domains ) { $ result = [ ] ; foreach ( $ domains as $ domain ) { if ( $ domain === '*' ) { $ result [ ] = [ 'preg' => '@.@' , 'original' => '*' ] ; continue ; } $ original = $ preg = $ domain ; if ( strpos ( $ domain , '://' ) === false ) { $ preg = ( $ this -> _isSsl ? 'https:/...
Normalize the origin to regular expressions and put in an array format
26,473
public function components ( $ components = null ) { if ( $ components === null && $ this -> _components === null ) { $ this -> _components = new ComponentRegistry ( $ this ) ; } if ( $ components !== null ) { $ components -> setController ( $ this ) ; $ this -> _components = $ components ; } return $ this -> _componen...
Get the component registry for this controller .
26,474
public function loadComponent ( $ name , array $ config = [ ] ) { list ( , $ prop ) = pluginSplit ( $ name ) ; return $ this -> { $ prop } = $ this -> components ( ) -> load ( $ name , $ config ) ; }
Add a component to the controller s registry .
26,475
protected function _loadComponents ( ) { if ( empty ( $ this -> components ) ) { return ; } $ registry = $ this -> components ( ) ; $ components = $ registry -> normalizeArray ( $ this -> components ) ; foreach ( $ components as $ properties ) { $ this -> loadComponent ( $ properties [ 'class' ] , $ properties [ 'confi...
Loads the defined components using the Component factory .
26,476
public function startupProcess ( ) { $ event = $ this -> dispatchEvent ( 'Controller.initialize' ) ; if ( $ event -> getResult ( ) instanceof Response ) { return $ event -> getResult ( ) ; } $ event = $ this -> dispatchEvent ( 'Controller.startup' ) ; if ( $ event -> getResult ( ) instanceof Response ) { return $ event...
Perform the startup process for this controller . Fire the Components and Controller callbacks in the correct order .
26,477
public function shutdownProcess ( ) { $ event = $ this -> dispatchEvent ( 'Controller.shutdown' ) ; if ( $ event -> getResult ( ) instanceof Response ) { return $ event -> getResult ( ) ; } return null ; }
Perform the various shutdown processes for this controller . Fire the Components and Controller callbacks in the correct order .
26,478
public function render ( $ view = null , $ layout = null ) { $ builder = $ this -> viewBuilder ( ) ; if ( ! $ builder -> getTemplatePath ( ) ) { $ builder -> setTemplatePath ( $ this -> _viewPath ( ) ) ; } if ( $ this -> request -> getParam ( 'bare' ) ) { $ builder -> disableAutoLayout ( ) ; } $ this -> autoRender = fa...
Instantiates the correct view class hands it its data and uses it to render the view output .
26,479
protected function _viewPath ( ) { $ viewPath = $ this -> name ; if ( $ this -> request -> getParam ( 'prefix' ) ) { $ prefixes = array_map ( 'Cake\Utility\Inflector::camelize' , explode ( '/' , $ this -> request -> getParam ( 'prefix' ) ) ) ; $ viewPath = implode ( DIRECTORY_SEPARATOR , $ prefixes ) . DIRECTORY_SEPARA...
Get the viewPath based on controller name and request prefix .
26,480
public function paginate ( $ object = null , array $ settings = [ ] ) { if ( is_object ( $ object ) ) { $ table = $ object ; } if ( is_string ( $ object ) || $ object === null ) { $ try = [ $ object , $ this -> modelClass ] ; foreach ( $ try as $ tableName ) { if ( empty ( $ tableName ) ) { continue ; } $ table = $ thi...
Handles pagination of records in Table objects .
26,481
protected function _validateTasks ( ) { foreach ( $ this -> _taskMap as $ taskName => $ task ) { $ class = App :: className ( $ task [ 'class' ] , 'Shell/Task' , 'Task' ) ; if ( ! class_exists ( $ class ) ) { throw new RuntimeException ( sprintf ( 'Task `%s` not found. Maybe you made a typo or a plugin is missing or no...
Checks that the tasks in the task map are actually available
26,482
public function runCommand ( $ argv , $ autoMethod = false , $ extra = [ ] ) { $ command = isset ( $ argv [ 0 ] ) ? Inflector :: underscore ( $ argv [ 0 ] ) : null ; $ this -> OptionParser = $ this -> getOptionParser ( ) ; try { list ( $ this -> params , $ this -> args ) = $ this -> OptionParser -> parse ( $ argv ) ; }...
Runs the Shell with the provided argv .
26,483
protected function _setOutputLevel ( ) { $ this -> _io -> setLoggers ( ConsoleIo :: NORMAL ) ; if ( ! empty ( $ this -> params [ 'quiet' ] ) ) { $ this -> _io -> level ( ConsoleIo :: QUIET ) ; $ this -> _io -> setLoggers ( ConsoleIo :: QUIET ) ; } if ( ! empty ( $ this -> params [ 'verbose' ] ) ) { $ this -> _io -> lev...
Set the output level based on the parameters .
26,484
protected function _displayHelp ( $ command ) { $ format = 'text' ; if ( ! empty ( $ this -> args [ 0 ] ) && $ this -> args [ 0 ] === 'xml' ) { $ format = 'xml' ; $ this -> _io -> setOutputAs ( ConsoleOutput :: RAW ) ; } else { $ this -> _welcome ( ) ; } $ subcommands = $ this -> OptionParser -> subcommands ( ) ; $ com...
Display the help in the correct format
26,485
public function shortPath ( $ file ) { $ shortPath = str_replace ( ROOT , null , $ file ) ; $ shortPath = str_replace ( '..' . DIRECTORY_SEPARATOR , '' , $ shortPath ) ; $ shortPath = str_replace ( DIRECTORY_SEPARATOR , '/' , $ shortPath ) ; return str_replace ( '//' , DIRECTORY_SEPARATOR , $ shortPath ) ; }
Makes absolute file path easier to read
26,486
protected function isNotModified ( $ request , $ file ) { $ modifiedSince = $ request -> getHeaderLine ( 'If-Modified-Since' ) ; if ( ! $ modifiedSince ) { return false ; } return strtotime ( $ modifiedSince ) === $ file -> lastChange ( ) ; }
Check the not modified header .
26,487
protected function getType ( $ file ) { $ extension = $ file -> ext ( ) ; if ( isset ( $ this -> typeMap [ $ extension ] ) ) { return $ this -> typeMap [ $ extension ] ; } return $ file -> mime ( ) ? : 'application/octet-stream' ; }
Return the type from a File object
26,488
public function addFields ( array $ fields ) { foreach ( $ fields as $ name => $ attrs ) { $ this -> addField ( $ name , $ attrs ) ; } return $ this ; }
Add multiple fields to the schema .
26,489
public function addField ( $ name , $ attrs ) { if ( is_string ( $ attrs ) ) { $ attrs = [ 'type' => $ attrs ] ; } $ attrs = array_intersect_key ( $ attrs , $ this -> _fieldDefaults ) ; $ this -> _fields [ $ name ] = $ attrs + $ this -> _fieldDefaults ; return $ this ; }
Adds a field to the schema .
26,490
public function field ( $ name ) { if ( ! isset ( $ this -> _fields [ $ name ] ) ) { return null ; } return $ this -> _fields [ $ name ] ; }
Get the attributes for a given field .
26,491
public function replyTo ( $ email = null , $ name = null ) { deprecationWarning ( 'Email::replyTo() is deprecated. Use Email::setReplyTo() or Email::getReplyTo() instead.' ) ; if ( $ email === null ) { return $ this -> getReplyTo ( ) ; } return $ this -> setReplyTo ( $ email , $ name ) ; }
Reply - To
26,492
public function setCharset ( $ charset ) { $ this -> charset = $ charset ; if ( ! $ this -> headerCharset ) { $ this -> headerCharset = $ charset ; } return $ this ; }
Charset setter .
26,493
public function setTransferEncoding ( $ encoding ) { $ encoding = strtolower ( $ encoding ) ; if ( ! in_array ( $ encoding , $ this -> _transferEncodingAvailable ) ) { throw new InvalidArgumentException ( sprintf ( 'Transfer encoding not available. Can be : %s.' , implode ( ', ' , $ this -> _transferEncodingAvailable )...
TransferEncoding setter .
26,494
protected function _validateEmail ( $ email , $ context ) { if ( $ this -> _emailPattern === null ) { if ( filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ) { return ; } } elseif ( preg_match ( $ this -> _emailPattern , $ email ) ) { return ; } $ context = ltrim ( $ context , '_' ) ; if ( $ email == '' ) { throw new Inv...
Validate email address
26,495
protected function _setEmailSingle ( $ varName , $ email , $ name , $ throwMessage ) { if ( $ email === [ ] ) { $ this -> { $ varName } = $ email ; return $ this ; } $ current = $ this -> { $ varName } ; $ this -> _setEmail ( $ varName , $ email , $ name ) ; if ( count ( $ this -> { $ varName } ) !== 1 ) { $ this -> { ...
Set only 1 email
26,496
public function setEmailFormat ( $ format ) { if ( ! in_array ( $ format , $ this -> _emailFormatAvailable ) ) { throw new InvalidArgumentException ( 'Format not available.' ) ; } $ this -> _emailFormat = $ format ; return $ this ; }
Sets email format .
26,497
public function setTransport ( $ name ) { if ( is_string ( $ name ) ) { $ transport = TransportFactory :: get ( $ name ) ; } elseif ( is_object ( $ name ) ) { $ transport = $ name ; } else { throw new InvalidArgumentException ( sprintf ( 'The value passed for the "$name" argument must be either a string, or an object, ...
Sets the transport .
26,498
public function setMessageId ( $ message ) { if ( is_bool ( $ message ) ) { $ this -> _messageId = $ message ; } else { if ( ! preg_match ( '/^\<.+@.+\>$/' , $ message ) ) { throw new InvalidArgumentException ( 'Invalid format to Message-ID. The text should be something like "<uuid@server.com>"' ) ; } $ this -> _messag...
Sets message ID .
26,499
public function messageId ( $ message = null ) { deprecationWarning ( 'Email::messageId() is deprecated. Use Email::setMessageId() or Email::getMessageId() instead.' ) ; if ( $ message === null ) { return $ this -> getMessageId ( ) ; } return $ this -> setMessageId ( $ message ) ; }
Message - ID