idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
25,800
public function setEpilog ( $ text ) { if ( is_array ( $ text ) ) { $ text = implode ( "\n" , $ text ) ; } $ this -> _epilog = $ text ; return $ this ; }
Sets an epilog to the parser . The epilog is added to the end of the options and arguments listing when help is generated .
25,801
public function epilog ( $ text = null ) { deprecationWarning ( 'ConsoleOptionParser::epliog() is deprecated. ' . 'Use ConsoleOptionParser::setEpilog()/getEpilog() instead.' ) ; if ( $ text !== null ) { return $ this -> setEpilog ( $ text ) ; } return $ this -> getEpilog ( ) ; }
Gets or sets an epilog to the parser . The epilog is added to the end of the options and arguments listing when help is generated .
25,802
public function addOption ( $ name , array $ options = [ ] ) { if ( $ name instanceof ConsoleInputOption ) { $ option = $ name ; $ name = $ option -> name ( ) ; } else { $ defaults = [ 'name' => $ name , 'short' => null , 'help' => '' , 'default' => null , 'boolean' => false , 'choices' => [ ] ] ; $ options += $ defaul...
Add an option to the option parser . Options allow you to define optional or required parameters for your console application . Options are defined by the parameters they use .
25,803
public function addArgument ( $ name , array $ params = [ ] ) { if ( $ name instanceof ConsoleInputArgument ) { $ arg = $ name ; $ index = count ( $ this -> _args ) ; } else { $ defaults = [ 'name' => $ name , 'help' => '' , 'index' => count ( $ this -> _args ) , 'required' => false , 'choices' => [ ] ] ; $ options = $...
Add a positional argument to the option parser .
25,804
public function addArguments ( array $ args ) { foreach ( $ args as $ name => $ params ) { if ( $ params instanceof ConsoleInputArgument ) { $ name = $ params ; $ params = [ ] ; } $ this -> addArgument ( $ name , $ params ) ; } return $ this ; }
Add multiple arguments at once . Take an array of argument definitions . The keys are used as the argument names and the values as params for the argument .
25,805
public function addOptions ( array $ options ) { foreach ( $ options as $ name => $ params ) { if ( $ params instanceof ConsoleInputOption ) { $ name = $ params ; $ params = [ ] ; } $ this -> addOption ( $ name , $ params ) ; } return $ this ; }
Add multiple options at once . Takes an array of option definitions . The keys are used as option names and the values as params for the option .
25,806
public function addSubcommand ( $ name , array $ options = [ ] ) { if ( $ name instanceof ConsoleInputSubcommand ) { $ command = $ name ; $ name = $ command -> name ( ) ; } else { $ name = Inflector :: underscore ( $ name ) ; $ defaults = [ 'name' => $ name , 'help' => '' , 'parser' => null ] ; $ options += $ defaults ...
Append a subcommand to the subcommand list . Subcommands are usually methods on your Shell but can also be used to document Tasks .
25,807
public function addSubcommands ( array $ commands ) { foreach ( $ commands as $ name => $ params ) { if ( $ params instanceof ConsoleInputSubcommand ) { $ name = $ params ; $ params = [ ] ; } $ this -> addSubcommand ( $ name , $ params ) ; } return $ this ; }
Add multiple subcommands at once .
25,808
public function argumentNames ( ) { $ out = [ ] ; foreach ( $ this -> _args as $ arg ) { $ out [ ] = $ arg -> name ( ) ; } return $ out ; }
Get the list of argument names .
25,809
public function help ( $ subcommand = null , $ format = 'text' , $ width = 72 ) { if ( $ subcommand === null ) { $ formatter = new HelpFormatter ( $ this ) ; $ formatter -> setAlias ( $ this -> rootName ) ; if ( $ format === 'text' ) { return $ formatter -> text ( $ width ) ; } if ( $ format === 'xml' ) { return ( stri...
Gets formatted help for this parser object .
25,810
protected function getCommandError ( $ command ) { $ rootCommand = $ this -> getCommand ( ) ; $ subcommands = array_keys ( ( array ) $ this -> subcommands ( ) ) ; $ bestGuess = $ this -> findClosestItem ( $ command , $ subcommands ) ; $ out = [ sprintf ( 'Unable to find the `%s %s` subcommand. See `bin/%s %s --help`.' ...
Get the message output in the console stating that the command can not be found and tries to guess what the user wanted to say . Output a list of available subcommands as well .
25,811
protected function getOptionError ( $ option ) { $ availableOptions = array_keys ( $ this -> _options ) ; $ bestGuess = $ this -> findClosestItem ( $ option , $ availableOptions ) ; $ out = [ sprintf ( 'Unknown option `%s`.' , $ option ) , '' ] ; if ( $ bestGuess !== null ) { $ out [ ] = sprintf ( 'Did you mean `%s` ?'...
Get the message output in the console stating that the option can not be found and tries to guess what the user wanted to say . Output a list of available options as well .
25,812
protected function getShortOptionError ( $ option ) { $ out = [ sprintf ( 'Unknown short option `%s`' , $ option ) ] ; $ out [ ] = '' ; $ out [ ] = 'Available short options are :' ; $ out [ ] = '' ; foreach ( $ this -> _shortOptions as $ short => $ long ) { $ out [ ] = sprintf ( ' - `%s` (short for `--%s`)' , $ short ,...
Get the message output in the console stating that the short option can not be found . Output a list of available short options and what option they refer to as well .
25,813
protected function findClosestItem ( $ needle , $ haystack ) { $ bestGuess = null ; foreach ( $ haystack as $ item ) { if ( preg_match ( '/^' . $ needle . '/' , $ item ) ) { return $ item ; } } foreach ( $ haystack as $ item ) { if ( preg_match ( '/' . $ needle . '/' , $ item ) ) { return $ item ; } $ score = levenshte...
Tries to guess the item name the user originally wanted using the some regex pattern and the levenshtein algorithm .
25,814
protected function _parseOption ( $ name , $ params ) { if ( ! isset ( $ this -> _options [ $ name ] ) ) { throw new ConsoleException ( $ this -> getOptionError ( $ name ) ) ; } $ option = $ this -> _options [ $ name ] ; $ isBoolean = $ option -> isBoolean ( ) ; $ nextValue = $ this -> _nextToken ( ) ; $ emptyNextValue...
Parse an option by its name index .
25,815
protected function _parseArg ( $ argument , $ args ) { if ( empty ( $ this -> _args ) ) { $ args [ ] = $ argument ; return $ args ; } $ next = count ( $ args ) ; if ( ! isset ( $ this -> _args [ $ next ] ) ) { throw new ConsoleException ( 'Too many arguments.' ) ; } if ( $ this -> _args [ $ next ] -> validChoice ( $ ar...
Parse an argument and ensure that the argument doesn t exceed the number of arguments and that the argument is a valid choice .
25,816
public function cacheMetadata ( $ enable = null ) { deprecationWarning ( 'CachedCollection::cacheMetadata() is deprecated. ' . 'Use CachedCollection::setCacheMetadata()/getCacheMetadata() instead.' ) ; if ( $ enable !== null ) { $ this -> setCacheMetadata ( $ enable ) ; } return $ this -> getCacheMetadata ( ) ; }
Sets the cache config name to use for caching table metadata or disables it if false is passed . If called with no arguments it returns the current configuration name .
25,817
protected function _getController ( ) { $ request = $ this -> request ; $ routerRequest = Router :: getRequest ( true ) ; if ( $ request === null ) { $ request = $ routerRequest ? : ServerRequestFactory :: fromGlobals ( ) ; } if ( $ request -> getParam ( 'controller' ) === false && $ routerRequest !== null ) { $ reques...
Get the controller instance to handle the exception . Override this method in subclasses to customize the controller used . This method returns the built in ErrorController normally or if an error is repeated a bare controller will be used .
25,818
public function render ( ) { $ exception = $ this -> error ; $ code = $ this -> _code ( $ exception ) ; $ method = $ this -> _method ( $ exception ) ; $ template = $ this -> _template ( $ exception , $ method , $ code ) ; $ unwrapped = $ this -> _unwrap ( $ exception ) ; if ( method_exists ( $ this , $ method ) ) { ret...
Renders the response for the exception .
25,819
protected function _method ( Exception $ exception ) { $ exception = $ this -> _unwrap ( $ exception ) ; list ( , $ baseClass ) = namespaceSplit ( get_class ( $ exception ) ) ; if ( substr ( $ baseClass , - 9 ) === 'Exception' ) { $ baseClass = substr ( $ baseClass , 0 , - 9 ) ; } $ method = Inflector :: variable ( $ b...
Get method name
25,820
protected function _template ( Exception $ exception , $ method , $ code ) { $ exception = $ this -> _unwrap ( $ exception ) ; $ isHttpException = $ exception instanceof HttpException ; if ( ! Configure :: read ( 'debug' ) && ! $ isHttpException || $ isHttpException ) { $ template = 'error500' ; if ( $ code < 500 ) { $...
Get template for rendering exception info .
25,821
protected function _code ( Exception $ exception ) { $ code = 500 ; $ exception = $ this -> _unwrap ( $ exception ) ; $ errorCode = $ exception -> getCode ( ) ; if ( $ errorCode >= 400 && $ errorCode < 600 ) { $ code = $ errorCode ; } return $ code ; }
Get HTTP status code .
25,822
protected function _outputMessageSafe ( $ template ) { $ helpers = [ 'Form' , 'Html' ] ; $ this -> controller -> helpers = $ helpers ; $ builder = $ this -> controller -> viewBuilder ( ) ; $ builder -> setHelpers ( $ helpers , false ) -> setLayoutPath ( '' ) -> setTemplatePath ( 'Error' ) ; $ view = $ this -> controlle...
A safer way to render error messages replaces all helpers with basics and doesn t call component methods .
25,823
protected function _shutdown ( ) { $ this -> controller -> dispatchEvent ( 'Controller.shutdown' ) ; $ dispatcher = DispatcherFactory :: create ( ) ; $ eventManager = $ dispatcher -> getEventManager ( ) ; foreach ( $ dispatcher -> filters ( ) as $ filter ) { $ eventManager -> on ( $ filter ) ; } $ args = [ 'request' =>...
Run the shutdown events .
25,824
protected function _resolveClassName ( $ class ) { if ( is_object ( $ class ) ) { return $ class ; } $ className = App :: className ( $ class , 'Mailer/Transport' , 'Transport' ) ; if ( ! $ className ) { $ className = App :: className ( $ class , 'Network/Email' , 'Transport' ) ; if ( $ className ) { deprecationWarning...
Resolve a mailer tranport classname .
25,825
protected function _create ( $ class , $ alias , $ config ) { $ instance = null ; if ( is_object ( $ class ) ) { $ instance = $ class ; } if ( ! $ instance ) { $ instance = new $ class ( $ config ) ; } if ( $ instance instanceof AbstractTransport ) { return $ instance ; } throw new RuntimeException ( 'Mailer transports...
Create the mailer transport instance .
25,826
protected function _fieldsAreNull ( $ entity , $ source ) { $ nulls = 0 ; $ schema = $ source -> getSchema ( ) ; foreach ( $ this -> _fields as $ field ) { if ( $ schema -> getColumn ( $ field ) && $ schema -> isNullable ( $ field ) && $ entity -> get ( $ field ) === null ) { $ nulls ++ ; } } return $ nulls === count (...
Checks whether or not the given entity fields are nullable and null .
25,827
protected function _confirm ( $ message , $ okCode , $ cancelCode = '' , $ options = [ ] ) { $ message = $ this -> _cleanConfirmMessage ( $ message ) ; $ confirm = "if (confirm({$message})) { {$okCode} } {$cancelCode}" ; $ escape = isset ( $ options [ 'escape' ] ) && $ options [ 'escape' ] === false ; if ( $ escape ) {...
Returns a string to be used as onclick handler for confirm dialogs .
25,828
public function build ( $ name = null ) { $ tables = [ $ name ] ; if ( empty ( $ name ) ) { $ tables = $ this -> _schema -> listTables ( ) ; } foreach ( $ tables as $ table ) { $ this -> _schema -> describe ( $ table , [ 'forceRefresh' => true ] ) ; } return $ tables ; }
Build metadata .
25,829
public function getSchema ( Connection $ connection ) { if ( ! method_exists ( $ connection , 'schemaCollection' ) ) { throw new RuntimeException ( 'The given connection object is not compatible with schema caching, as it does not implement a "schemaCollection()" method.' ) ; } $ config = $ connection -> config ( ) ; i...
Helper method to get the schema collection .
25,830
public function render ( array $ data , ContextInterface $ context ) { $ data += [ 'name' => '' , 'empty' => false , 'escape' => true , 'options' => [ ] , 'disabled' => null , 'val' => null , 'templateVars' => [ ] ] ; $ options = $ this -> _renderContent ( $ data ) ; $ name = $ data [ 'name' ] ; unset ( $ data [ 'name'...
Render a select box form input .
25,831
protected function _renderContent ( $ data ) { $ options = $ data [ 'options' ] ; if ( $ options instanceof Traversable ) { $ options = iterator_to_array ( $ options ) ; } if ( ! empty ( $ data [ 'empty' ] ) ) { $ options = $ this -> _emptyValue ( $ data [ 'empty' ] ) + ( array ) $ options ; } if ( empty ( $ options ) ...
Render the contents of the select element .
25,832
protected function _emptyValue ( $ value ) { if ( $ value === true ) { return [ '' => '' ] ; } if ( is_scalar ( $ value ) ) { return [ '' => $ value ] ; } if ( is_array ( $ value ) ) { return $ value ; } return [ ] ; }
Generate the empty value based on the input .
25,833
protected function _renderOptgroup ( $ label , $ optgroup , $ disabled , $ selected , $ templateVars , $ escape ) { $ opts = $ optgroup ; $ attrs = [ ] ; if ( isset ( $ optgroup [ 'options' ] , $ optgroup [ 'text' ] ) ) { $ opts = $ optgroup [ 'options' ] ; $ label = $ optgroup [ 'text' ] ; $ attrs = $ optgroup ; } $ g...
Render the contents of an optgroup element .
25,834
protected function _renderOptions ( $ options , $ disabled , $ selected , $ templateVars , $ escape ) { $ out = [ ] ; foreach ( $ options as $ key => $ val ) { $ arrayVal = ( is_array ( $ val ) || $ val instanceof Traversable ) ; if ( ( ! is_int ( $ key ) && $ arrayVal ) || ( is_int ( $ key ) && $ arrayVal && ( isset (...
Render a set of options .
25,835
protected function _isSelected ( $ key , $ selected ) { if ( $ selected === null ) { return false ; } $ isArray = is_array ( $ selected ) ; if ( ! $ isArray ) { $ selected = $ selected === false ? '0' : $ selected ; return ( string ) $ key === ( string ) $ selected ; } $ strict = ! is_numeric ( $ key ) ; return in_arra...
Helper method for deciding what options are selected .
25,836
public function toDatabase ( $ value , Driver $ driver ) { if ( is_string ( $ value ) ) { return $ this -> convertStringToBinaryUuid ( $ value ) ; } return $ value ; }
Convert binary uuid data into the database format .
25,837
public function toPHP ( $ value , Driver $ driver ) { if ( $ value === null ) { return null ; } if ( is_string ( $ value ) ) { return $ this -> convertBinaryUuidToString ( $ value ) ; } if ( is_resource ( $ value ) ) { return $ value ; } throw new Exception ( sprintf ( 'Unable to convert %s into binary uuid.' , gettype...
Convert binary uuid into resource handles
25,838
protected function _foreignOnClause ( $ on ) { if ( $ on === TableSchema :: ACTION_SET_NULL ) { return 'SET NULL' ; } if ( $ on === TableSchema :: ACTION_SET_DEFAULT ) { return 'SET DEFAULT' ; } if ( $ on === TableSchema :: ACTION_CASCADE ) { return 'CASCADE' ; } if ( $ on === TableSchema :: ACTION_RESTRICT ) { return ...
Generate an ON clause for a foreign key .
25,839
protected function _convertOnClause ( $ clause ) { if ( $ clause === 'CASCADE' || $ clause === 'RESTRICT' ) { return strtolower ( $ clause ) ; } if ( $ clause === 'NO ACTION' ) { return TableSchema :: ACTION_NO_ACTION ; } return TableSchema :: ACTION_SET_NULL ; }
Convert string on clauses to the abstract ones .
25,840
protected function _convertConstraintColumns ( $ references ) { if ( is_string ( $ references ) ) { return $ this -> _driver -> quoteIdentifier ( $ references ) ; } return implode ( ', ' , array_map ( [ $ this -> _driver , 'quoteIdentifier' ] , $ references ) ) ; }
Convert foreign key constraints references to a valid stringified list
25,841
public function dropTableSql ( TableSchema $ schema ) { $ sql = sprintf ( 'DROP TABLE %s' , $ this -> _driver -> quoteIdentifier ( $ schema -> name ( ) ) ) ; return [ $ sql ] ; }
Generate the SQL to drop a table .
25,842
public function add ( callable $ rule , $ name = null , array $ options = [ ] ) { $ this -> _rules [ ] = $ this -> _addError ( $ rule , $ name , $ options ) ; return $ this ; }
Adds a rule that will be applied to the entity both on create and update operations .
25,843
public function addCreate ( callable $ rule , $ name = null , array $ options = [ ] ) { $ this -> _createRules [ ] = $ this -> _addError ( $ rule , $ name , $ options ) ; return $ this ; }
Adds a rule that will be applied to the entity on create operations .
25,844
public function addUpdate ( callable $ rule , $ name = null , array $ options = [ ] ) { $ this -> _updateRules [ ] = $ this -> _addError ( $ rule , $ name , $ options ) ; return $ this ; }
Adds a rule that will be applied to the entity on update operations .
25,845
public function addDelete ( callable $ rule , $ name = null , array $ options = [ ] ) { $ this -> _deleteRules [ ] = $ this -> _addError ( $ rule , $ name , $ options ) ; return $ this ; }
Adds a rule that will be applied to the entity on delete operations .
25,846
public function checkCreate ( EntityInterface $ entity , array $ options = [ ] ) { return $ this -> _checkRules ( $ entity , $ options , array_merge ( $ this -> _rules , $ this -> _createRules ) ) ; }
Runs each of the rules by passing the provided entity and returns true if all of them pass . The rules selected will be only those specified to be run on create
25,847
public function checkUpdate ( EntityInterface $ entity , array $ options = [ ] ) { return $ this -> _checkRules ( $ entity , $ options , array_merge ( $ this -> _rules , $ this -> _updateRules ) ) ; }
Runs each of the rules by passing the provided entity and returns true if all of them pass . The rules selected will be only those specified to be run on update
25,848
public function checkDelete ( EntityInterface $ entity , array $ options = [ ] ) { return $ this -> _checkRules ( $ entity , $ options , $ this -> _deleteRules ) ; }
Runs each of the rules by passing the provided entity and returns true if all of them pass . The rules selected will be only those specified to be run on delete
25,849
protected function _checkRules ( EntityInterface $ entity , array $ options = [ ] , array $ rules = [ ] ) { $ success = true ; $ options += $ this -> _options ; foreach ( $ rules as $ rule ) { $ success = $ rule ( $ entity , $ options ) && $ success ; } return $ success ; }
Used by top level functions checkDelete checkCreate and checkUpdate this function iterates an array containing the rules to be checked and checks them all .
25,850
protected function _addError ( $ rule , $ name , $ options ) { if ( is_array ( $ name ) ) { $ options = $ name ; $ name = null ; } if ( ! ( $ rule instanceof RuleInvoker ) ) { $ rule = new RuleInvoker ( $ rule , $ name , $ options ) ; } else { $ rule -> setOptions ( $ options ) -> setName ( $ name ) ; } return $ rule ;...
Utility method for decorating any callable so that if it returns false the correct property in the entity is marked as invalid .
25,851
public function process ( $ value , array $ providers , array $ context = [ ] ) { $ context += [ 'data' => [ ] , 'newRecord' => true , 'providers' => $ providers ] ; if ( $ this -> _skip ( $ context ) ) { return true ; } if ( ! is_string ( $ this -> _rule ) && is_callable ( $ this -> _rule ) ) { $ callable = $ this -> ...
Dispatches the validation rule to the given validator method and returns a boolean indicating whether the rule passed or not . If a string is returned it is assumed that the rule failed and the error message was given as a result .
25,852
protected function _skip ( $ context ) { if ( ! is_string ( $ this -> _on ) && is_callable ( $ this -> _on ) ) { $ function = $ this -> _on ; return ! $ function ( $ context ) ; } $ newRecord = $ context [ 'newRecord' ] ; if ( ! empty ( $ this -> _on ) ) { if ( ( $ this -> _on === 'create' && ! $ newRecord ) || ( $ thi...
Checks if the validation rule should be skipped
25,853
protected function _addValidatorProps ( $ validator = [ ] ) { foreach ( $ validator as $ key => $ value ) { if ( ! isset ( $ value ) || empty ( $ value ) ) { continue ; } if ( $ key === 'rule' && is_array ( $ value ) && ! is_callable ( $ value ) ) { $ this -> _pass = array_slice ( $ value , 1 ) ; $ value = array_shift ...
Sets the rule properties from the rule entry in validate
25,854
public function current ( ) { if ( $ this -> _callback === null ) { return parent :: current ( ) ; } return call_user_func_array ( $ this -> _callback , parent :: current ( ) ) ; }
Returns the value resulting out of zipping all the elements for all the iterators with the same positional index .
25,855
public function unserialize ( $ iterators ) { parent :: __construct ( MultipleIterator :: MIT_NEED_ALL | MultipleIterator :: MIT_KEYS_NUMERIC ) ; $ this -> _iterators = unserialize ( $ iterators ) ; foreach ( $ this -> _iterators as $ it ) { $ this -> attachIterator ( $ it ) ; } }
Unserializes the passed string and rebuilds the ZipIterator instance
25,856
public function beforeSave ( Event $ event , EntityInterface $ entity ) { $ isNew = $ entity -> isNew ( ) ; $ config = $ this -> getConfig ( ) ; $ parent = $ entity -> get ( $ config [ 'parent' ] ) ; $ primaryKey = $ this -> _getPrimaryKey ( ) ; $ dirty = $ entity -> isDirty ( $ config [ 'parent' ] ) ; $ level = $ conf...
Before save listener . Transparently manages setting the lft and rght fields if the parent field is included in the parameters to be saved .
25,857
public function afterSave ( Event $ event , EntityInterface $ entity ) { if ( ! $ this -> _config [ 'level' ] || $ entity -> isNew ( ) ) { return ; } $ this -> _setChildrenLevel ( $ entity ) ; }
After save listener .
25,858
protected function _setChildrenLevel ( $ entity ) { $ config = $ this -> getConfig ( ) ; if ( $ entity -> get ( $ config [ 'left' ] ) + 1 === $ entity -> get ( $ config [ 'right' ] ) ) { return ; } $ primaryKey = $ this -> _getPrimaryKey ( ) ; $ primaryKeyValue = $ entity -> get ( $ primaryKey ) ; $ depths = [ $ primar...
Set level for descendants .
25,859
public function beforeDelete ( Event $ event , EntityInterface $ entity ) { $ config = $ this -> getConfig ( ) ; $ this -> _ensureFields ( $ entity ) ; $ left = $ entity -> get ( $ config [ 'left' ] ) ; $ right = $ entity -> get ( $ config [ 'right' ] ) ; $ diff = $ right - $ left + 1 ; if ( $ diff > 2 ) { $ query = $ ...
Also deletes the nodes in the subtree of the entity to be delete
25,860
protected function _setParent ( $ entity , $ parent ) { $ config = $ this -> getConfig ( ) ; $ parentNode = $ this -> _getNode ( $ parent ) ; $ this -> _ensureFields ( $ entity ) ; $ parentLeft = $ parentNode -> get ( $ config [ 'left' ] ) ; $ parentRight = $ parentNode -> get ( $ config [ 'right' ] ) ; $ right = $ ent...
Sets the correct left and right values for the passed entity so it can be updated to a new parent . It also makes the hole in the tree so the node move can be done without corrupting the structure .
25,861
protected function _setAsRoot ( $ entity ) { $ config = $ this -> getConfig ( ) ; $ edge = $ this -> _getMax ( ) ; $ this -> _ensureFields ( $ entity ) ; $ right = $ entity -> get ( $ config [ 'right' ] ) ; $ left = $ entity -> get ( $ config [ 'left' ] ) ; $ diff = $ right - $ left ; if ( $ right - $ left > 1 ) { $ in...
Updates the left and right column for the passed entity so it can be set as a new root in the tree . It also modifies the ordering in the rest of the tree so the structure remains valid
25,862
protected function _unmarkInternalTree ( ) { $ config = $ this -> getConfig ( ) ; $ this -> _table -> updateAll ( function ( $ exp ) use ( $ config ) { $ leftInverse = clone $ exp ; $ leftInverse -> setConjunction ( '*' ) -> add ( '-1' ) ; $ rightInverse = clone $ leftInverse ; return $ exp -> eq ( $ config [ 'leftFiel...
Helper method used to invert the sign of the left and right columns that are less than 0 . They were set to negative values before so their absolute value wouldn t change while performing other tree transformations .
25,863
public function findPath ( Query $ query , array $ options ) { if ( empty ( $ options [ 'for' ] ) ) { throw new InvalidArgumentException ( "The 'for' key is required for find('path')" ) ; } $ config = $ this -> getConfig ( ) ; list ( $ left , $ right ) = array_map ( function ( $ field ) { return $ this -> _table -> ali...
Custom finder method which can be used to return the list of nodes from the root to a specific node in the tree . This custom finder requires that the key for is passed in the options containing the id of the node to get its path for .
25,864
public function childCount ( EntityInterface $ node , $ direct = false ) { $ config = $ this -> getConfig ( ) ; $ parent = $ this -> _table -> aliasField ( $ config [ 'parent' ] ) ; if ( $ direct ) { return $ this -> _scope ( $ this -> _table -> find ( ) ) -> where ( [ $ parent => $ node -> get ( $ this -> _getPrimaryK...
Get the number of children nodes .
25,865
public function findChildren ( Query $ query , array $ options ) { $ config = $ this -> getConfig ( ) ; $ options += [ 'for' => null , 'direct' => false ] ; list ( $ parent , $ left , $ right ) = array_map ( function ( $ field ) { return $ this -> _table -> aliasField ( $ field ) ; } , [ $ config [ 'parent' ] , $ confi...
Get the children nodes of the current model
25,866
public function findTreeList ( Query $ query , array $ options ) { $ left = $ this -> _table -> aliasField ( $ this -> getConfig ( 'left' ) ) ; $ results = $ this -> _scope ( $ query ) -> find ( 'threaded' , [ 'parentField' => $ this -> getConfig ( 'parent' ) , 'order' => [ $ left => 'ASC' ] , ] ) ; return $ this -> fo...
Gets a representation of the elements in the tree as a flat list where the keys are the primary key for the table and the values are the display field for the table . Values are prefixed to visually indicate relative depth in the tree .
25,867
public function formatTreeList ( Query $ query , array $ options = [ ] ) { return $ query -> formatResults ( function ( $ results ) use ( $ options ) { $ options += [ 'keyPath' => $ this -> _getPrimaryKey ( ) , 'valuePath' => $ this -> _table -> getDisplayField ( ) , 'spacer' => '_' , ] ; return $ results -> listNested...
Formats query as a flat list where the keys are the primary key for the table and the values are the display field for the table . Values are prefixed to visually indicate relative depth in the tree .
25,868
public function removeFromTree ( EntityInterface $ node ) { return $ this -> _table -> getConnection ( ) -> transactional ( function ( ) use ( $ node ) { $ this -> _ensureFields ( $ node ) ; return $ this -> _removeFromTree ( $ node ) ; } ) ; }
Removes the current node from the tree by positioning it as a new root and re - parents all children up one level .
25,869
protected function _removeFromTree ( $ node ) { $ config = $ this -> getConfig ( ) ; $ left = $ node -> get ( $ config [ 'left' ] ) ; $ right = $ node -> get ( $ config [ 'right' ] ) ; $ parent = $ node -> get ( $ config [ 'parent' ] ) ; $ node -> set ( $ config [ 'parent' ] , null ) ; if ( $ right - $ left == 1 ) { re...
Helper function containing the actual code for removeFromTree
25,870
public function moveUp ( EntityInterface $ node , $ number = 1 ) { if ( $ number < 1 ) { return false ; } return $ this -> _table -> getConnection ( ) -> transactional ( function ( ) use ( $ node , $ number ) { $ this -> _ensureFields ( $ node ) ; return $ this -> _moveUp ( $ node , $ number ) ; } ) ; }
Reorders the node without changing its parent .
25,871
protected function _moveUp ( $ node , $ number ) { $ config = $ this -> getConfig ( ) ; list ( $ parent , $ left , $ right ) = [ $ config [ 'parent' ] , $ config [ 'left' ] , $ config [ 'right' ] ] ; list ( $ nodeParent , $ nodeLeft , $ nodeRight ) = array_values ( $ node -> extract ( [ $ parent , $ left , $ right ] ) ...
Helper function used with the actual code for moveUp
25,872
public function moveDown ( EntityInterface $ node , $ number = 1 ) { if ( $ number < 1 ) { return false ; } return $ this -> _table -> getConnection ( ) -> transactional ( function ( ) use ( $ node , $ number ) { $ this -> _ensureFields ( $ node ) ; return $ this -> _moveDown ( $ node , $ number ) ; } ) ; }
Reorders the node without changing the parent .
25,873
protected function _getNode ( $ id ) { $ config = $ this -> getConfig ( ) ; list ( $ parent , $ left , $ right ) = [ $ config [ 'parent' ] , $ config [ 'left' ] , $ config [ 'right' ] ] ; $ primaryKey = $ this -> _getPrimaryKey ( ) ; $ fields = [ $ parent , $ left , $ right ] ; if ( $ config [ 'level' ] ) { $ fields [ ...
Returns a single node from the tree from its primary key
25,874
protected function _recoverTree ( $ counter = 0 , $ parentId = null , $ level = - 1 ) { $ config = $ this -> getConfig ( ) ; list ( $ parent , $ left , $ right ) = [ $ config [ 'parent' ] , $ config [ 'left' ] , $ config [ 'right' ] ] ; $ primaryKey = $ this -> _getPrimaryKey ( ) ; $ aliasedPrimaryKey = $ this -> _tabl...
Recursive method used to recover a single level of the tree
25,875
protected function _getMax ( ) { $ field = $ this -> _config [ 'right' ] ; $ rightField = $ this -> _config [ 'rightField' ] ; $ edge = $ this -> _scope ( $ this -> _table -> find ( ) ) -> select ( [ $ field ] ) -> orderDesc ( $ rightField ) -> first ( ) ; if ( empty ( $ edge -> { $ field } ) ) { return 0 ; } return $ ...
Returns the maximum index value in the table .
25,876
protected function _sync ( $ shift , $ dir , $ conditions , $ mark = false ) { $ config = $ this -> _config ; foreach ( [ $ config [ 'leftField' ] , $ config [ 'rightField' ] ] as $ field ) { $ query = $ this -> _scope ( $ this -> _table -> query ( ) ) ; $ exp = $ query -> newExpr ( ) ; $ movement = clone $ exp ; $ mov...
Auxiliary function used to automatically alter the value of both the left and right columns by a certain amount that match the passed conditions
25,877
protected function _scope ( $ query ) { $ scope = $ this -> getConfig ( 'scope' ) ; if ( is_array ( $ scope ) ) { return $ query -> where ( $ scope ) ; } if ( is_callable ( $ scope ) ) { return $ scope ( $ query ) ; } return $ query ; }
Alters the passed query so that it only returns scoped records as defined in the tree configuration .
25,878
protected function _ensureFields ( $ entity ) { $ config = $ this -> getConfig ( ) ; $ fields = [ $ config [ 'left' ] , $ config [ 'right' ] ] ; $ values = array_filter ( $ entity -> extract ( $ fields ) ) ; if ( count ( $ values ) === count ( $ fields ) ) { return ; } $ fresh = $ this -> _table -> get ( $ entity -> ge...
Ensures that the provided entity contains non - empty values for the left and right fields
25,879
protected function _getPrimaryKey ( ) { if ( ! $ this -> _primaryKey ) { $ primaryKey = ( array ) $ this -> _table -> getPrimaryKey ( ) ; $ this -> _primaryKey = $ primaryKey [ 0 ] ; } return $ this -> _primaryKey ; }
Returns a single string value representing the primary key of the attached table
25,880
public function getLevel ( $ entity ) { $ primaryKey = $ this -> _getPrimaryKey ( ) ; $ id = $ entity ; if ( $ entity instanceof EntityInterface ) { $ id = $ entity -> get ( $ primaryKey ) ; } $ config = $ this -> getConfig ( ) ; $ entity = $ this -> _table -> find ( 'all' ) -> select ( [ $ config [ 'left' ] , $ config...
Returns the depth level of a node in the tree .
25,881
public function connection ( $ connection = null ) { deprecationWarning ( 'Query::connection() is deprecated. ' . 'Use Query::setConnection()/getConnection() instead.' ) ; if ( $ connection !== null ) { return $ this -> setConnection ( $ connection ) ; } return $ this -> getConnection ( ) ; }
Sets the connection instance to be used for executing and transforming this query When called with a null argument it will return the current connection instance .
25,882
public function execute ( ) { $ statement = $ this -> _connection -> run ( $ this ) ; $ this -> _iterator = $ this -> _decorateStatement ( $ statement ) ; $ this -> _dirty = false ; return $ this -> _iterator ; }
Compiles the SQL representation of this query and executes it using the configured connection object . Returns the resulting statement object .
25,883
public function sql ( ValueBinder $ generator = null ) { if ( ! $ generator ) { $ generator = $ this -> getValueBinder ( ) ; $ generator -> resetCount ( ) ; } return $ this -> getConnection ( ) -> compileQuery ( $ this , $ generator ) ; }
Returns the SQL representation of this object .
25,884
public function traverse ( callable $ visitor , array $ parts = [ ] ) { $ parts = $ parts ? : array_keys ( $ this -> _parts ) ; foreach ( $ parts as $ name ) { $ visitor ( $ this -> _parts [ $ name ] , $ name ) ; } return $ this ; }
Will iterate over every specified part . Traversing functions can aggregate results using variables in the closure or instance variables . This function is commonly used as a way for traversing all query parts that are going to be used for constructing a query .
25,885
public function distinct ( $ on = [ ] , $ overwrite = false ) { if ( $ on === [ ] ) { $ on = true ; } elseif ( is_string ( $ on ) ) { $ on = [ $ on ] ; } if ( is_array ( $ on ) ) { $ merge = [ ] ; if ( is_array ( $ this -> _parts [ 'distinct' ] ) ) { $ merge = $ this -> _parts [ 'distinct' ] ; } $ on = $ overwrite ? ar...
Adds a DISTINCT clause to the query to remove duplicates from the result set . This clause can only be used for select statements .
25,886
public function modifier ( $ modifiers , $ overwrite = false ) { $ this -> _dirty ( ) ; if ( $ overwrite ) { $ this -> _parts [ 'modifier' ] = [ ] ; } $ this -> _parts [ 'modifier' ] = array_merge ( $ this -> _parts [ 'modifier' ] , ( array ) $ modifiers ) ; return $ this ; }
Adds a single or multiple SELECT modifiers to be used in the SELECT .
25,887
public function from ( $ tables = [ ] , $ overwrite = false ) { if ( empty ( $ tables ) ) { deprecationWarning ( 'Using Query::from() to read state is deprecated. Use clause("from") instead.' ) ; return $ this -> _parts [ 'from' ] ; } $ tables = ( array ) $ tables ; if ( $ overwrite ) { $ this -> _parts [ 'from' ] = $ ...
Adds a single or multiple tables to be used in the FROM clause for this query . Tables can be passed as an array of strings array of expression objects a single expression or a single string .
25,888
public function join ( $ tables = null , $ types = [ ] , $ overwrite = false ) { if ( $ tables === null ) { deprecationWarning ( 'Using Query::join() to read state is deprecated. Use clause("join") instead.' ) ; return $ this -> _parts [ 'join' ] ; } if ( is_string ( $ tables ) || isset ( $ tables [ 'table' ] ) ) { $ t...
Adds a single or multiple tables to be used as JOIN clauses to this query . Tables can be passed as an array of strings an array describing the join parts an array with multiple join descriptions or a single string .
25,889
public function leftJoin ( $ table , $ conditions = [ ] , $ types = [ ] ) { return $ this -> join ( $ this -> _makeJoin ( $ table , $ conditions , QueryInterface :: JOIN_TYPE_LEFT ) , $ types ) ; }
Adds a single LEFT JOIN clause to the query .
25,890
public function rightJoin ( $ table , $ conditions = [ ] , $ types = [ ] ) { return $ this -> join ( $ this -> _makeJoin ( $ table , $ conditions , QueryInterface :: JOIN_TYPE_RIGHT ) , $ types ) ; }
Adds a single RIGHT JOIN clause to the query .
25,891
public function innerJoin ( $ table , $ conditions = [ ] , $ types = [ ] ) { return $ this -> join ( $ this -> _makeJoin ( $ table , $ conditions , QueryInterface :: JOIN_TYPE_INNER ) , $ types ) ; }
Adds a single INNER JOIN clause to the query .
25,892
protected function _makeJoin ( $ table , $ conditions , $ type ) { $ alias = $ table ; if ( is_array ( $ table ) ) { $ alias = key ( $ table ) ; $ table = current ( $ table ) ; } return [ $ alias => [ 'table' => $ table , 'conditions' => $ conditions , 'type' => $ type ] ] ; }
Returns an array that can be passed to the join method describing a single join clause
25,893
public function whereNotNull ( $ fields ) { if ( ! is_array ( $ fields ) ) { $ fields = [ $ fields ] ; } $ exp = $ this -> newExpr ( ) ; foreach ( $ fields as $ field ) { $ exp -> isNotNull ( $ field ) ; } return $ this -> where ( $ exp ) ; }
Convenience method that adds a NOT NULL condition to the query
25,894
public function whereNull ( $ fields ) { if ( ! is_array ( $ fields ) ) { $ fields = [ $ fields ] ; } $ exp = $ this -> newExpr ( ) ; foreach ( $ fields as $ field ) { $ exp -> isNull ( $ field ) ; } return $ this -> where ( $ exp ) ; }
Convenience method that adds a IS NULL condition to the query
25,895
public function whereInList ( $ field , array $ values , array $ options = [ ] ) { $ options += [ 'types' => [ ] , 'allowEmpty' => false , ] ; if ( $ options [ 'allowEmpty' ] && ! $ values ) { return $ this -> where ( '1=0' ) ; } return $ this -> where ( [ $ field . ' IN' => $ values ] , $ options [ 'types' ] ) ; }
Adds an IN condition or set of conditions to be used in the WHERE clause for this query .
25,896
public function whereNotInList ( $ field , array $ values , array $ options = [ ] ) { $ options += [ 'types' => [ ] , 'allowEmpty' => false , ] ; if ( $ options [ 'allowEmpty' ] && ! $ values ) { return $ this -> where ( [ $ field . ' IS NOT' => null ] ) ; } return $ this -> where ( [ $ field . ' NOT IN' => $ values ] ...
Adds a NOT IN condition or set of conditions to be used in the WHERE clause for this query .
25,897
public function orderDesc ( $ field , $ overwrite = false ) { if ( $ overwrite ) { $ this -> _parts [ 'order' ] = null ; } if ( ! $ field ) { return $ this ; } if ( ! $ this -> _parts [ 'order' ] ) { $ this -> _parts [ 'order' ] = new OrderByExpression ( ) ; } $ this -> _parts [ 'order' ] -> add ( new OrderClauseExpres...
Add an ORDER BY clause with a DESC direction .
25,898
public function group ( $ fields , $ overwrite = false ) { if ( $ overwrite ) { $ this -> _parts [ 'group' ] = [ ] ; } if ( ! is_array ( $ fields ) ) { $ fields = [ $ fields ] ; } $ this -> _parts [ 'group' ] = array_merge ( $ this -> _parts [ 'group' ] , array_values ( $ fields ) ) ; $ this -> _dirty ( ) ; return $ th...
Adds a single or multiple fields to be used in the GROUP BY clause for this query . Fields can be passed as an array of strings array of expression objects a single expression or a single string .
25,899
public function limit ( $ num ) { $ this -> _dirty ( ) ; if ( $ num !== null && ! is_object ( $ num ) ) { $ num = ( int ) $ num ; } $ this -> _parts [ 'limit' ] = $ num ; return $ this ; }
Sets the number of records that should be retrieved from database accepts an integer or an expression object that evaluates to an integer . In some databases this operation might not be supported or will require the query to be transformed in order to limit the result set size .