idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
42,100 | public static function startsWith ( string $ yourString , string $ startsWith , string $ encoding = null ) : bool { return mb_substr ( $ yourString , 0 , mb_strlen ( $ startsWith , $ encoding ?? Application :: getEncoding ( ) ) , $ encoding ?? Application :: getEncoding ( ) ) === $ startsWith ; } | Check if string starts with given string - it supports UTF - 8 but it s case sensitive |
42,101 | public static function endsWith ( string $ yourString , string $ endsWith , string $ encoding = null ) : bool { return mb_substr ( $ yourString , 0 - mb_strlen ( $ endsWith , $ encoding ?? Application :: getEncoding ( ) ) , null , $ encoding ?? Application :: getEncoding ( ) ) === $ endsWith ; } | Check if string ends with given string - it supports UTF - 8 but it s case sensitive |
42,102 | public static function camelCase ( string $ string , array $ noStrip = null , bool $ lowerCaseFirstLetter = null ) { $ string = preg_replace ( '/[^a-z0-9' . implode ( '' , $ noStrip ?? [ ] ) . ']+/i' , ' ' , $ string ) ; $ string = trim ( $ string ) ; $ string = ucwords ( $ string ) ; $ string = str_replace ( ' ' , '' ... | Make a camel case string out of given string |
42,103 | public function dump ( ) : void { $ dump = $ this -> config [ 'dump' ] ?? [ ] ; if ( is_array ( $ dump ) && count ( $ dump ) > 0 ) { $ dump = array_flip ( $ dump ) ; $ url = isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) ? ( $ _SERVER [ 'REQUEST_METHOD' ] . '=' . Application :: getCurrentURL ( ) ) : ( 'CLI=' . Application ::... | Dump some common stuff into log according to config |
42,104 | public static function getServerLoad ( ) : string { if ( function_exists ( 'sys_getloadavg' ) ) { $ a = sys_getloadavg ( ) ; foreach ( $ a as $ k => $ v ) { $ a [ $ k ] = round ( $ v , 2 ) ; } return implode ( ', ' , $ a ) ; } else { $ os = strtolower ( PHP_OS ) ; if ( strpos ( $ os , 'win' ) === false ) { if ( @ file_... | Get server load ... if linux returns all three averages if windows returns average load for all CPU cores |
42,105 | public static function signatureArray ( ) : array { $ numberOfIncludedFiles = count ( get_included_files ( ) ) ; $ serverIP = static :: ip ( ) ; $ domain = Application :: getDomain ( ) ; $ signature = [ ] ; $ signature [ ] = "server: {$serverIP} ({$domain})" ; if ( PHP_SAPI != 'cli' ) { $ method = Request :: method ( )... | Get the server s signature in this moment with all useful debug data |
42,106 | final public function setData ( array $ values ) : Model { if ( ! is_array ( $ this -> data ) ) { $ this -> data = $ values ; } else { $ this -> data = array_merge ( $ this -> data , $ values ) ; } return $ this ; } | Set the array of values |
42,107 | public static function create ( array $ data ) : Model { $ insert = new Insert ( static :: getTableName ( ) , $ data , static :: getAdapterConnection ( ) ) ; $ insert -> exec ( ) ; if ( static :: $ autoIncrement ) { if ( is_string ( static :: $ primaryKey ) && isset ( $ data [ static :: $ primaryKey ] ) ) { } else { $ ... | Insert the record in database with given array of data |
42,108 | public function reload ( ) : Model { $ pk = static :: $ primaryKey ; $ condition = null ; if ( is_array ( $ pk ) ) { if ( count ( $ pk ) === 0 ) { $ class = get_class ( $ this ) ; throw new Exception ( "Can not reload model of {$class}, primary key definition is incorrect, it can't be empty array" ) ; } $ select = [ ] ... | Reloads this model with the latest data from database . It s using primary key to fetch the data . If primary key contains multiple columns then all columns must be present in the model in order to refresh the data successfully . |
42,109 | public static function getLastInsertId ( string $ keyName = null ) { if ( static :: $ autoIncrement ) { if ( is_string ( static :: $ autoIncrement ) ) { $ keyName = static :: $ autoIncrement ; } else if ( is_string ( static :: $ primaryKey ) ) { $ keyName = static :: getTableName ( ) . '_' . static :: $ primaryKey . '_... | If you statically created new record in database to the table with auto incrementing field then you can use this static method to get the generated primary key |
42,110 | public static function increment ( string $ field , $ where , int $ howMuch = 1 ) : int { $ update = new Update ( static :: getTableName ( ) , null , static :: getAdapterConnection ( ) ) ; $ update -> increment ( $ field , $ howMuch ) ; if ( $ where instanceof Where ) { $ update -> where ( $ where ) ; } else if ( is_ar... | Increment one numeric field in table on the row identified by primary key . You can use this only if your primary key is just one field . |
42,111 | public static function delete ( $ where ) : int { $ delete = new Delete ( static :: getTableName ( ) , static :: getAdapterConnection ( ) ) ; if ( $ where instanceof Where ) { $ delete -> where ( $ where ) ; } else if ( is_array ( $ where ) ) { foreach ( $ where as $ field => $ value ) { $ delete -> where ( $ field , $... | Delete one or more records from the table defined in this model . If you pass array then array must contain field names and values that will be used in WHERE statement . If you pass primitive value method will treat that as passed value for primary key field . |
42,112 | public static function fetch ( $ where , array $ fields = null , string $ orderField = null , string $ orderDirection = null , int $ limit = null , int $ start = null ) : array { $ select = static :: select ( ) ; if ( $ fields !== null ) { $ select -> fields ( $ fields ) ; } if ( $ where instanceof Where ) { $ select -... | Fetch the array of initialized records from database |
42,113 | public static function fetchWithKey ( string $ key , $ where , array $ fields = null , string $ orderField = null , string $ orderDirection = null , int $ limit = null , int $ start = null ) : array { $ data = [ ] ; foreach ( static :: fetch ( $ where , $ fields , $ orderField , $ orderDirection , $ limit , $ start ) a... | Fetch the array of initialized records from database where key in the returned array is something from the results |
42,114 | public static function all ( string $ orderField = null , string $ orderDirection = null ) : array { $ select = static :: select ( ) ; if ( $ orderField !== null ) { $ select -> orderBy ( $ orderField , $ orderDirection ) ; } $ data = [ ] ; foreach ( $ select -> fetchAll ( ) as $ r ) { $ data [ ] = new static ( $ r ) ;... | Fetch all records from database |
42,115 | public static function isUnique ( string $ field , $ value , $ exceptionValue = null , string $ exceptionField = null ) : bool { $ select = static :: select ( ) ; $ select -> field ( 'COUNT(*)' , 'total' ) -> where ( $ field , $ value ) ; if ( $ exceptionValue !== null ) { if ( $ exceptionField === null ) { $ exception... | Check if some value exists in database or not . This is useful if you want for an example check if user s e - mail already is in database before you try to insert your data . |
42,116 | public static function count ( $ where = null ) : int { $ select = static :: select ( ) ; if ( $ where !== null ) { if ( $ where instanceof Where ) { $ select -> field ( 'COUNT(*)' , 'total' ) ; $ select -> where ( clone $ where ) ; } else if ( is_array ( $ where ) ) { $ select -> field ( 'COUNT(*)' , 'total' ) ; forea... | Count the records in table according to the parameters |
42,117 | public static function resultSet ( string $ tableAlias = null ) : ResultSet { $ rs = new ResultSet ( static :: getTableName ( ) , $ tableAlias ) ; $ rs -> setModelClass ( get_called_class ( ) ) -> setAdapter ( static :: getAdapterConnection ( ) ) ; return $ rs ; } | Get the ResultSet object of this model |
42,118 | public static function select ( string $ tableAlias = null ) : Select { $ select = new Select ( static :: getTableName ( ) , $ tableAlias ) ; $ select -> setAdapter ( static :: getAdapterConnection ( ) ) ; return $ select ; } | Get the initialized Select object with populated FROM and connection adapter set |
42,119 | public static function read ( string $ path , string $ filter = null ) : array { if ( is_dir ( $ path ) && $ handle = opendir ( $ path ) ) { $ files = [ ] ; if ( substr ( $ path , - 1 ) != '/' ) { $ path .= '/' ; } while ( false !== ( $ entry = readdir ( $ handle ) ) ) { if ( $ entry !== '.' && $ entry !== '..' ) { if ... | Get the list of all files and folders from the given folder |
42,120 | public static function mkdir ( string $ path , $ chmod = null ) : void { if ( ! is_dir ( $ path ) ) { if ( $ chmod === null ) { $ chmod = Application :: getConfig ( 'application' ) -> getArrayItem ( 'filesystem' , 'default_chmod' , 0644 ) ; } if ( ! mkdir ( $ path , $ chmod , true ) ) { throw new FilesystemException ( ... | Create the target directory recursively if needed |
42,121 | public static function rmdirRecursive ( string $ directory ) : void { if ( is_dir ( $ directory ) ) { static :: emptyDirectory ( $ directory ) ; if ( ! rmdir ( $ directory ) ) { throw new FilesystemException ( "Unable to remove directory on path={$directory}" ) ; } } } | Remove directory and content inside recursively |
42,122 | public static function emptyDirectory ( string $ directory ) : void { if ( is_dir ( $ directory ) ) { foreach ( new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ directory , \ FilesystemIterator :: SKIP_DOTS ) , \ RecursiveIteratorIterator :: CHILD_FIRST ) as $ path ) { if ( $ path -> isFile ( ) ) ... | Empty all directory content but do not delete the directory |
42,123 | public function asset ( string $ path , string $ assetSite = null ) : string { if ( strlen ( $ path ) == 0 ) { throw new \ InvalidArgumentException ( 'Expected non-empty string' ) ; } $ pos = strpos ( $ path , '//' ) ; if ( ( $ pos !== false && $ pos < 10 ) || substr ( $ path , 0 , 2 ) == '//' ) { return $ path ; } $ a... | Generate link to the resource file on the same domain |
42,124 | public static function init ( array $ config = null , bool $ reInit = false ) { if ( static :: $ config === null || $ reInit ) { if ( $ config === null ) { $ config = Application :: getConfig ( 'application' ) ; static :: $ config = $ config -> getArrayItem ( 'security' , 'csrf' , [ self :: PARAMETER_NAME => 'csrf' , s... | Initialize CSRF config |
42,125 | public static function generate ( string $ token = null , int $ length = null ) : Token { if ( $ token == null ) { if ( $ length == null ) { $ length = 64 ; } if ( function_exists ( 'openssl_random_pseudo_bytes' ) ) { $ token = bin2hex ( openssl_random_pseudo_bytes ( $ length ) ) ; if ( strlen ( $ token ) > $ length ) ... | Set the CSRF token into current session . |
42,126 | public static function isEnabled ( ) : bool { static :: init ( ) ; if ( array_key_exists ( self :: ENABLED , static :: $ config ) ) { return static :: $ config [ self :: ENABLED ] ?? false ; } return static :: getParameterName ( ) !== null ; } | Is CSRF check enabled in config or not |
42,127 | public static function hasTokenStored ( ) : bool { if ( static :: $ token === null ) { try { static :: $ token = static :: getStoredToken ( ) ; } catch ( SecurityException $ e ) { } } return static :: $ token !== null ; } | Is there CSRF token stored in the session? |
42,128 | public static function getStoredToken ( ) : Token { if ( static :: $ token !== null ) { return static :: $ token ; } $ sessionKeyName = static :: getSessionKeyName ( ) ; if ( $ sessionKeyName === null || strlen ( $ sessionKeyName ) == 0 ) { throw new Exception ( 'Can not get stored CSRF token when session key is not se... | Get currently stored CSRF token from session |
42,129 | public static function hasCookieToken ( ) : bool { $ cookieName = static :: getCookieName ( ) ; if ( $ cookieName === null || strlen ( $ cookieName ) == 0 ) { throw new Exception ( 'Can not check if CSRF token is in cookie when cookie name is not set in CSRF configuration' ) ; } return Cookie :: has ( $ cookieName ) ; ... | Is there a cookie with CSRF token present in this request? |
42,130 | public static function isTokenValid ( string $ token ) : bool { if ( ! static :: hasTokenStored ( ) ) { return false ; } $ storedToken = static :: getStoredToken ( ) ; return $ storedToken -> getToken ( ) === $ token ; } | Check if given CSRF token is valid |
42,131 | public static function getHtmlInputHidden ( ) : string { static :: init ( ) ; if ( ( $ parameterName = static :: getParameterName ( ) ) !== null ) { $ csrfValue = static :: getStoredToken ( ) -> getToken ( ) ; return sprintf ( '<input type="hidden" name="%s" value="%s"/>' , $ parameterName , $ csrfValue ) ; } else { re... | Get prepared HTML input that can be used directly in forms |
42,132 | public function embedCodeFor ( string $ url ) { if ( ! $ parsedUrl = $ this -> embedder -> parseUrl ( $ url ) ) { return null ; } return $ parsedUrl -> getEmbedCode ( ) ; } | Get the embed code for almost any hosted video service simply by peroviding its URL |
42,133 | public static function getMimeByExtension ( string $ extension ) : string { $ extension = strtolower ( $ extension ) ; if ( ! isset ( static :: $ types [ $ extension ] ) ) { throw new HttpException ( "Unknown file extension={$extension}" ) ; } return static :: $ types [ $ extension ] ; } | Get the MIME type by extension |
42,134 | protected function getCountQuery ( ) : Select { if ( $ this -> countQuery instanceof Select ) { return $ this -> countQuery ; } if ( $ this -> searchTerm !== null && $ this -> searchFields === null ) { $ fields = $ this -> getFields ( ) ; $ searchFields = [ ] ; foreach ( $ fields as $ field ) { $ searchFields [ ] = $ f... | Get SELECT query for total count |
42,135 | protected function getFileName ( ) : string { if ( $ this -> generatedFileName === null || Application :: isCli ( ) ) { if ( $ this -> fileNameFn !== null ) { $ this -> generatedFileName = call_user_func ( $ this -> fileNameFn ) ; } else { $ this -> generatedFileName = gmdate ( 'Y-m-d' ) . '.log' ; } } return $ this ->... | Get the name of log file |
42,136 | public function logMessage ( Message $ message ) : void { if ( in_array ( $ message -> getLevel ( ) , $ this -> config [ 'log' ] ) ) { $ fpFile = $ this -> getFileName ( ) ; if ( $ fpFile !== $ this -> fpFile ) { if ( $ this -> fp ) { @ fclose ( $ this -> fp ) ; } if ( $ this -> config [ 'path' ] === null ) { $ path = ... | Actually log message to file |
42,137 | public function getScheme ( ) : string { if ( ! isset ( $ this -> segments [ 'scheme' ] ) ) { throw new UrlException ( 'Unable to get scheme for ' . $ this -> url ) ; } return $ this -> segments [ 'scheme' ] ; } | Get URL s scheme |
42,138 | public function getHost ( ) : string { if ( ! isset ( $ this -> segments [ 'host' ] ) ) { throw new UrlException ( 'Unable to get host for ' . $ this -> url ) ; } return $ this -> segments [ 'host' ] ; } | Get URL s host |
42,139 | public function getPort ( ) : int { if ( ! isset ( $ this -> segments [ 'port' ] ) ) { throw new UrlException ( 'Unable to get port for ' . $ this -> url ) ; } return ( int ) $ this -> segments [ 'port' ] ; } | Get URL s port |
42,140 | public function getUser ( ) : string { if ( ! isset ( $ this -> segments [ 'user' ] ) ) { throw new UrlException ( 'Unable to get user for ' . $ this -> url ) ; } return $ this -> segments [ 'user' ] ; } | Get URL s user |
42,141 | public function getPass ( ) : string { if ( ! isset ( $ this -> segments [ 'pass' ] ) ) { throw new UrlException ( 'Unable to get pass for ' . $ this -> url ) ; } return $ this -> segments [ 'pass' ] ; } | Get URL s pass |
42,142 | public function close ( ) : void { if ( $ this -> pdo instanceof PDO ) { if ( $ this -> stmt !== null ) { $ this -> stmt -> closeCursor ( ) ; } $ this -> stmt = null ; $ this -> pdo = null ; } else if ( $ this -> pdo === null ) { } else { throw new AdapterException ( 'Unable to close database connection when PDO handle... | Close connection to database if it was opened |
42,143 | public static function isBoolTrue ( ? string $ input ) : ? bool { if ( $ input === null ) { return null ; } $ input = strtolower ( $ input ) ; if ( $ input === 'true' || $ input === '1' ) { return true ; } else if ( $ input === 'false' || $ input === '0' || $ input === '' ) { return false ; } throw new LanguageExceptio... | Helper for Postgres determining if there s a boolean value in database . This is useful because PDO on Postgres returns string for boolean values . |
42,144 | public function render ( $ content = null ) { if ( method_exists ( $ this , 'seed' ) ) { $ this -> append ( 'seed' , $ this -> seed ( ) -> all ( ) ) ; } return view ( "{$this->namespace}{$this->template}" , $ content ? : $ this -> content ) ; } | Render the page content into the relevant template . Can pass in optional replacement content to render instead of the default . |
42,145 | public function raw ( bool $ collapsed = false ) : \ Illuminate \ Support \ Collection { if ( $ collapsed ) { return $ this -> content -> collapse ( ) ; } return $ this -> content ; } | Return the raw content retrieved from the api for out - of - class processing . |
42,146 | public function setCreatedAtDateTime ( ? DateTime $ createdAt ) { $ this -> created_at = $ createdAt === null ? null : $ createdAt -> format ( 'Y-m-d H:i:s' ) ; return $ this ; } | Set the created at date time by passing instance of createdAt |
42,147 | public static function isEnabled ( string $ adapter ) : bool { $ config = static :: getConfig ( ) ; if ( ! $ config -> has ( $ adapter ) ) { return false ; } $ enabled = $ config -> getArrayItem ( $ adapter , 'enabled' ) ; if ( $ enabled === null ) { return false ; } return ( bool ) $ enabled ; } | You can check if configure mail adapter is enabled or not . |
42,148 | public function logMessage ( Message $ message ) : void { if ( in_array ( $ message -> getLevel ( ) , $ this -> config [ 'log' ] ) ) { if ( $ this -> config [ 'send_immediately' ] ) { call_user_func ( $ this -> config [ 'exec' ] , $ message ) ; } else { $ this -> messages [ ] = $ message ; if ( count ( $ this -> messag... | Actually execute something with our messages |
42,149 | public static function registerType ( string $ type , string $ class ) : void { if ( isset ( static :: $ types [ $ type ] ) ) { throw new ConfigException ( "Can not register database type={$type} when it was already registered" ) ; } static :: $ types [ $ type ] = $ class ; } | Register another database type |
42,150 | public static function hasAdapter ( string $ name ) : bool { return isset ( static :: $ adapters [ $ name ] ) && static :: $ adapters [ $ name ] instanceof AbstractAdapter ; } | Is there already adapter with given name |
42,151 | public static function removeAdapter ( string $ keyIdentifier ) : void { if ( isset ( static :: $ adapters [ $ keyIdentifier ] ) ) { static :: $ adapters [ $ keyIdentifier ] -> close ( ) ; unset ( static :: $ adapters [ $ keyIdentifier ] ) ; } } | Delete registered adapter . This action will also remove connection if it was connected to database |
42,152 | public static function select ( string $ table = null , string $ tableAlias = null ) : Query \ Select { return static :: getAdapter ( ) -> select ( $ table , $ tableAlias ) ; } | Get the SELECT query instance on default adapter |
42,153 | public static function insert ( string $ table = null , array $ rowValues = null ) : Query \ Insert { return static :: getAdapter ( ) -> insert ( $ table , $ rowValues ) ; } | Get the INSERT query instance on default adapter |
42,154 | public static function update ( string $ table = null , array $ values = null ) : Query \ Update { return static :: getAdapter ( ) -> update ( $ table , $ values ) ; } | Get the UPDATE query instance on default adapter |
42,155 | public static function create ( string $ content , string $ asName , string $ contentType = null ) : ContentDownload { $ self = new static ( $ content ) ; $ self -> setAsName ( $ asName ) ; if ( $ contentType !== null ) { $ self -> setContentType ( $ contentType ) ; } return $ self ; } | Shorthand for creating this class pass all required parameters at once |
42,156 | public static function set ( string $ key , $ value , int $ seconds = null ) : void { static :: getAdapter ( ) -> set ( $ key , $ value , $ seconds ) ; } | Set the value to default cache engine and overwrite if keys already exists |
42,157 | public static function setMulti ( array $ keyValuePairs , int $ seconds = null ) : void { static :: getAdapter ( ) -> setMulti ( $ keyValuePairs , $ seconds ) ; } | Set multiple values to default cache engine and overwrite if keys already exists |
42,158 | public static function getOrSet ( string $ key , \ Closure $ functionOnSet , int $ seconds = null ) { return static :: getAdapter ( ) -> getOrSet ( $ key , $ functionOnSet , $ seconds ) ; } | Get or set the key s value |
42,159 | public static function increment ( string $ key , int $ howMuch = 1 ) : int { return static :: getAdapter ( ) -> increment ( $ key , $ howMuch ) ; } | Increment value in cache |
42,160 | public static function decrement ( string $ key , int $ howMuch = 1 ) : int { return static :: getAdapter ( ) -> decrement ( $ key , $ howMuch ) ; } | Decrement value in cache |
42,161 | public function setQuery ( string $ query , $ bindings = null ) : Query { $ this -> query = $ query ; if ( $ bindings === null ) { $ this -> bindings = new Bindings ( ) ; } else if ( is_array ( $ bindings ) ) { $ this -> bindings = new Bindings ( ) ; $ this -> bindings -> setFromArray ( $ bindings ) ; } else if ( $ bin... | Set query that will be executed |
42,162 | public function getSQL ( ) : string { if ( $ this -> query === null ) { throw new Exception ( 'Query wasn\'t set' ) ; } if ( is_object ( $ this -> query ) ) { if ( method_exists ( $ this -> query , '__toString' ) ) { return $ this -> query -> __toString ( ) ; } } else { return trim ( $ this -> query ) ; } $ className =... | Get the SQL query without bindings |
42,163 | public function fetchAllObj ( string $ class = null ) : array { if ( ! $ this -> wasExecuted ( ) ) { $ this -> exec ( ) ; } if ( $ class === null ) { return $ this -> getAdapter ( ) -> getStatement ( ) -> fetchAll ( \ PDO :: FETCH_OBJ ) ; } else { $ objectInstances = [ ] ; foreach ( $ this -> fetchAll ( ) as $ r ) { $ ... | Fetch all results from this query and get array of stdClass instances or your custom class instances |
42,164 | public static function getKeyIndex ( ) : int { if ( self :: $ keyIndex == PHP_INT_MAX ) { self :: $ keyIndex = 0 ; } else { self :: $ keyIndex ++ ; } return self :: $ keyIndex ; } | Get next key index |
42,165 | public function debug ( bool $ oneLine = false ) : string { $ query = $ this -> getSQL ( ) ; foreach ( $ this -> getBindings ( ) -> getBindings ( ) as $ parameter => $ bind ) { if ( $ parameter [ 0 ] == ':' ) { $ parameter = substr ( $ parameter , 1 ) ; } $ value = $ bind -> getValue ( ) ; $ type = gettype ( $ value ) ... | Return some debug information about the query you built |
42,166 | public function addRows ( array $ rows ) : Insert { foreach ( $ rows as $ index => $ row ) { $ this -> add ( $ row ) ; } return $ this ; } | Add multiple rows into insert |
42,167 | public function getQuery ( ) : Query { $ bindings = new Bindings ( ) ; if ( count ( $ this -> data ) == 0 && $ this -> select === null ) { throw new Exception ( 'Can not execute Insert query, no records to insert' ) ; } if ( $ this -> table === null ) { throw new Exception ( 'Can not execute Insert query when table nam... | Get the Query string |
42,168 | protected static function parseArgvIntoParameters ( ) : void { if ( static :: $ parameters === null ) { static :: $ parameters = [ ] ; $ argv = static :: getArgv ( ) ; array_shift ( $ argv ) ; $ sizeof = count ( $ argv ) ; for ( $ i = 0 ; $ i < $ sizeof ; $ i ++ ) { $ p = $ argv [ $ i ] ; if ( substr ( $ p , 0 , 2 ) ==... | Parse the script arguments into parameters ready for later use |
42,169 | public function setUpdatedAtDateTime ( ? DateTime $ updatedAt ) : void { $ this -> updated_at = $ updatedAt === null ? null : $ updatedAt -> format ( 'Y-m-d H:i:s' ) ; } | Set the updated at date time by passing instance of updatedAt |
42,170 | private function getDbData ( $ sessionid ) : ? stdClass { $ r = null ; try { if ( $ this -> disableLog ) { Log :: temporaryDisable ( 'sql' ) ; } $ r = $ this -> getAdapter ( ) -> select ( $ this -> getTableName ( ) ) -> field ( 'time' ) -> field ( 'data' ) -> where ( 'id' , $ sessionid ) -> fetchFirstObj ( ) ; } catch ... | Get the session data from database |
42,171 | public function set ( string $ field , $ value ) : Update { $ this -> what [ $ field ] = $ value ; return $ this ; } | Set field to be updated |
42,172 | public function increment ( string $ field , int $ howMuch = 1 ) : Update { return $ this -> set ( $ field , new Expr ( "{$field} + {$howMuch}" ) ) ; } | Increment numeric field s value in database |
42,173 | public function getQuery ( ) : Query { if ( count ( $ this -> what ) == 0 ) { throw new Exception ( 'Can not build UPDATE query, SET is not defined' ) ; } if ( $ this -> table === null ) { throw new Exception ( 'Can not build UPDATE query when table name is not set' ) ; } $ sql = "UPDATE {$this->table}\nSET\n" ; foreac... | Get the query |
42,174 | public function rowCount ( ) : int { if ( ! $ this -> wasExecuted ( ) ) { $ this -> exec ( ) ; } return $ this -> getAdapter ( ) -> getStatement ( ) -> rowCount ( ) ; } | Get how many rows was deleted |
42,175 | public static function get ( string $ key ) : ? string { if ( isset ( $ _COOKIE ) && array_key_exists ( $ key , $ _COOKIE ) ) { return Crypt :: decrypt ( $ _COOKIE [ $ key ] ) ; } return null ; } | Get the value from encrypted cookie value |
42,176 | public static function rawGet ( string $ key ) : ? string { if ( isset ( $ _COOKIE ) && array_key_exists ( $ key , $ _COOKIE ) ) { return $ _COOKIE [ $ key ] ; } return null ; } | Get the raw value from cookie without decrypting data |
42,177 | public static function set ( string $ name , string $ value , ? int $ expire = null , ? string $ path = null , ? string $ domain = null , ? bool $ secure = null , ? bool $ httpOnly = null ) : string { $ encryptedValue = Crypt :: encrypt ( $ value ) ; setcookie ( $ name , $ encryptedValue , $ expire ?? 0 , $ path ?? '/'... | Set the cookie to encrypted value |
42,178 | public static function rawSet ( string $ name , string $ value , ? int $ expire = null , ? string $ path = null , ? string $ domain = null , ? bool $ secure = null , ? bool $ httpOnly = null ) : string { setcookie ( $ name , $ value , $ expire ?? 0 , $ path ?? '/' , $ domain ?? '' , $ secure ?? false , $ httpOnly ?? fa... | Set the raw cookie value without encryption |
42,179 | public function bind ( string $ field , $ value , string $ prefix = '' ) : string { if ( $ this -> bindings === null ) { $ this -> bindings = new Bindings ( ) ; } $ parameter = $ prefix . $ field ; $ bindName = $ this -> bindings -> makeAndSet ( $ parameter , $ value ) ; return $ bindName ; } | Bind some value for PDO |
42,180 | private function addCondition ( string $ link , $ field , $ value , string $ operator ) { $ this -> where [ ] = [ 'link' => $ link , 'field' => $ field , 'operator' => $ operator , 'value' => $ value ] ; return $ this ; } | Add condition to where statements |
42,181 | public function where ( $ field , $ valueOrOperator = null , $ value = null ) { if ( is_string ( $ field ) && $ valueOrOperator === null ) { throw new \ InvalidArgumentException ( 'Invalid second argument; argument must not be null in case when first argument is string' ) ; } return $ this -> addCondition ( 'AND' , $ f... | Add AND where statement |
42,182 | public function whereBetween ( string $ field , $ value1 , $ value2 ) { return $ this -> addCondition ( 'AND' , $ field , [ $ value1 , $ value2 ] , 'BETWEEN' ) ; } | Add WHERE field is BETWEEN two values |
42,183 | protected function getWhereSql ( array $ whereArray = null , $ cnt = 0 ) : string { if ( $ this -> bindings === null ) { $ this -> bindings = new Bindings ( ) ; } $ query = '' ; if ( $ whereArray === null ) { $ whereArray = $ this -> where ; } foreach ( $ whereArray as $ index => $ where ) { if ( $ index > 0 ) { $ quer... | Get where statement appended to query |
42,184 | public function getUrl ( ) : string { $ url = $ this -> url ; if ( $ this -> getMethod ( ) == self :: GET ) { if ( count ( $ this -> params ) > 0 ) { $ params = http_build_query ( $ this -> getParams ( ) ) ; if ( strpos ( '?' , $ url ) !== false && substr ( $ url , - 1 ) != '?' ) { $ url .= $ params ; } else { $ url .=... | Get the URL on which the request will be fired |
42,185 | public function setParam ( string $ name , $ value ) : Request { if ( is_object ( $ value ) ) { if ( property_exists ( $ value , '__toString' ) ) { $ value = $ value -> __toString ( ) ; } else { $ class = get_class ( $ value ) ; throw new HttpException ( "Can not set param={$name} when instance of {$class} can't be con... | Set the request parameter |
42,186 | protected function getCurlOptions ( ) : array { $ options = [ ] ; $ options [ CURLOPT_RETURNTRANSFER ] = true ; $ options [ CURLOPT_HEADER ] = true ; foreach ( $ this -> getOptions ( ) as $ option => $ value ) { $ options [ $ option ] = $ value ; } switch ( $ this -> getMethod ( ) ) { case self :: POST : if ( ! $ this ... | Get the prepared curl options for the HTTP request |
42,187 | public static function get ( string $ url , array $ params = null , array $ headers = null ) { return static :: quickRequest ( $ url , self :: GET , $ params , $ headers ) ; } | Make quick GET request |
42,188 | public static function post ( string $ url , array $ params = null , array $ headers = null ) { return static :: quickRequest ( $ url , self :: POST , $ params , $ headers ) ; } | Make quick POST request |
42,189 | public static function put ( string $ url , array $ params = null , array $ headers = null ) { return static :: quickRequest ( $ url , self :: PUT , $ params , $ headers ) ; } | Make quick PUT request |
42,190 | public static function delete ( string $ url , array $ params = null , array $ headers = null ) { return static :: quickRequest ( $ url , self :: DELETE , $ params , $ headers ) ; } | Make quick DELETE request |
42,191 | public function debug ( ) { $ constants = get_defined_constants ( true ) ; $ flipped = array_flip ( $ constants [ 'curl' ] ) ; $ curlOpts = preg_grep ( '/^CURLOPT_/' , $ flipped ) ; $ curlInfo = preg_grep ( '/^CURLINFO_/' , $ flipped ) ; $ options = [ ] ; foreach ( $ this -> getCurlOptions ( ) as $ const => $ value ) {... | Print settings and all values useful for troubleshooting |
42,192 | protected function getViewPath ( string $ view ) : string { if ( DS != '/' ) { $ view = str_replace ( '/' , DS , $ view ) ; } $ pos = strpos ( $ view , ':' ) ; if ( $ pos === false ) { return $ this -> viewPath . $ view . '.phtml' ; } else { return dirname ( substr ( $ this -> viewPath , 0 , - 1 ) ) . DS . 'modules' . ... | Get the path of the view |
42,193 | public function setViewPath ( string $ basePath ) : self { $ this -> viewPath = $ basePath ; if ( substr ( $ this -> viewPath , - 1 ) != '/' ) { $ this -> viewPath .= '/' ; } return $ this ; } | Set custom view path where views are stored . Any additional use within this instance will be relative to the path given here |
42,194 | public static function exists ( string $ view ) : bool { $ pos = strpos ( $ view , ':' ) ; if ( $ pos === false ) { $ path = Application :: getViewPath ( ) . $ view . '.phtml' ; } else { $ path = dirname ( substr ( Application :: getViewPath ( ) , 0 , - 1 ) ) . DS . 'modules' . DS . substr ( $ view , 0 , $ pos ) . DS .... | Does view exists or not in main view path |
42,195 | public function render ( string $ view , array $ with = null ) : string { $ path = $ this -> getViewPath ( $ view ) ; if ( ! file_exists ( $ path ) ) { throw new ResponseException ( "View ({$view}) not found on path={$path}" ) ; } if ( $ with !== null && count ( $ with ) > 0 ) { foreach ( $ with as $ variableName => $ ... | Render some other view file inside of parent view file |
42,196 | public function renderViewIf ( string $ view , array $ with = null ) : string { if ( $ this -> exists ( $ view ) ) { return $ this -> render ( $ view , $ with ) ; } else { return '' ; } } | Render view if exists on filesystem - if it doesn t exists it won t throw any error |
42,197 | public function renderViewInKeyIf ( string $ key , array $ with = null ) : string { if ( ! $ this -> has ( $ key ) ) { return '' ; } $ view = $ this -> $ key ; if ( static :: exists ( $ view ) ) { return $ this -> render ( $ view , $ with ) ; } else { return '' ; } } | Render view from key variable if exists - if it doesn t exists it won t throw any error |
42,198 | public function flush ( ) : void { $ this -> prepareFlush ( ) ; $ this -> runBeforeFlush ( ) ; $ path = $ this -> getViewPath ( $ this -> view ) ; if ( ! file_exists ( $ path ) ) { throw new ResponseException ( "View ({$this->view}) not found on path={$path}" ) ; } ob_start ( null , 0 , PHP_OUTPUT_HANDLER_CLEANABLE | P... | This method is called by framework but in some cases you ll want to call it by yourself . |
42,199 | public function getOutput ( ) : string { $ this -> prepareFlush ( ) ; $ path = $ this -> getViewPath ( $ this -> view ) ; if ( ! file_exists ( $ path ) ) { throw new ResponseException ( "View ({$this->view}) not found on path={$path}" ) ; } ob_start ( null , 0 , PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHAB... | Get the rendered view code . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.