idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
52,400
|
protected function compileNumber ( $ key , $ masque ) { if ( ! preg_match ( "/^number$/" , $ masque , $ match ) ) { return ; } if ( is_numeric ( $ this -> inputs [ $ key ] ) ) { return ; } $ this -> last_message = $ this -> lexique ( 'number' , $ key ) ; $ this -> fails = true ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Compile Number Rule
|
52,401
|
protected function compileInt ( $ key , $ masque ) { if ( ! preg_match ( "/^int$/" , $ masque , $ match ) ) { return ; } if ( is_int ( $ this -> inputs [ $ key ] ) ) { return ; } $ this -> last_message = $ this -> lexique ( 'int' , $ key ) ; $ this -> fails = true ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Complie Int Rule
|
52,402
|
protected function compileFloat ( $ key , $ masque ) { if ( ! preg_match ( "/^float$/" , $ masque , $ match ) ) { return ; } if ( is_float ( $ this -> inputs [ $ key ] ) ) { return ; } $ this -> last_message = $ this -> lexique ( 'float' , $ key ) ; $ this -> fails = true ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Complie Float Rule
|
52,403
|
protected function compileAlphaNum ( $ key , $ masque ) { if ( ! preg_match ( "/^alphanum$/" , $ masque ) ) { return ; } if ( Str :: isAlphaNum ( $ this -> inputs [ $ key ] ) ) { return ; } $ this -> last_message = $ this -> lexique ( 'alphanum' , $ key ) ; $ this -> fails = true ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Compile Alphanum Rule
|
52,404
|
protected function compileIn ( $ key , $ masque ) { if ( ! preg_match ( "/^in:(.+)$/" , $ masque , $ match ) ) { return ; } $ values = explode ( "," , end ( $ match ) ) ; foreach ( $ values as $ index => $ value ) { $ values [ $ index ] = trim ( $ value ) ; } if ( in_array ( $ this -> inputs [ $ key ] , $ values ) ) { return ; } $ this -> last_message = $ this -> lexique ( 'in' , [ 'attribute' => $ key , 'value' => implode ( ", " , $ values ) ] ) ; $ this -> fails = true ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Complie In Rule
|
52,405
|
protected function compileLower ( $ key , $ masque ) { if ( ! preg_match ( "/^lower/" , $ masque ) ) { return ; } if ( Str :: isLower ( $ this -> inputs [ $ key ] ) ) { return ; } $ this -> fails = true ; $ this -> last_message = $ this -> lexique ( 'lower' , $ key ) ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Compile Lower Rule
|
52,406
|
protected function compileUpper ( $ key , $ masque ) { if ( ! preg_match ( "/^upper/" , $ masque ) ) { return ; } if ( Str :: isUpper ( $ this -> inputs [ $ key ] ) ) { return ; } $ this -> fails = true ; $ this -> last_message = $ this -> lexique ( 'upper' , $ key ) ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Compile Upper Rule
|
52,407
|
protected function compileAlpha ( $ key , $ masque ) { if ( ! preg_match ( "/^alpha$/" , $ masque ) ) { return ; } if ( Str :: isAlpha ( $ this -> inputs [ $ key ] ) ) { return ; } $ this -> last_message = $ this -> lexique ( 'alpha' , $ key ) ; $ this -> fails = true ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Compile Alpha Rule
|
52,408
|
protected function compileExists ( $ key , $ masque ) { if ( ! preg_match ( "/^exists:(.+)$/" , $ masque , $ match ) ) { return ; } $ catch = end ( $ match ) ; $ parts = explode ( ',' , $ catch ) ; if ( count ( $ parts ) == 1 ) { $ exists = Database :: table ( $ parts [ 0 ] ) -> where ( $ key , $ this -> inputs [ $ key ] ) -> exists ( ) ; } else { $ exists = Database :: table ( $ parts [ 0 ] ) -> where ( $ parts [ 1 ] , $ this -> inputs [ $ key ] ) -> exists ( ) ; } if ( ! $ exists ) { $ this -> last_message = $ this -> lexique ( 'exists' , $ key ) ; $ this -> fails = true ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; } }
|
Compile Exists Rule
|
52,409
|
protected function compileDate ( $ key , $ masque ) { if ( ! preg_match ( "/^date?$/" , $ masque , $ match ) ) { return ; } if ( ! preg_match ( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/' , $ this -> inputs [ $ key ] ) ) { return ; } $ this -> fails = true ; $ this -> last_message = $ this -> lexique ( 'date' , $ key ) ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Compile Date Rule
|
52,410
|
protected function compileRegex ( $ key , $ masque ) { if ( ! preg_match ( "/^regex:(.+)+$/" , $ masque , $ match ) ) { return ; } $ regex = '/' . preg_quote ( $ match [ 1 ] ) . '/' ; if ( ! preg_match ( $ regex , $ this -> inputs [ $ key ] ) ) { return ; } $ this -> fails = true ; $ this -> last_message = $ this -> lexique ( 'regex' , $ key ) ; $ this -> errors [ $ key ] [ ] = [ "masque" => $ masque , "message" => $ this -> last_message ] ; }
|
Compile Regex Rule
|
52,411
|
public function store ( UploadFile $ file , $ location = null , array $ option = [ ] ) { if ( is_array ( $ location ) ) { $ option = $ location ; $ location = null ; } if ( isset ( $ option [ 'as' ] ) ) { $ filename = $ option [ 'as' ] ; } else { $ filename = $ file -> getHashName ( ) ; } if ( is_null ( $ location ) ) { $ location = $ filename ; } else { $ location = trim ( $ location , '/' ) . '/' . $ filename ; } return $ this -> put ( $ location , $ file -> getContent ( ) ) ; }
|
Function to upload a file
|
52,412
|
public function prepend ( $ file , $ content ) { $ tmp_content = file_get_contents ( $ file ) ; $ this -> put ( $ file , $ content ) ; return $ this -> append ( $ file , $ tmp_content ) ; }
|
Add content before the contents of the file
|
52,413
|
public function files ( $ dirname ) { $ dirname = $ this -> path ( $ dirname ) ; $ directory_contents = glob ( $ dirname . "/*" ) ; return array_filter ( $ directory_contents , function ( $ file ) { return filetype ( $ file ) == "file" ; } ) ; }
|
List the files of a folder passed as a parameter
|
52,414
|
public function get ( $ filename ) { $ filename = $ this -> path ( $ filename ) ; if ( ! ( is_file ( $ filename ) && stream_is_local ( $ filename ) ) ) { return null ; } return file_get_contents ( $ filename ) ; }
|
Recover the contents of the file
|
52,415
|
public function move ( $ target , $ source ) { $ this -> copy ( $ target , $ source ) ; $ this -> delete ( $ target ) ; }
|
Renames or moves a source file to a target file .
|
52,416
|
public function exists ( $ filename ) { $ filename = $ this -> path ( $ filename ) ; if ( ! $ this -> isDirectory ( $ filename ) ) { return file_exists ( $ filename ) ; } $ tmp = getcwd ( ) ; $ r = chdir ( $ filename ) ; chdir ( $ tmp ) ; return $ r ; }
|
Check the existence of a file
|
52,417
|
public function path ( $ filename ) { if ( preg_match ( '~^' . $ this -> base_directory . '~' , $ filename ) ) { return $ filename ; } return rtrim ( $ this -> base_directory , '/' ) . '/' . ltrim ( $ filename , '/' ) ; }
|
Resolves file path . Give the absolute path of a path
|
52,418
|
public function generate ( $ seeder ) { $ generator = new Generator ( $ this -> setting -> getSeederDirectory ( ) , "{$seeder}_seeder" ) ; if ( $ generator -> fileExists ( ) ) { echo "\033[0;31mThe seeder already exists.\033[00m" ; exit ( 1 ) ; } $ num = ( int ) $ this -> arg -> options ( ) -> get ( '--seed' , 5 ) ; $ generator -> write ( 'seed' , [ 'num' => $ num , 'name' => $ seeder ] ) ; echo "\033[0;32mThe seeder has been created.\033[00m\n" ; exit ( 0 ) ; }
|
Create a seeder
|
52,419
|
public function table ( $ table_name ) { $ table_name = trim ( $ table_name ) ; if ( is_null ( $ table_name ) ) { $ this -> throwFailsCommand ( 'Specify the seeder table name' , 'help seed' ) ; } if ( ! file_exists ( $ this -> setting -> getSeederDirectory ( ) . "/{$table_name}_seeder.php" ) ) { echo Color :: red ( "Seeder $table_name not exists." ) ; exit ( 1 ) ; } $ this -> make ( [ $ this -> setting -> getSeederDirectory ( ) . "/{$table_name}_seeder.php" ] ) ; }
|
Launch targeted seeding
|
52,420
|
private function login ( ) { [ 'username' => $ username , 'password' => $ password ] = $ this -> config ; set_error_handler ( function ( ) { } ) ; $ is_logged_in = ftp_login ( $ this -> connection , $ username , $ password ) ; restore_error_handler ( ) ; if ( ! $ is_logged_in ) { $ this -> disconnect ( ) ; throw new RuntimeException ( sprintf ( 'Could not login with connection: (s)ftp://%s@%s:%s' , $ username , $ this -> config [ 'hostname' ] , $ this -> config [ 'port' ] ) ) ; } }
|
Make FTP Login .
|
52,421
|
public function store ( UploadFile $ file , $ location = null , array $ option = [ ] ) { $ content = $ file -> getContent ( ) ; $ stream = fopen ( 'php://temp' , 'w+b' ) ; fwrite ( $ stream , $ content ) ; rewind ( $ stream ) ; $ result = $ this -> writeStream ( $ location , $ stream , $ option ) ; fclose ( $ stream ) ; if ( $ result === false ) { return false ; } $ result [ 'content' ] = $ content ; return $ result ; }
|
Store directly the upload file
|
52,422
|
public function append ( $ file , $ content ) { $ stream = fopen ( 'php://temp' , 'r+' ) ; fwrite ( $ stream , $ content ) ; rewind ( $ stream ) ; ftp_set_option ( $ this -> getConnection ( ) , FTP_AUTOSEEK , false ) ; $ size = ftp_size ( $ this -> getConnection ( ) , $ file ) ; $ result = ftp_fput ( $ this -> getConnection ( ) , $ file , $ stream , $ this -> transfer_mode , $ size ) ; fclose ( $ stream ) ; return $ result ; }
|
Append content a file .
|
52,423
|
public function prepend ( $ file , $ content ) { $ remote_file_content = $ this -> get ( $ file ) ; $ stream = fopen ( 'php://temp' , 'r+' ) ; fwrite ( $ stream , $ content ) ; fwrite ( $ stream , $ remote_file_content ) ; rewind ( $ stream ) ; ftp_set_option ( $ this -> getConnection ( ) , FTP_AUTOSEEK , false ) ; $ result = $ this -> writeStream ( $ file , $ stream ) ; fclose ( $ stream ) ; return $ result ; }
|
Write to the beginning of a file specify
|
52,424
|
public function files ( $ dirname = '.' ) { $ listing = $ this -> listDirectoryContents ( $ dirname ) ; return array_values ( array_filter ( $ listing , function ( $ item ) { return $ item [ 'type' ] === 'file' ; } ) ) ; }
|
List files in a directory
|
52,425
|
public function exists ( $ filename ) { $ listing = $ this -> listDirectoryContents ( ) ; $ dirname_info = array_filter ( $ listing , function ( $ item ) use ( $ filename ) { return $ item [ 'name' ] === $ filename ; } ) ; return count ( $ dirname_info ) !== 0 ; }
|
Check that a file exists
|
52,426
|
public function isDirectory ( $ dirname ) { $ listing = $ this -> listDirectoryContents ( ) ; $ dirname_info = array_filter ( $ listing , function ( $ item ) use ( $ dirname ) { return $ item [ 'type' ] === 'directory' && $ item [ 'name' ] === $ dirname ; } ) ; return count ( $ dirname_info ) !== 0 ; }
|
isDirectory alias of is_dir .
|
52,427
|
protected function listDirectoryContents ( $ directory = '.' ) { if ( $ directory && strpos ( $ directory , '.' ) !== 0 ) { ftp_chdir ( $ this -> getConnection ( ) , $ directory ) ; } $ listing = @ ftp_rawlist ( $ this -> getConnection ( ) , '.' ) ? : [ ] ; $ this -> setConnectionRoot ( ) ; return $ this -> normalizeDirectoryListing ( $ listing ) ; }
|
List the directory content
|
52,428
|
private function normalizeDirectoryListing ( $ listing ) { $ normalizedListing = [ ] ; foreach ( $ listing as $ child ) { $ chunks = preg_split ( "/\s+/" , $ child ) ; list ( $ item [ 'rights' ] , $ item [ 'number' ] , $ item [ 'user' ] , $ item [ 'group' ] , $ item [ 'size' ] , $ item [ 'month' ] , $ item [ 'day' ] , $ item [ 'time' ] , $ item [ 'name' ] ) = $ chunks ; $ item [ 'type' ] = $ chunks [ 0 ] { 0 } === 'd' ? 'directory' : 'file' ; array_splice ( $ chunks , 0 , 8 ) ; $ normalizedListing [ implode ( " " , $ chunks ) ] = $ item ; } return $ normalizedListing ; }
|
Normalize directory content listing
|
52,429
|
public static function make ( $ data , $ secure = false ) { $ method = $ secure === true ? 'secure' : 'data' ; $ rNum = '/^[0-9]+(\.[0-9]+)?$/' ; if ( is_string ( $ data ) ) { if ( ! preg_match ( $ rNum , $ data , $ match ) ) { return static :: $ method ( $ data ) ; } if ( count ( $ match ) == 2 ) { $ data = ( float ) $ data ; } else { $ data = ( int ) $ data ; } return $ data ; } if ( is_numeric ( $ data ) ) { return $ data ; } if ( is_array ( $ data ) ) { foreach ( $ data as $ key => $ value ) { $ data [ $ key ] = static :: make ( $ value , $ secure ) ; } return $ data ; } if ( is_object ( $ data ) ) { foreach ( $ data as $ key => $ value ) { $ data -> $ key = static :: make ( $ value , $ secure ) ; } return $ data ; } return $ data ; }
|
To clean the data
|
52,430
|
public static function setKey ( $ key , $ cipher = null ) { static :: $ key = $ key ; if ( ! is_null ( $ cipher ) ) { static :: $ cipher = $ cipher ; } }
|
Set the key
|
52,431
|
public function path ( ) { $ pos = strpos ( $ _SERVER [ 'REQUEST_URI' ] , '?' ) ; if ( $ pos ) { $ uri = substr ( $ _SERVER [ 'REQUEST_URI' ] , 0 , $ pos ) ; } else { $ uri = $ _SERVER [ 'REQUEST_URI' ] ; } return $ uri ; }
|
Get uri send by client .
|
52,432
|
public function method ( ) { $ method = isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) ? $ _SERVER [ 'REQUEST_METHOD' ] : null ; if ( $ method !== 'POST' ) { return $ method ; } if ( array_key_exists ( 'HTTP_X_HTTP_METHOD' , $ _SERVER ) ) { if ( in_array ( $ _SERVER [ 'HTTP_X_HTTP_METHOD' ] , [ 'PUT' , 'DELETE' ] ) ) { $ method = $ _SERVER [ 'HTTP_X_HTTP_METHOD' ] ; } } return $ method ; }
|
Returns the method of the request .
|
52,433
|
public function file ( $ key ) { if ( ! isset ( $ _FILES [ $ key ] ) ) { return null ; } if ( ! is_array ( $ _FILES [ $ key ] [ 'name' ] ) ) { return new UploadFile ( $ _FILES [ $ key ] ) ; } $ files = $ _FILES [ $ key ] ; $ collect = [ ] ; foreach ( $ files [ 'name' ] as $ key => $ name ) { $ file [ 'name' ] = $ name ; $ file [ 'type' ] = $ files [ 'type' ] [ $ key ] ; $ file [ 'size' ] = $ files [ 'size' ] [ $ key ] ; $ file [ 'error' ] = $ files [ 'error' ] [ $ key ] ; $ file [ 'tmp_name' ] = $ files [ 'tmp_name' ] [ $ key ] ; $ collect [ ] = new UploadFile ( $ file ) ; } return new Collection ( $ collect ) ; }
|
Load the factory for FILES
|
52,434
|
public function isAjax ( ) { if ( ! isset ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) ) { return false ; } $ xhr_obj = Str :: lower ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) ; if ( $ xhr_obj == 'xmlhttprequest' || $ xhr_obj == 'activexobject' ) { return true ; } return false ; }
|
Check if we are in the case of an AJAX request .
|
52,435
|
public function locale ( ) { $ accept_language = $ this -> getHeader ( 'accept_language' ) ; $ tmp = explode ( ';' , $ accept_language ) [ 0 ] ; preg_match ( '/^([a-z]+(?:-|_)?[a-z]+)/i' , $ tmp , $ match ) ; return end ( $ match ) ; }
|
Get the request locale .
|
52,436
|
public function lang ( ) { $ accept_language = $ this -> getHeader ( 'accept_language' ) ; $ language = explode ( ',' , explode ( ';' , $ accept_language ) [ 0 ] ) [ 0 ] ; preg_match ( '/([a-z]+)/' , $ language , $ match ) ; return end ( $ match ) ; }
|
Get request lang .
|
52,437
|
public function getHeader ( $ key ) { $ key = str_replace ( '-' , '_' , strtoupper ( $ key ) ) ; if ( $ this -> hasHeader ( $ key ) ) { return $ _SERVER [ $ key ] ; } if ( $ this -> hasHeader ( 'HTTP_' . $ key ) ) { return $ _SERVER [ 'HTTP_' . $ key ] ; } return null ; }
|
Get Request header
|
52,438
|
public function only ( $ exceptions ) { $ data = [ ] ; if ( ! is_array ( $ exceptions ) ) { $ exceptions = func_get_args ( ) ; } foreach ( $ exceptions as $ exception ) { if ( isset ( $ this -> input [ $ exception ] ) ) { $ data [ $ exception ] = $ this -> input [ $ exception ] ; } } return $ data ; }
|
Retrieves the values contained in the exception table
|
52,439
|
protected function checkParseFile ( $ filename , $ extended = true ) { $ tmp_filename = preg_replace ( '/@|\./' , '/' , $ filename ) . $ this -> config [ 'view.extension' ] ; if ( $ this -> config [ 'view.path' ] !== null ) { if ( ! file_exists ( $ this -> config [ 'view.path' ] . '/' . $ tmp_filename ) ) { throw new ViewException ( sprintf ( 'The view [%s] does not exists. %s/%s' , $ tmp_filename , $ this -> config [ 'view.path' ] , $ filename ) , E_ERROR ) ; } } else { if ( ! file_exists ( $ tmp_filename ) ) { throw new ViewException ( sprintf ( 'The view [%s] does not exists.' , $ tmp_filename ) , E_ERROR ) ; } } if ( $ extended ) { $ filename = $ tmp_filename ; } return $ filename ; }
|
Check the parsed file
|
52,440
|
public function match ( $ uri ) { if ( preg_match ( '~(.*)/$~' , $ uri , $ match ) ) { $ uri = end ( $ match ) ; } if ( preg_match ( '~(.*)/$~' , $ this -> path , $ match ) ) { $ this -> path = end ( $ match ) ; } if ( $ this -> path === $ uri ) { return true ; } $ path = implode ( '' , preg_split ( '/(\/:[a-z0-9-_]+\?)/' , $ this -> path ) ) ; if ( count ( explode ( '/' , $ path ) ) != count ( explode ( '/' , $ uri ) ) ) { if ( count ( explode ( '/' , $ this -> path ) ) != count ( explode ( '/' , $ uri ) ) ) { return false ; } } $ path = $ uri ; if ( empty ( $ this -> with ) ) { $ path = preg_replace ( '~:\w+(\?)?~' , '([^\s]+)$1' , $ this -> path ) ; preg_match_all ( '~:([a-z-0-9_-]+?)\?~' , $ this -> path , $ this -> keys ) ; $ this -> keys = end ( $ this -> keys ) ; return $ this -> checkRequestUri ( $ path , $ uri ) ; } if ( ! preg_match_all ( '~:([\w]+)?~' , $ this -> path , $ match ) ) { return $ this -> checkRequestUri ( $ path , $ uri ) ; } $ tmp_path = $ this -> path ; $ this -> keys = end ( $ match ) ; foreach ( $ this -> keys as $ key ) { if ( array_key_exists ( $ key , $ this -> with ) ) { $ tmp_path = preg_replace ( '~:' . $ key . '~' , '(' . $ this -> with [ $ key ] . ')' , $ tmp_path ) ; } } $ this -> with = [ ] ; if ( $ tmp_path != $ this -> path ) { $ path = $ tmp_path ; } return $ this -> checkRequestUri ( $ path , $ uri ) ; }
|
Lets check if the url of the query is conform to that defined by the router
|
52,441
|
private function checkRequestUri ( $ path , $ uri ) { if ( strstr ( $ path , '?' ) == '?' ) { $ uri = rtrim ( $ uri , '/' ) . '/' ; } $ path = str_replace ( '~' , '\\~' , $ path ) ; if ( preg_match ( '~^' . $ path . '$~' , $ uri , $ match ) ) { array_shift ( $ match ) ; $ this -> match = str_replace ( '/' , '' , $ match ) ; return true ; } return false ; }
|
Check the url for the search
|
52,442
|
public function where ( $ where , $ regex_constraint = null ) { if ( is_array ( $ where ) ) { $ other_rule = $ where ; } else { $ other_rule = [ $ where => $ regex_constraint ] ; } $ this -> with = array_merge ( $ this -> with , $ other_rule ) ; return $ this ; }
|
Add the url rules
|
52,443
|
public function call ( ) { foreach ( $ this -> keys as $ key => $ value ) { if ( ! isset ( $ this -> match [ $ key ] ) ) { continue ; } if ( ! is_int ( $ this -> match [ $ key ] ) ) { $ this -> params [ $ value ] = urldecode ( $ this -> match [ $ key ] ) ; continue ; } $ tmp = ( int ) $ this -> match [ $ key ] ; $ this -> params [ $ value ] = $ tmp ; $ this -> match [ $ key ] = $ tmp ; } return Actionner :: getInstance ( ) -> call ( $ this -> cb , $ this -> match ) ; }
|
Function to launch callback functions where the rule have matching .
|
52,444
|
public function name ( $ name ) { $ this -> name = $ name ; $ routes = ( array ) $ this -> config [ 'app.routes' ] ; $ this -> config [ 'app.routes' ] = array_merge ( $ routes , [ $ name => $ this -> getPath ( ) ] ) ; }
|
To give a name to the road
|
52,445
|
public function getParamter ( $ key ) { return isset ( $ this -> params [ $ key ] ) ? $ this -> params [ $ key ] : null ; }
|
Get a parameter element
|
52,446
|
public function send ( Message $ message ) { if ( empty ( $ message -> getTo ( ) ) || empty ( $ message -> getSubject ( ) ) || empty ( $ message -> getMessage ( ) ) ) { throw new InvalidArgumentException ( "An error has occurred. The sender or the message or object omits." , E_USER_ERROR ) ; } if ( isset ( $ this -> config [ 'mail' ] ) ) { $ section = $ this -> config [ 'mail' ] [ 'default' ] ; if ( ! $ message -> fromIsDefined ( ) ) { $ form = $ this -> config [ 'mail' ] [ $ section ] ; $ message -> from ( $ form [ "address" ] , $ form [ "username" ] ) ; } elseif ( ! Str :: isMail ( $ message -> getFrom ( ) ) ) { $ form = $ this -> config [ 'mail' ] [ $ message -> getFrom ( ) ] ; $ message -> from ( $ form [ "address" ] , $ form [ "username" ] ) ; } } $ to = '' ; $ message -> setDefaultHeader ( ) ; foreach ( $ message -> getTo ( ) as $ value ) { if ( $ value [ 0 ] !== null ) { $ to .= $ value [ 0 ] . ' <' . $ value [ 1 ] . '>' ; } else { $ to .= '<' . $ value [ 1 ] . '>' ; } } $ headers = $ message -> compileHeaders ( ) ; $ headers .= 'Content-Type: ' . $ message -> getType ( ) . '; charset=' . $ message -> getCharset ( ) . Message :: END ; $ headers .= 'Content-Transfer-Encoding: 8bit' . Message :: END ; $ status = @ mail ( $ to , $ message -> getSubject ( ) , $ message -> getMessage ( ) , $ headers ) ; return ( bool ) $ status ; }
|
Implement send email
|
52,447
|
public function belongsToMany ( string $ related , ? string $ primary_key = null , ? string $ foreign_key = null ) { $ relatedModel = app ( ) -> make ( $ related ) ; $ local_key = $ local_key ?? $ this -> getKey ( ) ; $ foreign_key = $ foreign_key ?? rtrim ( $ relatedModel -> getTable ( ) , 's' ) . '_id' ; return new BelongsToMany ( $ relatedModel , $ this , $ primary_key , $ foreign_key ) ; }
|
The belongs to many relative
|
52,448
|
public function hasMany ( string $ related , string $ primary_key = '' , string $ foreign_key = '' ) { $ relatedModel = app ( ) -> make ( $ related ) ; $ local_key = $ local_key ?? $ this -> getKey ( ) ; $ foreign_key = $ foreign_key ?? rtrim ( $ relatedModel -> getTable ( ) , 's' ) . '_id' ; return new HasMany ( $ relatedModel , $ this , $ primary_key , $ foreign_key ) ; }
|
The has many relative
|
52,449
|
private function formatParameters ( ) { foreach ( $ GLOBALS [ 'argv' ] as $ key => $ param ) { if ( $ key == 0 ) { continue ; } if ( $ key == 1 ) { $ this -> initCommand ( $ param ) ; continue ; } if ( $ key == 2 && preg_match ( '/^[a-z0-9_\/-]+$/i' , $ param ) ) { $ this -> options [ 'target' ] = $ param ; } elseif ( preg_match ( '/^--[a-z-]+$/' , $ param ) ) { $ this -> options [ 'options' ] [ $ param ] = true ; } elseif ( count ( $ part = explode ( '=' , $ param ) ) == 2 ) { $ this -> options [ 'options' ] [ $ part [ 0 ] ] = $ part [ 1 ] ; } else { $ this -> options [ 'trash' ] [ ] = $ param ; } } if ( isset ( $ this -> options [ 'options' ] ) ) { $ this -> options [ 'options' ] = new Collection ( $ this -> options [ 'options' ] ) ; } }
|
Format the options
|
52,450
|
public function getParameter ( $ key , $ default = null ) { return isset ( $ this -> options [ $ key ] ) ? $ this -> options [ $ key ] : $ default ; }
|
Retrieves a parameter
|
52,451
|
public function options ( $ key = null , $ default = null ) { $ option = $ this -> getParameter ( 'options' , new Collection ( ) ) ; if ( $ key == null ) { return $ option ; } return $ option -> get ( $ key , $ default ) ; }
|
Retrieves the options of the command
|
52,452
|
private function initCommand ( $ param ) { if ( ! preg_match ( '/^[a-z]+:[a-z]+$/' , $ param ) ) { $ this -> options [ 'command' ] = $ param ; return ; } $ part = explode ( ':' , $ param ) ; $ this -> options [ 'command' ] = $ part [ 0 ] ; $ this -> options [ 'action' ] = $ part [ 1 ] ; }
|
Initialize main command
|
52,453
|
public static function findAndDelete ( $ id , $ select = [ '*' ] ) { $ data = static :: find ( $ id , $ select ) ; static :: $ builder -> delete ( ) ; return $ data ; }
|
Find information and delete it
|
52,454
|
public static function findOrFail ( $ id , $ select = [ '*' ] ) { $ data = static :: find ( $ id , $ select ) ; if ( is_null ( $ data ) || count ( $ data ) == 0 ) { throw new NotFoundException ( 'No recordings found.' ) ; } return $ data ; }
|
Find information by id or throws an exception in data box not found
|
52,455
|
public static function create ( array $ data ) { $ static = new static ( ) ; if ( $ static -> timestamps ) { $ data = array_merge ( $ data , [ 'created_at' => date ( 'Y-m-d H:i:s' ) , 'updated_at' => date ( 'Y-m-d H:i:s' ) ] ) ; } if ( ! array_key_exists ( $ static -> primary_key , $ data ) ) { if ( $ static -> autoIncrement ) { $ id_value = [ $ static -> primary_key => null ] ; $ data = array_merge ( $ id_value , $ data ) ; } else { if ( $ static -> primary_key_type == 'string' ) { $ data = array_merge ( [ $ static -> primary_key => '' ] , $ data ) ; } } } $ static -> setAttributes ( $ data ) ; $ r = $ static -> save ( ) ; if ( $ r == 1 ) { $ static -> fireEvent ( 'oncreated' ) ; } return $ static ; }
|
Create a persist information
|
52,456
|
public static function query ( ) { if ( static :: $ builder instanceof Builder ) { if ( static :: $ builder -> getModel ( ) == static :: class ) { return static :: $ builder ; } } $ reflection = new \ ReflectionClass ( static :: class ) ; $ properties = $ reflection -> getDefaultProperties ( ) ; if ( $ properties [ 'table' ] == null ) { $ parts = explode ( '\\' , static :: class ) ; $ table = end ( $ parts ) ; $ table = Str :: camel ( strtolower ( $ table ) ) . 's' ; } else { $ table = $ properties [ 'table' ] ; } if ( ! is_null ( $ properties [ 'connexion' ] ) ) { DB :: connection ( $ properties [ 'connexion' ] ) ; } if ( ! is_null ( $ properties [ 'prefix' ] ) ) { $ prefix = $ properties [ 'prefix' ] ; } else { $ prefix = DB :: getConnectionAdapter ( ) -> getTablePrefix ( ) ; } $ table = $ prefix . $ table ; static :: $ builder = new Builder ( $ table , DB :: getPdo ( ) ) ; static :: $ builder -> setPrefix ( $ prefix ) ; static :: $ builder -> setModel ( static :: class ) ; return static :: $ builder ; }
|
Initialize the connection
|
52,457
|
public function getKeyValue ( ) { if ( array_key_exists ( $ this -> primary_key , $ this -> original ) ) { return $ this -> original [ $ this -> primary_key ] ; } return null ; }
|
Retrieves the primary key value
|
52,458
|
public function save ( ) { $ builder = static :: query ( ) ; $ primary_key_value = $ this -> getKeyValue ( ) ; if ( $ primary_key_value == null ) { $ r = $ builder -> insert ( $ this -> attributes ) ; $ primary_key_value = $ builder -> getLastInsertId ( ) ; if ( $ this -> primary_key_type == 'int' ) { $ primary_key_value = ( int ) $ primary_key_value ; } elseif ( $ this -> primary_key_type == 'float' ) { $ primary_key_value = ( float ) $ primary_key_value ; } elseif ( $ this -> primary_key_type == 'double' ) { $ primary_key_value = ( double ) $ primary_key_value ; } else { $ primary_key_value = ( string ) $ primary_key_value ; } $ this -> attributes [ $ this -> primary_key ] = $ primary_key_value ; $ this -> original = $ this -> attributes ; if ( $ r == 1 ) { $ this -> fireEvent ( 'oncreated' ) ; } return $ r ; } if ( ! $ builder -> exists ( $ this -> primary_key , $ primary_key_value ) ) { return 0 ; } $ this -> original [ $ this -> primary_key ] = $ primary_key_value ; $ update_data = [ ] ; foreach ( $ this -> attributes as $ key => $ value ) { if ( ! isset ( $ this -> original [ $ key ] ) || $ this -> original [ $ key ] != $ value ) { $ update_data [ $ key ] = $ value ; } } $ r = $ builder -> where ( $ this -> primary_key , $ primary_key_value ) -> update ( $ update_data ) ; if ( $ r == 1 ) { $ this -> fireEvent ( 'onupdate' ) ; } return $ r ; }
|
Save aliase on insert action
|
52,459
|
public function touch ( ) { if ( ! $ this -> timestamps ) { return false ; } $ this -> setAttribute ( 'updated_at' , date ( 'Y-m-d H:i:s' ) ) ; return ( bool ) $ this -> save ( ) ; }
|
Used to update the timestamp .
|
52,460
|
public function isUploaded ( ) { if ( ! $ this -> isValid ( ) ) { return false ; } if ( ! isset ( $ this -> file [ 'tmp_name' ] , $ this -> file [ 'error' ] ) ) { return false ; } return is_uploaded_file ( $ this -> file [ 'tmp_name' ] ) && $ this -> file [ 'error' ] === UPLOAD_ERR_OK ; }
|
Check if the file is uploader
|
52,461
|
public function moveTo ( $ to , $ filename = null ) { if ( ! isset ( $ this -> file [ 'tmp_name' ] ) ) { return false ; } if ( ! is_null ( $ filename ) ) { $ filename = $ this -> getHashName ( ) ; } if ( ! is_dir ( $ to ) ) { @ mkdir ( $ to , 0777 , true ) ; } $ resolve = rtrim ( $ to , '/' ) . '/' . $ filename ; return ( bool ) move_uploaded_file ( $ this -> file [ 'tmp_name' ] , $ resolve ) ; }
|
Move the uploader file to a directory .
|
52,462
|
public function get ( $ url , array $ data = [ ] ) { $ this -> resetAndAssociateUrl ( $ url ) ; $ this -> addFields ( $ data ) ; return new Parser ( $ this -> ch ) ; }
|
Make get requete
|
52,463
|
public function post ( $ url , array $ data = [ ] ) { $ this -> resetAndAssociateUrl ( $ url ) ; if ( ! curl_setopt ( $ this -> ch , CURLOPT_POST , true ) ) { if ( ! empty ( $ this -> attach ) ) { curl_setopt ( $ this -> ch , CURLOPT_SAFE_UPLOAD , true ) ; foreach ( $ this -> attach as $ key => $ attach ) { $ this -> attach [ $ key ] = '@' . ltrim ( '@' , $ attach ) ; } $ data = array_merge ( $ this -> attach , $ data ) ; } $ this -> addFields ( $ data ) ; } return new Parser ( $ this -> ch ) ; }
|
make post requete
|
52,464
|
public function put ( $ url , array $ data = [ ] ) { $ this -> resetAndAssociateUrl ( $ url ) ; if ( ! curl_setopt ( $ this -> ch , CURLOPT_PUT , true ) ) { $ this -> addFields ( $ data ) ; } return new Parser ( $ this -> ch ) ; }
|
Make put requete
|
52,465
|
public static function makeCsrfToken ( $ time = null ) { if ( Session :: getInstance ( ) -> has ( '__bow.csrf' ) ) { return true ; } if ( is_int ( $ time ) ) { static :: $ expirate_at = $ time ; } $ token = static :: make ( ) ; Session :: getInstance ( ) -> add ( '__bow.csrf' , [ 'token' => $ token , 'expirate' => time ( ) + static :: $ expirate_at , 'field' => '<input type="hidden" name="_token" value="' . $ token . '"/>' ] ) ; Session :: getInstance ( ) -> add ( '_token' , $ token ) ; return true ; }
|
Csrf token creator
|
52,466
|
public static function make ( ) { $ salt = date ( 'Y-m-d H:i:s' , time ( ) - 10000 ) . uniqid ( rand ( ) , true ) ; $ token = base64_encode ( base64_encode ( openssl_random_pseudo_bytes ( 6 ) ) . $ salt ) ; return Str :: slice ( hash ( 'sha256' , $ token ) , 1 , 62 ) ; }
|
GGenerate an encrypted key
|
52,467
|
public static function csrfExpirated ( $ time = null ) { if ( Session :: getInstance ( ) -> has ( '__bow.csrf' ) ) { return false ; } if ( $ time === null ) { $ time = time ( ) ; } $ csrf = Session :: getInstance ( ) -> get ( '__bow.csrf' ) ; if ( $ csrf [ 'expirate' ] >= ( int ) $ time ) { return true ; } return false ; }
|
Check if the token expires
|
52,468
|
public static function verify ( $ token , $ strict = false ) { if ( ! Session :: getInstance ( ) -> has ( '__bow.csrf' ) ) { return false ; } $ csrf = Session :: getInstance ( ) -> get ( '__bow.csrf' ) ; if ( $ token !== $ csrf [ 'token' ] ) { return false ; } $ status = true ; if ( $ strict ) { $ status = $ status && static :: CsrfExpirated ( time ( ) ) ; } return $ status ; }
|
Check if csrf token is valid
|
52,469
|
private function throwFailsCommand ( $ message , $ command = null ) { echo Color :: red ( $ message ) . "\n" ; if ( ! is_null ( $ command ) ) { echo Color :: green ( sprintf ( 'Type "php bow %s" for more information' , $ command ) ) ; } exit ( 1 ) ; }
|
Throw fails command
|
52,470
|
private function updateOrigin ( ) { foreach ( $ this -> array as $ key => $ value ) { $ this -> dataSet ( $ this -> origin , $ key , $ value ) ; } }
|
Update the original data
|
52,471
|
private function find ( $ origin , $ segment ) { $ parts = explode ( '.' , $ segment ) ; $ array = [ ] ; foreach ( $ parts as $ key => $ part ) { if ( $ key != 0 ) { if ( isset ( $ array [ $ part ] ) && is_array ( $ array [ $ part ] ) ) { $ array = & $ array [ $ part ] ; } continue ; } if ( ! isset ( $ origin [ $ part ] ) ) { return null ; } if ( ! is_array ( $ origin [ $ part ] ) ) { return [ $ origin [ $ part ] ] ; } $ array = & $ origin [ $ part ] ; } return $ array ; }
|
Find information to the origin array
|
52,472
|
public function toJson ( array $ default = null ) { if ( ! $ this -> returnTransfertToPlain ( ) ) { if ( is_array ( $ default ) ) { return json_encode ( $ default ) ; } return false ; } $ data = $ this -> raw ( ) ; return json_encode ( $ data ) ; }
|
Get response content as json
|
52,473
|
private function returnTransfert ( ) { if ( ! curl_setopt ( $ this -> ch , CURLOPT_RETURNTRANSFER , true ) ) { $ this -> close ( ) ; return false ; } return true ; }
|
Set Curl CURLOPT_RETURNTRANSFER option
|
52,474
|
private function returnTransfertToRaw ( ) { if ( $ this -> returnTransfert ( ) ) { if ( ! curl_setopt ( $ this -> ch , CURLOPT_BINARYTRANSFER , true ) ) { $ this -> close ( ) ; return false ; } } return true ; }
|
Set Curl CURLOPT_BINARYTRANSFER option
|
52,475
|
private function returnTransfertToPlain ( ) { if ( $ this -> returnTransfert ( ) ) { if ( ! curl_setopt ( $ this -> ch , CURLOPT_TRANSFERTEXT , true ) ) { $ this -> close ( ) ; return false ; } } return true ; }
|
Set Curl CURLOPT_TRANSFERTEXT option
|
52,476
|
public static function configure ( array $ config ) { if ( ! is_null ( static :: $ instance ) ) { return static :: $ instance ; } static :: $ config = $ config ; static :: $ session = Session :: getInstance ( ) ; return static :: $ instance = new Auth ( $ config [ $ config [ 'default' ] ] ) ; }
|
Configure Auth system
|
52,477
|
public static function onTransmission ( $ event , $ fn , $ priority = 0 ) { if ( ! static :: bound ( $ event ) ) { static :: $ events [ '__bow.transmission.event' ] [ $ event ] = [ ] ; } if ( ! is_string ( $ fn ) ) { throw new EventException ( 'The transmission event must be a string function name' ) ; } static :: $ events [ '__bow.transmission.event' ] [ $ event ] [ ] = new Listener ( $ fn , $ priority ) ; Session :: getInstance ( ) -> add ( "__bow.event.listener" , static :: $ events [ '__bow.transmission.event' ] ) ; }
|
Send an event from page to page
|
52,478
|
public static function off ( $ event ) { if ( static :: bound ( $ event ) ) { unset ( static :: $ events [ $ event ] , static :: $ events [ '__bow.transmission.event' ] [ $ event ] , static :: $ events [ '__bow.once.event' ] [ $ event ] ) ; } }
|
off removes an event saves
|
52,479
|
public static function bound ( $ event ) { return array_key_exists ( $ event , static :: $ events ) || array_key_exists ( $ event , isset ( static :: $ events [ '__bow.transmission.event' ] ) ? static :: $ events [ '__bow.transmission.event' ] : [ ] ) || array_key_exists ( $ event , isset ( static :: $ events [ '__bow.once.event' ] ) ? static :: $ events [ '__bow.once.event' ] : [ ] ) ; }
|
Check whether an event is already recorded at least once .
|
52,480
|
public function pipe ( $ middleware , array $ params = [ ] ) { if ( is_callable ( $ middleware ) ) { $ this -> middlewares [ ] = $ middleware ; } else { $ this -> middlewares [ ] = [ 'class' => $ middleware , 'params' => $ params ] ; } return $ this ; }
|
Add a middleware to the runtime collection
|
52,481
|
public function process ( Request $ request , ... $ args ) { if ( ! isset ( $ this -> middlewares [ $ this -> index ] ) || empty ( $ this -> middlewares ) ) { return Dispatcher :: PIPE_EMPTY ; } $ middleware = $ this -> middlewares [ $ this -> index ] ; $ this -> index ++ ; $ params = $ args ; if ( is_array ( $ middleware ) ) { if ( isset ( $ middleware [ 'params' ] ) ) { $ params = array_merge ( $ args , $ middleware [ 'params' ] ) ; } if ( isset ( $ middleware [ 'class' ] ) ) { $ middleware = [ new $ middleware [ 'class' ] , 'process' ] ; } } $ params = [ $ request , [ $ this , 'process' ] , $ params ] ; return call_user_func_array ( $ middleware , $ params ) ; }
|
Start the middleware running process
|
52,482
|
public function gc ( $ maxlifetime ) { $ this -> sessions ( ) -> where ( 'time' , '<' , $ this -> createTimestamp ( time ( ) + $ maxlifetime ) ) -> delete ( ) ; return true ; }
|
Garbage collector for cleans old sessions
|
52,483
|
public function read ( $ session_id ) { $ session = $ this -> sessions ( ) -> where ( 'id' , $ session_id ) -> first ( ) ; if ( is_null ( $ session ) ) { return '' ; } return $ session -> data ; }
|
Read the session information
|
52,484
|
public function download ( $ file , $ filename = null , array $ headers = [ ] , $ disposition = 'attachment' ) { $ type = mime_content_type ( $ file ) ; if ( $ filename == null ) { $ filename = basename ( $ file ) ; } $ this -> addHeader ( 'Content-Disposition' , $ disposition . '; filename=' . $ filename ) ; $ this -> addHeader ( 'Content-Type' , $ type ) ; $ this -> addHeader ( 'Content-Length' , filesize ( $ file ) ) ; $ this -> addHeader ( 'Content-Encoding' , 'base64' ) ; foreach ( $ headers as $ key => $ value ) { $ this -> addHeader ( $ key , $ value ) ; } $ this -> download_filename = $ file ; $ this -> download = true ; return $ this -> buildHttpResponse ( ) ; }
|
Download the given file as an argument
|
52,485
|
public function status ( $ code ) { if ( in_array ( ( int ) $ code , array_keys ( self :: $ header ) , true ) ) { $ this -> code = $ code ; @ header ( 'HTTP/1.1 ' . $ code . ' ' . self :: $ header [ $ code ] , $ this -> override , $ code ) ; } return $ this ; }
|
Modify http headers
|
52,486
|
private function buildHttpResponse ( ) { $ status_text = static :: $ header [ $ this -> code ] ?? 'Unkdown' ; @ header ( 'HTTP/1.1 ' . $ this -> code . ' ' . $ status_text , $ this -> override , $ this -> code ) ; foreach ( $ this -> getHeaders ( ) as $ key => $ header ) { header ( sprintf ( '%s: %s' , $ key , $ header ) ) ; } if ( $ this -> download ) { readfile ( $ this -> download_filename ) ; die ; } return $ this -> getContent ( ) ; }
|
Build HTTP Response
|
52,487
|
public function send ( $ data , $ code = 200 , array $ headers = [ ] ) { if ( is_array ( $ data ) || $ data instanceof \ stdClass || is_object ( $ data ) ) { return $ this -> json ( $ data , $ code , $ headers ) ; } $ this -> code = $ code ; foreach ( $ headers as $ key => $ value ) { $ this -> addHeader ( $ key , $ value ) ; } $ this -> content = $ data ; return $ this -> buildHttpResponse ( ) ; }
|
Equivalent to an echo except that it ends the application
|
52,488
|
public function render ( $ template , $ data = [ ] , $ code = 200 , array $ headers = [ ] ) { $ this -> code = $ code ; $ this -> withHeaders ( $ headers ) ; $ view = View :: parse ( $ template , $ data ) ; $ this -> content = $ view -> sendContent ( ) ; return $ this -> buildHttpResponse ( ) ; }
|
Make view rendering
|
52,489
|
public function generate ( $ controller ) { $ generator = new Generator ( $ this -> setting -> getControllerDirectory ( ) , $ controller ) ; if ( $ generator -> fileExists ( ) ) { echo Color :: danger ( 'The controller already exists' ) ; exit ( 1 ) ; } $ prefix = preg_replace ( "/controller/i" , "" , strtolower ( $ controller ) ) ; $ model = ucfirst ( $ prefix ) ; $ prefix = '/' . trim ( $ prefix , '/' ) ; $ model_namespace = '' ; $ options = $ this -> arg -> options ( ) ; if ( $ options -> has ( '--with-view' ) && $ this -> readline ( "Do you want me to create the associated views? " ) ) { $ model = preg_replace ( "/controller/i" , "" , strtolower ( $ controller ) ) ; $ model = strtolower ( $ model ) ; $ this -> createDefaultView ( $ model , $ filename ) ; } $ prefix = Str :: plurial ( Str :: snake ( $ prefix ) ) ; $ this -> createResourceController ( $ generator , $ prefix , $ controller , $ model_namespace ) ; exit ( 0 ) ; }
|
Command used to set up the resource system .
|
52,490
|
private function createResourceController ( Generator $ generator , $ prefix , $ controller , $ model_namespace = '' ) { $ generator -> write ( 'controller/rest' , [ 'modelNamespace' => $ model_namespace , 'prefix' => $ prefix , 'baseNamespace' => $ this -> namespaces [ 'controller' ] ] ) ; echo Color :: green ( 'The controller Rest was well created.' ) ; }
|
Create rest controller
|
52,491
|
private function createDefaultView ( $ model , $ filename ) { @ mkdir ( config ( 'view.path' ) . "/" . $ model , 0766 ) ; foreach ( [ "create" , "edit" , "show" , "index" ] as $ value ) { $ filename = "$model/$value" . config ( 'view.extension' ) ; touch ( config ( 'view.path' ) . '/' . $ filename ) ; echo "$filename added\n" ; } }
|
Create the default view for rest Generation
|
52,492
|
public static function isMail ( $ email ) { $ parts = explode ( '@' , $ email ) ; if ( ! is_string ( $ email ) || count ( $ parts ) != 2 ) { return false ; } return ( bool ) filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ; }
|
Check if the email is a valid email .
|
52,493
|
public static function isDomain ( $ domain ) { if ( ! is_string ( $ domain ) ) { throw new \ ErrorException ( 'Accept string ' . gettype ( $ domain ) . ' given' ) ; } return ( bool ) preg_match ( '/^((https?|ftps?|ssl|url|git):\/\/)?[a-zA-Z0-9-_.]+\.[a-z]{2,6}$/' , $ domain ) ; }
|
Check if the string is a domain
|
52,494
|
public static function isAlphaNum ( $ str ) { if ( ! is_string ( $ str ) ) { throw new \ ErrorException ( 'Accept string ' . gettype ( $ str ) . ' given' ) ; } return ( bool ) preg_match ( '/^[a-zA-Z0-9]+$/' , $ str ) ; }
|
Check if the string is in alphanumeric
|
52,495
|
public static function isNumeric ( $ str ) { if ( ! is_string ( $ str ) ) { throw new \ ErrorException ( 'Accept string ' . gettype ( $ str ) . ' given' ) ; } return ( bool ) preg_match ( '/^[0-9]+(\.[0-9]+)?$/' , $ str ) ; }
|
Check if the string is in numeric
|
52,496
|
public static function isAlpha ( $ str ) { if ( ! is_string ( $ str ) ) { throw new \ ErrorException ( 'Accept string ' . gettype ( $ str ) . ' given' ) ; } return ( bool ) preg_match ( '/^[a-zA-Z]+$/' , $ str ) ; }
|
Check if the string is in alpha
|
52,497
|
public static function isSlug ( $ str ) { if ( ! is_string ( $ str ) ) { throw new \ ErrorException ( 'Accept string ' . gettype ( $ str ) . ' given' ) ; } return ( bool ) preg_match ( '/^[a-z0-9-]+[a-z0-9]+$/' , $ str ) ; }
|
Check if the string is in slug format
|
52,498
|
public static function getWords ( $ words , $ len ) { $ wordParts = explode ( ' ' , $ words ) ; $ sentence = '' ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ sentence .= ' ' . $ wordParts [ $ i ] ; } return trim ( $ sentence ) ; }
|
Returns a determined number of words in a string .
|
52,499
|
public static function shuffleWords ( $ words ) { $ wordParts = explode ( ' ' , trim ( $ words ) ) ; $ wordPartsLen = count ( $ wordParts ) ; $ rand = [ ] ; do { $ r = rand ( 0 , $ wordPartsLen - 1 ) ; if ( ! in_array ( $ r , $ rand ) ) { $ rand [ ] = $ r ; } } while ( count ( $ rand ) != $ wordPartsLen ) ; $ sentence = '' ; foreach ( $ rand as $ word ) { $ sentence .= $ wordParts [ $ word ] . ' ' ; } return trim ( $ sentence ) ; }
|
Returns a string of words whose words are mixed .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.