idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
38,100
public static function create ( array $ columns = [ ] , bool $ raw = false , bool $ whitelist = true ) { $ model = new static ( $ columns , $ raw , $ whitelist ) ; $ model -> save ( ) ; return $ model ; }
Creates a new record and returns the model .
38,101
protected function hasOne ( string $ model , ? string $ foreignKey = null ) : HasOne { $ related = new $ model ; return new HasOne ( $ related -> getConnection ( ) , $ this , $ related , $ foreignKey ) ; }
Returns a HasOne relation .
38,102
protected function hasOnePolymorphic ( string $ model , string $ polymorphicType ) : HasOnePolymorphic { $ related = new $ model ; return new HasOnePolymorphic ( $ related -> getConnection ( ) , $ this , $ related , $ polymorphicType ) ; }
Returns a HasOnePolymorphic relation .
38,103
protected function hasMany ( string $ model , ? string $ foreignKey = null ) : HasMany { $ related = new $ model ; return new HasMany ( $ related -> getConnection ( ) , $ this , $ related , $ foreignKey ) ; }
Returns a HasMany relation .
38,104
protected function hasManyPolymorphic ( string $ model , string $ polymorphicType ) : HasManyPolymorphic { $ related = new $ model ; return new HasManyPolymorphic ( $ related -> getConnection ( ) , $ this , $ related , $ polymorphicType ) ; }
Returns a HasManyPolymorphic relation .
38,105
protected function manyToMany ( string $ model , ? string $ foreignKey = null , ? string $ junctionTable = null , ? string $ junctionKey = null ) : ManyToMany { $ related = new $ model ; return new ManyToMany ( $ related -> getConnection ( ) , $ this , $ related , $ foreignKey , $ junctionTable , $ junctionKey ) ; }
Returns a ManyToMany relation .
38,106
protected function belongsTo ( string $ model , ? string $ foreignKey = null ) : BelongsTo { $ related = new $ model ; return new BelongsTo ( $ related -> getConnection ( ) , $ this , $ related , $ foreignKey ) ; }
Returns a BelongsTo relation .
38,107
protected function belongsToPolymorphic ( string $ model , string $ polymorphicType ) : BelongsToPolymorphic { $ related = new $ model ; return new BelongsToPolymorphic ( $ related -> getConnection ( ) , $ this , $ related , $ polymorphicType ) ; }
Returns a BelongsToPolymorphic relation .
38,108
public function getModified ( ) : array { $ modified = [ ] ; foreach ( $ this -> columns as $ key => $ value ) { if ( ! array_key_exists ( $ key , $ this -> original ) || $ this -> original [ $ key ] !== $ value ) { $ modified [ $ key ] = $ value ; } } return $ modified ; }
Returns the modified column values of the record .
38,109
protected function insertRecord ( Query $ query ) : void { if ( $ this -> primaryKeyType === static :: PRIMARY_KEY_TYPE_INCREMENTING ) { $ this -> columns [ $ this -> primaryKey ] = $ query -> insertAndGetId ( $ this -> columns , $ this -> primaryKey ) ; } else { switch ( $ this -> primaryKeyType ) { case static :: PRIMARY_KEY_TYPE_UUID : $ this -> columns [ $ this -> primaryKey ] = UUID :: v4 ( ) ; break ; case static :: PRIMARY_KEY_TYPE_CUSTOM : $ this -> columns [ $ this -> primaryKey ] = $ this -> generatePrimaryKey ( ) ; break ; } $ query -> insert ( $ this -> columns ) ; } }
Inserts a new record into the database .
38,110
public function save ( ) : bool { $ success = true ; if ( ! $ this -> isPersisted ) { $ this -> insertRecord ( $ this -> builder ( ) ) ; $ this -> isPersisted = true ; } elseif ( $ this -> isModified ( ) ) { $ success = $ this -> updateRecord ( $ this -> builder ( ) ) ; } if ( $ success ) { $ this -> synchronize ( ) ; } return $ success ; }
Saves the record to the database .
38,111
public function protect ( $ column ) { if ( $ column === false ) { $ this -> protected = [ ] ; } else { $ this -> protected = array_unique ( array_merge ( $ this -> protected , ( array ) $ column ) ) ; } return $ this ; }
Excludes the chosen columns and relations from array and json representations of the record . You expose all fields by passing FALSE .
38,112
public function expose ( $ column ) { if ( $ column === true ) { $ this -> protected = [ ] ; } else { $ this -> protected = array_diff ( $ this -> protected , ( array ) $ column ) ; } return $ this ; }
Exposes the chosen columns and relations in the array and json representations of the record . You can expose all fields by passing TRUE .
38,113
public function toArray ( ) : array { $ columns = $ this -> columns ; if ( ! empty ( $ this -> protected ) ) { $ columns = array_diff_key ( $ columns , array_flip ( $ this -> protected ) ) ; } foreach ( $ columns as $ name => $ value ) { $ value = $ this -> getColumnValue ( $ name ) ; if ( $ value instanceof DateTimeInterface ) { $ value = $ value -> format ( $ this -> dateOutputFormat ) ; } $ columns [ $ name ] = $ value ; } foreach ( $ this -> related as $ relation => $ related ) { if ( in_array ( $ relation , $ this -> protected ) ) { continue ; } $ columns += [ $ relation => ( $ related === false ? $ related : $ related -> toArray ( ) ) ] ; } return $ columns ; }
Returns an array representation of the record .
38,114
public function validate ( string $ string ) { $ validated = mb_substr ( $ string , static :: MAC_LENGTH , null , '8bit' ) ; if ( hash_equals ( $ this -> getSignature ( $ validated ) , mb_substr ( $ string , 0 , static :: MAC_LENGTH , '8bit' ) ) ) { return $ validated ; } return false ; }
Returns the original string if the signature is valid or FALSE if not .
38,115
public function escapeHTML ( ? string $ string , string $ charset , bool $ doubleEncode = true ) : string { return htmlspecialchars ( $ string , ENT_QUOTES , $ charset , $ doubleEncode ) ; }
Returns a string that has been escaped for a HTML body context .
38,116
protected function attributeEscaper ( array $ matches ) : string { $ chr = $ matches [ 0 ] ; $ ord = ord ( $ chr ) ; if ( ( $ ord <= 0x1f && $ chr !== "\t" && $ chr !== "\n" && $ chr !== "\r" ) || ( $ ord >= 0x7f && $ ord <= 0x9f ) ) { return '&#xFFFD;' ; } if ( strlen ( $ chr ) > 1 ) { $ chr = mb_convert_encoding ( $ chr , 'UTF-16BE' , 'UTF-8' ) ; } $ hex = bin2hex ( $ chr ) ; $ ord = hexdec ( $ hex ) ; if ( isset ( $ this -> htmlNamedEntityMap [ $ ord ] ) ) { return '&' . $ this -> htmlNamedEntityMap [ $ ord ] . ';' ; } if ( $ ord > 255 ) { return sprintf ( '&#x%04X;' , $ ord ) ; } return sprintf ( '&#x%02X;' , $ ord ) ; }
Escapes characters for use in a HTML attribute context .
38,117
public function escapeAttribute ( ? string $ string , string $ charset ) : string { if ( $ charset !== 'UTF-8' ) { $ string = mb_convert_encoding ( $ string , 'UTF-8' , $ charset ) ; } $ string = preg_replace_callback ( '/[^a-z0-9,\.\-_]/iSu' , [ $ this , 'attributeEscaper' ] , $ string ) ; if ( $ charset !== 'UTF-8' ) { $ string = mb_convert_encoding ( $ string , $ charset , 'UTF-8' ) ; } return $ string ; }
Returns a string that has been escaped for a HTML attribute context .
38,118
protected function cssEscaper ( array $ matches ) : string { $ chr = $ matches [ 0 ] ; if ( strlen ( $ chr ) === 1 ) { $ ord = ord ( $ chr ) ; } else { $ chr = mb_convert_encoding ( $ chr , 'UTF-16BE' , 'UTF-8' ) ; $ ord = hexdec ( bin2hex ( $ chr ) ) ; } return sprintf ( '\\%X ' , $ ord ) ; }
Escapes characters for use in a CSS context .
38,119
public function escapeCSS ( ? string $ string , string $ charset ) : string { if ( $ string === '' || ctype_digit ( $ string ) ) { return $ string ; } if ( $ charset !== 'UTF-8' ) { $ string = mb_convert_encoding ( $ string , 'UTF-8' , $ charset ) ; } $ string = preg_replace_callback ( '/[^a-z0-9]/iSu' , [ $ this , 'cssEscaper' ] , $ string ) ; if ( $ charset !== 'UTF-8' ) { $ string = mb_convert_encoding ( $ string , $ charset , 'UTF-8' ) ; } return $ string ; }
Returns a string that has been escaped for a CSS context .
38,120
protected function javascriptEscaper ( array $ matches ) : string { $ chr = $ matches [ 0 ] ; if ( strlen ( $ chr ) === 1 ) { return sprintf ( '\\x%02X' , ord ( $ chr ) ) ; } $ chr = mb_convert_encoding ( $ chr , 'UTF-16BE' , 'UTF-8' ) ; return sprintf ( '\\u%04s' , strtoupper ( bin2hex ( $ chr ) ) ) ; }
Escapes characters for use in a Javascript context .
38,121
public function escapeJavascript ( ? string $ string , string $ charset ) : string { if ( $ charset !== 'UTF-8' ) { $ string = mb_convert_encoding ( $ string , 'UTF-8' , $ charset ) ; } $ string = preg_replace_callback ( '/[^a-z0-9,\._]/iSu' , [ $ this , 'javascriptEscaper' ] , $ string ) ; if ( $ charset !== 'UTF-8' ) { $ string = mb_convert_encoding ( $ string , $ charset , 'UTF-8' ) ; } return $ string ; }
Returns a string that has been escaped for a Javascript context .
38,122
protected function parseBody ( $ rawBody , $ contentType ) : array { if ( $ contentType === 'application/x-www-form-urlencoded' ) { $ parsed = [ ] ; parse_str ( $ rawBody , $ parsed ) ; return $ parsed ; } elseif ( $ contentType === 'application/json' || $ contentType === 'text/json' || strpos ( $ contentType , '+json' ) !== false ) { return json_decode ( $ rawBody , true ) ?? [ ] ; } return [ ] ; }
Converts the request body into an associative array .
38,123
protected function registerAdapterInstance ( AdapterInterface $ adapter ) : string { $ this -> adapters [ $ name = $ adapter -> getName ( ) ] = $ adapter ; return $ name ; }
Registers an adapter instance .
38,124
protected function registerAdapterFactory ( string $ name , Closure $ factory ) : string { $ this -> adapterFactories [ $ name ] = $ factory ; return $ name ; }
Registers an adapter factory .
38,125
protected function registerAdapter ( $ adapter ) : string { if ( $ adapter instanceof AdapterInterface ) { return $ this -> registerAdapterInstance ( $ adapter ) ; } [ $ name , $ factory ] = $ adapter ; return $ this -> registerAdapterFactory ( $ name , $ factory ) ; }
Registers an adapter .
38,126
protected function adapterFactory ( string $ name ) : AdapterInterface { $ factory = $ this -> adapterFactories [ $ name ] ; return $ this -> adapters [ $ name ] = $ factory ( ) ; }
Creates an adapter instance using a factory .
38,127
public function adapter ( ? string $ name = null ) : AdapterInterface { $ name = $ name ?? $ this -> defaultAdapter ; return $ this -> adapters [ $ name ] ?? $ this -> adapterFactory ( $ name ) ; }
Returns an adapter instance .
38,128
public static function start ( string $ applicationPath ) { if ( ! empty ( static :: $ instance ) ) { throw new LogicException ( 'The application has already been started.' ) ; } static :: $ instance = new static ( $ applicationPath ) ; return static :: $ instance -> boot ( ) ; }
Starts the application and returns a singleton instance of the application .
38,129
public function setLanguage ( array $ language ) : void { $ this -> language = $ language [ 'strings' ] ; foreach ( $ language [ 'locale' ] as $ category => $ locale ) { setlocale ( $ category , $ locale ) ; } }
Sets the application language settings .
38,130
public function getPackage ( string $ package ) : Package { if ( ! isset ( $ this -> packages [ $ package ] ) ) { throw new RuntimeException ( vsprintf ( 'Unknown package [ %s ].' , [ $ package ] ) ) ; } return $ this -> packages [ $ package ] ; }
Returns a package by its name .
38,131
protected function serviceRegistrar ( string $ type ) : void { foreach ( $ this -> config -> get ( 'application.services.' . $ type ) as $ service ) { ( new $ service ( $ this , $ this -> container , $ this -> config ) ) -> register ( ) ; } }
Registers services in the container .
38,132
protected function registerServices ( ) : void { $ this -> serviceRegistrar ( 'core' ) ; if ( $ this -> isCommandLine ( ) ) { $ this -> registerCLIServices ( ) ; } else { $ this -> registerWebServices ( ) ; } }
Register services in the container .
38,133
protected function registerClassAliases ( ) : void { $ aliases = $ this -> config -> get ( 'application.class_aliases' ) ; if ( ! empty ( $ aliases ) ) { $ aliasLoader = new AliasLoader ( $ aliases ) ; spl_autoload_register ( [ $ aliasLoader , 'load' ] ) ; } }
Registers class aliases .
38,134
protected function bootstrap ( ) : void { ( function ( $ app , $ container ) : void { include $ this -> applicationPath . '/bootstrap.php' ; } ) ( $ this , $ this -> container ) ; }
Loads the application bootstrap file .
38,135
protected function packageBooter ( string $ type ) : void { foreach ( $ this -> config -> get ( 'application.packages.' . $ type ) as $ package ) { $ package = new $ package ( $ this -> container ) ; $ package -> boot ( ) ; $ this -> packages [ $ package -> getName ( ) ] = $ package ; } }
Boots packages .
38,136
protected function bootPackages ( ) : void { $ this -> packageBooter ( 'core' ) ; if ( $ this -> isCommandLine ( ) ) { $ this -> bootCliPackages ( ) ; } else { $ this -> bootWebPackages ( ) ; } }
Boot packages .
38,137
protected function configFactory ( ) : Config { return new Config ( new Loader ( $ this -> container -> get ( FileSystem :: class ) , $ this -> applicationPath . '/config' ) , $ this -> getEnvironment ( ) ) ; }
Creates a configuration instance .
38,138
protected function initialize ( ) : void { $ this -> container = $ this -> containerFactory ( ) ; $ this -> container -> registerInstance ( [ Container :: class , 'container' ] , $ this -> container ) ; $ this -> container -> registerInstance ( [ Application :: class , 'app' ] , $ this ) ; $ this -> container -> registerInstance ( [ FileSystem :: class , 'fileSystem' ] , new FileSystem ) ; $ this -> config = $ this -> configFactory ( ) ; $ this -> container -> registerInstance ( [ Config :: class , 'config' ] , $ this -> config ) ; }
Sets up the framework core .
38,139
public function boot ( ) { $ this -> initialize ( ) ; $ this -> configure ( ) ; $ this -> registerServices ( ) ; $ this -> registerClassAliases ( ) ; $ this -> bootstrap ( ) ; $ this -> bootPackages ( ) ; return $ this ; }
Boots the application .
38,140
protected function attributes ( array $ attributes ) : string { $ attr = '' ; foreach ( $ attributes as $ attribute => $ value ) { if ( is_int ( $ attribute ) ) { $ attribute = $ value ; } $ attr .= ' ' . $ attribute . '="' . $ value . '"' ; } return $ attr ; }
Takes an array of attributes and turns it into a string .
38,141
protected function buildMedia ( string $ type , $ files , array $ attributes ) : string { $ sources = '' ; foreach ( ( array ) $ files as $ file ) { $ sources .= $ this -> tag ( 'source' , [ 'src' => $ file ] ) ; } return $ this -> tag ( $ type , $ attributes , $ sources ) ; }
Helper method for building media tags .
38,142
protected function raw ( Raw $ raw ) : string { $ parameters = $ raw -> getParameters ( ) ; if ( ! empty ( $ parameters ) ) { $ this -> params = array_merge ( $ this -> params , $ parameters ) ; } return $ raw -> getSql ( ) ; }
Compiles a raw SQL statement .
38,143
protected function subquery ( Subquery $ subquery , bool $ enclose = true ) : string { $ query = $ subquery -> getQuery ( ) ; if ( $ query instanceof Closure ) { $ builder = $ query ; $ query = $ this -> query -> newInstance ( ) -> inSubqueryContext ( ) ; $ builder ( $ query ) ; } $ query = $ query -> getCompiler ( ) -> select ( ) ; $ this -> params = array_merge ( $ this -> params , $ query [ 'params' ] ) ; if ( $ enclose ) { $ query [ 'sql' ] = '(' . $ query [ 'sql' ] . ')' ; } if ( ( $ alias = $ subquery -> getAlias ( ) ) !== null ) { $ query [ 'sql' ] .= ' AS ' . $ this -> escapeIdentifier ( $ alias ) ; } return $ query [ 'sql' ] ; }
Compiles subquery merges parameters and returns subquery SQL .
38,144
public function escapeIdentifiers ( array $ identifiers ) : array { foreach ( $ identifiers as $ key => $ identifier ) { $ identifiers [ $ key ] = $ this -> escapeIdentifier ( $ identifier ) ; } return $ identifiers ; }
Returns an array of escaped identifiers .
38,145
public function escapeTable ( string $ table ) : string { $ segments = [ ] ; foreach ( explode ( '.' , $ table ) as $ segment ) { $ segments [ ] = $ this -> escapeIdentifier ( $ segment ) ; } return implode ( '.' , $ segments ) ; }
Escapes a table name .
38,146
protected function setOperations ( array $ setOperations ) : string { if ( empty ( $ setOperations ) ) { return '' ; } $ sql = '' ; foreach ( $ setOperations as $ setOperation ) { $ sql .= $ this -> subquery ( $ setOperation [ 'query' ] , false ) . ' ' . $ setOperation [ 'operation' ] . ' ' ; } return $ sql ; }
Compiles set operations .
38,147
public function escapeColumn ( string $ column ) : string { $ segments = [ ] ; foreach ( explode ( '.' , $ column ) as $ segment ) { if ( $ segment === '*' ) { $ segments [ ] = $ segment ; } else { $ segments [ ] = $ this -> escapeIdentifier ( $ segment ) ; } } return implode ( '.' , $ segments ) ; }
Escapes a column name .
38,148
protected function compileColumnName ( string $ column ) : string { if ( $ this -> hasJsonPath ( $ column ) ) { $ segments = explode ( static :: JSON_PATH_SEPARATOR , $ column ) ; $ column = $ this -> escapeColumn ( array_shift ( $ segments ) ) ; return $ this -> buildJsonGet ( $ column , $ segments ) ; } return $ this -> escapeColumn ( $ column ) ; }
Compiles a column name .
38,149
public function columns ( array $ columns , bool $ allowAlias = false ) : string { $ pieces = [ ] ; foreach ( $ columns as $ column ) { $ pieces [ ] = $ this -> column ( $ column , $ allowAlias ) ; } return implode ( ', ' , $ pieces ) ; }
Returns a comma - separated list of compiled columns .
38,150
protected function param ( $ param , bool $ enclose = true ) : string { if ( $ param instanceof Raw ) { return $ this -> raw ( $ param ) ; } elseif ( $ param instanceof Subquery ) { return $ this -> subquery ( $ param , $ enclose ) ; } elseif ( $ param instanceof DateTimeInterface ) { $ this -> params [ ] = $ param -> format ( static :: $ dateFormat ) ; return '?' ; } $ this -> params [ ] = $ param ; return '?' ; }
Returns raw SQL or a paramter placeholder .
38,151
protected function params ( array $ params , bool $ enclose = true ) : string { $ pieces = [ ] ; foreach ( $ params as $ param ) { $ pieces [ ] = $ this -> param ( $ param , $ enclose ) ; } return implode ( ', ' , $ pieces ) ; }
Returns a comma - separated list of parameters .
38,152
protected function between ( array $ where ) : string { return $ this -> column ( $ where [ 'column' ] ) . ( $ where [ 'not' ] ? ' NOT BETWEEN ' : ' BETWEEN ' ) . $ this -> param ( $ where [ 'value1' ] ) . ' AND ' . $ this -> param ( $ where [ 'value2' ] ) ; }
Compiles BETWEEN clauses .
38,153
protected function in ( array $ where ) : string { $ values = $ this -> params ( $ where [ 'values' ] , false ) ; return $ this -> column ( $ where [ 'column' ] ) . ( $ where [ 'not' ] ? ' NOT IN ' : ' IN ' ) . '(' . $ values . ')' ; }
Compiles IN clauses .
38,154
protected function joinCondition ( array $ condition ) : string { return $ this -> column ( $ condition [ 'column1' ] ) . ' ' . $ condition [ 'operator' ] . ' ' . $ this -> column ( $ condition [ 'column2' ] ) ; }
Compiles a JOIN condition .
38,155
protected function joinConditions ( Join $ join ) : string { $ conditions = [ ] ; $ conditionCounter = 0 ; foreach ( $ join -> getConditions ( ) as $ condition ) { $ conditions [ ] = ( $ conditionCounter > 0 ? $ condition [ 'separator' ] . ' ' : null ) . $ this -> { $ condition [ 'type' ] } ( $ condition ) ; $ conditionCounter ++ ; } return implode ( ' ' , $ conditions ) ; }
Compiles JOIN conditions .
38,156
protected function joins ( array $ joins ) : string { if ( empty ( $ joins ) ) { return '' ; } $ sql = [ ] ; foreach ( $ joins as $ join ) { $ sql [ ] = $ join -> getType ( ) . ' JOIN ' . $ this -> table ( $ join -> getTable ( ) ) . ' ON ' . $ this -> joinConditions ( $ join ) ; } return ' ' . implode ( ' ' , $ sql ) ; }
Compiles JOIN clauses .
38,157
protected function orderings ( array $ orderings ) : string { if ( empty ( $ orderings ) ) { return '' ; } $ sql = [ ] ; foreach ( $ orderings as $ order ) { $ sql [ ] = $ this -> columns ( $ order [ 'column' ] ) . ' ' . $ order [ 'order' ] ; } return ' ORDER BY ' . implode ( ', ' , $ sql ) ; }
Compiles ORDER BY clauses .
38,158
protected function havingCondictions ( array $ havings ) : string { $ conditions = [ ] ; $ conditionCounter = 0 ; foreach ( $ havings as $ having ) { $ conditions [ ] = ( $ conditionCounter > 0 ? $ having [ 'separator' ] . ' ' : null ) . $ this -> column ( $ having [ 'column' ] ) . ' ' . $ having [ 'operator' ] . ' ' . $ this -> param ( $ having [ 'value' ] ) ; $ conditionCounter ++ ; } return implode ( ' ' , $ conditions ) ; }
Compiles HAVING conditions .
38,159
protected function insertWithValues ( array $ values ) : string { $ sql = 'INSERT INTO ' ; $ sql .= $ this -> escapeTable ( $ this -> query -> getTable ( ) ) ; $ sql .= ' (' . implode ( ', ' , $ this -> escapeIdentifiers ( array_keys ( $ values ) ) ) . ')' ; $ sql .= ' VALUES' ; $ sql .= ' (' . $ this -> params ( $ values ) . ')' ; return $ sql ; }
Returns a INSERT query with values .
38,160
public function insert ( array $ values = [ ] ) : array { $ sql = $ this -> query -> getPrefix ( ) ; if ( empty ( $ values ) ) { $ sql .= $ this -> insertWithoutValues ( ) ; } else { $ sql .= $ this -> insertWithValues ( $ values ) ; } return [ 'sql' => $ sql , 'params' => $ this -> params ] ; }
Compiles a INSERT query .
38,161
protected function updateColumns ( array $ columns ) : string { $ pieces = [ ] ; foreach ( $ columns as $ column => $ value ) { $ param = $ this -> param ( $ value ) ; if ( $ this -> hasJsonPath ( $ column ) ) { $ segments = explode ( static :: JSON_PATH_SEPARATOR , $ column ) ; $ column = $ this -> escapeColumn ( array_shift ( $ segments ) ) ; $ pieces [ ] = $ this -> buildJsonSet ( $ column , $ segments , $ param ) ; } else { $ pieces [ ] = $ this -> escapeColumn ( $ column ) . ' = ' . $ param ; } } return implode ( ', ' , $ pieces ) ; }
Compiles update columns .
38,162
public function update ( array $ values ) : array { $ sql = $ this -> query -> getPrefix ( ) ; $ sql .= 'UPDATE ' ; $ sql .= $ this -> escapeTable ( $ this -> query -> getTable ( ) ) ; $ sql .= ' SET ' ; $ sql .= $ this -> updateColumns ( $ values ) ; $ sql .= $ this -> wheres ( $ this -> query -> getWheres ( ) ) ; return [ 'sql' => $ sql , 'params' => $ this -> params ] ; }
Compiles a UPDATE query .
38,163
public function delete ( ) : array { $ sql = $ this -> query -> getPrefix ( ) ; $ sql .= 'DELETE FROM ' ; $ sql .= $ this -> escapeTable ( $ this -> query -> getTable ( ) ) ; $ sql .= $ this -> wheres ( $ this -> query -> getWheres ( ) ) ; return [ 'sql' => $ sql , 'params' => $ this -> params ] ; }
Compiles a DELETE query .
38,164
public function encrypt ( string $ string ) : string { return $ this -> signer -> sign ( $ this -> adapter -> encrypt ( $ string ) ) ; }
Encrypts string .
38,165
public function decrypt ( string $ string ) { $ string = $ this -> signer -> validate ( $ string ) ; if ( $ string === false ) { throw new CryptoException ( 'Ciphertex has been modified or an invalid authentication key has been provided.' ) ; } return $ this -> adapter -> decrypt ( $ string ) ; }
Decrypts string .
38,166
protected function convertToBytes ( $ size ) { if ( is_numeric ( $ unit = substr ( $ size , - 3 ) ) === false ) { $ size = substr ( $ size , 0 , - 3 ) ; switch ( $ unit ) { case 'KiB' : return $ size * 1024 ; case 'MiB' : return $ size * ( 1024 ** 2 ) ; case 'GiB' : return $ size * ( 1024 ** 3 ) ; case 'TiB' : return $ size * ( 1024 ** 4 ) ; case 'PiB' : return $ size * ( 1024 ** 5 ) ; case 'EiB' : return $ size * ( 1024 ** 6 ) ; case 'ZiB' : return $ size * ( 1024 ** 7 ) ; case 'YiB' : return $ size * ( 1024 ** 8 ) ; default : throw new RuntimeException ( vsprintf ( 'Invalid unit type [ %s ].' , [ $ unit ] ) ) ; } } return ( int ) $ size ; }
Convert human friendly size to bytes .
38,167
public function isEmpty ( string $ path ) : bool { if ( is_dir ( $ path ) ) { return ( new FilesystemIterator ( $ path ) ) -> valid ( ) === false ; } return filesize ( $ path ) === 0 ; }
Returns TRUE if a file or directory is empty and FALSE if not .
38,168
public function removeDirectory ( string $ path ) : bool { foreach ( new FilesystemIterator ( $ path ) as $ item ) { if ( $ item -> isDir ( ) ) { $ this -> removeDirectory ( $ item -> getPathname ( ) ) ; } else { unlink ( $ item -> getPathname ( ) ) ; } } return rmdir ( $ path ) ; }
Deletes a directory and its contents from disk .
38,169
public static function put ( string $ file , $ data , bool $ lock = false ) { return file_put_contents ( $ file , $ data , $ lock ? LOCK_EX : 0 ) ; }
Writes the supplied data to a file .
38,170
public static function prepend ( string $ file , $ data , bool $ lock = false ) { return file_put_contents ( $ file , $ data . file_get_contents ( $ file ) , $ lock ? LOCK_EX : 0 ) ; }
Prepends the supplied data to a file .
38,171
public static function append ( string $ file , $ data , bool $ lock = false ) { return file_put_contents ( $ file , $ data , $ lock ? FILE_APPEND | LOCK_EX : FILE_APPEND ) ; }
Appends the supplied data to a file .
38,172
public static function truncate ( string $ file , bool $ lock = false ) : bool { return ( 0 === file_put_contents ( $ file , null , $ lock ? LOCK_EX : 0 ) ) ; }
Truncates a file .
38,173
public function file ( string $ file , string $ openMode = 'r' , bool $ useIncludePath = false ) { return new SplFileObject ( $ file , $ openMode , $ useIncludePath ) ; }
Returns a SplFileObject .
38,174
protected function normalizeKeys ( array $ array ) : array { $ normalized = [ ] ; foreach ( $ array as $ key => $ value ) { $ normalized [ mb_strtolower ( $ key ) ] = $ value ; } return $ normalized ; }
Returns an array where all array keys lower case .
38,175
protected function getOptions ( array $ options , string $ default ) : string { $ highlighted = [ ] ; foreach ( array_keys ( $ options ) as $ option ) { $ highlighted [ ] = $ option === $ default ? mb_strtoupper ( $ option ) : $ option ; } return implode ( '/' , $ highlighted ) ; }
Returns a slash - separated list of valid options where the default one is highlighted as upper - case .
38,176
public function ask ( string $ question , $ default = 'n' , ? array $ options = null ) { $ options = $ options === null ? [ 'y' => true , 'n' => false ] : $ this -> normalizeKeys ( $ options ) ; $ input = parent :: ask ( trim ( $ question ) . ' [' . $ this -> getOptions ( $ options , $ default ) . '] ' ) ; $ input = mb_strtolower ( empty ( $ input ) ? $ default : $ input ) ; if ( ! isset ( $ options [ $ input ] ) ) { return $ this -> ask ( $ question , $ default , $ options ) ; } return $ options [ $ input ] ; }
Asks user for confirmation and returns value corresponding to the chosen value .
38,177
protected function wordWrap ( string $ string , int $ width ) : string { return trim ( preg_replace ( sprintf ( '/(.{1,%1$u})(?:\s|$)|(.{%1$u})/uS' , $ width ) , '$1$2' . PHP_EOL , $ string ) ) ; }
Wraps a string to a given number of characters .
38,178
protected function escape ( string $ string ) : string { if ( $ this -> formatter !== null ) { return $ this -> formatter -> escape ( $ string ) ; } return $ string ; }
Escapes style tags if we have a formatter .
38,179
protected function format ( string $ string ) : string { $ lineWidth = $ this -> width - ( static :: PADDING * 2 ) ; $ lines = explode ( PHP_EOL , PHP_EOL . $ this -> wordWrap ( $ string , $ lineWidth ) . PHP_EOL ) ; foreach ( $ lines as $ key => $ value ) { $ value = $ this -> escape ( $ value ) . str_repeat ( ' ' , $ lineWidth - mb_strlen ( $ value ) ) ; $ lines [ $ key ] = sprintf ( '%1$s%2$s%1$s' , str_repeat ( ' ' , static :: PADDING ) , $ value ) ; } return implode ( PHP_EOL , $ lines ) ; }
Formats the string .
38,180
public function render ( string $ message , string $ template = Alert :: DEFAULT ) : string { return sprintf ( $ template , $ this -> format ( $ message ) ) . PHP_EOL ; }
Renders an alert .
38,181
public function getAction ( ) { if ( $ this -> action instanceof Closure || empty ( $ this -> namespace ) ) { return $ this -> action ; } return $ this -> namespace . $ this -> action ; }
Returns the route action .
38,182
public function prefix ( string $ prefix ) : Route { if ( ! empty ( $ prefix ) ) { $ this -> prefix .= '/' . trim ( $ prefix , '/' ) ; } return $ this ; }
Adds a prefix to the route .
38,183
public function middleware ( $ middleware ) : Route { $ this -> middleware = array_merge ( $ this -> middleware , ( array ) $ middleware ) ; return $ this ; }
Adds a set of middleware .
38,184
public function constraint ( $ constraint ) : Route { $ this -> constraints = array_merge ( $ this -> constraints , ( array ) $ constraint ) ; return $ this ; }
Adds a set of constraints .
38,185
protected function hasStty ( ) : bool { if ( static :: $ hasStty === null ) { exec ( 'stty 2>&1' , $ output , $ status ) ; static :: $ hasStty = $ status === 0 ; } return static :: $ hasStty ; }
Do we have stty support?
38,186
protected function fallbackHandler ( ) : void { $ this -> handle ( Throwable :: class , function ( $ e ) : void { echo '[ ' . get_class ( $ e ) . '] ' . $ e -> getMessage ( ) . ' on line [ ' . $ e -> getLine ( ) . ' ] in [ ' . $ e -> getFile ( ) . ' ]' ; echo PHP_EOL ; echo $ e -> getTraceAsString ( ) ; } ) ; }
Adds basic fallback handler to the stack .
38,187
public function disableLoggingFor ( $ exceptionType ) : void { $ this -> disableLoggingFor = array_unique ( array_merge ( $ this -> disableLoggingFor , ( array ) $ exceptionType ) ) ; }
Disables logging for an exception type .
38,188
public function handle ( string $ exceptionType , $ handler ) : void { array_unshift ( $ this -> handlers , [ 'exceptionType' => $ exceptionType , 'handler' => $ handler ] ) ; }
Prepends an exception handler to the stack .
38,189
public function clearHandlers ( string $ exceptionType ) : void { foreach ( $ this -> handlers as $ key => $ handler ) { if ( $ handler [ 'exceptionType' ] === $ exceptionType ) { unset ( $ this -> handlers [ $ key ] ) ; } } }
Clears all error handlers for an exception type .
38,190
public function replaceHandlers ( string $ exceptionType , Closure $ handler ) : void { $ this -> clearHandlers ( $ exceptionType ) ; $ this -> handle ( $ exceptionType , $ handler ) ; }
Replaces all error handlers for an exception type with a new one .
38,191
protected function shouldExceptionBeLogged ( Throwable $ exception ) : bool { if ( $ this -> logger === null ) { return false ; } foreach ( $ this -> disableLoggingFor as $ exceptionType ) { if ( $ exception instanceof $ exceptionType ) { return false ; } } return true ; }
Should the exception be logged?
38,192
protected function handleException ( $ handler , Throwable $ exception ) { if ( $ handler instanceof Closure ) { return $ handler ( $ exception ) ; } return $ this -> handlerFactory ( $ handler ) -> handle ( $ exception ) ; }
Handle the exception .
38,193
public function handler ( Throwable $ exception ) : void { try { $ this -> clearOutputBuffers ( ) ; foreach ( $ this -> handlers as $ handler ) { if ( $ exception instanceof $ handler [ 'exceptionType' ] ) { if ( $ this -> handleException ( $ handler [ 'handler' ] , $ exception ) !== null ) { break ; } } } if ( $ this -> shouldExceptionBeLogged ( $ exception ) ) { $ this -> getLogger ( ) -> error ( $ exception -> getMessage ( ) , [ 'exception' => $ exception ] ) ; } } catch ( Throwable $ e ) { $ this -> clearOutputBuffers ( ) ; echo $ e -> getMessage ( ) . ' on line [ ' . $ e -> getLine ( ) . ' ] in [ ' . $ e -> getFile ( ) . ' ]' . PHP_EOL ; } exit ( 1 ) ; }
Handles uncaught exceptions .
38,194
public function getMimeType ( ) : ? string { $ info = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mime = finfo_file ( $ info , $ this -> getPathname ( ) ) ; finfo_close ( $ info ) ; return $ mime ? : null ; }
Returns the MIME type of the file .
38,195
public function getMimeEncoding ( ) : ? string { $ info = finfo_open ( FILEINFO_MIME_ENCODING ) ; $ encoding = finfo_file ( $ info , $ this -> getPathname ( ) ) ; finfo_close ( $ info ) ; return $ encoding ? : null ; }
Returns the MIME encoding of the file .
38,196
public function getHash ( string $ algorithm = 'sha256' , bool $ raw = false ) : string { return hash_file ( $ algorithm , $ this -> getPathname ( ) , $ raw ) ; }
Generates a hash using the contents of the file .
38,197
public function validateHash ( string $ hash , string $ algorithm = 'sha256' , bool $ raw = false ) : bool { return hash_equals ( $ hash , $ this -> getHash ( $ algorithm , $ raw ) ) ; }
Returns true if the file matches the provided hash and false if not .
38,198
public function getHmac ( string $ key , string $ algorithm = 'sha256' , bool $ raw = false ) : string { return hash_hmac_file ( $ algorithm , $ this -> getPathname ( ) , $ key , $ raw ) ; }
Generates a HMAC using the contents of the file .
38,199
public function validateHmac ( string $ hmac , string $ key , string $ algorithm = 'sha256' , bool $ raw = false ) : bool { return hash_equals ( $ hmac , $ this -> getHmac ( $ key , $ algorithm , $ raw ) ) ; }
Returns true if the file matches the provided HMAC and false if not .