idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
52,500
|
public static function load ( $ filename ) { if ( static :: $ env != null ) { return ; } static :: $ env = json_decode ( trim ( file_get_contents ( $ filename ) ) , true ) ; if ( json_last_error ( ) == JSON_ERROR_SYNTAX ) { throw new \ ErrorException ( '' ) ; } if ( json_last_error ( ) == JSON_ERROR_INVALID_PROPERTY_NAME ) { throw new \ ErrorException ( 'Check environment file json syntax (.env.json)' ) ; } if ( json_last_error ( ) != JSON_ERROR_NONE ) { throw new \ ErrorException ( json_last_error_msg ( ) ) ; } }
|
Load env file
|
52,501
|
public static function get ( $ key , $ default = null ) { $ value = getenv ( Str :: upper ( $ key ) ) ; if ( is_string ( $ value ) ) { return $ value ; } return isset ( static :: $ env [ $ key ] ) ? static :: $ env [ $ key ] : $ default ; }
|
Retrieve information from the environment
|
52,502
|
public static function set ( $ key , $ value ) { if ( isset ( static :: $ env -> $ key ) ) { return static :: $ env -> $ key = $ value ; } return putenv ( Str :: upper ( $ key ) . '=' . $ value ) ; }
|
Allows you to modify the information of the environment
|
52,503
|
public function call ( $ command , $ action , ... $ rest ) { $ class = $ this -> actions [ $ action ] ; $ instance = new $ class ( $ this -> setting , $ this -> arg ) ; if ( method_exists ( $ instance , $ command ) ) { return call_user_func_array ( [ $ instance , $ command ] , $ rest ) ; } }
|
The call command
|
52,504
|
public static function configure ( $ config = [ ] ) { if ( empty ( static :: $ config ) ) { static :: $ config = $ config ; } if ( ! in_array ( $ config [ 'driver' ] , [ "smtp" , "mail" ] ) ) { throw new MailException ( "The type is not known." , E_USER_ERROR ) ; } if ( $ config [ 'driver' ] == "mail" ) { if ( ! static :: $ instance instanceof Native ) { static :: $ instance = new Native ( $ config [ 'mail' ] ) ; } } else { if ( ! static :: $ instance instanceof Smtp ) { static :: $ instance = new Smtp ( $ config [ 'smtp' ] ) ; } } return static :: $ instance ; }
|
Configure la classe Mail
|
52,505
|
public static function raw ( $ to , $ subject , $ data , array $ headers = [ ] ) { if ( ! is_array ( $ to ) ) { $ to = [ $ to ] ; } $ message = new Message ( ) ; $ message -> toList ( $ to ) -> subject ( $ subject ) -> setMessage ( $ data ) ; foreach ( $ headers as $ key => $ value ) { $ message -> addHeader ( $ key , $ value ) ; } return static :: $ instance -> send ( $ message ) ; }
|
Send mail similar to the PHP mail function
|
52,506
|
private function push ( $ allow , $ excepted ) { if ( $ excepted === null ) { $ excepted = '*' ; } $ this -> response -> addHeader ( $ allow , $ excepted ) ; return $ this ; }
|
The access control
|
52,507
|
public function allowOrigin ( array $ excepted ) { if ( ! is_array ( $ excepted ) ) { throw new AccessControlException ( 'Attend un tableau.' . gettype ( $ excepted ) . ' donner.' , E_USER_ERROR ) ; } return $ this -> push ( 'Access-Control-Allow-Origin' , implode ( ', ' , $ excepted ) ) ; }
|
Active Access - control - Allow - Origin
|
52,508
|
public function allowMethods ( array $ excepted ) { if ( count ( $ excepted ) == 0 ) { throw new AccessControlException ( 'Parameter is empty.' , E_USER_ERROR ) ; } return $ this -> push ( 'Access-Control-Allow-Methods' , implode ( ', ' , $ excepted ) ) ; }
|
Active Access - control - Allow - Methods
|
52,509
|
public function allowHeaders ( array $ excepted ) { if ( count ( $ excepted ) == 0 ) { throw new AccessControlException ( 'Parameter is empty.' , E_USER_ERROR ) ; } return $ this -> push ( 'Access-Control-Allow-Headers' , implode ( ', ' , $ excepted ) ) ; }
|
Active Access - control - Allow - Headers
|
52,510
|
public function exposeHeaders ( array $ excepted ) { if ( count ( $ excepted ) == 0 ) { throw new AccessControlException ( 'Le tableau est vide.' . gettype ( $ excepted ) . ' donner.' , E_USER_ERROR ) ; } return $ this -> push ( 'Access-Control-Expose-Headers' , implode ( ', ' , $ excepted ) ) ; }
|
Active Access - control - Expose - Headers
|
52,511
|
public function select ( array $ select = [ '*' ] ) { if ( count ( $ select ) == 0 ) { return $ this ; } if ( count ( $ select ) == 1 && $ select [ 0 ] == '*' ) { $ this -> select = '*' ; } else { $ this -> select = '`' . implode ( '`, `' , $ select ) . '`' ; } return $ this ; }
|
Add select column .
|
52,512
|
public function leftJoin ( $ table , callable $ callable = null ) { $ table = $ this -> getPrefix ( ) . $ table ; if ( is_null ( $ this -> join ) ) { $ this -> join = 'left join `' . $ table . '`' ; if ( is_callable ( $ callable ) ) { $ callable ( $ this ) ; } return $ this ; } if ( ! preg_match ( '/^(inner|right)\sjoin\s.*/' , $ this -> join ) ) { $ this -> join .= ', `' . $ table . '`' ; if ( is_callable ( $ callable ) ) { $ callable ( $ this ) ; } return $ this ; } throw new QueryBuilderException ( 'The inner join clause is already in effect.' , E_ERROR ) ; }
|
Left Join clause
|
52,513
|
public function rightJoin ( $ table , callable $ callable ) { $ table = $ this -> getPrefix ( ) . $ table ; if ( is_null ( $ this -> join ) ) { $ this -> join = 'right join `' . $ table . '`' ; if ( is_callable ( $ callable ) ) { $ callable ( $ this ) ; } return $ this ; } if ( ! preg_match ( '/^(inner|left)\sjoin\s.*/' , $ this -> join ) ) { $ this -> join .= ', `' . $ table . '`' ; if ( is_callable ( $ callable ) ) { $ callable ( $ this ) ; } return $ this ; } throw new QueryBuilderException ( 'The inner join clause is already initialized.' , E_ERROR ) ; }
|
Right Join clause
|
52,514
|
public function having ( $ column , $ comp = '=' , $ value = null , $ boolean = 'and' ) { if ( ! $ this -> isComporaisonOperator ( $ comp ) ) { $ value = $ comp ; $ comp = '=' ; } if ( is_null ( $ this -> havin ) ) { $ this -> havin = '`' . $ column . '` ' . $ comp . ' ' . $ value ; } else { $ this -> havin .= ' ' . $ boolean . ' `' . $ column . '` ' . $ comp . ' ' . $ value ; } return $ this ; }
|
clause having is used with a groupBy
|
52,515
|
public function orderBy ( $ column , $ type = 'asc' ) { if ( ! is_null ( $ this -> order ) ) { return $ this ; } if ( ! in_array ( $ type , [ 'asc' , 'desc' ] ) ) { $ type = 'asc' ; } $ this -> order = 'order by `' . $ column . '` ' . $ type ; return $ this ; }
|
Clause Order By
|
52,516
|
public function take ( $ limit ) { if ( is_null ( $ this -> limit ) ) { $ this -> limit = ( int ) $ limit ; return $ this ; } if ( preg_match ( '/^([\d]+),\s$/' , $ this -> limit , $ match ) ) { $ this -> limit = end ( $ match ) . ', ' . $ limit ; } return $ this ; }
|
Take = Limit
|
52,517
|
public function get ( array $ columns = [ ] ) { if ( count ( $ columns ) > 0 ) { $ this -> select ( $ columns ) ; } $ sql = $ this -> toSql ( ) ; $ stmt = $ this -> connection -> prepare ( $ sql ) ; $ this -> bind ( $ stmt , $ this -> where_data_binding ) ; $ this -> where_data_binding = [ ] ; $ stmt -> execute ( ) ; $ data = Sanitize :: make ( $ stmt -> fetchAll ( ) ) ; $ stmt -> closeCursor ( ) ; if ( ! $ this -> first ) { return $ data ; } $ current = current ( $ data ) ; $ this -> first = false ; if ( $ current == false ) { return null ; } return $ current ; }
|
Get make only on the select request If the first selection mode is not active
|
52,518
|
public function last ( ) { $ where = $ this -> where ; $ whereData = $ this -> where_data_binding ; $ c = $ this -> count ( ) ; $ this -> where = $ where ; $ this -> where_data_binding = $ whereData ; return $ this -> jump ( $ c - 1 ) -> take ( 1 ) -> first ( ) ; }
|
Get the last record
|
52,519
|
public function transition ( callable $ cb ) { $ where = $ this -> where ; $ data = $ this -> get ( ) ; if ( call_user_func_array ( $ cb , [ $ data ] ) === true ) { $ this -> where = $ where ; } return $ this ; }
|
Start a transaction in the database .
|
52,520
|
public function remove ( $ column , $ comp = '=' , $ value = null ) { $ this -> where = null ; return $ this -> where ( $ column , $ comp , $ value ) -> delete ( ) ; }
|
Remove simplified stream from delete .
|
52,521
|
public function distinct ( $ column ) { if ( ! is_null ( $ this -> select ) ) { $ this -> select .= " distinct `$column`" ; } else { $ this -> select = "distinct `$column`" ; } return $ this ; }
|
Allows a query with the DISTINCT clause
|
52,522
|
private function incrementAction ( $ column , $ step = 1 , $ sign = '' ) { $ sql = 'update `' . $ this -> table . '` set `' . $ column . '` = `' . $ column . '` ' . $ sign . ' ' . $ step ; if ( ! is_null ( $ this -> where ) ) { $ sql .= ' ' . $ this -> where ; $ this -> where = null ; } $ stmt = $ this -> connection -> prepare ( $ sql ) ; $ this -> bind ( $ stmt , $ this -> where_data_binding ) ; $ stmt -> execute ( ) ; return ( int ) $ stmt -> rowCount ( ) ; }
|
Method to customize the increment and decrement methods
|
52,523
|
private function insertOne ( array $ value ) { $ fields = array_keys ( $ value ) ; $ sql = 'insert into `' . $ this -> table . '` values (' ; $ sql .= implode ( ', ' , Util :: add2points ( $ fields , true ) ) ; $ sql .= ');' ; $ stmt = $ this -> connection -> prepare ( $ sql ) ; $ this -> bind ( $ stmt , $ value ) ; $ stmt -> execute ( ) ; return ( int ) $ stmt -> rowCount ( ) ; }
|
Insert On insert one row in the table
|
52,524
|
public function insertAndGetLastId ( array $ values ) { $ this -> insert ( $ values ) ; $ n = $ this -> connection -> lastInsertId ( ) ; return $ n ; }
|
InsertAndGetLastId action launches the insert and lastInsertId actions
|
52,525
|
public function paginate ( $ n , $ current = 0 , $ chunk = null ) { -- $ current ; if ( $ current <= 0 ) { $ jump = 0 ; $ current = 1 ; } else { $ jump = $ n * $ current ; $ current ++ ; } $ where = $ this -> where ; $ dataBind = $ this -> where_data_binding ; $ data = $ this -> jump ( $ jump ) -> take ( $ n ) -> get ( ) ; $ this -> where = $ where ; $ this -> where_data_binding = $ dataBind ; $ restOfPage = ceil ( $ this -> count ( ) / $ n ) - $ current ; if ( is_int ( $ chunk ) ) { $ data = array_chunk ( $ data , $ chunk ) ; } $ data = [ 'next' => $ current >= 1 && $ restOfPage > 0 ? $ current + 1 : false , 'previous' => ( $ current - 1 ) <= 0 ? 1 : ( $ current - 1 ) , 'total' => ( int ) ( $ restOfPage + $ current ) , 'current' => $ current , 'data' => $ data ] ; return new Collection ( $ data ) ; }
|
Paginate make pagination system
|
52,526
|
public function exists ( $ column = null , $ value = null ) { if ( $ column == null && $ value == null ) { return $ this -> count ( ) > 0 ; } return $ this -> where ( $ column , $ value ) -> count ( ) > 0 ; }
|
Check if a value already exists in the DB
|
52,527
|
public function toSql ( ) { $ sql = 'select ' ; if ( is_null ( $ this -> select ) ) { $ sql .= '* from `' . $ this -> table . '`' ; } else { $ sql .= $ this -> select . ' from `' . $ this -> table . '`' ; $ this -> select = null ; } if ( ! is_null ( $ this -> join ) ) { $ sql .= ' ' . $ this -> join ; $ this -> join = null ; } if ( ! is_null ( $ this -> where ) ) { $ sql .= ' where ' . $ this -> where ; $ this -> where = null ; } if ( ! is_null ( $ this -> order ) ) { $ sql .= ' ' . $ this -> order ; $ this -> order = null ; } if ( ! is_null ( $ this -> limit ) ) { $ sql .= ' limit ' . $ this -> limit ; $ this -> limit = null ; } if ( ! is_null ( $ this -> group ) ) { $ sql .= ' group by ' . $ this -> group ; $ this -> group = null ; if ( ! is_null ( $ this -> havin ) ) { $ sql .= ' having ' . $ this -> havin ; } } return $ sql . ';' ; }
|
Formats the select request
|
52,528
|
public static function debug ( ) { $ vars = func_get_args ( ) ; $ cloner = new VarCloner ( ) ; $ dumper = 'cli' === PHP_SAPI ? new CliDumper ( ) : new HtmlDumper ( ) ; $ dumper -> setStyles ( [ 'default' => 'background-color:#fff; color:#FF8400; line-height:1.2em; font:12px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: normal' , 'num' => 'font-weight:bold; color:#1299DA' , 'const' => 'font-weight:bold' , 'str' => 'color:#111111' , 'note' => 'color:#1299DA' , 'ref' => 'color:#A0A0A0' , 'public' => 'color:blue' , 'protected' => 'color:#111' , 'private' => 'color:#478' , 'meta' => 'color:#B729D9' , 'key' => 'color:#212' , 'index' => 'color:#1200DA' , ] ) ; $ handler = function ( $ vars ) use ( $ cloner , $ dumper ) { if ( ! is_array ( $ vars ) ) { $ vars = [ $ vars ] ; } foreach ( $ vars as $ var ) { $ dumper -> dump ( $ cloner -> cloneVar ( $ var ) ) ; } } ; call_user_func_array ( $ handler , [ $ vars ] ) ; }
|
Run a var_dump on the variables passed in parameter .
|
52,529
|
public static function sep ( ) { if ( static :: $ sep !== null ) { return static :: $ sep ; } if ( defined ( 'PHP_EOL' ) ) { static :: $ sep = PHP_EOL ; } else { static :: $ sep = ( strpos ( PHP_OS , 'WIN' ) === false ) ? '\n' : '\r\n' ; } return static :: $ sep ; }
|
sep separator \ r \ n or \ n
|
52,530
|
public static function rangeField ( $ data ) { $ field = '' ; $ i = 0 ; foreach ( $ data as $ key => $ value ) { $ field .= ( $ i > 0 ? ', ' : '' ) . '`' . $ key . '` = ' . $ value ; $ i ++ ; } return $ field ; }
|
Function to secure the data .
|
52,531
|
private function loadFrontLogger ( Logger $ monolog ) { $ whoops = new \ Whoops \ Run ; if ( app_env ( 'APP_ENV' ) == 'development' ) { $ whoops -> pushHandler ( new \ Whoops \ Handler \ PrettyPageHandler ) ; } if ( class_exists ( \ App \ ErrorHandle :: class ) ) { $ handler = new \ Whoops \ Handler \ CallbackHandler ( function ( $ exception , $ inspector , $ run ) use ( $ monolog ) { $ monolog -> error ( $ exception -> getMessage ( ) , $ exception -> getTrace ( ) ) ; return call_user_func_array ( [ new \ App \ ErrorHandle , 'handle' ] , [ $ exception ] ) ; } ) ; $ whoops -> pushHandler ( $ handler ) ; } $ whoops -> register ( ) ; }
|
Loader view logger
|
52,532
|
private function loadFileLogger ( $ log_dir , $ name ) { $ monolog = new Logger ( $ name ) ; $ monolog -> pushHandler ( new StreamHandler ( $ log_dir . '/bow.log' , Logger :: DEBUG ) ) ; $ monolog -> pushHandler ( new FirePHPHandler ( ) ) ; return $ monolog ; }
|
Loader file logger via Monolog
|
52,533
|
public function open ( ) { if ( is_resource ( $ this -> stream ) ) { throw new ResourceException ( 'The temporary file is already open.' ) ; } $ this -> stream = fopen ( $ this -> lock_filename , 'w+b' ) ; }
|
Open the streaming
|
52,534
|
public function read ( ) { if ( ! $ this -> isOpen ( ) ) { $ this -> open ( ) ; } $ this -> stream = fopen ( $ this -> lock_filename , 'r' ) ; $ content = stream_get_contents ( $ this -> stream ) ; $ this -> close ( ) ; return $ content ; }
|
Read content of temp
|
52,535
|
public function generate ( $ controller ) { $ generator = new Generator ( $ this -> setting -> getControllerDirectory ( ) , $ controller ) ; if ( $ generator -> fileExists ( ) ) { echo "\033[0;31mThe controller already exists.\033[00m\n" ; exit ( 1 ) ; } if ( $ this -> arg -> options ( '--no-plain' ) ) { $ generator -> write ( 'controller/no-plain' , [ 'baseNamespace' => $ this -> namespaces [ 'controller' ] ] ) ; } else { $ generator -> write ( 'controller/controller' , [ 'baseNamespace' => $ this -> namespaces [ 'controller' ] ] ) ; } echo "\033[0;32mThe controller was well created.\033[00m\n" ; exit ( 0 ) ; }
|
The add controller command
|
52,536
|
public function withInput ( array $ data = [ ] ) { if ( count ( $ data ) == 0 ) { $ this -> request -> session ( ) -> add ( '__bow.old' , $ this -> request -> all ( ) ) ; } else { $ this -> request -> session ( ) -> add ( '__bow.old' , $ data ) ; } return $ this ; }
|
Redirection with the query information
|
52,537
|
public function to ( $ path , $ status = 302 ) { $ this -> to = $ path ; $ this -> response -> status ( $ status ) ; return $ this ; }
|
Redirect to another URL
|
52,538
|
public function addColumn ( $ name , $ type , array $ attributes = [ ] ) { if ( $ this -> scope == 'alter' ) { $ command = 'ADD COLUMN' ; } else { $ command = null ; } $ this -> sqls [ ] = $ this -> composeAddColumn ( trim ( $ name , '`' ) , compact ( 'name' , 'type' , 'attributes' , 'command' ) ) ; return $ this ; }
|
Add new column in the table
|
52,539
|
public function dropColumn ( $ name ) { if ( $ this -> adapter == 'mysql' ) { $ this -> dropColumnOnMysql ( $ name ) ; } else { $ this -> dropColumnOnSqlite ( $ name ) ; } return $ this ; }
|
Drop table column
|
52,540
|
public function dropForeign ( $ name ) { $ names = ( array ) $ name ; foreach ( $ names as $ name ) { $ this -> sqls [ ] = sprintf ( 'DROP FOREIGN KEY `%s`' , $ name ) ; } return $ this ; }
|
Drop constraintes column ;
|
52,541
|
public function addIndex ( $ name ) { if ( $ this -> scope == 'alter' ) { $ command = 'ADD INDEX' ; } else { $ command = 'INDEX' ; } $ this -> sqls [ ] = sprintf ( '%s `%s`' , $ command , $ name ) ; return $ this ; }
|
Add table index ;
|
52,542
|
public function dropIndex ( $ name ) { $ names = ( array ) $ name ; foreach ( $ names as $ name ) { $ this -> sqls [ ] = sprintf ( 'DROP INDEX `%s`' , $ name ) ; } return $ this ; }
|
Drop table index ;
|
52,543
|
private function composeAddColumn ( $ name , array $ description ) { $ type = strtoupper ( $ description [ 'type' ] ) ; $ attributes = $ description [ 'attributes' ] ; $ default = $ attributes [ 'default' ] ?? null ; $ size = $ attributes [ 'size' ] ?? false ; $ primary = $ attributes [ 'primary' ] ?? false ; $ increment = $ attributes [ 'increment' ] ?? false ; $ nullable = $ attributes [ 'nullable' ] ?? false ; $ unique = $ attributes [ 'unique' ] ?? false ; $ check = $ attributes [ 'check' ] ?? false ; if ( $ type == 'STRING' ) { $ type = 'VARCHAR' ; if ( ! $ size ) { $ size = 255 ; } } if ( $ size ) { $ type = sprintf ( '%s(%s)' , $ type , $ size ) ; } if ( $ increment ) { $ type = sprintf ( '%s AUTO_INCREMENT' , $ type ) ; } if ( $ primary ) { $ type = sprintf ( '%s PRIMARY KEY' , $ type ) ; } if ( $ unique ) { $ type = sprintf ( '%s UNIQUE' , $ type ) ; } if ( $ nullable ) { $ type = sprintf ( '%s NULL' , $ type ) ; } else { $ type = sprintf ( '%s NOT NULL' , $ type ) ; } if ( $ default ) { $ type = sprintf ( '%s DEFAULT %s' , $ type , $ default ) ; } if ( $ check ) { $ type = sprintf ( '%s CHECK (%s)' , $ type , $ check ) ; } return trim ( sprintf ( '%s `%s` %s' , $ description [ 'command' ] , $ name , $ type ) ) ; }
|
Compose sql instruction
|
52,544
|
public function exists ( $ column = null , $ value = null ) { if ( $ value == null && $ value == null ) { return $ this -> count ( ) > 0 ; } if ( $ value == null ) { $ value = $ column ; $ column = ( new $ this -> model ) -> getKey ( ) ; } return $ this -> where ( $ column , $ value ) -> count ( ) > 0 ; }
|
Check if rows exists
|
52,545
|
public static function confirgure ( $ base_directory ) { if ( static :: $ directory === null || static :: $ directory !== $ base_directory ) { static :: $ directory = $ base_directory ; } if ( ! is_dir ( $ base_directory ) ) { @ mkdir ( $ base_directory , 0777 ) ; } }
|
Cache configuration method
|
52,546
|
public static function forever ( $ key , $ data ) { if ( is_callable ( $ data ) ) { $ content = $ data ( ) ; } else { $ content = $ data ; } $ meta [ '__bow_meta' ] = [ 'expire_at' => '+' ] ; $ meta [ 'content' ] = $ content ; return ( bool ) file_put_contents ( static :: makeHashFilename ( $ key , true ) , serialize ( $ meta ) ) ; }
|
Adds a cache that will persist
|
52,547
|
public static function get ( $ key , $ default = null ) { if ( ! static :: has ( $ key ) ) { static :: $ with_meta = false ; return $ default ; } $ cache = unserialize ( file_get_contents ( static :: makeHashFilename ( $ key ) ) ) ; if ( ! static :: $ with_meta ) { unset ( $ cache [ '__bow_meta' ] ) ; $ cache = $ cache [ 'content' ] ; } return $ cache ; }
|
Retrieve an entry in the cache
|
52,548
|
public static function addTime ( $ key , $ time ) { static :: $ with_meta = true ; $ cache = static :: get ( $ key ) ; static :: $ with_meta = false ; if ( $ cache == null ) { return false ; } if ( $ cache [ '__bow_meta' ] [ 'expire_at' ] == '+' ) { $ cache [ '__bow_meta' ] [ 'expire_at' ] = time ( ) ; } $ cache [ '__bow_meta' ] [ 'expire_at' ] += $ time ; return ( bool ) file_put_contents ( static :: makeHashFilename ( $ key ) , serialize ( $ cache ) ) ; }
|
Increase the cache expiration time
|
52,549
|
public static function timeOf ( $ key ) { static :: $ with_meta = true ; $ cache = static :: get ( $ key ) ; static :: $ with_meta = false ; if ( $ cache == null ) { return false ; } return $ cache [ '__bow_meta' ] [ 'expire_at' ] ; }
|
Retrieves the cache expiration time
|
52,550
|
public static function forget ( $ key ) { $ filename = static :: makeHashFilename ( $ key ) ; if ( ! file_exists ( $ filename ) ) { return false ; } $ r = ( bool ) @ unlink ( $ filename ) ; $ parts = explode ( '/' , $ filename ) ; array_pop ( $ parts ) ; $ dirname = implode ( '/' , $ parts ) ; if ( is_dir ( $ dirname ) ) { @ rmdir ( $ dirname ) ; } return $ r ; }
|
Delete an entry in the cache
|
52,551
|
private static function makeHashFilename ( $ key , $ make_group_directory = false ) { $ hash = hash ( 'sha256' , '/bow_' . $ key ) ; $ group = Str :: slice ( $ hash , 0 , 2 ) ; if ( $ make_group_directory ) { if ( ! is_dir ( static :: $ directory . '/' . $ group ) ) { @ mkdir ( static :: $ directory . '/' . $ group ) ; } } return static :: $ directory . '/' . $ group . '/' . $ hash ; }
|
Format the file
|
52,552
|
public function send ( Message $ message ) { $ this -> connection ( ) ; $ error = true ; if ( $ this -> username !== null ) { $ this -> write ( 'MAIL FROM: <' . $ this -> username . '>' , 250 ) ; } else { if ( $ message -> getFrom ( ) !== null ) { $ this -> write ( 'MAIL FROM: <' . $ message -> getFrom ( ) . '>' , 250 ) ; } } foreach ( $ message -> getTo ( ) as $ value ) { if ( $ value [ 0 ] !== null ) { $ to = $ value [ 0 ] . '<' . $ value [ 1 ] . '>' ; } else { $ to = '<' . $ value [ 1 ] . '>' ; } $ this -> write ( 'RCPT TO: ' . $ to , 250 ) ; } $ this -> write ( 'DATA' , 354 ) ; $ data = 'Subject: ' . $ message -> getSubject ( ) . Message :: END ; $ data .= $ message -> compileHeaders ( ) ; $ data .= 'Content-Type: ' . $ message -> getType ( ) . '; charset=' . $ message -> getCharset ( ) . Message :: END ; $ data .= 'Content-Transfer-Encoding: 8bit' . Message :: END ; $ data .= Message :: END . $ message -> getMessage ( ) . Message :: END ; $ this -> write ( $ data ) ; try { $ this -> write ( '.' , 250 ) ; } catch ( SmtpException $ e ) { echo $ e -> getMessage ( ) ; } $ status = $ this -> disconnect ( ) ; if ( $ status == 221 ) { $ error = false ; } return ( bool ) $ error ; }
|
Start sending mail
|
52,553
|
private function connection ( ) { $ url = $ this -> url ; if ( $ this -> secure === true ) { $ url = 'ssl://' . $ this -> url ; } $ this -> sock = fsockopen ( $ url , $ this -> port , $ errno , $ errstr , $ this -> timeout ) ; if ( $ this -> sock == null ) { throw new SocketException ( 'Impossible to get connected to ' . $ this -> url . ':' . $ this -> port , E_USER_ERROR ) ; } stream_set_timeout ( $ this -> sock , $ this -> timeout , 0 ) ; $ code = $ this -> read ( ) ; $ host = isset ( $ _SERVER [ 'HTTP_HOST' ] ) && preg_match ( '/^[\w.-]+\z/' , $ _SERVER [ 'HTTP_HOST' ] ) ? $ _SERVER [ 'HTTP_HOST' ] : 'localhost' ; if ( $ code == 220 ) { $ code = $ this -> write ( 'EHLO ' . $ host , 250 , 'HELO' ) ; if ( $ code != 250 ) { $ this -> write ( 'EHLO ' . $ host , 250 , 'HELO' ) ; } } if ( $ this -> tls === true ) { $ this -> write ( 'STARTTLS' , 220 ) ; $ secured = @ stream_socket_enable_crypto ( $ this -> sock , true , STREAM_CRYPTO_METHOD_TLS_CLIENT ) ; if ( ! $ secured ) { throw new ErrorException ( 'Can not secure your connection with tls' , E_ERROR ) ; } } if ( $ this -> username !== null && $ this -> password !== null ) { $ this -> write ( 'AUTH LOGIN' , 334 ) ; $ this -> write ( base64_encode ( $ this -> username ) , 334 , 'username' ) ; $ this -> write ( base64_encode ( $ this -> password ) , 235 , 'password' ) ; } }
|
Connect to an SMTP server
|
52,554
|
private function read ( ) { $ s = null ; for ( ; ! feof ( $ this -> sock ) ; ) { if ( ( $ line = fgets ( $ this -> sock , 1e3 ) ) == null ) { continue ; } $ s = explode ( ' ' , $ line ) [ 0 ] ; if ( preg_match ( '#^[0-9]+$#' , $ s ) ) { break ; } } return ( int ) $ s ; }
|
Read the current connection stream .
|
52,555
|
private function write ( $ command , $ code = null , $ message = null ) { if ( $ message == null ) { $ message = $ command ; } $ command = $ command . Message :: END ; fwrite ( $ this -> sock , $ command , strlen ( $ command ) ) ; $ response = null ; if ( $ code !== null ) { $ response = $ this -> read ( ) ; if ( ! in_array ( $ response , ( array ) $ code ) ) { $ message = isset ( $ message ) ? $ message : '' ; throw new SmtpException ( sprintf ( 'SMTP server did not accept %s with code [%s]' , $ message , $ response ) , E_ERROR ) ; } } return $ response ; }
|
Start an SMTP command
|
52,556
|
public function has ( $ key , $ strict = false ) { $ isset = isset ( $ this -> storage [ $ key ] ) ; if ( $ isset ) { if ( $ strict === true ) { $ isset = $ isset && ! empty ( $ this -> storage [ $ key ] ) ; } } return $ isset ; }
|
Check existence of a key in the session collection
|
52,557
|
public function isEmpty ( ) { $ isEmpty = empty ( $ this -> storage ) ; if ( $ isEmpty === false ) { if ( $ this -> length ( ) == 1 ) { if ( is_null ( $ this -> values ( ) [ 0 ] ) ) { $ isEmpty = true ; } } } return $ isEmpty ; }
|
Check if a collection is empty .
|
52,558
|
public function get ( $ key , $ default = null ) { if ( $ this -> has ( $ key ) ) { return $ this -> storage [ $ key ] == null ? $ default : $ this -> storage [ $ key ] ; } if ( $ default !== null ) { if ( is_callable ( $ default ) ) { return call_user_func ( $ default ) ; } return $ default ; } return null ; }
|
Allows to recover a value or value collection .
|
52,559
|
public function values ( ) { $ r = [ ] ; foreach ( $ this -> storage as $ value ) { array_push ( $ r , $ value ) ; } return new Collection ( $ r ) ; }
|
Get the list of values of collection
|
52,560
|
public function keys ( ) { $ r = [ ] ; foreach ( $ this -> storage as $ key => $ value ) { array_push ( $ r , $ key ) ; } return new Collection ( $ r ) ; }
|
Get the list of keys of collection
|
52,561
|
public function collectionify ( $ key ) { $ data = [ ] ; if ( $ this -> has ( $ key ) ) { $ data = $ this -> storage [ $ key ] ; if ( ! is_array ( $ data ) ) { $ data = [ $ data ] ; } } return new Collection ( $ data ) ; }
|
To retrieve a value or value collection form d instance de collection .
|
52,562
|
public function set ( $ key , $ value ) { if ( $ this -> has ( $ key ) ) { $ old = $ this -> storage [ $ key ] ; $ this -> storage [ $ key ] = $ value ; return $ old ; } $ this -> storage [ $ key ] = $ value ; return null ; }
|
Modify an entry in the collection or the addition if not
|
52,563
|
public function each ( callable $ cb ) { foreach ( $ this -> storage as $ key => $ value ) { call_user_func_array ( $ cb , [ $ value , $ key ] ) ; } }
|
Browse all the values of the collection
|
52,564
|
public function merge ( $ array ) { if ( is_array ( $ array ) ) { $ this -> storage = array_merge ( $ this -> storage , $ array ) ; } elseif ( $ array instanceof Collection ) { $ this -> storage = array_merge ( $ this -> storage , $ array -> toArray ( ) ) ; } else { throw new \ ErrorException ( 'Must be take 1 parameter to be array or Collection' , E_ERROR ) ; } return $ this ; }
|
Merge the collection with a painting or other collection
|
52,565
|
private function aggregate ( $ type , $ cb = null ) { $ data = [ ] ; $ this -> recursive ( $ this -> storage , function ( $ value ) use ( & $ data ) { if ( is_numeric ( $ value ) ) { $ data [ ] = $ value ; } } ) ; $ r = call_user_func_array ( $ type , $ data ) ; if ( is_callable ( $ cb ) ) { call_user_func_array ( $ cb , [ $ r ] ) ; } return $ r ; }
|
Aggregate Execute max|min
|
52,566
|
public function excepts ( array $ except ) { $ data = [ ] ; $ this -> recursive ( $ this -> storage , function ( $ value , $ key ) use ( & $ data , $ except ) { if ( in_array ( $ key , $ except ) ) { $ data [ $ key ] = $ value ; } } ) ; return new Collection ( $ data ) ; }
|
Returns the key list and return an instance of Collection .
|
52,567
|
public function ignores ( array $ ignores ) { $ data = [ ] ; $ this -> recursive ( $ this -> storage , function ( $ value , $ key ) use ( & $ data , $ ignores ) { if ( ! in_array ( $ key , $ ignores ) ) { $ data [ $ key ] = $ value ; } } ) ; return new Collection ( $ data ) ; }
|
Ignore the key that is given to it and return an instance of Collection .
|
52,568
|
public function update ( $ key , $ data , $ overide = false ) { if ( ! $ this -> has ( $ key ) ) { return false ; } if ( ! is_array ( $ this -> storage [ $ key ] ) || $ overide === true ) { $ this -> storage [ $ key ] = $ data ; return true ; } if ( ! is_array ( $ data ) ) { $ data = [ $ data ] ; } $ this -> storage [ $ key ] = array_merge ( $ this -> storage [ $ key ] , $ data ) ; return true ; }
|
Update an existing value in the collection
|
52,569
|
public function yieldify ( ) { foreach ( $ this -> storage as $ key => $ value ) { yield ( object ) [ 'value' => $ value , 'key' => $ key , 'done' => false ] ; } yield ( object ) [ 'value' => null , 'key' => null , 'done' => true ] ; }
|
Launches a generator
|
52,570
|
public function toArray ( ) { $ collection = [ ] ; $ this -> recursive ( $ this -> storage , function ( $ value , $ key ) use ( & $ collection ) { if ( is_object ( $ value ) ) { $ collection [ $ key ] = ( array ) $ value ; } else { $ collection [ $ key ] = $ value ; } } ) ; return $ collection ; }
|
Returns the elements of the collection in table format
|
52,571
|
public function push ( $ value , $ key = null ) { if ( $ key == null ) { $ this -> storage [ ] = $ value ; } else { $ this -> storage [ $ key ] = $ value ; } return $ this ; }
|
Add after the last item in the collection
|
52,572
|
private function recursive ( array $ data , callable $ cb ) { foreach ( $ data as $ key => $ value ) { if ( is_array ( $ value ) || is_object ( $ value ) ) { $ this -> recursive ( ( array ) $ value , $ cb ) ; } else { $ cb ( $ value , $ key ) ; } } }
|
Recursive walk of a table or object
|
52,573
|
public static function parse ( $ viewname , array $ data = [ ] ) { static :: $ content = static :: getInstance ( ) -> getTemplate ( ) -> render ( $ viewname , $ data ) ; return static :: $ instance ; }
|
Parse the view
|
52,574
|
public static function pushEngine ( $ name , $ engine ) { if ( array_key_exists ( $ name , static :: $ engines ) ) { return true ; } if ( ! class_exists ( $ engine ) ) { throw new ViewException ( $ engine . ' does not exists.' ) ; } static :: $ engines [ $ name ] = $ engine ; return true ; }
|
Ajouter un moteur de template
|
52,575
|
public function setFetchMode ( $ fetch ) { $ this -> fetch = $ fetch ; $ this -> pdo -> setAttribute ( PDO :: ATTR_DEFAULT_FETCH_MODE , $ fetch ) ; }
|
Sets the data recovery mode .
|
52,576
|
public function pushMiddleware ( $ middlewares , $ end = false ) { $ middlewares = ( array ) $ middlewares ; if ( $ end ) { array_merge ( $ this -> middlewares , $ middlewares ) ; } else { array_merge ( $ middlewares , $ this -> middlewares ) ; } }
|
Add a middleware to the list
|
52,577
|
private function dispatchControllers ( array $ functions , array $ param ) { $ response = null ; foreach ( $ functions as $ function ) { $ response = call_user_func_array ( $ function [ 'action' ] , array_merge ( $ function [ 'injection' ] , $ param ) ) ; if ( $ response === true ) { continue ; } if ( $ response === false || is_null ( $ response ) ) { return $ response ; } } return $ response ; }
|
Execution of define controller
|
52,578
|
public function injector ( $ classname , $ method = null ) { $ params = [ ] ; $ reflection = new \ ReflectionClass ( $ classname ) ; if ( is_null ( $ method ) ) { $ method = "__invoke" ; } $ parameters = $ reflection -> getMethod ( $ method ) -> getParameters ( ) ; foreach ( $ parameters as $ parameter ) { $ class = $ parameter -> getClass ( ) ; if ( is_null ( $ class ) ) { continue ; } $ constructor = $ class -> getName ( ) ; if ( ! class_exists ( $ constructor , true ) ) { continue ; } if ( ! in_array ( strtolower ( $ constructor ) , $ this -> getInjectorExceptedType ( ) ) ) { if ( method_exists ( $ constructor , 'getInstance' ) ) { $ params [ ] = $ constructor :: getInstance ( ) ; } else { $ params [ ] = new $ constructor ( ) ; } } } return $ params ; }
|
Make any class injection
|
52,579
|
public function injectorForClosure ( callable $ closure ) { $ reflection = new \ ReflectionFunction ( $ closure ) ; $ parameters = $ reflection -> getParameters ( ) ; $ params = [ ] ; foreach ( $ parameters as $ parameter ) { $ type = $ parameter -> getType ( ) ; if ( is_null ( $ type ) ) { continue ; } $ class = trim ( $ type -> getName ( ) ) ; if ( ! class_exists ( $ class , true ) ) { continue ; } if ( ! in_array ( strtolower ( $ class ) , $ this -> getInjectorExceptedType ( ) ) ) { if ( method_exists ( $ class , 'getInstance' ) ) { $ params [ ] = $ class :: getInstance ( ) ; } else { $ params [ ] = new $ class ( ) ; } } } return $ params ; }
|
Injection for closure
|
52,580
|
public function execute ( $ arr , $ arg ) { if ( is_callable ( $ arr ) ) { return call_user_func_array ( $ arr , $ arg ) ; } if ( is_array ( $ arr ) ) { return call_user_func_array ( $ arr , $ arg ) ; } $ controller = $ this -> controller ( $ arr ) ; if ( $ controller [ 'action' ] [ 1 ] == null ) { array_splice ( $ controller [ 'action' ] , 1 , 1 ) ; } if ( is_array ( $ controller ) ) { return call_user_func_array ( $ controller [ 'action' ] , array_merge ( $ controller [ 'injection' ] , $ arg ) ) ; } return false ; }
|
Successively launches a function list .
|
52,581
|
public function controller ( $ controller_name ) { if ( is_null ( $ controller_name ) ) { return null ; } $ parts = preg_split ( '/::|@/' , $ controller_name ) ; if ( count ( $ parts ) == 1 ) { $ parts [ 1 ] = '__invoke' ; } list ( $ class , $ method ) = $ parts ; if ( ! class_exists ( $ class , true ) ) { $ class = sprintf ( '%s\\%s' , $ this -> namespaces [ 'controller' ] , ucfirst ( $ class ) ) ; } $ injections = $ this -> injector ( $ class , $ method ) ; return [ 'action' => [ new $ class ( ) , $ method ] , 'injection' => $ injections ] ; }
|
Load the controllers defined as string
|
52,582
|
public function closure ( $ closure ) { if ( ! is_callable ( $ closure ) ) { return null ; } $ injections = $ this -> injectorForClosure ( $ closure ) ; return [ 'action' => $ closure , 'injection' => $ injections ] ; }
|
Load the closure define as action
|
52,583
|
public function setDefaultHeader ( ) { $ this -> headers [ ] = "Mime-Version: 1.0" ; $ this -> headers [ ] = "Date: " . date ( "r" ) ; $ this -> headers [ ] = "X-Mailer: PHP/" . phpversion ( ) ; if ( $ this -> subject ) { $ this -> headers [ ] = "Subject: " . $ this -> subject ; } }
|
Set the default header
|
52,584
|
public function to ( $ to , $ name = null ) { $ this -> to [ ] = $ this -> formatEmail ( $ to , $ name ) ; return $ this ; }
|
Define the receiver
|
52,585
|
public function toList ( array $ to ) { foreach ( $ to as $ name => $ to ) { $ this -> to [ ] = $ this -> formatEmail ( $ to , ! is_int ( $ name ) ? $ name : null ) ; } return $ this ; }
|
Define the receiver in list
|
52,586
|
private function formatEmail ( $ email , $ name = null ) { if ( ! is_string ( $ name ) && preg_match ( '/^(.+)\s+<(.*)>\z$/' , $ email , $ matches ) ) { array_shift ( $ matches ) ; $ name = $ matches [ 0 ] ; $ email = $ matches [ 1 ] ; } if ( ! Str :: isMail ( $ email ) ) { throw new \ InvalidArgumentException ( "$email is not valid email." , E_USER_ERROR ) ; } return [ $ name , $ email ] ; }
|
Format the email receiver
|
52,587
|
public function addFile ( $ file ) { if ( ! is_file ( $ file ) ) { throw new MailException ( "File not found." , E_USER_ERROR ) ; } $ this -> attachement [ ] = $ file ; return $ this ; }
|
Add an attachment file
|
52,588
|
public function compileHeaders ( ) { if ( count ( $ this -> attachement ) > 0 ) { $ this -> headers [ ] = "Content-type: multipart/mixed; boundary=\"{$this->boundary}\"" . self :: END ; foreach ( $ this -> attachement as $ file ) { $ filename = basename ( $ file ) ; $ this -> headers [ ] = "--" . $ this -> boundary ; $ this -> headers [ ] = "Content-Type: application/octet-stream; name=\"{$filename}\"" ; $ this -> headers [ ] = "Content-Transfer-Encoding: base64" ; $ this -> headers [ ] = "Content-Disposition: attachment" . self :: END ; $ this -> headers [ ] = chunk_split ( base64_encode ( file_get_contents ( $ file ) ) ) ; } $ this -> headers [ ] = "--" . $ this -> boundary ; } return implode ( self :: END , $ this -> headers ) . self :: END ; }
|
Compile the mail header
|
52,589
|
public function from ( $ from , $ name = null ) { $ this -> from = ( $ name !== null ) ? ( ucwords ( $ name ) . " <{$from}>" ) : $ from ; return $ this ; }
|
Define the sender of the mail
|
52,590
|
private function type ( $ message , $ type ) { $ this -> type = $ type ; $ this -> message = $ message ; return $ this ; }
|
Add message body and set message type
|
52,591
|
public function addBcc ( $ mail , $ name = null ) { $ mail = ( $ name !== null ) ? ( ucwords ( $ name ) . " <{$mail}>" ) : $ mail ; $ this -> headers [ ] = "Bcc: $mail" ; return $ this ; }
|
Adds blind carbon copy
|
52,592
|
public function addCc ( $ mail , $ name = null ) { $ mail = ( $ name !== null ) ? ( ucwords ( $ name ) . " <{$mail}>" ) : $ mail ; $ this -> headers [ ] = "Cc: $mail" ; return $ this ; }
|
Add carbon copy
|
52,593
|
public function addReplyTo ( $ mail , $ name = null ) { $ mail = ( $ name !== null ) ? ( ucwords ( $ name ) . " <{$mail}>" ) : $ mail ; $ this -> headers [ ] = "Replay-To: $mail" ; return $ this ; }
|
Add Reply - To
|
52,594
|
public function addReturnPath ( $ mail , $ name = null ) { $ mail = ( $ name !== null ) ? ( ucwords ( $ name ) . " <{$mail}>" ) : $ mail ; $ this -> headers [ ] = "Return-Path: $mail" ; return $ this ; }
|
Add Return - Path
|
52,595
|
public function run ( ) { $ include = $ this -> arg -> getParameter ( '--include' ) ; if ( is_string ( $ include ) ) { $ bootstraps = array_merge ( $ this -> setting -> getBootstrap ( ) , ( array ) $ include ) ; $ this -> setting -> setBootstrap ( $ bootstraps ) ; } if ( ! class_exists ( '\Psy\Shell' ) ) { echo Color :: red ( 'Please, insall psy/psysh:@stable' ) ; return ; } $ config = new \ Psy \ Configuration ( ) ; $ config -> setUpdateCheck ( \ Psy \ VersionUpdater \ Checker :: NEVER ) ; $ prompt = $ this -> arg -> options ( '--prompt' ) ; if ( is_null ( $ prompt ) ) { $ prompt = '(bow) >>' ; } $ prompt = trim ( $ prompt ) . ' ' ; $ config -> setPrompt ( $ prompt ) ; $ shell = new \ Psy \ Shell ( $ config ) ; $ shell -> setIncludes ( $ this -> setting -> getBootstrap ( ) ) ; return $ shell -> run ( ) ; }
|
Launch the REPL console
|
52,596
|
public static function connection ( $ name = null ) { if ( is_null ( $ name ) || strlen ( $ name ) == 0 ) { if ( is_null ( static :: $ name ) ) { static :: $ name = static :: $ config [ 'default' ] ; } $ name = static :: $ name ; } if ( ! isset ( static :: $ config [ 'connection' ] [ $ name ] ) ) { throw new ConnectionException ( 'The connection "' . $ name . '" is not defined.' ) ; } if ( $ name !== static :: $ name ) { static :: $ adapter = null ; } $ config = static :: $ config [ 'connection' ] [ $ name ] ; static :: $ name = $ name ; if ( static :: $ adapter === null ) { if ( $ name == 'mysql' ) { static :: $ adapter = new MysqlAdapter ( $ config ) ; } elseif ( $ name == 'sqlite' ) { static :: $ adapter = new SqliteAdapter ( $ config ) ; } else { throw new ConnectionException ( 'This driver is not praised' ) ; } static :: $ adapter -> setFetchMode ( static :: $ config [ 'fetch' ] ) ; } if ( static :: $ adapter -> getConnection ( ) instanceof PDO && $ name == static :: $ name ) { return static :: getInstance ( ) ; } return static :: getInstance ( ) ; }
|
Connection starts the connection on the DB
|
52,597
|
public static function update ( $ sqlstatement , array $ data = [ ] ) { static :: verifyConnection ( ) ; if ( preg_match ( "/^update\s[\w\d_`]+\s\bset\b\s.+\s\bwhere\b\s.+$/i" , $ sqlstatement ) ) { return static :: executePrepareQuery ( $ sqlstatement , $ data ) ; } return false ; }
|
Execute an UPDATE request
|
52,598
|
public static function select ( $ sqlstatement , array $ data = [ ] ) { static :: verifyConnection ( ) ; if ( ! preg_match ( "/^(select\s.+?\sfrom\s.+;?|desc\s.+;?)$/i" , $ sqlstatement ) ) { throw new DatabaseException ( 'Syntax Error on the Request' , E_USER_ERROR ) ; } $ pdostatement = static :: $ adapter -> getConnection ( ) -> prepare ( $ sqlstatement ) ; static :: $ adapter -> bind ( $ pdostatement , Sanitize :: make ( $ data , true ) ) ; $ pdostatement -> execute ( ) ; return Sanitize :: make ( $ pdostatement -> fetchAll ( ) ) ; }
|
Execute a SELECT request
|
52,599
|
public static function selectOne ( $ sqlstatement , array $ data = [ ] ) { static :: verifyConnection ( ) ; if ( ! preg_match ( "/^select\s.+?\sfrom\s.+;?$/i" , $ sqlstatement ) ) { throw new DatabaseException ( 'Syntax Error on the Request' , E_USER_ERROR ) ; } $ pdostatement = static :: $ adapter -> getConnection ( ) -> prepare ( $ sqlstatement ) ; static :: $ adapter -> bind ( $ pdostatement , $ data ) ; $ pdostatement -> execute ( ) ; return Sanitize :: make ( $ pdostatement -> fetch ( ) ) ; }
|
Executes a select query and returns a single record
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.