idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
48,100
public function setSortableColumns ( $ columns ) { if ( ! empty ( $ this -> columns ( ) -> sortable ) ) { $ columns = array_merge ( $ columns , $ this -> columns ( ) -> sortable ) ; } return $ columns ; }
Make custom columns sortable
48,101
public function names ( $ names ) { if ( is_string ( $ names ) ) { $ names = [ 'name' => $ names ] ; } $ this -> names = $ names ; $ this -> createNames ( ) ; return $ this ; }
Set the names for the PostType
48,102
public function register ( ) { add_action ( 'init' , [ & $ this , 'registerPostType' ] ) ; add_action ( 'init' , [ & $ this , 'registerTaxonomies' ] ) ; add_action ( 'restrict_manage_posts' , [ & $ this , 'modifyFilters' ] ) ; if ( isset ( $ this -> columns ) ) { add_filter ( "manage_{$this->name}_posts_columns" , [ & $ this , 'modifyColumns' ] , 10 , 1 ) ; add_filter ( "manage_{$this->name}_posts_custom_column" , [ & $ this , 'populateColumns' ] , 10 , 2 ) ; add_filter ( 'manage_edit-' . $ this -> name . '_sortable_columns' , [ & $ this , 'setSortableColumns' ] ) ; add_action ( 'pre_get_posts' , [ & $ this , 'sortSortableColumns' ] ) ; } }
Register the PostType to WordPress
48,103
public function registerPostType ( ) { $ options = $ this -> createOptions ( ) ; if ( ! post_type_exists ( $ this -> name ) ) { register_post_type ( $ this -> name , $ options ) ; } }
Register the PostType
48,104
public function createNames ( ) { $ required = [ 'name' , 'singular' , 'plural' , 'slug' , ] ; foreach ( $ required as $ key ) { if ( isset ( $ this -> names [ $ key ] ) ) { $ this -> $ key = $ this -> names [ $ key ] ; continue ; } if ( in_array ( $ key , [ 'singular' , 'plural' ] ) ) { $ name = ucwords ( strtolower ( str_replace ( [ '-' , '_' ] , ' ' , $ this -> names [ 'name' ] ) ) ) ; } if ( $ key === 'slug' ) { $ name = strtolower ( str_replace ( [ ' ' , '_' ] , '-' , $ this -> names [ 'name' ] ) ) ; } if ( in_array ( $ key , [ 'plural' , 'slug' ] ) ) { $ name .= 's' ; } $ this -> $ key = $ name ; } }
Create the required names for the PostType
48,105
public function createOptions ( ) { $ options = [ 'public' => true , 'rewrite' => [ 'slug' => $ this -> slug ] ] ; $ options = array_replace_recursive ( $ options , $ this -> options ) ; if ( ! isset ( $ options [ 'labels' ] ) ) { $ options [ 'labels' ] = $ this -> createLabels ( ) ; } if ( ! isset ( $ options [ 'menu_icon' ] ) && isset ( $ this -> icon ) ) { $ options [ 'menu_icon' ] = $ this -> icon ; } return $ options ; }
Create options for PostType
48,106
public function createLabels ( ) { $ labels = [ 'name' => $ this -> plural , 'singular_name' => $ this -> singular , 'menu_name' => $ this -> plural , 'all_items' => $ this -> plural , 'add_new' => "Add New" , 'add_new_item' => "Add New {$this->singular}" , 'edit_item' => "Edit {$this->singular}" , 'new_item' => "New {$this->singular}" , 'view_item' => "View {$this->singular}" , 'search_items' => "Search {$this->plural}" , 'not_found' => "No {$this->plural} found" , 'not_found_in_trash' => "No {$this->plural} found in Trash" , 'parent_item_colon' => "Parent {$this->singular}:" , ] ; return array_replace_recursive ( $ labels , $ this -> labels ) ; }
Create the labels for the PostType
48,107
public function registerTaxonomies ( ) { if ( ! empty ( $ this -> taxonomies ) ) { foreach ( $ this -> taxonomies as $ taxonomy ) { register_taxonomy_for_object_type ( $ taxonomy , $ this -> name ) ; } } }
Register Taxonomies to the PostType
48,108
public function modifyFilters ( $ posttype ) { if ( $ posttype === $ this -> name ) { $ filters = $ this -> getFilters ( ) ; foreach ( $ filters as $ taxonomy ) { if ( ! taxonomy_exists ( $ taxonomy ) ) { continue ; } $ tax = get_taxonomy ( $ taxonomy ) ; $ terms = get_terms ( [ 'taxonomy' => $ taxonomy , 'orderby' => 'name' , 'hide_empty' => false , ] ) ; if ( empty ( $ terms ) ) { continue ; } $ selected = null ; if ( isset ( $ _GET [ $ taxonomy ] ) ) { $ selected = sanitize_title ( $ _GET [ $ taxonomy ] ) ; } $ dropdown_args = [ 'option_none_value' => '' , 'hide_empty' => 0 , 'hide_if_empty' => false , 'show_count' => true , 'taxonomy' => $ tax -> name , 'name' => $ taxonomy , 'orderby' => 'name' , 'hierarchical' => true , 'show_option_none' => "Show all {$tax->label}" , 'value_field' => 'slug' , 'selected' => $ selected ] ; wp_dropdown_categories ( $ dropdown_args ) ; } } }
Modify and display filters on the admin edit screen
48,109
public function getFilters ( ) { $ filters = [ ] ; if ( ! is_null ( $ this -> filters ) ) { return $ this -> filters ; } if ( is_null ( $ this -> filters ) && ! empty ( $ this -> taxonomies ) ) { return $ this -> taxonomies ; } return $ filters ; }
Calculate the filters for the PostType
48,110
public function populateColumns ( $ column , $ post_id ) { if ( isset ( $ this -> columns -> populate [ $ column ] ) ) { call_user_func_array ( $ this -> columns ( ) -> populate [ $ column ] , [ $ column , $ post_id ] ) ; } }
Populate custom columns for the PostType
48,111
public function initialize ( $ limit , $ total , $ qry_url = '?' ) { $ this -> limit = $ limit ; $ this -> total = $ total ; $ this -> page = ! isset ( $ _GET [ "page" ] ) ? 1 : ( int ) ( $ _GET [ "page" ] ) ; $ this -> startpoint = ( $ this -> page * $ this -> limit ) - $ this -> limit ; }
Initialize Pagination instance .
48,112
public function dispatch ( $ route , $ request ) { $ request -> setParam ( 'Closure' , $ route [ 4 ] ) ; if ( isset ( $ route [ 3 ] ) && is_string ( $ route [ 3 ] ) ) { $ view = $ route [ 3 ] ; $ data = $ route [ 4 ] ; return [ 'view' => [ $ view , $ data ] ] ; } elseif ( isset ( $ route [ 2 ] ) && is_string ( $ route [ 2 ] ) ) { list ( $ controller , $ method ) = explode ( '@' , $ route [ 2 ] ) ; return [ 'controller' => [ $ controller , $ method ] ] ; } elseif ( isset ( $ route [ 2 ] ) && ( $ route [ 2 ] instanceof Closure || get_class ( $ route [ 2 ] ) === "Closure" ) ) { $ function = $ route [ 2 ] ; $ reflectionFunction = new ReflectionFunction ( $ function ) ; $ numReqParam = $ reflectionFunction -> getNumberOfRequiredParameters ( ) ; if ( $ numReqParam > count ( $ request -> getParam ( 'Closure' ) ) ) { throw new Exception ( 'Invaliding number of required parameter passed in route\'s callable function: ' . $ route [ 1 ] ) ; } ob_start ( ) ; if ( $ request -> getParam ( 'Closure' ) !== false && is_array ( $ request -> getParam ( 'Closure' ) ) ) { $ return = call_user_func_array ( $ route [ 2 ] , $ request -> getParam ( 'Closure' ) ) ; } else { throw new Exception ( 'Invaliding parameter passed in route\'s callable function: ' . $ route [ 1 ] ) ; } $ output = ob_get_clean ( ) ; return [ 'output' => [ $ output , $ return ] ] ; } else { throw new Exception ( 'Invaliding route is registered for: ' . $ route [ 1 ] ) ; } }
Dispatch Request to controller or method .
48,113
static public function get ( $ route , $ mix = null , $ view = null ) { self :: $ instance -> register ( 'GET' , $ route , $ mix , $ view ) ; }
register a GET method route .
48,114
static public function post ( $ route , $ mix = null , $ view = null ) { self :: $ instance -> register ( 'POST' , $ route , $ mix , $ view ) ; }
register a POST method route .
48,115
static public function view ( $ route , $ view = null , array $ data = [ ] ) { self :: $ instance -> register ( 'GET' , $ route , null , $ view , $ data ) ; }
register a GET method route with view .
48,116
public function register ( $ method , $ route , $ mix = null , $ view = null , $ data = [ ] ) { if ( $ mix == null && $ view == null ) { $ mix = 'IndexController@index' ; } if ( is_string ( $ mix ) && $ mix !== null ) { if ( strpos ( $ mix , '@' ) === false ) { $ mix = $ mix . '@index' ; } } $ route = trim ( $ route , '/ ' ) ; $ route = ( self :: $ instance -> prefix == null ) ? $ route : self :: $ instance -> prefix . '/' . $ route ; $ array = $ route === '' ? [ ] : explode ( '/' , $ route ) ; $ size = count ( $ array ) ; $ route = '/' . $ route ; if ( strpos ( $ route , '{' ) !== false ) { $ to = 0 ; $ param = true ; foreach ( $ array as $ i => $ uriPiece ) { $ uriPiece = trim ( $ uriPiece ) ; if ( strpos ( $ uriPiece , '{' ) !== false ) { if ( strpos ( $ uriPiece , '{' ) === 0 && strpos ( $ uriPiece , '}' ) !== false && strpos ( $ uriPiece , '}' ) === ( strlen ( $ uriPiece ) - 1 ) ) { $ args [ $ uriPiece ] = rtrim ( ltrim ( $ uriPiece , '{' ) , '}' ) ; } else { $ args [ $ uriPiece ] = null ; } } else { $ to = $ i + 1 ; $ args [ $ uriPiece ] = null ; } } $ base_size = $ to ; $ base_route = array_slice ( $ array , 0 , $ to , true ) ; } else { $ param = false ; $ base_size = $ size ; $ args = null ; $ base_route = $ route ; } $ base_route = is_array ( $ base_route ) ? implode ( '/' , $ base_route ) : $ base_route ; if ( trim ( $ base_route ) === '' ) $ base_route = '/' ; self :: $ instance -> routes [ ] = [ $ method , $ route , $ mix , $ view , $ data , $ args , $ size , $ base_size , $ param ] ; }
register a route .
48,117
public function sortRoute ( ) { $ sort = uasort ( $ this -> routes , function ( $ a , $ b ) { if ( $ a [ 7 ] == $ b [ 7 ] ) { return 0 ; } return ( $ a [ 7 ] > $ b [ 7 ] ) ? - 1 : 1 ; } ) ; }
sort registered routes by there base uri .
48,118
static public function group ( $ closure ) { $ backtrace = debug_backtrace ( ) ; if ( self :: $ instance -> prefix == null ) { exit ( 'Can not be called statically or directly. Use Route::prefix(name)->group(routes-to-be-registered)' ) ; } if ( $ closure instanceof Closure ) { call_user_func ( $ closure ) ; } self :: $ instance -> prefix = null ; }
Registered group routes .
48,119
static public function redirect ( $ routeFrom , $ routeTo , $ http_response_code = 302 ) { $ closure = function ( $ routeTo , $ replace , $ http_response_code ) { Response :: $ redirectHeader = [ $ routeTo , $ replace , $ http_response_code ] ; } ; self :: $ instance -> register ( 'GET' , $ routeFrom , $ closure , null , [ $ routeTo , true , $ http_response_code ] ) ; }
Registered redirect routes .
48,120
static public function getRoute ( $ uri = null ) { $ routes = self :: $ instance -> routes ; if ( $ uri === null ) { foreach ( $ routes as $ i => $ route ) { $ routes [ $ i ] = \ array_diff_key ( $ routes [ $ i ] , [ 3 => "xy" , 4 => "xy" , 5 => "xy" , 6 => "xy" , 7 => "xy" , 8 => "xy" ] ) ; if ( ! is_string ( $ routes [ $ i ] [ 2 ] ) && is_object ( $ routes [ $ i ] [ 2 ] ) && is_callable ( $ routes [ $ i ] [ 2 ] ) && $ routes [ $ i ] [ 2 ] instanceof \ Closure ) { $ routes [ $ i ] [ 2 ] = "Closure" ; } } return $ routes ; } else { foreach ( $ routes as $ i => $ route ) { if ( $ route [ 1 ] === "/" . ltrim ( $ uri , "/" ) ) { return $ route ; } } } }
Get specific or all Registered redirect routes .
48,121
public function checkUpdate ( ) { $ url = 'https://repo.packagist.org/p/ironphp/ironphp.json' ; $ packagistJson = @ file_get_contents ( $ url ) ; if ( $ packagistJson === true ) { $ packagistArray = json_decode ( $ packagistJson , true ) ; $ packagistData = $ packagistArray [ 'packages' ] [ 'ironphp/ironphp' ] [ 'dev-master' ] ; $ time = $ packagistData [ 'time' ] ; $ version = $ packagistData [ 'version' ] ; $ branchAlias = $ packagistData [ 'extra' ] [ 'branch-alias' ] [ 'dev-master' ] ; date_default_timezone_set ( 'Asia/Kolkata' ) ; $ parsedTime = date_parse ( $ time ) ; $ timeStamp = mktime ( $ parsedTime [ 'hour' ] , $ parsedTime [ 'minute' ] , $ parsedTime [ 'second' ] , $ parsedTime [ 'month' ] , $ parsedTime [ 'day' ] , $ parsedTime [ 'year' ] ) ; } $ installData = $ this -> app -> getIntallTime ( ) ; if ( $ packagistJson === true ) { echo Colors :: WHITE . " " . str_replace ( 'T' , ' ' , substr ( date ( DATE_ATOM , $ timeStamp ) , 0 , 19 ) ) ; echo Colors :: GREEN . "\nChecking updates... " . Colors :: WHITE ; if ( $ timeStamp > $ installData -> time ) { if ( $ branchAlias != $ this -> app -> version ( ) ) { print "Package have an update " . $ branchAlias ; } else { print "Package have an update " . $ version ; } } else { print "There is no update." ; } } else { echo Colors :: GREEN . "\nChecking updates... " . Colors :: WHITE . " No internet!" ; } }
Check application update .
48,122
public function findModel ( $ model ) { $ file = $ this -> basePath ( "app/Model/$model.php" ) ; if ( $ this -> findFile ( $ file ) ) { return $ file ; } else { throw new Exception ( $ file . " Model file is missing." ) ; exit ; } }
Find a Model .
48,123
public function findView ( $ view ) { $ file = $ this -> basePath ( "app/View/$view.php" ) ; if ( $ this -> findFile ( $ file ) ) { return $ file ; } else { throw new Exception ( $ file . " View file is missing." ) ; exit ; } }
Find a View .
48,124
public function findTemplate ( $ template ) { $ file = $ this -> basePath ( "app/Template/$template" ) ; if ( $ this -> findFile ( $ file ) ) { return $ file ; } elseif ( $ this -> findFile ( $ file . '.html' ) ) { return $ file . '.html' ; } elseif ( $ this -> findFile ( $ file . '.php' ) ) { return $ file . '.php' ; } else { throw new Exception ( $ file . " Template file is missing." ) ; exit ; } }
Find a Template .
48,125
public function findController ( $ controller ) { $ file = $ this -> basePath ( "app/Controller/$controller.php" ) ; if ( $ this -> findFile ( $ file ) ) { return true ; } else { throw new Exception ( $ file . " Controller file is missing." ) ; exit ; } }
Find a Controller .
48,126
public function hasMethod ( $ controllerObj , $ method ) { if ( method_exists ( $ controllerObj , $ method ) ) { return true ; } else { throw new Exception ( $ method . " method is missing in " . get_class ( $ controllerObj ) . " Controller." ) ; exit ; } }
Check if Controller has method or not .
48,127
public function requireFile ( $ file , $ return = false ) { if ( $ this -> findFile ( $ file ) ) { if ( $ return !== false ) { return require ( $ file ) ; } else { require ( $ file ) ; } } else { throw new Exception ( $ file . " file is missing." ) ; exit ; } }
Require a file .
48,128
public function setKey ( ) { if ( trim ( env ( 'APP_KEY' ) ) != '' ) { return true ; } $ appKey = '' ; for ( $ i = 0 ; $ i < 32 ; $ i ++ ) { $ appKey .= chr ( rand ( 0 , 255 ) ) ; } $ appKey = 'base64:' . base64_encode ( $ appKey ) ; $ file = $ this -> basePath ( '.env' ) ; $ lines = $ this -> parseEnvFile ( $ file ) ; $ flag = false ; foreach ( $ lines as $ i => $ line ) { $ lines [ $ i ] = trim ( $ line ) ; $ lines [ $ i ] = trim ( $ line , "\n" ) ; if ( strpos ( $ line , 'APP_KEY' ) !== false ) { $ data = explode ( '=' , $ line , 2 ) ; if ( ! isset ( $ data [ 1 ] ) || trim ( $ data [ 1 ] ) == '' ) { $ lines [ $ i ] = "APP_KEY=" . $ appKey ; $ flag = true ; } } } if ( $ flag == false ) { $ lines = [ "APP_KEY=" . $ appKey ] + $ lines ; } $ data = implode ( "\n" , $ lines ) ; if ( file_put_contents ( $ file , $ data ) ) { putenv ( "APP_KEY=$appKey" ) ; $ _ENV [ 'APP_KEY' ] = $ appKey ; $ _SERVER [ 'APP_KEY' ] = $ appKey ; return true ; } else { throw new Exception ( 'Failed to write in .env file.' ) ; } }
Set Application secret key .
48,129
public function findCommand ( $ command , $ system = true ) { $ file = dirname ( __DIR__ ) . "/Console/Command/" . ucfirst ( $ command ) . "Command.php" ; if ( $ this -> findFile ( $ file ) ) { return true ; } else { return false ; } }
Find a Command .
48,130
public function setTimezone ( $ default ) { $ timezone = "" ; if ( is_link ( "/etc/localtime" ) ) { $ filename = readlink ( "/etc/localtime" ) ; $ pos = strpos ( $ filename , "zoneinfo" ) ; if ( $ pos ) { $ timezone = substr ( $ filename , $ pos + strlen ( "zoneinfo/" ) ) ; } else { $ timezone = $ default ; } } elseif ( is_link ( "/etc/timezone" ) ) { $ timezone = file_get_contents ( "/etc/timezone" ) ; if ( ! strlen ( $ timezone ) ) { $ timezone = $ default ; } } else { $ timezone = $ default ; } date_default_timezone_set ( $ timezone ) ; }
Set timezone .
48,131
private function getPagination ( ) { if ( $ this -> pagination == null ) { $ this -> pagination = new \ Friday \ Helper \ Pagination ( ) ; } return $ this -> pagination ; }
Get Instance of Pagination .
48,132
private function getDataMapper ( ) { if ( $ this -> dataMapper == null ) { $ this -> dataMapper = new \ Friday \ Model \ DataMapper ( self :: $ app -> config ) ; } return $ this -> dataMapper ; }
Get instance of DataMapper .
48,133
public function register ( $ time = 60 ) { $ _SESSION [ 'session_id' ] = session_id ( ) ; $ _SESSION [ 'session_time' ] = intval ( $ time ) ; $ _SESSION [ 'session_start' ] = $ this -> newTime ( ) ; }
Register the session .
48,134
private function timeNow ( ) { $ currentHour = date ( 'H' ) ; $ currentMin = date ( 'i' ) ; $ currentSec = date ( 's' ) ; $ currentMon = date ( 'm' ) ; $ currentDay = date ( 'd' ) ; $ currentYear = date ( 'y' ) ; return mktime ( $ currentHour , $ currentMin , $ currentSec , $ currentMon , $ currentDay , $ currentYear ) ; }
Returns the current time .
48,135
private function newTime ( ) { $ currentHour = date ( 'H' ) ; $ currentMin = date ( 'i' ) ; $ currentSec = date ( 's' ) ; $ currentMon = date ( 'm' ) ; $ currentDay = date ( 'd' ) ; $ currentYear = date ( 'y' ) ; return mktime ( $ currentHour , ( $ currentMin + $ _SESSION [ 'session_time' ] ) , $ currentSec , $ currentMon , $ currentDay , $ currentYear ) ; }
Generates new time .
48,136
public function serve ( $ host = '127.0.0.1' , $ port = '8000' , $ public_html = 'public' ) { print Colors :: LIGHT_CYAN . "Built-in development server started [/public]: " . Colors :: YELLOW . "<http://$host:$port>" . Colors :: WHITE . PHP_EOL . "You can exit with `CTRL+C`" . PHP_EOL . Colors :: BG_BLACK . Colors :: WHITE ; exec ( "php -S $host:$port -t $public_html" ) ; }
Run app in development server .
48,137
public function run ( ) { $ output = PHP_EOL . $ this -> key ( ) . Colors :: BG_BLACK . Colors :: WHITE ; return $ output ; }
Execute Command .
48,138
public function key ( ) { $ set = $ this -> getConsole ( ) -> setKey ( ) ; return $ set ? Colors :: GREEN . "Application key set successfully." : Colors :: RED . "Error: Key is not set." ; }
Generate new key .
48,139
public function getRoute ( $ route = null ) { $ routes = $ this -> getConsole ( ) -> getRoutes ( $ route ) ; $ l1 = 10 ; $ l2 = 10 ; $ l3 = 10 ; $ list = "" ; foreach ( $ routes as $ route ) { if ( $ l1 < strlen ( $ route [ 1 ] ) ) { $ l1 = strlen ( $ route [ 1 ] ) ; } if ( $ l2 < strlen ( $ route [ 0 ] ) ) { $ l2 = strlen ( $ route [ 0 ] ) ; } if ( $ l3 < strlen ( $ route [ 2 ] ) ) { $ l3 = strlen ( $ route [ 2 ] ) ; } } foreach ( $ routes as $ route ) { $ list .= "| $route[1]" . str_repeat ( ' ' , $ l1 - strlen ( $ route [ 1 ] ) ) . " | $route[0]" . str_repeat ( ' ' , $ l2 - strlen ( $ route [ 0 ] ) ) . " | $route[2]" . str_repeat ( ' ' , $ l3 - strlen ( $ route [ 2 ] ) ) . " |+" . str_repeat ( '-' , $ l1 + 2 ) . "+" . str_repeat ( '-' , $ l2 + 2 ) . "+" . str_repeat ( '-' , $ l3 + 2 ) . "+" ; } $ list = "+" . str_repeat ( '-' , $ l1 + 2 ) . "+" . str_repeat ( '-' , $ l2 + 2 ) . "+" . str_repeat ( '-' , $ l3 + 2 ) . "+| " . Colors :: GREEN . Colors :: BG_BLACK . "URI" . Colors :: WHITE . Colors :: BG_BLACK . str_repeat ( ' ' , $ l1 - strlen ( 'URI' ) ) . " | " . Colors :: GREEN . Colors :: BG_BLACK . "Method" . Colors :: WHITE . Colors :: BG_BLACK . str_repeat ( ' ' , $ l2 - strlen ( 'Method' ) ) . " | " . Colors :: GREEN . Colors :: BG_BLACK . "Action" . Colors :: WHITE . Colors :: BG_BLACK . str_repeat ( ' ' , $ l3 - strlen ( 'Action' ) ) . " |+" . str_repeat ( '-' , $ l1 + 2 ) . "+" . str_repeat ( '-' , $ l2 + 2 ) . "+" . str_repeat ( '-' , $ l3 + 2 ) . "+" . $ list ; return $ list ; }
Return list of routes .
48,140
public function executeHelp ( $ command , $ option = [ ] ) { $ commandClass = "\\Friday\\Console\\Command\\" . ucfirst ( $ command ) . "Command" ; $ cmd = new $ commandClass ( $ option ) ; return $ cmd -> help ( ) ; }
Execute Help command .
48,141
public function getWelInfo ( ) { return Colors :: BG_BLACK . Colors :: LIGHT_BLUE . str_repeat ( "-" , 73 ) . PHP_EOL . Colors :: WHITE . "Welcome to " . Colors :: GREEN . "IronPHP" . Colors :: WHITE . " Framework " . Colors :: YELLOW . "" . Application :: VERSION . Colors :: WHITE . " (env: " . Colors :: YELLOW . ( env ( 'APP_ENV' ) === 'dev' ? 'development' : 'production' ) . Colors :: WHITE . ", debug: " . Colors :: YELLOW . ( env ( 'APP_DEBUG' ) ? 'true' : 'false' ) . Colors :: WHITE . ")" . PHP_EOL . Colors :: LIGHT_BLUE . str_repeat ( "-" , 73 ) . PHP_EOL ; }
Get welcome info of Console Application .
48,142
public function setTable ( $ table , $ pagination ) { $ this -> where = null ; $ this -> limit = null ; $ this -> order = null ; $ this -> duplicateUpdate = null ; $ this -> query = null ; $ this -> pagination = $ pagination ; $ this -> table = $ table ; return $ this ; }
Sets the database table name .
48,143
public function getAll ( $ fields = null , $ sqlQuery = false ) { $ sql = $ this -> buildQuery ( 'select' , $ fields ) ; if ( $ sqlQuery === true ) { return $ this -> getQuery ( ) ; } $ result = $ this -> executeQuery ( $ sql ) ; if ( $ result -> num_rows == 0 ) { return [ ] ; } while ( $ row = $ result -> fetch_array ( MYSQLI_ASSOC ) ) { $ data [ ] = $ row ; } return $ data ; }
Get all fields from table
48,144
public function getPaginated ( $ limit = 1 , $ fields = null , $ sqlQuery = false ) { $ sql = $ this -> buildQuery ( 'select' , $ fields , [ 'count' => null , 'field' => 'num' ] ) ; $ result = $ this -> executeQuery ( $ sql ) ; $ row = $ result -> fetch_array ( MYSQLI_ASSOC ) ; $ total = $ row [ 'num' ] ; if ( $ total == 0 && $ sqlQuery == false ) { return [ ] ; } $ this -> pagination -> initialize ( $ limit , $ total ) ; return $ this -> limit ( $ limit , $ this -> pagination -> getStartPoint ( ) ) -> getAll ( $ fields , $ sqlQuery ) ; }
Get paginated fields from table
48,145
public function update ( $ sqlQuery = false ) { $ field = func_get_args ( ) ; if ( func_num_args ( ) == 0 ) { echo 'no data to save' ; exit ; } elseif ( func_num_args ( ) == 1 ) { if ( is_array ( $ field [ 0 ] ) ) { $ data = $ field [ 0 ] ; } else { $ data = $ field [ 0 ] ; } } else { echo 'invalid data' ; exit ; } $ sql = $ this -> buildQuery ( 'update' , $ data ) ; if ( $ sqlQuery === true ) { return $ this -> getQuery ( ) ; } $ result = $ this -> executeQuery ( $ sql ) ; return $ result ; }
Update data to table
48,146
public function where ( $ where , $ glue = 'AND' ) { if ( is_array ( $ where ) && count ( $ where ) != 0 ) { foreach ( $ where as $ field => $ value ) { $ array [ ] = " `$field` = " . ( ( is_string ( $ value ) ? "'$value'" : $ value ) ) ; } $ this -> where = " WHERE" . implode ( " $glue" , $ array ) ; } elseif ( is_string ( $ where ) && trim ( $ where ) != '' ) { $ where = trim ( $ where ) ; $ where = trim ( $ where , 'WHERE ' ) ; $ where = rtrim ( $ where ) ; $ this -> where = ' WHERE ' . $ where ; } return $ this ; }
Create WHERE clause
48,147
public function orderBy ( $ field , $ order = 'ASC' ) { if ( is_string ( $ field ) && trim ( $ field ) != '' ) { $ field = trim ( $ field ) ; $ field = ltrim ( $ field , 'ORDER BY ' ) ; $ this -> order = ' ORDER BY `' . $ field . '`' . ( ( $ order == 'DESC' ) ? ' DESC' : ' ASC' ) ; } return $ this ; }
Create ORDER BY clause
48,148
public function executeQuery ( $ sql ) { $ result = $ this -> connection -> query ( $ sql ) ; $ this -> errno = $ this -> connection -> errno ; $ this -> error = $ this -> connection -> error ; if ( $ this -> connection -> errno ) { echo 'Query Error [' . $ this -> errno . '] : ' . $ this -> error . ' : ' . $ sql ; } if ( $ this -> errno == 1054 ) { echo 'Table not set properly in query' ; } return $ result ; }
Run sql query .
48,149
function sanitizeFormValue ( $ str ) { $ str = trim ( $ str ) ; if ( get_magic_quotes_gpc ( ) ) { $ str = stripslashes ( $ str ) ; } return $ this -> connection -> real_escape_string ( $ str ) ; }
Function to sanitize values received from the form . Prevents SQL injection .
48,150
public function run ( ) { $ controller = "Controller\\" . $ this -> controller ; call_user_func_array ( array ( $ controller , $ this -> action ) , $ this -> params ) ; }
Call method of controller with parameters .
48,151
public function addHeaders ( array $ headers = [ ] ) { $ this -> headers = [ ] ; if ( $ headers != [ ] ) { foreach ( $ headers as $ header ) { $ this -> headers [ ] = $ header ; } } return $ this ; }
Add headers .
48,152
public function sendHeader ( $ output = null , $ replace = true , $ http_response_code = null ) { if ( ! headers_sent ( ) ) { if ( static :: $ redirectHeader !== null ) { $ this -> redirect ( ) ; } if ( $ this -> version === 'HTTP/1.1' ) { if ( count ( $ this -> headers ) === 0 ) { header ( "$this->version $this->header" ) ; } } else { throw new Exception ( "Invalid HTTP version " . $ this -> version . "." ) ; exit ; } foreach ( $ this -> headers as $ header ) { if ( $ http_response_code == null ) { header ( "$header" , $ replace ) ; } else { header ( "$header" , $ replace , $ http_response_code ) ; } } if ( $ output ) { print $ output ; exit ; } } }
Send a HTTP header .
48,153
public function commandError ( $ errorMessage ) { $ output = PHP_EOL . Colors :: BG_RED . str_repeat ( " " , strlen ( $ errorMessage ) + 4 ) . PHP_EOL . Colors :: WHITE . " $errorMessage " . PHP_EOL . Colors :: BG_RED . str_repeat ( " " , strlen ( $ errorMessage ) + 4 ) . PHP_EOL . Colors :: BG_BLACK . Colors :: WHITE ; return $ output ; }
Command Error .
48,154
public function logging ( $ log = false ) { if ( $ log !== false ) { if ( ! ini_get ( 'log_errors' ) ) { ini_set ( 'log_errors' , true ) ; } if ( ! ini_get ( 'error_log' ) ) { ini_set ( 'error_log' , $ log ) ; } } }
Set PHP internal logging file .
48,155
public function getParam ( $ key ) { if ( ! isset ( $ this -> params [ $ key ] ) ) { throw new InvalidArgumentException ( "The request parameter with key '$key' is invalid." ) ; } return $ this -> params [ $ key ] ; }
Get specific parameter .
48,156
public function renderView ( $ viewPath = null , $ data = [ ] , $ layout = null ) { ob_start ( ) ; require ( $ viewPath ) ; $ viewData = ob_get_contents ( ) ; ob_end_clean ( ) ; foreach ( $ data as $ key => $ val ) { if ( is_array ( $ val ) ) { if ( $ key == 'meta' ) { $ this -> data [ 'meta' ] = $ val ; } } else { $ viewData = str_replace ( '{{' . $ key . '}}' , $ val , $ viewData ) ; } } return $ viewData ; }
Renders View for given data template file and layout .
48,157
public function model ( $ model ) { $ modelPath = self :: $ instance -> app -> findModel ( $ model ) ; $ modelClass = "App\\Model\\" . $ model ; $ this -> model = new $ modelClass ( ) ; self :: $ instance -> modelService = new ModelService ( ) ; self :: $ instance -> modelService -> initialize ( self :: $ instance -> app ) ; return $ this -> model ; }
Create Instance of Model .
48,158
public function view ( $ view , $ data = [ ] ) { $ viewPath = self :: $ instance -> app -> findView ( $ view ) ; echo self :: $ instance -> renderView ( $ viewPath , $ data ) ; }
Display View .
48,159
public function template ( $ template , $ data = [ ] ) { $ templatePath = self :: $ instance -> app -> findTemplate ( $ template ) ; echo self :: $ instance -> renderTemplate ( $ templatePath , $ data ) ; }
Display Template .
48,160
public function parseUri ( ) { $ uri = parse_url ( $ _SERVER [ "REQUEST_URI" ] , PHP_URL_PATH ) ; $ uri = str_replace ( [ '{' , '}' ] , '' , urldecode ( $ uri ) ) ; $ extDir = dirname ( dirname ( $ _SERVER [ 'SCRIPT_NAME' ] ) ) ; $ uri = str_replace ( $ extDir , '' , $ uri ) ; $ uri = rtrim ( $ uri , '/' ) ; $ uri = empty ( $ uri ) ? '/' : $ uri ; $ serverRequestMethod = $ _SERVER [ 'REQUEST_METHOD' ] ; $ params = $ GLOBALS [ '_' . $ serverRequestMethod ] ; if ( ! empty ( $ _SERVER [ 'HTTPS' ] ) && ( 'on' == $ _SERVER [ 'HTTPS' ] ) ) { $ https = true ; } else { $ https = false ; } $ host = $ _SERVER [ 'HTTP_HOST' ] . str_replace ( '\\' , '/' , $ extDir ) ; $ ip = $ _SERVER [ 'REMOTE_ADDR' ] ; if ( $ serverRequestMethod === 'POST' ) { $ params = [ 'GET' => $ _GET , 'POST' => $ params ] ; } else { $ params = [ 'GET' => $ params , 'POST' => [ ] ] ; } return [ 'uri' => $ uri , 'params' => $ params , 'method' => $ serverRequestMethod , 'https' => $ https , 'host' => $ host , 'ip' => $ ip ] ; }
Parse Uri and get path uri params server method .
48,161
public function getBuilder ( AbstractModel $ model ) : ? AbstractBuilder { if ( $ model instanceof PhpClass ) { return $ this -> classBuilder ; } if ( $ model instanceof PhpConstant ) { return $ this -> constantBuilder ; } if ( $ model instanceof PhpFunction ) { return $ this -> functionBuilder ; } if ( $ model instanceof PhpInterface ) { return $ this -> interfaceBuilder ; } if ( $ model instanceof PhpMethod ) { return $ this -> methodBuilder ; } if ( $ model instanceof PhpParameter ) { return $ this -> parameterBuilder ; } if ( $ model instanceof PhpProperty ) { return $ this -> propertyBuilder ; } if ( $ model instanceof PhpTrait ) { return $ this -> traitBuilder ; } return null ; }
Returns the related builder for the given model
48,162
public function setVisibility ( string $ visibility ) { if ( $ visibility !== self :: VISIBILITY_PRIVATE && $ visibility !== self :: VISIBILITY_PROTECTED && $ visibility !== self :: VISIBILITY_PUBLIC ) { throw new \ InvalidArgumentException ( sprintf ( 'The visibility "%s" does not exist.' , $ visibility ) ) ; } $ this -> visibility = $ visibility ; return $ this ; }
Sets the members visibility
48,163
public function addTrait ( $ trait ) { if ( $ trait instanceof PhpTrait ) { $ name = $ trait -> getName ( ) ; $ qname = $ trait -> getQualifiedName ( ) ; $ namespace = $ trait -> getNamespace ( ) ; if ( $ namespace != $ this -> getNamespace ( ) ) { $ this -> addUseStatement ( $ qname ) ; } } else { $ name = $ trait ; } if ( ! in_array ( $ name , $ this -> traits ) ) { $ this -> traits [ ] = $ name ; } return $ this ; }
Adds a trait .
48,164
public function hasTrait ( $ trait ) : bool { if ( ! $ trait instanceof PhpTrait ) { $ trait = new PhpTrait ( $ trait ) ; } $ name = $ trait -> getName ( ) ; return in_array ( $ name , $ this -> traits ) ; }
Checks whether a trait exists
48,165
public function removeTrait ( $ trait ) { if ( $ trait instanceof PhpTrait ) { $ name = $ trait -> getName ( ) ; } else { $ name = $ trait ; } $ index = array_search ( $ name , $ this -> traits ) ; if ( $ index !== false ) { unset ( $ this -> traits [ $ index ] ) ; if ( $ trait instanceof PhpTrait ) { $ qname = $ trait -> getQualifiedName ( ) ; $ this -> removeUseStatement ( $ qname ) ; } } return $ this ; }
Removes a trait .
48,166
private function isPrimitive ( $ value ) : bool { return ( is_string ( $ value ) || is_int ( $ value ) || is_float ( $ value ) || is_bool ( $ value ) || is_null ( $ value ) || ( $ value instanceof PhpConstant ) ) ; }
Returns whether the given value is a primitive
48,167
public function setExpression ( string $ expr ) { $ this -> expression = $ expr ; $ this -> hasExpression = true ; return $ this ; }
Sets an expression
48,168
private function parseValue ( ValueInterface $ obj , Node $ node ) { $ value = $ node instanceof Const_ ? $ node -> value : $ node -> default ; if ( $ value !== null ) { if ( $ this -> isPrimitive ( $ value ) ) { $ obj -> setValue ( $ this -> getPrimitiveValue ( $ value ) ) ; } else { $ obj -> setExpression ( $ this -> getExpression ( $ value ) ) ; } } }
Parses the value of a node into the model
48,169
private function isPrimitive ( Node $ node ) { return $ node instanceof String_ || $ node instanceof LNumber || $ node instanceof DNumber || $ this -> isBool ( $ node ) || $ this -> isNull ( $ node ) ; }
Returns whether this node is a primitive value
48,170
private function getPrimitiveValue ( Node $ node ) { if ( $ this -> isBool ( $ node ) ) { return ( bool ) $ this -> getExpression ( $ node ) ; } if ( $ this -> isNull ( $ node ) ) { return null ; } return $ node -> value ; }
Returns the primitive value
48,171
private function isBool ( Node $ node ) { if ( $ node instanceof ConstFetch ) { $ const = $ node -> name -> parts [ 0 ] ; if ( isset ( $ this -> constMap [ $ const ] ) ) { return is_bool ( $ this -> constMap [ $ const ] ) ; } return is_bool ( $ const ) ; } }
Returns whether this node is a boolean value
48,172
private function getExpression ( Node $ node ) { if ( $ node instanceof ConstFetch ) { $ const = $ node -> name -> parts [ 0 ] ; if ( isset ( $ this -> constMap [ $ const ] ) ) { return $ this -> constMap [ $ const ] ; } return $ const ; } if ( $ node instanceof ClassConstFetch ) { return $ node -> class -> parts [ 0 ] . '::' . $ node -> name ; } if ( $ node instanceof MagicConst ) { return $ node -> getName ( ) ; } if ( $ node instanceof Array_ ) { $ prettyPrinter = new PrettyPrinter ( ) ; return $ prettyPrinter -> prettyPrintExpr ( $ node ) ; } }
Returns the value from a node
48,173
public function setProfile ( $ profile ) { if ( is_string ( $ profile ) ) { $ profile = new Profile ( $ profile ) ; } $ this -> profile = $ profile ; return $ this ; }
Sets the code style profile
48,174
public function setGenerateDocblock ( bool $ generate ) { $ this -> options [ 'generateDocblock' ] = $ generate ; if ( ! $ generate ) { $ this -> options [ 'generateEmptyDocblock' ] = $ generate ; } return $ this ; }
Sets whether docblocks should be generated
48,175
public function setGenerateEmptyDocblock ( bool $ generate ) { $ this -> options [ 'generateEmptyDocblock' ] = $ generate ; if ( $ generate ) { $ this -> options [ 'generateDocblock' ] = $ generate ; } return $ this ; }
Sets whether empty docblocks are generated
48,176
public static function create ( $ name = null , $ value = null , $ isExpression = false ) { return new static ( $ name , $ value , $ isExpression ) ; }
Creates a new PHP constant
48,177
public function setType ( ? string $ type , string $ description = null ) { $ this -> type = $ type ; if ( null !== $ description ) { $ this -> setTypeDescription ( $ description ) ; } return $ this ; }
Sets the type
48,178
public function getDocblockTag ( ) : ParamTag { return ParamTag :: create ( ) -> setType ( $ this -> getType ( ) ) -> setVariable ( $ this -> getName ( ) ) -> setDescription ( $ this -> getTypeDescription ( ) ) ; }
Returns a docblock tag for this parameter
48,179
public function setDocblock ( $ doc ) { if ( is_string ( $ doc ) ) { $ doc = trim ( $ doc ) ; $ doc = new Docblock ( $ doc ) ; } $ this -> docblock = $ doc ; return $ this ; }
Sets the docblock
48,180
public function setDescription ( $ description ) { if ( is_array ( $ description ) ) { $ description = implode ( "\n" , $ description ) ; } $ this -> description = $ description ; return $ this ; }
Sets the description which will also be used when generating a docblock
48,181
private function getVisibility ( Node $ node ) { if ( $ node -> isPrivate ( ) ) { return AbstractPhpMember :: VISIBILITY_PRIVATE ; } if ( $ node -> isProtected ( ) ) { return AbstractPhpMember :: VISIBILITY_PROTECTED ; } return AbstractPhpMember :: VISIBILITY_PUBLIC ; }
Returns the visibility from a node
48,182
public static function fromFile ( string $ filename ) : PhpTrait { $ trait = new PhpTrait ( ) ; $ parser = new FileParser ( $ filename ) ; $ parser -> addVisitor ( new TraitParserVisitor ( $ trait ) ) ; $ parser -> addVisitor ( new MethodParserVisitor ( $ trait ) ) ; $ parser -> addVisitor ( new ConstantParserVisitor ( $ trait ) ) ; $ parser -> addVisitor ( new PropertyParserVisitor ( $ trait ) ) ; $ parser -> parse ( ) ; return $ trait ; }
Creates a PHP trait from a file
48,183
public function generateDocblock ( ) { $ docblock = $ this -> getDocblock ( ) ; $ docblock -> setShortDescription ( $ this -> getDescription ( ) ) ; $ docblock -> setLongDescription ( $ this -> getLongDescription ( ) ) ; $ this -> generateTypeTag ( new ReturnTag ( ) ) ; $ this -> generateParamDocblock ( ) ; }
Generates docblock based on provided information
48,184
public function setProperties ( array $ properties ) { foreach ( $ this -> properties as $ prop ) { $ prop -> setParent ( null ) ; } $ this -> properties -> clear ( ) ; foreach ( $ properties as $ prop ) { $ this -> setProperty ( $ prop ) ; } return $ this ; }
Sets a collection of properties
48,185
public function hasProperty ( $ nameOrProperty ) : bool { if ( $ nameOrProperty instanceof PhpProperty ) { $ nameOrProperty = $ nameOrProperty -> getName ( ) ; } return $ this -> properties -> has ( $ nameOrProperty ) ; }
Checks whether a property exists
48,186
public function getProperty ( $ nameOrProperty ) : PhpProperty { if ( $ nameOrProperty instanceof PhpProperty ) { $ nameOrProperty = $ nameOrProperty -> getName ( ) ; } if ( ! $ this -> properties -> has ( $ nameOrProperty ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The property "%s" does not exist.' , $ nameOrProperty ) ) ; } return $ this -> properties -> get ( $ nameOrProperty ) ; }
Returns a property
48,187
public function clearProperties ( ) { foreach ( $ this -> properties as $ property ) { $ property -> setParent ( null ) ; } $ this -> properties -> clear ( ) ; return $ this ; }
Clears all properties
48,188
public function setParameters ( array $ parameters ) { $ this -> parameters = [ ] ; foreach ( $ parameters as $ parameter ) { $ this -> addParameter ( $ parameter ) ; } return $ this ; }
Sets a collection of parameters
48,189
public function hasParameter ( string $ name ) : bool { foreach ( $ this -> parameters as $ param ) { if ( $ param -> getName ( ) == $ name ) { return true ; } } return false ; }
Checks whether a parameter exists
48,190
public function addSimpleParameter ( string $ name , string $ type = null , $ defaultValue = null ) { $ parameter = new PhpParameter ( $ name ) ; $ parameter -> setType ( $ type ) ; if ( 2 < func_num_args ( ) ) { $ parameter -> setValue ( $ defaultValue ) ; } $ this -> addParameter ( $ parameter ) ; return $ this ; }
A quick way to add a parameter which is created from the given parameters
48,191
public function addSimpleDescParameter ( string $ name , string $ type = null , string $ typeDescription = null , $ defaultValue = null ) { $ parameter = new PhpParameter ( $ name ) ; $ parameter -> setType ( $ type ) ; $ parameter -> setTypeDescription ( $ typeDescription ) ; if ( 3 < func_num_args ( ) == 3 ) { $ parameter -> setValue ( $ defaultValue ) ; } $ this -> addParameter ( $ parameter ) ; return $ this ; }
A quick way to add a parameter with description which is created from the given parameters
48,192
public function getParameter ( $ nameOrIndex ) : PhpParameter { if ( is_int ( $ nameOrIndex ) ) { $ this -> checkPosition ( $ nameOrIndex ) ; return $ this -> parameters [ $ nameOrIndex ] ; } foreach ( $ this -> parameters as $ param ) { if ( $ param -> getName ( ) === $ nameOrIndex ) { return $ param ; } } throw new \ InvalidArgumentException ( sprintf ( 'There is no parameter named "%s".' , $ nameOrIndex ) ) ; }
Returns a parameter by index or name
48,193
public function replaceParameter ( int $ position , PhpParameter $ parameter ) { $ this -> checkPosition ( $ position ) ; $ this -> parameters [ $ position ] = $ parameter ; return $ this ; }
Replaces a parameter at a given position
48,194
public function removeParameter ( $ param ) { if ( is_int ( $ param ) ) { $ this -> removeParameterByPosition ( $ param ) ; } else if ( is_string ( $ param ) ) { $ this -> removeParameterByName ( $ param ) ; } else if ( $ param instanceof PhpParameter ) { $ this -> removeParameterByName ( $ param -> getName ( ) ) ; } return $ this ; }
Remove a parameter at a given position
48,195
protected function generateParamDocblock ( ) { $ docblock = $ this -> getDocblock ( ) ; $ tags = $ docblock -> getTags ( 'param' ) ; foreach ( $ this -> parameters as $ param ) { $ ptag = $ param -> getDocblockTag ( ) ; $ tag = $ tags -> find ( $ ptag , function ( ParamTag $ tag , ParamTag $ ptag ) { return $ tag -> getVariable ( ) == $ ptag -> getVariable ( ) ; } ) ; if ( $ tag !== null ) { $ tag -> setDescription ( $ ptag -> getDescription ( ) ) ; $ tag -> setType ( $ ptag -> getType ( ) ) ; } else { $ docblock -> appendTag ( $ ptag ) ; } } }
Generates docblock for params
48,196
public function setUseStatements ( array $ useStatements ) { $ this -> useStatements -> clear ( ) ; foreach ( $ useStatements as $ alias => $ useStatement ) { $ this -> addUseStatement ( $ useStatement , $ alias ) ; } return $ this ; }
Sets use statements
48,197
public function addUseStatement ( string $ qualifiedName , string $ alias = null ) { if ( ! is_string ( $ alias ) ) { if ( false === strpos ( $ qualifiedName , '\\' ) ) { $ alias = $ qualifiedName ; } else { $ alias = substr ( $ qualifiedName , strrpos ( $ qualifiedName , '\\' ) + 1 ) ; } } $ this -> useStatements -> set ( $ alias , $ qualifiedName ) ; return $ this ; }
Adds a use statement with an optional alias
48,198
public function declareUses ( string ... $ uses ) { foreach ( $ uses as $ name ) { $ this -> declareUse ( $ name ) ; } return $ this ; }
Declares multiple use statements at once .
48,199
public function removeUseStatement ( string $ qualifiedName ) { $ this -> useStatements -> remove ( $ this -> useStatements -> getKey ( $ qualifiedName ) ) ; return $ this ; }
Removes a use statement