idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
42,200 | public static function bake ( $ seed = [ ] , bool $ timetravel = true ) { $ future = false ; $ bread = collect ( $ seed ) -> map ( function ( $ crumb ) use ( & $ future , $ timetravel ) { if ( ! $ crumb ) { return ; } $ status = $ future && ! $ timetravel ? 'disabled' : 'enabled' ; $ future = ( $ currentCrumb = ( url (... | Generate a Breadcrumb navigation trail . Set time travel to false to disable forward navigation . Useful in Checkout for example . |
42,201 | public function urlWithQuerystring ( string $ url , string $ allowedParameters = null ) : string { if ( ! $ allowedParameters ) { return $ url ; } $ allowedParameters = str_start ( $ allowedParameters , '/' ) ; $ allowedParameters = str_finish ( $ allowedParameters , '/' ) ; $ currentQuery = collect ( request ( ) -> qu... | Returns a url with query string where the final querystring is a filtered version of the current querystring . |
42,202 | private function registerBlueprints ( ) { Blueprint :: macro ( 'active' , function ( $ name = 'active' , $ default = false ) { return $ this -> boolean ( $ name ) -> default ( $ default ) ; } ) ; Blueprint :: macro ( 'featured' , function ( $ name = 'featured' , $ default = false ) { return $ this -> boolean ( $ name )... | Register additional table blueprints for use in database migrations |
42,203 | public static function host ( ) : ? string { $ ip = self :: ip ( ) ; if ( isset ( static :: $ hosts [ $ ip ] ) ) { return static :: $ hosts [ $ ip ] ; } $ host = gethostbyaddr ( $ ip ) ; static :: $ hosts [ $ ip ] = ( $ host === '' ) ? null : $ host ; return static :: $ hosts [ $ ip ] ; } | Get the host name of remote user . This will use gethostbyaddr function or its cached version |
42,204 | public static function ipWithProxy ( $ delimiter = ',' ) : string { $ ip = self :: ip ( ) ; if ( isset ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) && $ ip != $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) { $ ip .= "{$delimiter}{$_SERVER['HTTP_X_FORWARDED_FOR']}" ; } return $ ip ; } | Get remote IP address with additional IP sent over proxy if exists |
42,205 | public static function getRawData ( ) : string { if ( static :: $ rawData === null ) { static :: $ rawData = file_get_contents ( 'php://input' ) ; if ( static :: $ rawData === false ) { throw new RequestException ( 'Unable to read raw data from request' ) ; } } return static :: $ rawData ; } | Get raw data of the request |
42,206 | private static function get ( string $ resourceName , string $ name , string $ default = null , array $ allowedValues = null ) { switch ( $ resourceName ) { case 'GET' : $ resource = $ _GET ; break ; case 'POST' : if ( ! isset ( $ _POST ) ) { return $ default ; } $ resource = $ _POST ; break ; case 'PUT' : if ( $ _SERV... | Fetch the value from the resource |
42,207 | public static function getGetParameter ( string $ name , string $ default = null , array $ allowed = null ) : string { return self :: get ( 'GET' , $ name , $ default , $ allowed ) ; } | Returns the GET parameter |
42,208 | public static function getPostParameter ( string $ name , string $ default = null , array $ allowed = null ) : string { return self :: get ( 'POST' , $ name , $ default , $ allowed ) ; } | Returns the POST parameter |
42,209 | public static function getPutParameter ( string $ name , string $ default = null , array $ allowed = null ) : string { return self :: get ( 'PUT' , $ name , $ default , $ allowed ) ; } | Returns the PUT parameter |
42,210 | public static function getDeleteParameter ( string $ name , $ default = null , array $ allowed = null ) : string { return self :: get ( 'DELETE' , $ name , $ default , $ allowed ) ; } | Returns the DELETE parameter |
42,211 | public static function requireParams ( string ... $ requiredParameters ) : array { if ( KOLDY_CLI ) { throw new ApplicationException ( 'Unable to require parameters in CLI mode. Check \Koldy\Cli for that' ) ; } switch ( $ _SERVER [ 'REQUEST_METHOD' ] ) { default : $ parameters = static :: getInputVars ( ) ; break ; cas... | Get the required parameters . Return bad request if any of them is missing . |
42,212 | public static function requireParamsObj ( string ... $ requiredParameters ) : stdClass { $ class = new stdClass ( ) ; foreach ( static :: requireParams ( ... $ requiredParameters ) as $ param => $ value ) { $ class -> $ param = $ value ; } return $ class ; } | Get required parameters as object |
42,213 | public static function getAllParametersObj ( ) : stdClass { $ values = new stdClass ( ) ; foreach ( static :: getAllParameters ( ) as $ name => $ value ) { $ values -> $ name = $ value ; } return $ values ; } | Get all parameters in stdClass |
42,214 | public static function only ( ... $ params ) : bool { if ( static :: parametersCount ( ) != count ( is_array ( $ params [ 0 ] ) ? $ params [ 0 ] : $ params ) ) { return false ; } return static :: containsParams ( ... $ params ) ; } | Return true if request contains only parameters from method argument . If there are more parameters then defined method will return false . |
42,215 | public static function containsParams ( ... $ params ) : bool { $ params = array_flip ( is_array ( $ params [ 0 ] ) ? $ params [ 0 ] : $ params ) ; foreach ( static :: getAllParameters ( ) as $ name => $ value ) { if ( array_key_exists ( $ name , $ params ) ) { unset ( $ params [ $ name ] ) ; } } return count ( $ param... | Return true if request contains all of the parameters from method argument . If there are more parameters then params passed to methods method will still return true . |
42,216 | public static function doesntContainParams ( ... $ params ) : bool { if ( is_array ( $ params [ 0 ] ) ) { $ params = $ params [ 0 ] ; } $ targetCount = count ( $ params ) ; $ params = array_flip ( $ params ) ; foreach ( static :: getAllParameters ( ) as $ name => $ value ) { if ( array_key_exists ( $ name , $ params ) ... | Return true only if request doesn t have any of the params from method argument . |
42,217 | public static function encode ( $ data ) : string { $ json = json_encode ( $ data ) ; if ( $ json === false ) { $ errNo = json_last_error ( ) ; $ msg = json_last_error_msg ( ) ; throw new Exception ( "Unable to encode data to JSON, error ({$errNo}): {$msg}" , $ errNo ) ; } return $ json ; } | JSON helper to quickly encode some data |
42,218 | private static function getMeasure ( int $ size , int $ count = 0 , int $ round = 0 ) : string { if ( $ size >= 1024 ) { return self :: getMeasure ( ( int ) round ( $ size / 1024 ) , ++ $ count , $ round ) ; } else { return round ( $ size , $ round ) . ' ' . self :: $ measure [ $ count ] ; } } | Get file s measure |
42,219 | public static function bytesToString ( int $ bytes , int $ round = 0 ) : string { return self :: getMeasure ( $ bytes , 0 , $ round ) ; } | Get bytes size as string |
42,220 | public static function stringToBytes ( string $ string ) : int { $ original = trim ( $ string ) ; $ number = ( int ) $ original ; if ( $ number === $ original || $ number === 0 ) { return $ number ; } else { $ char = strtoupper ( substr ( $ original , - 1 , 1 ) ) ; switch ( $ char ) { case 'K' : return $ number * 1024 ... | Get the number of bytes from string |
42,221 | public static function stringToUtf8 ( string $ string ) : string { if ( ! mb_check_encoding ( $ string , 'UTF-8' ) || ! ( $ string === mb_convert_encoding ( mb_convert_encoding ( $ string , 'UTF-32' , 'UTF-8' ) , 'UTF-8' , 'UTF-32' ) ) ) { $ string = mb_convert_encoding ( $ string , 'UTF-8' ) ; if ( ! mb_check_encoding... | Convert given string into proper UTF - 8 string |
42,222 | public function logMessage ( Message $ message ) : void { if ( in_array ( $ message -> getLevel ( ) , $ this -> config [ 'log' ] ) ) { if ( $ this -> getMessageFunction !== null ) { $ line = call_user_func ( $ this -> getMessageFunction , $ message ) ; } else { $ time = $ message -> getTime ( ) -> format ( 'y-m-d H:i:s... | Actually print message out |
42,223 | public function getVar ( $ whatVar , $ default = null ) { if ( is_numeric ( $ whatVar ) ) { $ whatVar = ( int ) $ whatVar + 1 ; if ( isset ( $ this -> uri [ $ whatVar ] ) ) { $ value = trim ( $ this -> uri [ $ whatVar ] ) ; return ( $ value != '' ) ? $ value : $ default ; } else { return $ default ; } } else { if ( iss... | Get the variable value from parameters |
42,224 | public function handleException ( Throwable $ e ) : void { $ exceptionHandlerPath = null ; if ( ( $ module = Application :: getCurrentModule ( ) ) !== null ) { $ exceptionHandlerPath = Application :: getModulePath ( $ module ) . 'controllers/ExceptionHandler.php' ; if ( ! is_file ( $ exceptionHandlerPath ) ) { $ except... | If your app throws any kind of exception it will end up here so handle it! |
42,225 | public static function createMigration ( string $ name ) : void { $ directory = Application :: getApplicationPath ( 'migrations' ) ; if ( ! is_dir ( $ directory ) ) { Directory :: mkdir ( $ directory , 0755 ) ; } $ timestamp = time ( ) ; $ className = Util :: camelCase ( $ name , null , false ) ; $ phpClassName = "Migr... | Create migration with given name |
42,226 | public function getQuery ( ) : Query { if ( $ this -> table === null ) { throw new Exception ( 'Unable to build DELETE query when table name is not set' ) ; } $ sql = "DELETE FROM {$this->table}" ; if ( $ this -> hasWhere ( ) ) { $ sql .= "\nWHERE{$this->getWhereSql()}" ; } return new Query ( $ sql , $ this -> getBindi... | Get the query that will be executed |
42,227 | public static function link ( string $ path , string $ assetSite = null ) : Redirect { return self :: temporary ( Application :: route ( ) -> asset ( $ path , $ assetSite ) ) ; } | Redirect client the the given link under the same domain . |
42,228 | public function addPHPErrorMessage ( string $ message , string $ file , int $ number , int $ line ) : self { $ this -> messages [ ] = [ 'type' => self :: TYPE_PHP , 'message' => $ message , 'file' => $ file , 'number' => $ number , 'line' => $ line ] ; return $ this ; } | Add standard PHP error message . This is usually for framework s internal use . |
42,229 | public function getMessage ( string $ delimiter = ' ' ) : string { $ messages = $ this -> getMessages ( ) ; $ return = [ ] ; foreach ( $ messages as $ part ) { if ( is_array ( $ part ) ) { $ type = $ part [ 'type' ] ?? '' ; if ( ! in_array ( $ type , [ self :: TYPE_PHP ] ) ) { $ return [ ] = print_r ( $ part , true ) ;... | Get the actual message only depending on data we have . It s like get the message line |
42,230 | public function getDefaultLine ( ) : string { $ messages = $ this -> getMessages ( ) ; if ( count ( $ messages ) == 0 ) { return '' ; } $ who = $ this -> getWho ( ) ?? Log :: getWho ( ) ; return "{$this->getTimeFormatted()}\t{$who}\t{$this->getLevel()}\t{$this->getMessage()}" ; } | Get the default message line that includes time level who triggered it and the information |
42,231 | final public static function encrypt ( string $ plainText , string $ key = null , string $ method = null ) : string { if ( $ method === null ) { $ method = static :: getMethod ( ) ; if ( ! in_array ( $ method , openssl_get_cipher_methods ( ) ) ) { throw new CryptException ( "OpenSSL method={$method} defined in applicat... | Encrypt given texts . If method is not provided default will be used |
42,232 | public function loadFrom ( string $ path ) : void { $ this -> path = $ path ; if ( is_file ( $ path ) ) { $ this -> data = require $ path ; if ( ! is_array ( $ this -> data ) ) { throw new ConfigException ( "Config loaded from path={$path} is not an array" ) ; } $ this -> loadedAt = time ( ) ; } else { throw new Config... | After config instance is constructed you should load configuration from file by using this method . Otherwise configuration should be set by using set or setData methods . |
42,233 | public function isOlderThen ( int $ numberOfSeconds ) : bool { if ( $ this -> loadedAt == null ) { throw new ConfigException ( 'Can not know how old is config when config is not set nor loaded yet; Please load config first for config name=' . $ this -> name ) ; } return time ( ) - $ numberOfSeconds > $ this -> loadedAt... | Returns true if loaded configuration is older then the seconds passed as first argument false otherwise . This is useful if your CLI script is running for the long time and there s possibility that config was updated in meantime . |
42,234 | public function has ( string $ key ) : bool { if ( ! is_array ( $ this -> data ) ) { throw new ConfigException ( 'Unable to get config data when config wasn\'t loaded for config name=' . $ this -> name ) ; } return array_key_exists ( $ key , $ this -> data ) ; } | Returns true if requested key exists in current configuration false otherwise . |
42,235 | public function get ( string $ key , $ defaultValue = null ) { if ( ! is_array ( $ this -> data ) ) { throw new ConfigException ( 'Unable to get config data when config wasn\'t loaded for config name=' . $ this -> name ) ; } if ( ! array_key_exists ( $ key , $ this -> data ) ) { return $ defaultValue ; } if ( ! $ this ... | Gets the value on requested key . First argument is key s name second argument is default value you want to get if key is not set . |
42,236 | public function delete ( string $ key ) : void { if ( array_key_exists ( $ key , $ this -> data ) ) { unset ( $ this -> data [ $ key ] ) ; } } | When config is loaded or set you can delete the presence of key by providing its name as first argument . This is advanced usage and should be avoided as much as possible . If configuration was loaded from file this won t alter the file on file system . |
42,237 | public function getArrayItem ( string $ key , string $ subKey , $ defaultValue = null ) { $ expectedArray = $ this -> get ( $ key , [ ] ) ; if ( ! is_array ( $ expectedArray ) ) { $ type = gettype ( $ expectedArray ) ; throw new ConfigException ( "Trying to fetch array from config={$this->name()} under key={$key}, but ... | If targeted key in first level is array then you can use this to fetch the key from that array |
42,238 | public function getFirstKey ( ) : string { $ config = $ this -> data ; if ( count ( $ config ) == 0 ) { throw new ConfigException ( 'Unable to get first config key when config is empty' ) ; } $ key = array_keys ( $ config ) [ 0 ] ; if ( $ this -> isPointerConfig ( ) ) { $ counter = 0 ; while ( is_string ( $ key ) && $ ... | Get the first key in config . Useful for pointer configs . |
42,239 | public function checkPresence ( array $ keys , bool $ throwException = true ) : array { $ missingKeys = [ ] ; foreach ( $ keys as $ key ) { if ( ! array_key_exists ( $ key , $ this -> data ) ) { $ missingKeys [ ] = $ key ; } } if ( $ throwException && count ( $ missingKeys ) > 0 ) { $ missingKeys = implode ( ', ' , $ m... | Checks the presence of given config keys ; if any of required keys is missing exception will be thrown . If you want to know which keys are missing then pass false as second argument and you ll get the array of missing keys . |
42,240 | public function removeHeader ( string $ name ) { if ( array_key_exists ( $ name , $ this -> headers ) ) { unset ( $ this -> headers [ $ name ] ) ; } return $ this ; } | Remove the header |
42,241 | protected function getAddressValue ( string $ email , string $ name = null ) { if ( $ name === null || $ name == '' ) { return $ email ; } else { return "{$name} <{$email}>" ; } } | Internal helper to get the proper address header value |
42,242 | public function attachFile ( string $ filePath , string $ name = null ) { $ this -> attachedFiles [ ] = [ 'path' => $ filePath , 'name' => $ name ] ; return $ this ; } | Attach file to e - mail |
42,243 | public static function is ( string $ controller , string $ action ) : bool { return $ controller == Application :: route ( ) -> getControllerUrl ( ) && $ action == Application :: route ( ) -> getActionUrl ( ) ; } | Are given controller and action current working controller and action? |
42,244 | public static function isModule ( string $ module , string $ controller = null , string $ action = null ) : bool { $ route = Application :: route ( ) ; if ( $ module === $ route -> getModuleUrl ( ) ) { if ( $ controller === null ) { return true ; } else { if ( $ controller === $ route -> getControllerUrl ( ) ) { if ( $... | Is this the matching module controller and action? |
42,245 | public function handle ( $ request , Closure $ next , $ guard = null , $ field = null ) { if ( ! App :: environment ( config ( 'auth.environments' , [ 'staging' ] ) ) ) { return $ next ( $ request ) ; } return parent :: handle ( $ request , $ next , $ guard ) ; } | Only allow authenticated users on environments specified in the auth config . |
42,246 | public static function terminateWithError ( string $ message , int $ errorCode = 503 ) : void { http_response_code ( $ errorCode ) ; header ( 'Retry-After: 300' ) ; print $ message ; exit ( 1 ) ; } | Terminate execution immediately - use it when there s no other way of recovering from error usually in boot procedure when exceptions are not loaded yet and etc . |
42,247 | public static function getApplicationPath ( string $ append = null ) : string { if ( $ append === null ) { return static :: $ applicationPath ; } else { return str_replace ( DS . DS , DS , static :: $ applicationPath . $ append ) ; } } | Get the path to application folder with ending slash |
42,248 | public static function getStoragePath ( string $ append = null ) : string { if ( $ append === null ) { return static :: $ storagePath ; } else { return str_replace ( DS . DS , DS , static :: $ storagePath . $ append ) ; } } | Get the path to storage folder with ending slash |
42,249 | public static function getPublicPath ( string $ append = null ) : string { if ( $ append === null ) { return static :: $ publicPath ; } else { return str_replace ( DS . DS , DS , static :: $ publicPath . $ append ) ; } } | Get the path to the public folder with ending slash |
42,250 | public static function getViewPath ( string $ append = null ) : string { if ( $ append === null ) { return static :: $ viewPath ; } else { return str_replace ( DS . DS , DS , static :: $ viewPath . $ append ) ; } } | Get the path to directory with views |
42,251 | public static function getConfig ( string $ name , bool $ isPointerConfig = false ) : Config { if ( isset ( static :: $ configs [ $ name ] ) ) { return static :: $ configs [ $ name ] ; } $ applicationConfig = static :: $ configs [ 'application' ] ?? null ; if ( $ applicationConfig === null ) { throw new ConfigException... | Get the configs from any config file fetched by config name . Config name is the name on file system so you can fetch Koldy s config files or your own configs . |
42,252 | public static function getCurrentURL ( ) : Url { if ( static :: $ currentUrl instanceof Url ) { return static :: $ currentUrl ; } if ( Application :: isCli ( ) ) { throw new ApplicationException ( 'Can not get current URL while running in CLI mode; URL doesn\'t exist in CLI mode' ) ; } static :: $ currentUrl = new Url ... | Get full current URL with schema |
42,253 | public static function route ( ) : AbstractRoute { if ( static :: $ routing === null ) { $ config = static :: getConfig ( 'application' ) ; $ routingClassName = $ config -> get ( 'routing_class' ) ; $ routeOptions = $ config -> get ( 'routing_options' ) ?? [ ] ; if ( $ routingClassName == null ) { static :: terminateWi... | Get the initialized routing class |
42,254 | public static function registerModule ( string $ name ) : void { if ( ! isset ( static :: $ registeredModules [ $ name ] ) ) { $ modulePath = static :: getModulePath ( $ name ) ; static :: prependIncludePath ( $ modulePath . 'controllers' , $ modulePath . 'library' ) ; static :: $ registeredModules [ $ name ] = true ; ... | Register module by registering include path and by running init . php in module root folder |
42,255 | public static function getModulePath ( $ name ) : string { $ modulePath = static :: $ modulePath ; return str_replace ( DS . DS , DS , $ modulePath . DS . $ name . DS ) ; } | Get the path on file system to the module WITH ending slash |
42,256 | public static function getKey ( ) : string { $ key = static :: getConfig ( 'application' ) -> get ( 'key' ) ; if ( $ key === null || $ key === '' ) { throw new ApplicationException ( 'The key \'key\' in application config is invalid; please set non-empty string there' ) ; } if ( $ key == ' __ENTERSomeRandomKeyHere __' ... | Get the key defined in application config |
42,257 | public function setDeletedAtDateTime ( ? DateTime $ deletedAt ) : void { $ this -> deleted_at = $ deletedAt === null ? null : $ deletedAt -> format ( 'Y-m-d H:i:s' ) ; } | Set the deleted at date time by passing instance of deletedAt |
42,258 | public static function make ( string $ parameter ) : string { $ parameter = str_replace ( '.' , '_' , $ parameter ) ; $ parameter = str_replace ( ',' , '_' , $ parameter ) ; $ parameter = str_replace ( ' ' , '_' , $ parameter ) ; $ parameter = str_replace ( '-' , '_' , $ parameter ) ; $ parameter = str_replace ( '(' , ... | Make unique bind name according to given parameter name |
42,259 | public function get ( string $ parameter ) : Bind { if ( ! $ this -> has ( $ parameter ) ) { throw new Exception ( "Bind name \"{$parameter}\" does not exists" ) ; } return $ this -> bindings [ $ parameter ] ; } | Get already binded parameter |
42,260 | public function getAsArray ( ) : array { $ data = [ ] ; foreach ( $ this -> getBindings ( ) as $ bind ) { $ data [ $ bind -> getParameter ( ) ] = $ bind -> getValue ( ) ; } return $ data ; } | Gets all bindings as key value assoc array where key is parameter and value is its value . |
42,261 | public function setFromArray ( array $ data ) : void { foreach ( $ data as $ parameter => $ value ) { $ this -> bindings [ $ parameter ] = new Bind ( $ parameter , $ value ) ; } } | Set the bindings by providing assoc array of parameter = > value |
42,262 | public static function dec2big ( string $ number ) : string { static :: checkExtensionOrFail ( ) ; $ alphabet = static :: NUMBERS ; $ number = trim ( ( string ) $ number ) ; if ( strlen ( $ number ) == 0 ) { throw new Exception ( 'Got empty number for dec2big, can not proceed' ) ; } $ mod = ( string ) count ( $ alphabe... | Convert decimal number into your numeric system |
42,263 | public static function big2dec ( string $ alpha ) : string { static :: checkExtensionOrFail ( ) ; if ( strlen ( $ alpha ) <= 0 ) { throw new Exception ( 'Got empty string in big2dec, can not proceed' ) ; } $ alphabet = array_flip ( static :: NUMBERS ) ; $ mod = ( string ) count ( $ alphabet ) ; $ x = '0' ; for ( $ i = ... | The reverse procedure convert number from your numeric system into decimal number |
42,264 | public static function create ( string $ path , string $ asName = null , string $ contentType = null ) : FileDownload { $ self = new static ( new File ( $ path ) ) ; if ( $ asName !== null ) { $ self -> setAsName ( $ asName ) ; } if ( $ contentType !== null ) { $ self -> setContentType ( $ contentType ) ; } return $ se... | Return file download |
42,265 | public function exec ( ) : void { if ( Application :: route ( ) -> isAjax ( ) ) { $ this -> handleExceptionInAjax ( $ this -> e ) ; } else { $ this -> handleExceptionInNormalRequest ( $ this -> e ) ; } } | Execute exception handler |
42,266 | public function query ( string $ query , array $ bindings = null ) : Query { $ this -> lastQuery = new Query ( $ query , $ bindings , $ this -> configKey ) ; return $ this -> lastQuery ; } | Get new query |
42,267 | public function getCanonicalAttribute ( ) { if ( $ canonical = $ this -> canonicalUrl ) { return $ canonical ; } if ( method_exists ( $ this , 'baseCanonical' ) ) { return $ this -> baseCanonical ( ) ; } return url ( ) -> current ( ) ; } | Return the canonical URL to be rendered in the browser |
42,268 | protected function getEmail ( ) : AbstractMailAdapter { if ( isset ( $ this -> config [ self :: FN_CONFIG_KEY ] ) ) { $ mail = call_user_func ( $ this -> config [ self :: FN_CONFIG_KEY ] , $ this -> messages ) ; if ( ! ( $ mail instanceof AbstractMailAdapter ) ) { throw new Exception ( 'Function defined in mail config ... | Get the Mail instance ready |
42,269 | protected function sendEmail ( ) : void { if ( ! $ this -> emailing ) { $ mail = $ this -> getEmail ( ) ; try { $ this -> emailing = true ; $ mail -> send ( ) ; $ this -> messages = [ ] ; $ this -> emailing = false ; } catch ( Mail \ Exception $ e ) { Log :: alert ( 'Can not send log message(s) with e-mail logger' , $ ... | Send e - mail report if system detected that e - mail should be sent |
42,270 | public function from ( string $ table , string $ alias = null , $ field = null ) : Select { $ this -> from [ ] = [ 'table' => $ table , 'alias' => $ alias ] ; if ( $ field !== null ) { if ( is_array ( $ field ) ) { foreach ( $ field as $ fld ) { $ this -> field ( ( $ alias ?? $ table ) . '.' . $ fld ) ; } } else { $ th... | Set the table FROM which fields will be fetched |
42,271 | public function innerJoin ( string $ table , $ firstTableField , string $ operator = null , string $ secondTableField = null ) : Select { $ this -> joins [ ] = [ 'type' => 'INNER JOIN' , 'table' => $ table , 'first' => $ firstTableField , 'operator' => $ operator , 'second' => $ secondTableField ] ; return $ this ; } | Inner join two tables |
42,272 | public function field ( string $ field , string $ as = null ) : Select { $ this -> fields [ ] = [ 'name' => $ field , 'as' => $ as ] ; return $ this ; } | Add one field that will be fetched |
42,273 | public function fields ( array $ fields , string $ alias = null ) : Select { $ alias = ( $ alias === null ) ? '' : "{$alias}." ; foreach ( $ fields as $ field => $ as ) { if ( is_numeric ( $ field ) ) { $ this -> field ( $ alias . $ as ) ; } else { $ this -> field ( $ alias . $ field , $ as ) ; } } return $ this ; } | Add fields to fetch by passing array of fields |
42,274 | public function having ( string $ field , string $ operator = null , $ value = null ) : Select { $ this -> having [ ] = [ 'link' => 'AND' , 'field' => $ field , 'operator' => $ operator , 'value' => $ value ] ; return $ this ; } | Add HAVING to your SELECT query |
42,275 | public function orderBy ( string $ field , string $ direction = null ) : Select { if ( $ direction === null ) { $ direction = 'ASC' ; } else { $ direction = strtoupper ( $ direction ) ; } if ( $ direction !== 'ASC' && $ direction !== 'DESC' ) { throw new Exception ( "Can not use invalid direction order ({$direction}) i... | Add field to ORDER BY |
42,276 | public function limit ( int $ start , int $ howMuch ) : Select { $ this -> limit = new \ stdClass ; $ this -> limit -> start = $ start ; $ this -> limit -> howMuch = $ howMuch ; return $ this ; } | Set the LIMIT on query results |
42,277 | public function page ( int $ number , int $ limitPerPage ) : Select { return $ this -> limit ( ( $ number - 1 ) * $ limitPerPage , $ limitPerPage ) ; } | Limit the results by page |
42,278 | public function fetchAll ( ) : array { if ( ! $ this -> wasExecuted ( ) ) { $ this -> exec ( ) ; } return $ this -> getAdapter ( ) -> getStatement ( ) -> fetchAll ( PDO :: FETCH_ASSOC ) ; } | Fetch all records by this query |
42,279 | public function fetchAllGenerator ( ) : Generator { if ( ! $ this -> wasExecuted ( ) ) { $ this -> exec ( ) ; } $ statement = $ this -> getAdapter ( ) -> getStatement ( ) ; while ( $ record = $ statement -> fetch ( PDO :: FETCH_ASSOC ) ) { yield $ record ; } $ statement -> closeCursor ( ) ; } | Fetch all records by getting Generator back |
42,280 | public function fetchAllObjGenerator ( string $ class = null ) : Generator { if ( ! $ this -> wasExecuted ( ) ) { $ this -> exec ( ) ; } $ statement = $ this -> getAdapter ( ) -> getStatement ( ) ; if ( $ class === null ) { while ( $ record = $ statement -> fetch ( PDO :: FETCH_OBJ ) ) { yield $ record ; } } else { whi... | Fetch all records from the executed SELECT statement and get the Generator back . |
42,281 | public function fetchAllOf ( string $ field ) : array { $ array = [ ] ; foreach ( $ this -> fetchAllGenerator ( ) as $ record ) { $ array [ ] = $ record [ $ field ] ?? null ; } return $ array ; } | Fetch all records and return array of values from each row from given field name . |
42,282 | public function fetchAllOfGenerator ( string $ field ) : Generator { foreach ( $ this -> fetchAllGenerator ( ) as $ index => $ record ) { yield $ index => $ record [ $ field ] ?? null ; } } | Fetch all records and return Generator of values from each row from given field name . |
42,283 | public function fetchFirst ( ) : ? array { if ( ! $ this -> wasExecuted ( ) ) { $ this -> exec ( ) ; } $ this -> resetLimit ( ) -> limit ( 0 , 1 ) ; $ results = $ this -> fetchAll ( ) ; return isset ( $ results [ 0 ] ) ? $ results [ 0 ] : null ; } | Fetch only first record as object or return null if there is no records |
42,284 | protected function getFirst ( string $ key , $ default = null ) { return collect ( $ this -> content -> get ( $ key ) ) -> first ( ) ; } | Helper to get the first item within a collection |
42,285 | public function withFeatured ( int $ count = 1 ) { if ( ! $ items = $ this -> get ( 'items' ) ) { $ this -> append ( 'featured' , [ ] ) ; return $ this ; } $ featured = $ items -> shift ( ) ; $ this -> content [ 'items' ] = $ items ; $ this -> append ( 'featured' , [ $ featured ] ) ; return $ this ; } | Moves the first X elements into a separate collection item |
42,286 | public function take ( int $ max = null ) { $ items = $ this -> get ( 'items' ) ; if ( ! isset ( $ max ) ) { $ max = $ items -> count ( ) ; } if ( $ items -> count ( ) >= $ max ) { $ items = $ items -> take ( $ max ) ; } $ this -> content [ 'items' ] = $ items ; return $ this ; } | Limit the number of items returned |
42,287 | public function append ( string $ key , $ value ) { $ this -> content -> put ( $ key , $ value ) ; return $ this ; } | Add new fields to the content |
42,288 | private function prepareFileSelector ( ModelIdInterface $ modelId , Ajax $ ajax = null ) { $ inputProvider = $ this -> itemContainer -> getEnvironment ( ) -> getInputProvider ( ) ; $ propertyName = $ inputProvider -> getParameter ( 'field' ) ; $ information = ( array ) $ GLOBALS [ 'TL_DCA' ] [ $ modelId -> getDataProvi... | Prepare the file selector . |
42,289 | private function prepareValuesForFileSelector ( $ propertyName , ModelIdInterface $ modelId , DcCompat $ combat ) { $ inputProvider = $ this -> itemContainer -> getEnvironment ( ) -> getInputProvider ( ) ; $ fileSelectorValues = [ ] ; foreach ( \ array_filter ( \ explode ( ',' , $ inputProvider -> getParameter ( 'value... | Prepare the values for the file selector . |
42,290 | private function setupItemContainer ( ModelIdInterface $ modelId ) { $ dispatcher = $ GLOBALS [ 'container' ] [ 'event-dispatcher' ] ; $ translator = new TranslatorChain ( ) ; $ translator -> add ( new LangArrayTranslator ( $ dispatcher ) ) ; $ factory = new DcGeneralFactory ( ) ; $ this -> itemContainer = $ factory ->... | Setup the item container . |
42,291 | private function runAjaxRequest ( ) { if ( ! ( $ _POST && Environment :: get ( 'isAjaxRequest' ) ) ) { return null ; } $ ajax = new Ajax ( Input :: post ( 'action' ) ) ; $ ajax -> executePreActions ( ) ; return $ ajax ; } | Run the ajax request if is determine for run . |
42,292 | public function update ( $ event , $ value ) { if ( null === $ value ) { return ; } $ event -> setHtml ( $ value ) ; $ event -> stopPropagation ( ) ; } | Set the HTML code for the button . |
42,293 | private function process ( Action $ action , EnvironmentInterface $ environment ) { $ inputProvider = $ environment -> getInputProvider ( ) ; $ translator = $ environment -> getTranslator ( ) ; $ editInformation = $ GLOBALS [ 'container' ] [ 'dc-general.edit-information' ] ; $ renderInformation = new \ ArrayObject ( ) ... | Process the override all handler . |
42,294 | protected function handleInvalidPropertyValueBag ( PropertyValueBagInterface $ propertyValueBag = null , ModelInterface $ model = null , EnvironmentInterface $ environment ) { @ \ trigger_error ( 'This function where remove in 3.0. ' . __CLASS__ . '::' . __FUNCTION__ , E_USER_DEPRECATED ) ; if ( ( null === $ propertyVa... | Handle invalid property value bag . |
42,295 | private function handleOverrideCollection ( Action $ action , \ ArrayObject $ renderInformation , PropertyValueBagInterface $ propertyValues = null , EnvironmentInterface $ environment ) { if ( ! $ propertyValues ) { return ; } $ revertCollection = $ this -> getCollectionFromSession ( $ action , $ environment ) ; $ thi... | Handle override of model collection . |
42,296 | private function getOverrideProperties ( Action $ action , EnvironmentInterface $ environment ) { $ selectProperties = $ this -> getPropertiesFromSession ( $ action , $ environment ) ; $ properties = [ ] ; foreach ( \ array_keys ( $ selectProperties ) as $ propertyName ) { $ properties [ $ propertyName ] = $ selectProp... | Return the select properties from the session . |
42,297 | private function renderFieldSets ( Action $ action , \ ArrayObject $ renderInformation , PropertyValueBagInterface $ propertyValues = null , EnvironmentInterface $ environment ) { $ properties = $ this -> getOverrideProperties ( $ action , $ environment ) ; $ model = $ this -> getIntersectionModel ( $ action , $ enviro... | Render the field sets . |
42,298 | private function getModelFromWidget ( Widget $ widget ) { if ( $ widget -> dataContainer ) { return $ widget -> dataContainer -> getModel ( ) ; } return $ widget -> getModel ( ) ; } | Get the model from the widget . |
42,299 | private function getPropertyValueErrors ( PropertyValueBagInterface $ propertyValueBag , $ propertyName , array $ errors ) { if ( ( null !== $ propertyValueBag ) && $ propertyValueBag -> hasPropertyValue ( $ propertyName ) && $ propertyValueBag -> isPropertyValueInvalid ( $ propertyName ) ) { $ errors = \ array_merge (... | Get the merged property value errors . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.