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 ] [ ] = [ "masq...
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" => $ masq...
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" =...
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 ] [ ] = [ "m...
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 ) ) { ...
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" => $ m...
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" => $ m...
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" => $ ...
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...
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 -...
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 -> le...
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 ) ) ...
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 ) ; $ ...
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 ( "Se...
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 Ru...
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 ) ...
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 -> getConne...
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 ) ; $ r...
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 -> normalizeDi...
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' ] , ...
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 ) ...
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' ] ) ) { $ met...
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 ...
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 V...
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-_]+\?...
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 ( '/' , '' , $ matc...
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...
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 -> co...
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 B...
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 ( $ rel...
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 ( ...
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 -> autoInc...
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 [ 'ta...
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_val...
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 ; retur...
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 -> a...
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...
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 && ...
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 ...
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 :: $ ev...
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....
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 ( $ middlew...
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 ->...
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...
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 , $ va...
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 ( $ co...
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 c...
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 a...
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 ...
Returns a string of words whose words are mixed .