idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
26,600
public function get ( Carbon $ dt = NULL ) { if ( ! $ dt ) { $ dt = new Carbon ( ) ; } $ dt -> setTime ( 0 , 0 , 0 ) ; $ fyStart = Carbon :: create ( $ dt -> year , $ this -> month , $ this -> day , 0 , 0 , 0 ) ; $ fyEnd = clone $ fyStart ; $ fyEnd -> addYear ( ) -> subDay ( ) ; if ( ! $ dt -> between ( $ fyStart , $ fyEnd , TRUE ) ) { $ fyEnd -> year ( $ dt -> year ) ; } return $ fyEnd ; }
Get the FY end date
26,601
private function buildDigitList ( $ digitList ) { if ( is_int ( $ digitList ) ) { return new IntegerDigitList ( $ digitList ) ; } elseif ( is_string ( $ digitList ) ) { return new StringDigitList ( $ digitList ) ; } elseif ( is_array ( $ digitList ) ) { return new ArrayDigitList ( $ digitList ) ; } throw new \ InvalidArgumentException ( 'Unexpected number base type' ) ; }
Returns an appropriate type of digit list based on the parameter .
26,602
public function hasDigit ( $ digit ) { try { $ this -> digits -> getValue ( $ digit ) ; } catch ( DigitList \ InvalidDigitException $ ex ) { return false ; } return true ; }
Tells if the given digit is part of this numeral system .
26,603
public function getValues ( array $ digits ) { $ values = [ ] ; foreach ( $ digits as $ digit ) { $ values [ ] = $ this -> digits -> getValue ( $ digit ) ; } return $ values ; }
Returns the decimal values for given digits .
26,604
public function getDigits ( array $ decimals ) { $ digits = [ ] ; foreach ( $ decimals as $ decimal ) { $ digits [ ] = $ this -> digits -> getDigit ( $ decimal ) ; } return $ digits ; }
Returns the digits representing the given decimal values .
26,605
public function findCommonRadixRoot ( NumberBase $ base ) { $ common = array_intersect ( $ this -> getRadixRoots ( ) , $ base -> getRadixRoots ( ) ) ; return count ( $ common ) > 0 ? max ( $ common ) : false ; }
Finds the largest integer root shared by the radix of both numeral systems .
26,606
private function getRadixRoots ( ) { $ radix = count ( $ this -> digits ) ; $ roots = [ $ radix ] ; for ( $ i = 2 ; ( $ root = ( int ) ( $ radix ** ( 1 / $ i ) ) ) > 1 ; $ i ++ ) { if ( $ root ** $ i === $ radix ) { $ roots [ ] = $ root ; } } return $ roots ; }
Returns all integer roots for the radix .
26,607
public function canonizeDigits ( array $ digits ) { $ result = $ this -> getDigits ( $ this -> getValues ( $ digits ) ) ; return empty ( $ result ) ? [ $ this -> digits -> getDigit ( 0 ) ] : $ result ; }
Replaces all values in the array with actual digits from the digit list .
26,608
public function splitString ( $ string ) { if ( $ this -> digits -> hasStringConflict ( ) ) { throw new \ RuntimeException ( 'The number base does not support string presentation' ) ; } $ pattern = $ this -> getDigitPattern ( ) ; if ( ( string ) $ string === '' ) { $ digits = [ ] ; } elseif ( is_int ( $ pattern ) ) { $ digits = str_split ( $ string , $ this -> digitPattern ) ; } else { preg_match_all ( $ pattern , $ string , $ match ) ; $ digits = $ match [ 0 ] ; } return $ this -> canonizeDigits ( $ digits ) ; }
Splits number string into individual digits .
26,609
private function getDigitPattern ( ) { if ( ! isset ( $ this -> digitPattern ) ) { $ lengths = array_map ( 'strlen' , $ this -> digits -> getDigits ( ) ) ; if ( count ( array_flip ( $ lengths ) ) === 1 ) { $ this -> digitPattern = array_pop ( $ lengths ) ; } else { $ this -> digitPattern = sprintf ( '(%s|.+)s%s' , implode ( '|' , array_map ( 'preg_quote' , $ this -> digits -> getDigits ( ) ) ) , $ this -> digits -> isCaseSensitive ( ) ? '' : 'i' ) ; } } return $ this -> digitPattern ; }
Creates and returns the pattern for splitting strings into digits .
26,610
public function isValid ( ) { foreach ( $ this -> validators as $ validator ) { if ( ! $ validator -> isValid ( ) ) { foreach ( $ validator -> getErrors ( ) as $ name => $ messages ) { if ( ! isset ( $ this -> errors [ $ name ] ) ) { $ this -> errors [ $ name ] = array ( ) ; } $ this -> errors [ $ name ] = $ messages ; } } } return ! $ this -> hasErrors ( ) ; }
Runs the validation against all defined validators
26,611
public function replace ( $ key , $ value ) { if ( $ value === "" || is_null ( $ value ) || $ value === false ) { $ this -> url = preg_replace ( "#/{" . $ key . "}.*$#" , "" , $ this -> getUrl ( ) ) ; } else { $ this -> url = str_replace ( "{" . $ key . "}" , $ value , $ this -> getUrl ( ) ) ; } return $ this ; }
Replace a substring for making URL templates
26,612
public function validate ( ) { if ( ! $ this -> isValid ( $ this -> getUrl ( ) ) ) { throw new InvalidUrl ( sprintf ( '"%s" is not a valid url' , $ this -> url ) ) ; } return $ this ; }
Validate the url
26,613
protected function executeCommandHook ( $ method , $ event_type ) { foreach ( $ this -> getCommandsByMethodEventType ( $ method , $ event_type ) as $ command ) { if ( is_string ( $ command ) ) { $ command = ( new CommandHook ( ) ) -> setType ( 'raw' ) -> setCommand ( $ command ) ; } elseif ( is_array ( $ command ) ) { $ command = CommandHook :: createWithData ( $ command ) ; } if ( ! $ command instanceof CommandHookInterface ) { continue ; } switch ( $ command -> getType ( ) ) { case 'symfony' : $ this -> executeSymfonyCmdHook ( $ command , $ method ) ; break ; default : $ this -> executeEngineCmdHook ( $ command ) ; break ; } } return $ this ; }
Execute command hook .
26,614
protected function executeEngineCmdHook ( CommandHookInterface $ hook_command ) { $ options = $ hook_command -> getOptions ( ) ; $ service = isset ( $ options [ 'service' ] ) ? $ options [ 'service' ] : null ; $ localhost = ( boolean ) isset ( $ options [ 'localhost' ] ) ? $ options [ 'localhost' ] : ! isset ( $ service ) ; $ command = $ this -> resolveHookCommand ( $ hook_command ) ; return $ this -> executeEngineCommand ( $ command , $ service , [ ] , false , $ localhost ) ; }
Execute engine command hook .
26,615
protected function resolveHookCommand ( CommandHookInterface $ command_hook ) { $ command = null ; switch ( $ command_hook -> getType ( ) ) { case 'raw' : $ command = $ command_hook -> getCommand ( ) ; break ; case 'engine' : $ command = $ this -> getEngineCommand ( $ command_hook ) ; break ; case 'project' : $ command = $ this -> getProjectCommand ( $ command_hook ) ; break ; } return isset ( $ command ) ? $ command : false ; }
Resolve hook command .
26,616
protected function executeSymfonyCmdHook ( CommandHookInterface $ command_hook , $ method ) { $ command = $ command_hook -> getCommand ( ) ; $ container = ProjectX :: getContainer ( ) ; $ application = $ container -> get ( 'application' ) ; try { $ info = $ this -> getCommandInfo ( $ method ) ; $ command = $ application -> find ( $ command ) ; if ( $ command -> getName ( ) === $ info -> getName ( ) ) { throw new \ Exception ( sprintf ( 'Unable to call the %s command hook due to it ' . 'invoking the parent method.' , $ command -> getName ( ) ) ) ; } } catch ( CommandNotFoundException $ exception ) { throw new CommandHookRuntimeException ( sprintf ( 'Unable to find %s command in the project-x command ' . 'hook.' , $ command ) ) ; } catch ( \ Exception $ exception ) { throw new CommandHookRuntimeException ( $ exception -> getMessage ( ) ) ; } $ exec = $ this -> taskSymfonyCommand ( $ command ) ; $ definition = $ command -> getDefinition ( ) ; if ( $ command_hook -> hasOptions ( ) ) { foreach ( $ command_hook -> getOptions ( ) as $ option => $ value ) { if ( is_numeric ( $ option ) ) { $ option = $ value ; $ value = null ; } if ( ! $ definition -> hasOption ( $ option ) ) { continue ; } $ exec -> opt ( $ option , $ value ) ; } } if ( $ command_hook -> hasArguments ( ) ) { foreach ( $ command_hook -> getArguments ( ) as $ arg => $ value ) { if ( ! isset ( $ value ) || ! $ definition -> hasArgument ( $ arg ) ) { continue ; } $ exec -> arg ( $ arg , $ value ) ; } } return $ exec -> run ( ) ; }
Execute symfony command hook .
26,617
protected function getProjectCommand ( CommandHookInterface $ command_hook ) { $ method = $ command_hook -> getCommand ( ) ; $ project = $ this -> getProjectInstance ( ) ; if ( ! method_exists ( $ project , $ method ) ) { throw new CommandHookRuntimeException ( sprintf ( "The %s method doesn't exist on the project." , $ method ) ) ; } $ args = array_merge ( $ command_hook -> getOptions ( ) , $ command_hook -> getArguments ( ) ) ; return call_user_func_array ( [ $ project , $ method ] , [ $ args ] ) ; }
Get project command .
26,618
protected function getEngineCommand ( CommandHookInterface $ command_hook ) { $ method = $ command_hook -> getCommand ( ) ; $ engine = $ this -> getEngineInstance ( ) ; if ( ! method_exists ( $ engine , $ method ) ) { throw new CommandHookRuntimeException ( sprintf ( "The %s method doesn't exist on the environment engine." , $ method ) ) ; } $ args = array_merge ( $ command_hook -> getOptions ( ) , $ command_hook -> getArguments ( ) ) ; return call_user_func_array ( [ $ engine , $ method ] , [ $ args ] ) ; }
Get environment engine command .
26,619
protected function getCommandsByMethodEventType ( $ method , $ event_type ) { $ hooks = ProjectX :: getProjectConfig ( ) -> getCommandHooks ( ) ; if ( empty ( $ hooks ) ) { return [ ] ; } $ info = $ this -> getCommandInfo ( $ method ) ; list ( $ command , $ action ) = explode ( ':' , $ info -> getName ( ) ) ; if ( ! isset ( $ hooks [ $ command ] [ $ action ] [ $ event_type ] ) ) { return [ ] ; } return $ hooks [ $ command ] [ $ action ] [ $ event_type ] ; }
Get commands by method event type .
26,620
public function setDriversOrder ( array $ driversOrder ) { foreach ( $ driversOrder as $ driver ) { if ( ! in_array ( $ driver , $ this -> supportedDrivers ) ) { throw new RedisProxyException ( 'Driver "' . $ driver . '" is not supported' ) ; } } $ this -> driversOrder = $ driversOrder ; return $ this ; }
Set driver priorities - default is 1 . redis 2 . predis
26,621
public function exists ( $ key ) { $ this -> init ( ) ; $ result = $ this -> driver -> exists ( $ key ) ; return ( bool ) $ result ; }
Determine if a key exists
26,622
public function get ( $ key ) { $ this -> init ( ) ; $ result = $ this -> driver -> get ( $ key ) ; return $ this -> convertFalseToNull ( $ result ) ; }
Get the value of a key
26,623
public function getset ( $ key , $ value ) { $ this -> init ( ) ; $ result = $ this -> driver -> getset ( $ key , $ value ) ; return $ this -> convertFalseToNull ( $ result ) ; }
Set the string value of a key and return its old value
26,624
public function expire ( $ key , $ seconds ) { $ this -> init ( ) ; $ result = $ this -> driver -> expire ( $ key , $ seconds ) ; return ( bool ) $ result ; }
Set a key s time to live in seconds
26,625
public function pexpire ( $ key , $ miliseconds ) { $ this -> init ( ) ; $ result = $ this -> driver -> pexpire ( $ key , $ miliseconds ) ; return ( bool ) $ result ; }
Set a key s time to live in milliseconds
26,626
public function expireat ( $ key , $ timestamp ) { $ this -> init ( ) ; $ result = $ this -> driver -> expireat ( $ key , $ timestamp ) ; return ( bool ) $ result ; }
Set the expiration for a key as a UNIX timestamp
26,627
public function pexpireat ( $ key , $ milisecondsTimestamp ) { $ this -> init ( ) ; $ result = $ this -> driver -> pexpireat ( $ key , $ milisecondsTimestamp ) ; return ( bool ) $ result ; }
Set the expiration for a key as a UNIX timestamp specified in milliseconds
26,628
public function psetex ( $ key , $ miliseconds , $ value ) { $ this -> init ( ) ; $ result = $ this -> driver -> psetex ( $ key , $ miliseconds , $ value ) ; if ( $ result == '+OK' ) { return true ; } return $ this -> transformResult ( $ result ) ; }
Set the value and expiration in milliseconds of a key
26,629
public function persist ( $ key ) { $ this -> init ( ) ; $ result = $ this -> driver -> persist ( $ key ) ; return ( bool ) $ result ; }
Remove the expiration from a key
26,630
public function setnx ( $ key , $ value ) { $ this -> init ( ) ; $ result = $ this -> driver -> setnx ( $ key , $ value ) ; return ( bool ) $ result ; }
Set the value of a key only if the key does not exist
26,631
public function incrby ( $ key , $ increment = 1 ) { $ this -> init ( ) ; return $ this -> driver -> incrby ( $ key , ( int ) $ increment ) ; }
Increment the integer value of a key by the given amount
26,632
public function incrbyfloat ( $ key , $ increment = 1 ) { $ this -> init ( ) ; return $ this -> driver -> incrbyfloat ( $ key , $ increment ) ; }
Increment the float value of a key by the given amount
26,633
public function decrby ( $ key , $ decrement = 1 ) { $ this -> init ( ) ; return $ this -> driver -> decrby ( $ key , ( int ) $ decrement ) ; }
Decrement the integer value of a key by the given number
26,634
public function dump ( $ key ) { $ this -> init ( ) ; $ result = $ this -> driver -> dump ( $ key ) ; return $ this -> convertFalseToNull ( $ result ) ; }
Return a serialized version of the value stored at the specified key
26,635
public function mset ( ... $ dictionary ) { $ this -> init ( ) ; if ( is_array ( $ dictionary [ 0 ] ) ) { $ result = $ this -> driver -> mset ( ... $ dictionary ) ; return $ this -> transformResult ( $ result ) ; } $ dictionary = $ this -> prepareKeyValue ( $ dictionary , 'mset' ) ; $ result = $ this -> driver -> mset ( $ dictionary ) ; return $ this -> transformResult ( $ result ) ; }
Set multiple values to multiple keys
26,636
public function hdel ( $ key , ... $ fields ) { $ fields = $ this -> prepareArguments ( 'hdel' , ... $ fields ) ; $ this -> init ( ) ; return $ this -> driver -> hdel ( $ key , ... $ fields ) ; }
Delete one or more hash fields returns number of deleted fields
26,637
public function hincrby ( $ key , $ field , $ increment = 1 ) { $ this -> init ( ) ; return $ this -> driver -> hincrby ( $ key , $ field , ( int ) $ increment ) ; }
Increment the integer value of hash field by given number
26,638
public function hincrbyfloat ( $ key , $ field , $ increment = 1 ) { $ this -> init ( ) ; return $ this -> driver -> hincrbyfloat ( $ key , $ field , $ increment ) ; }
Increment the float value of hash field by given amount
26,639
public function hmset ( $ key , ... $ dictionary ) { $ this -> init ( ) ; if ( is_array ( $ dictionary [ 0 ] ) ) { $ result = $ this -> driver -> hmset ( $ key , ... $ dictionary ) ; return $ this -> transformResult ( $ result ) ; } $ dictionary = $ this -> prepareKeyValue ( $ dictionary , 'hmset' ) ; $ result = $ this -> driver -> hmset ( $ key , $ dictionary ) ; return $ this -> transformResult ( $ result ) ; }
Set multiple values to multiple hash fields
26,640
public function hmget ( $ key , ... $ fields ) { $ fields = array_unique ( $ this -> prepareArguments ( 'hmget' , ... $ fields ) ) ; $ this -> init ( ) ; $ values = [ ] ; foreach ( $ this -> driver -> hmget ( $ key , $ fields ) as $ value ) { $ values [ ] = $ this -> convertFalseToNull ( $ value ) ; } return array_combine ( $ fields , $ values ) ; }
Multi hash get
26,641
public function sadd ( $ key , ... $ members ) { $ members = $ this -> prepareArguments ( 'sadd' , ... $ members ) ; $ this -> init ( ) ; return $ this -> driver -> sadd ( $ key , ... $ members ) ; }
Add one or more members to a set
26,642
public function spop ( $ key , $ count = 1 ) { $ this -> init ( ) ; if ( $ count == 1 || $ count === null ) { $ result = $ this -> driver -> spop ( $ key ) ; return $ this -> convertFalseToNull ( $ result ) ; } $ members = [ ] ; for ( $ i = 0 ; $ i < $ count ; ++ $ i ) { $ member = $ this -> driver -> spop ( $ key ) ; if ( ! $ member ) { break ; } $ members [ ] = $ member ; } return empty ( $ members ) ? null : $ members ; }
Remove and return one or multiple random members from a set
26,643
public function sscan ( $ key , & $ iterator , $ pattern = null , $ count = null ) { if ( ( string ) $ iterator === '0' ) { return null ; } $ this -> init ( ) ; if ( $ this -> actualDriver ( ) === self :: DRIVER_PREDIS ) { $ returned = $ this -> driver -> sscan ( $ key , $ iterator , [ 'match' => $ pattern , 'count' => $ count ] ) ; $ iterator = $ returned [ 0 ] ; return $ returned [ 1 ] ; } return $ this -> driver -> sscan ( $ key , $ iterator , $ pattern , $ count ) ; }
Incrementally iterate Set elements
26,644
public function rpush ( $ key , ... $ elements ) { $ elements = $ this -> prepareArguments ( 'rpush' , ... $ elements ) ; $ this -> init ( ) ; return $ this -> driver -> rpush ( $ key , ... $ elements ) ; }
Append one or multiple values to a list
26,645
public function lpop ( $ key ) { $ this -> init ( ) ; $ result = $ this -> driver -> lpop ( $ key ) ; return $ this -> convertFalseToNull ( $ result ) ; }
Remove and get the first element in a list
26,646
public function rpop ( $ key ) { $ this -> init ( ) ; $ result = $ this -> driver -> rpop ( $ key ) ; return $ this -> convertFalseToNull ( $ result ) ; }
Remove and get the last element in a list
26,647
public function zadd ( $ key , ... $ dictionary ) { $ this -> init ( ) ; if ( is_array ( $ dictionary [ 0 ] ) ) { $ return = 0 ; foreach ( $ dictionary [ 0 ] as $ member => $ score ) { $ res = $ this -> zadd ( $ key , $ score , $ member ) ; $ return += $ res ; } return $ return ; } return $ this -> driver -> zadd ( $ key , ... $ dictionary ) ; }
Add one or more members to a sorted set or update its score if it already exists
26,648
public function zrevrange ( $ key , $ start , $ stop , $ withscores = false ) { $ this -> init ( ) ; if ( $ this -> actualDriver ( ) === self :: DRIVER_PREDIS ) { return $ this -> driver -> zrevrange ( $ key , $ start , $ stop , [ 'WITHSCORES' => $ withscores ] ) ; } return $ this -> driver -> zrevrange ( $ key , $ start , $ stop , $ withscores ) ; }
Return a range of members in a sorted set by index with scores ordered from high to low
26,649
private function convertFalseToNull ( $ result ) { return $ this -> actualDriver ( ) === self :: DRIVER_REDIS && $ result === false ? null : $ result ; }
Returns null instead of false for Redis driver
26,650
private function transformResult ( $ result ) { if ( $ this -> actualDriver ( ) === self :: DRIVER_PREDIS && $ result instanceof Status ) { $ result = $ result -> getPayload ( ) === 'OK' ; } return $ result ; }
Transforms Predis result Payload to boolean
26,651
private function prepareKeyValue ( array $ dictionary , $ command ) { $ keys = array_values ( array_filter ( $ dictionary , function ( $ key ) { return $ key % 2 == 0 ; } , ARRAY_FILTER_USE_KEY ) ) ; $ values = array_values ( array_filter ( $ dictionary , function ( $ key ) { return $ key % 2 == 1 ; } , ARRAY_FILTER_USE_KEY ) ) ; if ( count ( $ keys ) != count ( $ values ) ) { throw new RedisProxyException ( "Wrong number of arguments for $command command" ) ; } return array_combine ( $ keys , $ values ) ; }
Create array from input array - odd keys are used as keys even keys are used as values
26,652
public static function dump ( $ variable , $ exit = true ) { if ( is_object ( $ variable ) && method_exists ( $ variable , '__toString' ) ) { echo $ variable ; } else { if ( is_bool ( $ variable ) ) { var_dump ( $ variable ) ; } else { $ text = sprintf ( '<pre>%s</pre>' , print_r ( $ variable , true ) ) ; print $ text ; } } if ( $ exit === true ) { exit ( ) ; } }
Dumps a variable
26,653
public static function router ( $ directory , $ config = 'config.yml' ) { $ request = Server :: get ( 'PHP_SELF' ) ; $ root = Server :: get ( 'DOCUMENT_ROOT' ) ; $ file = $ root . $ request ; if ( file_exists ( $ file ) && ! is_dir ( $ file ) ) { return false ; } else { Bootstrap :: start ( $ directory , $ config ) ; return true ; } }
Simple script router
26,654
public function init ( ) { Profiler :: start ( 'init' , 'init' ) ; $ this -> initTime = microtime ( true ) ; $ this -> init = true ; Log :: d ( 'Initializing framework...' ) ; date_default_timezone_set ( 'Europe/Madrid' ) ; $ this -> setupLanguage ( ) ; Profiler :: stop ( 'init' ) ; $ this -> manager = new ModuleManager ( $ this -> config , $ this -> directory ) ; $ this -> manager -> init ( ) ; Log :: d ( 'Module manager initialized' ) ; $ this -> inited = true ; }
Inicializar la apliacion de forma interna
26,655
public function install ( ) { define ( 'GL_INSTALL' , true ) ; $ this -> init ( ) ; echo '<pre>' ; $ fail = false ; $ db = new DatabaseManager ( ) ; if ( $ db -> connectAndSelect ( ) ) { $ this -> setDatabase ( $ db ) ; $ this -> log ( 'Connection to database ok' ) ; $ this -> log ( 'Installing Database...' ) ; $ models = $ this -> getModels ( ) ; foreach ( $ models as $ model ) { $ instance = new $ model ( null ) ; if ( $ instance instanceof Model ) { $ diff = $ instance -> getStructureDifferences ( $ db , isset ( $ _GET [ 'drop' ] ) ) ; $ this -> log ( 'Installing table \'' . $ instance -> getTableName ( ) . '\' generated by ' . get_class ( $ instance ) . '...' , 2 ) ; foreach ( $ diff as $ action ) { $ this -> log ( 'Action: ' . $ action [ 'sql' ] . '...' , 3 , false ) ; if ( isset ( $ _GET [ 'exec' ] ) ) { try { DBStructure :: runAction ( $ db , $ instance , $ action ) ; $ this -> log ( '[OK]' , 0 ) ; } catch ( \ Exception $ ex ) { $ this -> log ( '[FAIL]' , 0 ) ; $ fail = true ; } } echo "\n" ; } } } if ( ! isset ( $ _GET [ 'exec' ] ) ) { $ this -> log ( 'Please <a href="?exec">click here</a> to make this changes in the database.' ) ; } else { $ db2 = new DBStructure ( ) ; $ db2 -> setDatabaseUpdate ( ) ; $ this -> log ( 'All done site ready for develop/production!' ) ; } } else { if ( $ db -> getConnection ( ) !== null ) { if ( isset ( $ _GET [ 'create_database' ] ) ) { if ( $ db -> exec ( 'CREATE DATABASE ' . $ this -> config [ 'database' ] [ 'database' ] ) ) { echo 'Database created successful! Please reload the navigator' ; } else { echo 'Can not create the database!' ; } } else { echo 'Can\'t select the database <a href="install.php?create_database">Try to create database</a>' ; } } else { echo 'Cannot connect to database' ; } } }
Instala la base de datos con los modelos actualmente cargados en el init
26,656
public function build ( $ class , array $ args ) { $ class = $ this -> normalizeClassName ( $ class ) ; if ( isset ( $ this -> cache [ $ class ] ) ) { return $ this -> cache [ $ class ] ; } else { if ( class_exists ( $ class , true ) ) { $ instance = $ this -> getInstance ( $ class , $ args ) ; $ this -> cache [ $ class ] = $ instance ; return $ instance ; } else { throw new RuntimeException ( sprintf ( 'Can not build non-existing class "%s". The class does not exist or it does not follow PSR-0' , $ class ) ) ; } } }
Builds an instance of a class passing arguments to its constructor
26,657
private function getInstance ( $ class , array $ args ) { switch ( count ( $ args ) ) { case 0 : return new $ class ; case 1 : return new $ class ( $ args [ 0 ] ) ; case 2 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] ) ; case 3 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] ) ; case 4 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] , $ args [ 3 ] ) ; case 5 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] , $ args [ 3 ] , $ args [ 4 ] ) ; case 6 : return new $ class ( $ args [ 0 ] , $ args [ 1 ] , $ args [ 2 ] , $ args [ 3 ] , $ args [ 4 ] , $ args [ 5 ] ) ; default : $ reflection = new ReflectionClass ( ) ; return $ reflection -> newInstanceArgs ( $ args ) ; } }
Builds and returns an instance of a class
26,658
public function locateApacheServer ( ) : bool { if ( $ this -> getApacheCtl ( ) ) { $ this -> getApacheInfo ( ) ; $ this -> getApacheInstancesPath ( ) ; $ this -> getPHPModule ( ) ; } return $ this -> apachectl !== false && $ this -> apache_config_path !== false ; }
Locates Apache HTTP Server instance running in the S . O .
26,659
public function getApacheCtl ( ) { if ( $ this -> apachectl === false ) { $ shell = new CNabuShell ( ) ; $ response = array ( ) ; if ( $ shell -> exec ( 'whereis apachectl' , null , $ response ) && count ( $ response ) === 1 ) { $ parts = preg_split ( '/\\s/' , preg_replace ( '/^apachectl: /' , '' , $ response [ 0 ] ) ) ; $ this -> apachectl = $ parts [ 0 ] ; } } return $ this -> apachectl ; }
Locates the Apache Control Application full path installed in the S . O .
26,660
public function getApacheInfo ( ) { if ( $ this -> apachectl !== false ) { $ shell = new CNabuShell ( ) ; $ response = array ( ) ; if ( $ shell -> exec ( $ this -> apachectl , array ( '-V' => '' ) , $ response ) ) { $ this -> parseApacheInfo ( $ response ) ; } } }
Gets Apache Information about installed Apache HTTP Server .
26,661
private function parseApacheInfo ( array $ data = null ) { $ this -> apache_info = null ; if ( is_array ( $ data ) && count ( $ data ) > 0 ) { foreach ( $ data as $ line ) { $ this -> interpretApacheInfoData ( $ line ) || $ this -> interpretApacheInfoVariable ( $ line ) ; } } }
Parse Apache Information lines to get valid values .
26,662
public function getApacheInstancesPath ( ) { if ( $ this -> apache_config_path === false && is_array ( $ this -> apache_compiles ) && array_key_exists ( 'SERVER_CONFIG_FILE' , $ this -> apache_compiles ) ) { $ config_file = $ this -> apache_compiles [ 'SERVER_CONFIG_FILE' ] ; if ( is_file ( $ config_file ) ) { $ base_path = dirname ( $ config_file ) ; if ( is_dir ( $ base_path . DIRECTORY_SEPARATOR . 'other' ) ) { $ this -> apache_config_path = $ base_path . DIRECTORY_SEPARATOR . 'other' ; } elseif ( is_dir ( $ base_path . DIRECTORY_SEPARATOR . 'conf.d' ) ) { $ this -> apache_config_path = $ base_path . DIRECTORY_SEPARATOR . 'conf.d' ; } } elseif ( array_key_exists ( 'HTTPD_ROOT' , $ this -> apache_compiles ) ) { $ base_path = preg_replace ( '/"$/' , '' , preg_replace ( '/^"/' , '' , $ this -> apache_compiles [ 'HTTPD_ROOT' ] ) ) ; if ( is_dir ( $ base_path . DIRECTORY_SEPARATOR . 'conf.d' ) ) { $ this -> apache_config_path = $ base_path . DIRECTORY_SEPARATOR . 'conf.d' ; } elseif ( is_dir ( $ base_path . DIRECTORY_SEPARATOR . 'other' ) ) { $ this -> apache_config_path = $ base_path . DIRECTORY_SEPARATOR . 'other' ; } } } return $ this -> apache_config_path ; }
Get the Apache Instances Path .
26,663
private function interpretApacheInfoVariable ( string $ line ) { $ content = preg_split ( '/^\\s+-D\\s+/' , $ line , 2 ) ; if ( count ( $ content ) === 2 ) { $ parts = preg_split ( '/=/' , $ content [ 1 ] , 2 ) ; if ( count ( $ parts ) === 2 ) { $ this -> apache_compiles [ $ parts [ 0 ] ] = str_replace ( '"' , '' , $ parts [ 1 ] ) ; } elseif ( count ( $ parts ) === 1 ) { $ this -> apache_compiles [ $ content [ 1 ] ] = true ; } } }
Interpret Apache Infromation Variable line .
26,664
public function getServerVersion ( ) : string { return ( is_array ( $ this -> apache_info ) && array_key_exists ( 'server-version' , $ this -> apache_info ) ) ? $ this -> apache_info [ 'server-version' ] : 'Unknown' ; }
Gets the Apache HTTP Server Version .
26,665
public function createStandaloneConfiguration ( ) : bool { $ retval = false ; if ( $ this -> apache_config_path ) { $ file = new CApacheStandaloneFile ( $ this , $ this -> nb_server , $ this -> nb_site ) ; $ file -> create ( ) ; $ file -> exportToFile ( $ this -> apache_config_path . DIRECTORY_SEPARATOR . self :: APACHE_CONFIG_FILENAME ) ; $ retval = true ; } return $ retval ; }
Creates the Standalone Configuration files .
26,666
public function createHostedConfiguration ( ) : bool { $ retval = false ; if ( $ this -> apache_config_path ) { $ index_list = $ this -> nb_server -> getSitesIndex ( ) ; $ index_list -> iterate ( function ( $ site_key , $ nb_site ) { $ this -> createHostedFile ( $ nb_site ) ; return true ; } ) ; $ this -> createHostedIndex ( $ index_list ) ; $ retval = true ; } return $ retval ; }
Creates the Hosted Configuration files .
26,667
public function createClusteredConfiguration ( ) { $ retval = false ; if ( $ this -> apache_config_path ) { $ index_list = $ this -> nb_server -> getSitesIndex ( ) ; $ index_list -> iterate ( function ( $ site_key , $ nb_site ) { $ this -> createSiteFolders ( $ nb_site ) ; $ this -> createClusteredFile ( $ nb_site ) ; return true ; } ) ; $ this -> createClusteredIndex ( $ index_list ) ; $ retval = true ; } return $ retval ; }
Creates the Clustered Configuration files .
26,668
private function createHostedIndex ( CNabuSiteList $ index_list ) { $ index = new CApacheHostedIndex ( $ this , $ index_list ) ; $ index -> create ( ) ; $ index -> exportToFile ( $ this -> apache_config_path . DIRECTORY_SEPARATOR . self :: APACHE_CONFIG_FILENAME ) ; }
Create Hosted hosts index file .
26,669
private function createClusteredIndex ( CNabuSiteList $ index_list ) { $ index = new CApacheClusteredIndex ( $ this , $ index_list ) ; $ index -> create ( ) ; $ index -> exportToFile ( $ this -> apache_config_path . DIRECTORY_SEPARATOR . self :: APACHE_CONFIG_FILENAME ) ; }
Create Clustered hosts index file .
26,670
private function createHostedFile ( CNabuSite $ nb_site ) { $ file = new CApacheHostedFile ( $ this , $ this -> nb_server , $ nb_site ) ; $ file -> create ( ) ; $ path = $ this -> nb_server -> getVirtualHostsPath ( ) . DIRECTORY_SEPARATOR . $ nb_site -> getBasePath ( ) . NABU_VHOST_CONFIG_FOLDER . DIRECTORY_SEPARATOR . $ this -> nb_server -> getKey ( ) ; if ( ! is_dir ( $ path ) ) { mkdir ( $ path , 0755 , true ) ; } if ( ! is_dir ( $ path ) ) { throw new ENabuCoreException ( ENabuCoreException :: ERROR_FOLDER_NOT_FOUND , array ( $ path ) ) ; } $ filename = $ path . DIRECTORY_SEPARATOR . NABU_VHOST_CONFIG_FILENAME ; $ file -> exportToFile ( $ filename ) ; }
Create Hosted per Site file configuration .
26,671
private function createClusteredFile ( CNabuSite $ nb_site ) { $ file = new CApacheClusteredFile ( $ this , $ this -> nb_server , $ nb_site ) ; $ file -> create ( ) ; $ path = self :: NABU_APACHE_ETC_PATH . DIRECTORY_SEPARATOR . $ nb_site -> getBasePath ( ) ; if ( ! is_dir ( $ path ) ) { mkdir ( $ path , 0755 , true ) ; } if ( ! is_dir ( $ path ) ) { throw new ENabuCoreException ( ENabuCoreException :: ERROR_FOLDER_NOT_FOUND , array ( $ path ) ) ; } $ filename = $ path . DIRECTORY_SEPARATOR . NABU_VHOST_CONFIG_FILENAME ; $ file -> exportToFile ( $ filename ) ; }
Create Clustered per Site file configuration .
26,672
private function validatePath ( string $ path ) : string { if ( ! is_dir ( $ path ) && ! mkdir ( $ path , 0755 , true ) ) { throw new ENabuCoreException ( ENabuCoreException :: ERROR_HOST_PATH_NOT_FOUND , array ( $ path ) ) ; } return $ path ; }
Validates a path to ensure that it exists and is available . If not exists tries to create it .
26,673
public function createSiteFolders ( CNabuSite $ nb_site ) : bool { $ vhosts_path = $ this -> validatePath ( $ this -> nb_server -> getVirtualHostsPath ( ) ) ; $ vlib_path = $ this -> validatePath ( $ this -> nb_server -> getVirtualLibrariesPath ( ) ) ; $ vcache_path = $ this -> validatePath ( $ this -> nb_server -> getVirtualCachePath ( ) ) ; $ nb_cluster_user = $ nb_site -> getClusterUser ( ) ; if ( $ nb_cluster_user === null ) { throw new ENabuCoreException ( ENabuCoreException :: ERROR_OBJECT_EXPECTED ) ; } $ nb_cluster_user_group = $ nb_cluster_user -> getGroup ( ) ; if ( $ nb_cluster_user_group === null ) { throw new ENabuCoreException ( ENabuCoreException :: ERROR_OBJECT_EXPECTED ) ; } $ owner_name = $ nb_cluster_user -> getOSNick ( ) ; $ owner_group = $ nb_cluster_user_group -> getOSNick ( ) ; $ vhosts_path = $ nb_site -> getVirtualHostPath ( $ this -> nb_server ) ; if ( ! is_dir ( $ vhosts_path ) ) { if ( ! mkdir ( $ vhosts_path , 0755 , true ) ) { throw new ENabuCoreException ( ENabuCoreException :: ERROR_HOST_PATH_NOT_FOUND , array ( $ vhosts_path ) ) ; } else { chown ( $ vhosts_path , $ owner_name ) ; chgrp ( $ vhosts_path , $ owner_group ) ; } } $ vlib_path = $ nb_site -> getVirtualLibrariesPath ( $ this -> nb_server ) ; if ( ! is_dir ( $ vlib_path ) ) { if ( ! mkdir ( $ vlib_path , 0755 , true ) ) { throw new ENabuCoreException ( ENabuCoreException :: ERROR_HOST_PATH_NOT_FOUND , array ( $ vlib_path ) ) ; } else { chown ( $ vlib_path , APACHE_HTTPD_SYS_USER ) ; chgrp ( $ vlib_path , $ owner_group ) ; } } $ vcache_path = $ nb_site -> getVirtualCachePath ( $ this -> nb_server ) ; if ( ! is_dir ( $ vcache_path ) ) { if ( ! mkdir ( $ vcache_path , 0755 , true ) ) { throw new ENabuCoreException ( ENabuCoreException :: ERROR_HOST_PATH_NOT_FOUND , array ( $ vcache_path ) ) ; } else { chown ( $ vcache_path , APACHE_HTTPD_SYS_USER ) ; chgrp ( $ vcache_path , $ owner_group ) ; } } return true ; }
Create Site Folders for the requested Site .
26,674
public function index ( ) { if ( Checkout :: config ( ) -> simple_checkout ) { return $ this -> redirect ( $ this -> Link ( 'finish' ) ) ; } if ( ! ( Checkout :: config ( ) -> login_form ) || Member :: currentUserID ( ) ) { return $ this -> redirect ( $ this -> Link ( 'billing' ) ) ; } $ this -> customise ( array ( 'Title' => _t ( 'Checkout.SignIn' , "Sign in" ) , "Login" => true , 'LoginForm' => $ this -> LoginForm ( ) ) ) ; $ this -> extend ( "onBeforeIndex" ) ; return $ this -> renderWith ( array ( 'Checkout' , 'Page' ) ) ; }
If user logged in redirect to billing info else show login register or checkout as guest options .
26,675
public function billing ( ) { $ form = $ this -> BillingForm ( ) ; if ( Checkout :: config ( ) -> simple_checkout ) { return $ this -> redirect ( $ this -> Link ( 'finish' ) ) ; } if ( ! Member :: currentUserID ( ) && ! Checkout :: config ( ) -> guest_checkout ) { return $ this -> redirect ( $ this -> Link ( 'index' ) ) ; } if ( Member :: currentUserID ( ) ) { $ form -> loadDataFrom ( Member :: currentUser ( ) ) ; } $ this -> customise ( array ( 'Title' => _t ( 'Checkout.BillingDetails' , "Billing Details" ) , 'Form' => $ form ) ) ; $ this -> extend ( "onBeforeBilling" ) ; return $ this -> renderWith ( array ( 'Checkout_billing' , 'Checkout' , 'Page' ) ) ; }
Catch the default dilling information of the visitor
26,676
public function delivery ( ) { $ cart = ShoppingCart :: get ( ) ; if ( Checkout :: config ( ) -> simple_checkout ) { return $ this -> redirect ( $ this -> Link ( 'finish' ) ) ; } if ( $ cart -> isCollection ( ) ) { return $ this -> redirect ( $ this -> Link ( 'finish' ) ) ; } if ( ! $ cart -> isDeliverable ( ) ) { return $ this -> redirect ( $ this -> Link ( 'finish' ) ) ; } if ( ! Member :: currentUserID ( ) && ! Checkout :: config ( ) -> guest_checkout ) { return $ this -> redirect ( $ this -> Link ( 'index' ) ) ; } $ this -> customise ( array ( 'Title' => _t ( 'Checkout.DeliveryDetails' , "Delivery Details" ) , 'Form' => $ this -> DeliveryForm ( ) ) ) ; $ this -> extend ( "onBeforeDelivery" ) ; return $ this -> renderWith ( array ( 'Checkout_delivery' , 'Checkout' , 'Page' ) ) ; }
Use to catch the users delivery details if different to their billing details
26,677
public function finish ( ) { $ billing_data = Session :: get ( "Checkout.BillingDetailsForm.data" ) ; $ delivery_data = Session :: get ( "Checkout.DeliveryDetailsForm.data" ) ; if ( ! Checkout :: config ( ) -> simple_checkout && ! is_array ( $ billing_data ) && ! is_array ( $ delivery_data ) ) { return $ this -> redirect ( $ this -> Link ( 'index' ) ) ; } if ( ! Member :: currentUserID ( ) && ! Checkout :: config ( ) -> guest_checkout ) { return $ this -> redirect ( $ this -> Link ( 'index' ) ) ; } if ( Checkout :: config ( ) -> simple_checkout ) { $ title = _t ( 'Checkout.SelectPaymentMethod' , "Select Payment Method" ) ; } else { $ title = _t ( 'Checkout.SeelctPostagePayment' , "Select Postage and Payment Method" ) ; } $ this -> customise ( array ( 'Title' => $ title , 'Form' => $ this -> PostagePaymentForm ( ) ) ) ; $ this -> extend ( "onBeforeFinish" ) ; return $ this -> renderWith ( array ( 'Checkout_finish' , 'Checkout' , 'Page' ) ) ; }
Final step allowing user to select postage and payment method
26,678
public function LoginForm ( ) { $ form = CheckoutLoginForm :: create ( $ this , 'LoginForm' ) ; $ form -> setAttribute ( "action" , $ this -> Link ( "LoginForm" ) ) ; $ form -> Fields ( ) -> add ( HiddenField :: create ( "BackURL" ) -> setValue ( $ this -> Link ( ) ) ) ; $ form -> Actions ( ) -> dataFieldByName ( 'action_dologin' ) -> addExtraClass ( "btn btn-primary" ) ; $ this -> extend ( "updateLoginForm" , $ form ) ; return $ form ; }
Generate a login form
26,679
public function BillingForm ( ) { $ form = BillingDetailsForm :: create ( $ this , 'BillingForm' ) ; $ data = Session :: get ( "Checkout.BillingDetailsForm.data" ) ; if ( is_array ( $ data ) ) { $ form -> loadDataFrom ( $ data ) ; } elseif ( $ member = Member :: currentUser ( ) ) { $ form -> loadDataFrom ( $ member ) ; if ( $ member -> DefaultAddress ( ) ) { $ form -> loadDataFrom ( $ member -> DefaultAddress ( ) ) ; } } $ this -> extend ( "updateBillingForm" , $ form ) ; return $ form ; }
Form to capture the users billing details
26,680
public function DeliveryForm ( ) { $ form = DeliveryDetailsForm :: create ( $ this , 'DeliveryForm' ) ; $ data = Session :: get ( "Checkout.DeliveryDetailsForm.data" ) ; if ( is_array ( $ data ) ) { $ form -> loadDataFrom ( $ data ) ; } $ this -> extend ( "updateDeliveryForm" , $ form ) ; return $ form ; }
Form to capture users delivery details
26,681
public static function getFullColumnName ( $ column , $ table = null ) { if ( $ table === null ) { if ( method_exists ( get_called_class ( ) , 'getTableName' ) ) { $ table = static :: getTableName ( ) ; } else { throw new LogicException ( sprintf ( 'The method getTableName() is not declared in %s, therefore a full column name cannot be generated' , get_called_class ( ) ) ) ; } } return sprintf ( '%s.%s' , $ table , $ column ) ; }
Returns full column name prepending table name
26,682
protected static function getWithPrefix ( $ table ) { $ prefix = static :: $ prefix ; if ( is_null ( $ prefix ) || empty ( $ prefix ) ) { return $ table ; } return sprintf ( '%s_%s' , $ prefix , $ table ) ; }
Returns table name with a prefix
26,683
final protected function executeSqlFromFile ( $ file ) { if ( is_file ( $ file ) ) { return $ this -> executeSqlFromString ( file_get_contents ( $ file ) ) ; } else { throw new RuntimeException ( sprintf ( 'Can not read file at "%s"' , $ file ) ) ; } }
Executes raw SQL from a file
26,684
final protected function valueExists ( $ column , $ value ) { $ this -> validateShortcutData ( ) ; return ( bool ) $ this -> db -> select ( ) -> count ( $ column ) -> from ( static :: getTableName ( ) ) -> whereEquals ( $ column , $ value ) -> queryScalar ( ) ; }
Determines whether column value already exists
26,685
final public function deleteByPks ( array $ ids ) { foreach ( $ ids as $ id ) { if ( ! $ this -> deleteByPk ( $ id ) ) { return false ; } } return true ; }
Deletes rows by their associated primary keys
26,686
final public function findColumnByPk ( $ id , $ column ) { $ this -> validateShortcutData ( ) ; return $ this -> fetchOneColumn ( $ column , $ this -> getPk ( ) , $ id ) ; }
Returns column s value by provided PK
26,687
final public function getLastPk ( $ table = null ) { if ( $ table === null ) { $ this -> validateShortcutData ( ) ; $ table = static :: getTableName ( ) ; } return $ this -> db -> select ( ) -> max ( $ this -> getPk ( ) ) -> from ( $ table ) -> queryScalar ( ) ; }
Returns last primary key
26,688
final public function syncWithJunction ( $ table , $ masterValue , array $ slaves , $ masterColumn = self :: PARAM_JUNCTION_MASTER_COLUMN , $ slaveColumn = self :: PARAM_JUNCTION_SLAVE_COLUMN ) { $ this -> removeFromJunction ( $ table , $ masterValue , $ masterColumn ) ; $ this -> insertIntoJunction ( $ table , $ masterValue , $ slaves , $ masterColumn , $ slaveColumn ) ; return true ; }
Synchronizes a junction table
26,689
final public function removeFromJunction ( $ table , $ masterValue , $ masterColumn = self :: PARAM_JUNCTION_MASTER_COLUMN ) { if ( ! is_array ( $ masterValue ) ) { $ masterValue = array ( $ masterValue ) ; } return $ this -> db -> delete ( ) -> from ( $ table ) -> whereIn ( $ masterColumn , $ masterValue ) -> execute ( ) ; }
Removes all records from junction table associated with master s key
26,690
final public function insertIntoJunction ( $ table , $ masterValue , array $ slaves , $ masterColumn = self :: PARAM_JUNCTION_MASTER_COLUMN , $ slaveColumn = self :: PARAM_JUNCTION_SLAVE_COLUMN ) { if ( ! empty ( $ slaves ) ) { return $ this -> db -> insertIntoJunction ( $ table , array ( $ masterColumn , $ slaveColumn ) , $ masterValue , $ slaves ) -> execute ( ) ; } else { return false ; } }
Inserts a record into junction table
26,691
final public function getMasterIdsFromJunction ( $ table , $ value , $ masterColumn = self :: PARAM_JUNCTION_MASTER_COLUMN , $ slaveColumn = self :: PARAM_JUNCTION_SLAVE_COLUMN ) { return $ this -> getIdsFromJunction ( $ table , $ masterColumn , $ slaveColumn , $ value ) ; }
Fetches master values associated with a slave in junction table
26,692
private function getIdsFromJunction ( $ table , $ column , $ key , $ value ) { return $ this -> db -> select ( $ column ) -> from ( $ table ) -> whereEquals ( $ key , $ value ) -> queryAll ( $ column ) ; }
Fetches values from junction table
26,693
final protected function getColumnSumWithAverages ( array $ columns , array $ averages , array $ constraints , $ precision = 2 ) { $ db = $ this -> db -> select ( ) ; foreach ( $ columns as $ column ) { $ db -> sum ( $ column , $ column ) ; } foreach ( $ averages as $ average ) { $ db -> avg ( $ average , $ average ) ; } $ db -> from ( static :: getTableName ( ) ) ; if ( ! empty ( $ constraints ) ) { $ iteration = 0 ; foreach ( $ constraints as $ key => $ value ) { if ( $ iteration === 0 ) { $ db -> whereEquals ( $ key , $ value ) ; } else { $ db -> andWhereEquals ( $ key , $ value ) ; } $ iteration ++ ; } } $ data = $ db -> queryAll ( ) ; if ( isset ( $ data [ 0 ] ) ) { return Math :: roundCollection ( $ data [ 0 ] , $ precision ) ; } else { return array ( ) ; } }
Counts the sum of a column by district id
26,694
private function persistRecord ( array $ data , array $ fillable = array ( ) , $ set ) { if ( ! empty ( $ fillable ) && ! ArrayUtils :: keysExist ( $ data , $ fillable ) ) { throw new LogicException ( 'Can not persist the entity due to fillable protection. Make sure all fillable keys exist in the entity' ) ; } $ this -> validateShortcutData ( ) ; if ( isset ( $ data [ $ this -> getPk ( ) ] ) && $ data [ $ this -> getPk ( ) ] ) { $ result = $ this -> db -> update ( static :: getTableName ( ) , $ data ) -> whereEquals ( $ this -> getPk ( ) , $ data [ $ this -> getPk ( ) ] ) -> execute ( ) ; return $ set === true ? $ data : $ result ; } else { if ( array_key_exists ( $ this -> getPk ( ) , $ data ) ) { unset ( $ data [ $ this -> getPk ( ) ] ) ; } $ result = $ this -> db -> insert ( static :: getTableName ( ) , $ data ) -> execute ( ) ; if ( $ set === true ) { $ data [ $ this -> getPk ( ) ] = $ this -> getMaxId ( ) ; return $ data ; } else { return $ result ; } } }
Persists a row
26,695
final public function persistMany ( array $ collection , array $ fillable = array ( ) ) { foreach ( $ collection as $ item ) { $ this -> persist ( $ item , $ fillable ) ; } return true ; }
Inserts or updates many records at once
26,696
final public function updateColumns ( array $ data , array $ allowedColumns = array ( ) ) { foreach ( $ data as $ column => $ values ) { foreach ( $ values as $ id => $ value ) { if ( ! empty ( $ allowedColumns ) && ! in_array ( $ column , $ allowedColumns ) ) { continue ; } $ this -> updateColumnByPk ( $ id , $ column , $ value ) ; } } return true ; }
Update multiple columns at once
26,697
final public function updateColumnsByPk ( $ pk , $ data ) { $ this -> validateShortcutData ( ) ; return $ this -> db -> update ( static :: getTableName ( ) , $ data ) -> whereEquals ( $ this -> getPk ( ) , $ pk ) -> execute ( ) ; }
Updates column values by a primary key
26,698
final public function isPrimaryKeyValue ( $ value ) { $ column = $ this -> getPk ( ) ; return ( bool ) $ this -> db -> select ( $ column ) -> from ( static :: getTableName ( ) ) -> whereEquals ( $ column , $ value ) -> query ( $ column ) ; }
Checks whether PK value exists
26,699
final public function fetchOneColumn ( $ column , $ key , $ value ) { $ this -> validateShortcutData ( ) ; return $ this -> db -> select ( $ column ) -> from ( static :: getTableName ( ) ) -> whereEquals ( $ key , $ value ) -> query ( $ column ) ; }
Fetches one column