idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
47,100 | protected function processYoutube ( $ url ) { $ firstMatches = [ ] ; $ pattern = '%^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=))([^"&?/ ]{11})(?:.+)?$%xs' ; if ( preg_match ( $ pattern , $ url , $ firstMatches ) ) { $ toEmbed = $ firstMatches [ 1 ] ; $ patternForAdditiona... | Processes YouTube url |
47,101 | protected function setProtocolToHttps ( $ url ) { $ processUrl = trim ( $ url ) ; if ( strpos ( $ url , 'http://' ) === 0 ) { $ processUrl = substr ( $ processUrl , 7 ) ; } elseif ( strpos ( $ processUrl , 'https://' ) === 0 ) { $ processUrl = substr ( $ processUrl , 8 ) ; } elseif ( strpos ( $ processUrl , '//' ) === ... | Change every protocol to https and add it if missing |
47,102 | protected function getCompileService ( ) { if ( $ this -> compileService === null ) { $ this -> compileService = GeneralUtility :: makeInstance ( CompileService :: class ) ; } return $ this -> compileService ; } | Get the compile service |
47,103 | public static function getLinesFromBottom ( $ file , $ count = 1 ) { $ fl = @ fopen ( $ file , "r" ) ; $ lines = array ( ) ; $ bytes = 0 ; if ( $ fl === false ) { return false ; } $ count = max ( 1 , ( int ) $ count ) ; for ( $ x_pos = 0 , $ ln = 0 , $ line = '' , $ still = true ; $ still ; $ x_pos -- ) { if ( fseek ( ... | Read lines from the bottom of giver file |
47,104 | public static function start ( $ path = '' , $ lifetime = 0 ) { if ( self :: $ sessionState === self :: SESSION_NOT_STARTED ) { if ( empty ( $ path ) ) { $ sub = array ( 'inc' ) ; $ url = parse_url ( get_current_url ( ) ) ; $ path = dirname ( $ url [ 'path' ] . 'fake' ) ; if ( in_array ( basename ( $ path ) , $ sub ) )... | Overwrite the original session start to specify a path at root of the installation |
47,105 | public static function write_close ( ) { if ( self :: $ sessionState === self :: SESSION_STARTED ) { self :: $ sessionState = self :: SESSION_NOT_STARTED ; return session_write_close ( ) ; } return true ; } | Write the tmp file and close it |
47,106 | public static function changePassword ( $ username , $ new_password ) { self :: setUser ( $ username , $ new_password ) ; self :: log ( 'changepwd' , $ username ) ; self :: save ( ) ; return true ; } | Change the password with logging |
47,107 | public static function create ( ) { if ( file_exists ( self :: $ authFile ) ) return false ; if ( @ touch ( self :: $ authFile ) === false ) return false ; self :: $ auth = array ( 'generated' => date ( 'U' ) , 'security' => self :: generateSecurityToken ( ) , 'anonymous' => array ( ) , 'users' => array ( ) , ) ; self ... | Create a new authentication file |
47,108 | public static function getClientIp ( ) { $ ip = '' ; if ( isset ( $ _SERVER [ 'HTTP_CLIENT_IP' ] ) ) { $ ip = $ _SERVER [ 'HTTP_CLIENT_IP' ] ; } elseif ( isset ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ) { $ ip = $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ; } elseif ( isset ( $ _SERVER [ 'HTTP_X_FORWARDED' ] ) ) { $ ip = $ _S... | Get the local ip address of the current client according to proxy and more ... |
47,109 | public static function getCurrentUsername ( ) { if ( is_array ( self :: $ api_session ) ) { $ auth = self :: $ api_session ; } else { $ auth = self :: sessionRead ( ) ; } return ( isset ( $ auth [ 'username' ] ) ) ? $ auth [ 'username' ] : null ; } | Get the current logged in user or null |
47,110 | public static function getUser ( $ username = null ) { if ( is_null ( $ username ) ) $ username = self :: getCurrentUsername ( ) ; if ( self :: userExists ( $ username ) ) { return self :: $ auth [ 'users' ] [ $ username ] ; } return null ; } | Return the data of a user |
47,111 | public static function getUsernameFromAccessToken ( $ accesstoken ) { $ users = self :: getUsers ( ) ; foreach ( $ users as $ username => $ user ) { if ( $ user [ 'at' ] === $ accesstoken ) { return $ username ; } } return null ; } | Find a user from its access token |
47,112 | public static function getUsers ( ) { if ( ! is_array ( self :: $ auth ) ) throw new Exception ( 'Authentication not initialized' ) ; if ( isset ( self :: $ auth [ 'users' ] ) ) { return self :: $ auth [ 'users' ] ; } else { return array ( ) ; } } | Return the array of users |
47,113 | public static function init ( ) { self :: $ authFile = self :: getAuthFilePath ( ) ; if ( self :: isAuthSet ( ) ) { self :: reload ( ) ; } return true ; } | Set file etc ... |
47,114 | public static function isAnonymousEnabled ( $ files = false ) { if ( ! isset ( self :: $ auth [ 'anonymous' ] ) ) return false ; if ( ! is_array ( self :: $ auth [ 'anonymous' ] ) ) return false ; if ( $ files === false ) { return ( count ( self :: $ auth [ 'anonymous' ] ) > 0 ) ; } $ found = 0 ; foreach ( self :: $ au... | Tell if at least one log file is accessible anonymously |
47,115 | public static function isSignValid ( $ given_sign , $ values , $ username = null ) { return ( self :: sign ( $ values , $ username ) === $ given_sign ) ; } | Tell whether a signature is valid for given values or not |
47,116 | public static function isValidPassword ( $ username , $ password ) { if ( ! self :: userExists ( $ username ) ) return false ; $ compute = self :: getPasswordHash ( $ username , $ password ) ; return ( $ compute === self :: $ auth [ 'users' ] [ $ username ] [ 'pwd' ] ) ; } | Tell whether a password is valid or not |
47,117 | public static function log ( $ action , $ username = null , $ timestamp = null , $ ip = null , $ useragent = null ) { if ( ! is_array ( self :: $ auth ) ) throw new Exception ( 'Authentication not initialized' ) ; if ( ! isset ( self :: $ auth [ 'logs' ] ) ) { self :: $ auth [ 'logs' ] = array ( ) ; } if ( is_null ( $ ... | Log an action |
47,118 | public static function release ( ) { if ( is_null ( self :: $ authFileP ) ) return ; $ a = @ flock ( self :: $ authFileP , LOCK_UN ) ; @ fclose ( self :: $ authFileP ) ; self :: $ authFileP = null ; self :: $ currentlylocked = false ; } | Release the database file |
47,119 | public static function save ( ) { self :: lock ( ) ; if ( is_null ( self :: $ authFileP ) ) throw new Exception ( 'No lock has been requested' ) ; $ file = '<?php if (realpath(__FILE__)===realpath($_SERVER["SCRIPT_FILENAME"])) {header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");die();}?>' . "\n" ; $ file .= json_enco... | Save modifications on disk |
47,120 | public static function setAdmin ( $ username , $ password = null , $ logs = null ) { return self :: setUser ( $ username , $ password , $ roles = array ( 'admin' ) , $ logs ) ; } | Set an admin |
47,121 | public static function setLogAnonymous ( $ log , $ anonymous ) { if ( ! is_array ( self :: $ auth ) ) throw new Exception ( 'Authentication not initialized' ) ; $ anon = array ( ) ; if ( isset ( self :: $ auth [ 'anonymous' ] ) ) { $ anon = self :: $ auth [ 'anonymous' ] ; } if ( $ anonymous === true ) { $ anon [ ] = $... | Set a log anonymous or not |
47,122 | public static function setUser ( $ username , $ password = null , $ roles = null , $ logs = null , $ regeneratetokens = false ) { if ( ! is_array ( self :: $ auth ) ) throw new Exception ( 'Authentication not initialized' ) ; if ( isset ( self :: $ auth [ 'users' ] [ $ username ] ) ) { $ user = self :: $ auth [ 'users'... | Set a user |
47,123 | public static function signIn ( $ username , $ password ) { $ ip = self :: getClientIp ( ) ; $ ua = ( isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ) ? $ _SERVER [ 'HTTP_USER_AGENT' ] : '' ; $ ts = date ( "U" ) ; if ( self :: isValidPassword ( $ username , $ password ) ) { self :: sessionWrite ( array ( 'username' => $ use... | Sign in user |
47,124 | public static function signInAs ( $ username ) { $ ip = self :: getClientIp ( ) ; $ ua = ( isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ) ? $ _SERVER [ 'HTTP_USER_AGENT' ] : '' ; $ ts = date ( "U" ) ; $ cu = self :: getCurrentUsername ( ) ; self :: sessionWrite ( array ( 'username' => $ username ) ) ; self :: reload ( ) ;... | Sign in as a user |
47,125 | public static function signInWithAccessToken ( $ accesstoken ) { $ username = self :: getUsernameFromAccessToken ( $ accesstoken ) ; if ( is_null ( $ username ) ) return false ; $ ip = self :: getClientIp ( ) ; $ ua = ( isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ) ? $ _SERVER [ 'HTTP_USER_AGENT' ] : '' ; $ ts = date ( "... | Sign in user with its access token The signin is only available for this call no session |
47,126 | public static function signOut ( ) { $ username = self :: getCurrentUsername ( ) ; if ( ! is_null ( $ username ) ) { $ ip = self :: getClientIp ( ) ; $ ua = ( isset ( $ _SERVER [ 'HTTP_USER_AGENT' ] ) ) ? $ _SERVER [ 'HTTP_USER_AGENT' ] : '' ; $ ts = date ( "U" ) ; self :: log ( 'signout' , $ username , $ ts , $ ip , $... | Sign out the current user and return its username |
47,127 | public static function userCanOnLogs ( $ log , $ action , $ value , $ username = null ) { if ( is_null ( $ username ) ) $ username = self :: getCurrentUsername ( ) ; if ( is_null ( $ username ) ) return false ; if ( ! self :: userExists ( $ username ) ) return false ; if ( in_array ( 'admin' , self :: $ auth [ 'users' ... | Tell if a user has an access on a log file |
47,128 | public static function userExists ( $ username ) { if ( ! is_array ( self :: $ auth ) ) throw new Exception ( 'Authentication not initialized' ) ; return ( isset ( self :: $ auth [ 'users' ] [ $ username ] ) ) ; } | Tell whether user exists or not |
47,129 | public static function userHasRole ( $ role , $ username = null ) { if ( is_null ( $ username ) ) $ username = self :: getCurrentUsername ( ) ; if ( is_null ( $ username ) ) return false ; if ( ! self :: userExists ( $ username ) ) return false ; if ( in_array ( 'admin' , self :: $ auth [ 'users' ] [ $ username ] [ 'ro... | Tell if a user has a role or not |
47,130 | private static function getPasswordHash ( $ username , $ password ) { return sha1 ( self :: getSecurityToken ( ) . $ username . self :: getGenerated ( ) . $ password ) ; } | Generate a hash from a username and a password |
47,131 | private static function lock ( ) { if ( self :: $ currentlylocked === false ) { self :: $ authFileP = fopen ( self :: $ authFile , "a+" ) ; if ( flock ( self :: $ authFileP , LOCK_EX ) ) { self :: $ currentlylocked = true ; } else { throw new Exception ( 'Unable to lock file' ) ; } } return true ; } | Lock the database file |
47,132 | private static function read ( ) { self :: lock ( ) ; if ( is_null ( self :: $ authFileP ) ) throw new Exception ( 'No lock has been requested' ) ; return stream_get_contents ( self :: $ authFileP , - 1 , 0 ) ; } | Read the database |
47,133 | private static function sessionRead ( ) { if ( isset ( $ _SERVER [ 'SERVER_PROTOCOL' ] ) ) { if ( isset ( $ _SESSION [ 'auth' ] ) ) return $ _SESSION [ 'auth' ] ; Session :: start ( ) ; return ( isset ( $ _SESSION [ 'auth' ] ) ) ? $ _SESSION [ 'auth' ] : array ( ) ; } else { $ json = @ file_get_contents ( '_cli_fake_se... | Read a session |
47,134 | private static function write ( $ content ) { self :: lock ( ) ; if ( is_null ( self :: $ authFileP ) ) throw new Exception ( 'No lock has been requested' ) ; ftruncate ( self :: $ authFileP , 0 ) ; fwrite ( self :: $ authFileP , $ content ) ; return fflush ( self :: $ authFileP ) ; } | Write the database |
47,135 | public function getCloneExemptAttributes ( ) { $ defaults = [ $ this -> getKeyName ( ) , $ this -> getCreatedAtColumn ( ) , $ this -> getUpdatedAtColumn ( ) , ] ; $ count_columns = array_map ( function ( $ count_column ) { return $ count_column . '_count' ; } , $ this -> withCount ) ; $ defaults = array_merge ( $ defau... | Return the list of attributes on this model that should be cloned |
47,136 | public function addCloneableRelation ( $ relation ) { $ relations = $ this -> getCloneableRelations ( ) ; if ( in_array ( $ relation , $ relations ) ) return ; $ relations [ ] = $ relation ; $ this -> cloneable_relations = $ relations ; } | Add a relation to cloneable_relations uniquely |
47,137 | public function duplicate ( $ model , $ relation = null ) { $ clone = $ this -> cloneModel ( $ model ) ; $ this -> duplicateAttachments ( $ clone ) ; $ this -> saveClone ( $ clone , $ relation , $ model ) ; $ this -> cloneRelations ( $ model , $ clone ) ; return $ clone ; } | Clone a model instance and all of it s files and relations |
47,138 | public function duplicateTo ( $ model , $ connection ) { $ this -> write_connection = $ connection ; $ clone = $ this -> duplicate ( $ model ) ; $ this -> write_connection = null ; return $ clone ; } | Clone a model instance to a specific database connection |
47,139 | protected function cloneModel ( $ model ) { $ exempt = method_exists ( $ model , 'getCloneExemptAttributes' ) ? $ model -> getCloneExemptAttributes ( ) : null ; $ clone = $ model -> replicate ( $ exempt ) ; if ( $ this -> write_connection ) $ clone -> setConnection ( $ this -> write_connection ) ; return $ clone ; } | Create duplicate of the model |
47,140 | protected function duplicateAttachments ( $ clone ) { if ( ! $ this -> attachment || ! method_exists ( $ clone , 'getCloneableFileAttributes' ) ) return ; foreach ( $ clone -> getCloneableFileAttributes ( ) as $ attribute ) { if ( ! $ original = $ clone -> getAttribute ( $ attribute ) ) continue ; $ clone -> setAttribu... | Duplicate all attachments given them a new name and update the attribute value |
47,141 | protected function saveClone ( $ clone , $ relation = null , $ src , $ child = null ) { if ( $ relation ) $ child = true ; if ( method_exists ( $ clone , 'onCloning' ) ) $ clone -> onCloning ( $ src , $ child ) ; $ this -> events -> dispatch ( 'cloner::cloning: ' . get_class ( $ src ) , [ $ clone , $ src ] ) ; if ( $ r... | Save the clone . If a relation was passed save the clone onto that relation . Otherwise just save it . |
47,142 | protected function cloneRelations ( $ model , $ clone ) { if ( ! method_exists ( $ model , 'getCloneableRelations' ) ) return ; foreach ( $ model -> getCloneableRelations ( ) as $ relation_name ) { $ this -> duplicateRelation ( $ model , $ relation_name , $ clone ) ; } } | Loop through relations and clone or re - attach them |
47,143 | protected function duplicateRelation ( $ model , $ relation_name , $ clone ) { $ relation = call_user_func ( [ $ model , $ relation_name ] ) ; if ( is_a ( $ relation , 'Illuminate\Database\Eloquent\Relations\BelongsToMany' ) ) { $ this -> duplicatePivotedRelation ( $ relation , $ relation_name , $ clone ) ; } else $ th... | Duplicate relationships to the clone |
47,144 | protected function duplicatePivotedRelation ( $ relation , $ relation_name , $ clone ) { if ( $ this -> write_connection ) return ; $ relation -> get ( ) -> each ( function ( $ foreign ) use ( $ clone , $ relation_name ) { $ pivot_attributes = array_except ( $ foreign -> pivot -> getAttributes ( ) , [ $ foreign -> pivo... | Duplicate a many - to - many style relation where we are just attaching the relation to the dupe |
47,145 | protected function duplicateDirectRelation ( $ relation , $ relation_name , $ clone ) { $ relation -> get ( ) -> each ( function ( $ foreign ) use ( $ clone , $ relation_name ) { $ this -> duplicate ( $ foreign , $ clone -> $ relation_name ( ) ) ; } ) ; } | Duplicate a one - to - many style relation where the foreign model is ALSO cloned and then associated |
47,146 | public function duplicate ( $ url ) { $ current_path = $ this -> helpers -> path ( $ url ) ; $ filename = basename ( $ current_path ) ; $ dst_disk = $ this -> disks ? $ this -> disks -> getFilesystem ( 'dst' ) : $ this -> disk ; $ new_path = $ this -> storage -> makeNestedAndUniquePath ( $ filename , $ dst_disk ) ; if ... | Duplicate a file given it s URL |
47,147 | public static function matchExists ( $ matchId ) { $ db = Db :: obtain ( ) ; $ r = $ db -> queryFirstPDO ( 'SELECT match_id FROM ' . Db :: realTablename ( 'matches' ) . ' WHERE match_id = ?' , array ( $ matchId ) ) ; return ( ( bool ) $ r ) ; } | Delete match data from db |
47,148 | public function load ( ) { $ request = new request ( self :: STEAM_MATCH_URL , array ( 'match_id' => $ this -> getMatchId ( ) ) ) ; $ matchInfo = $ request -> send ( ) ; if ( null === $ matchInfo ) { return null ; } $ match = new Match ( ) ; $ players = array ( ) ; foreach ( $ matchInfo -> players -> player as $ key =>... | Load match info by match_id |
47,149 | public static function obtain ( $ server = null , $ user = null , $ pass = null , $ database = null , $ pref = null ) { if ( null === self :: $ _instance ) { self :: $ _instance = new db ( $ server , $ user , $ pass , $ database , $ pref ) ; } return self :: $ _instance ; } | Obtain an instance of Database object |
47,150 | public function connectPDO ( $ selectDb = true ) { if ( null !== self :: $ _linkId ) { return true ; } try { self :: $ _linkId = new PDO ( 'mysql:host=' . $ this -> _server , $ this -> _user , $ this -> _pass , array ( PDO :: MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' ) ) ; self :: $ _linkId -> setAttribute ( PDO ... | Connect to a Database host and select database using variable initialized above |
47,151 | private function _queryPDO ( $ sql , array $ params = array ( ) ) { try { $ this -> _queryId = self :: $ _linkId -> prepare ( $ sql ) ; $ i = 1 ; foreach ( $ params as $ key => $ val ) { $ type = $ this -> getPDOConstantType ( $ val ) ; $ this -> _queryId -> bindValue ( $ i , $ val , $ type ) ; ++ $ i ; } return $ this... | Prepares and executes a sql query |
47,152 | public function queryFirstPDO ( $ sql , array $ params = array ( ) ) { $ query_id = $ this -> _queryPDO ( $ sql , $ params ) ; if ( $ query_id === false ) { return false ; } $ out = $ this -> _fetchPDO ( ) ; $ this -> _freeResultPDO ( ) ; return $ out ; } | Run the query fetches the first row only frees resultset |
47,153 | public function updatePDO ( $ table , array $ data , array $ where = array ( ) ) { if ( count ( $ data ) === 0 ) { return false ; } $ q = "UPDATE `$table` SET " ; foreach ( $ data as $ key => $ val ) { if ( null !== $ val ) { $ q .= "`$key`=?, " ; } } $ q = rtrim ( $ q , ', ' ) . ' WHERE ' ; foreach ( $ where as $ key ... | Does an update query with an array for data and array as a param for the where clause |
47,154 | public function insertPDO ( $ table , array $ data = array ( ) ) { if ( count ( $ data ) === 0 ) { return false ; } $ q = "INSERT INTO `$table` " ; $ v = '' ; $ n = '' ; foreach ( $ data as $ key => $ val ) { $ n .= "`$key`, " ; if ( strtolower ( $ val ) === 'now()' ) { $ v .= 'NOW(), ' ; unset ( $ data [ $ key ] ) ; }... | Does an insert query with an array for data . |
47,155 | public function deletePDO ( $ table , array $ where = array ( ) , $ limit = 1 ) { $ limit = ( int ) $ limit ; if ( count ( $ where ) === 0 ) { return false ; } $ q = "DELETE FROM `$table` " ; $ q .= 'WHERE ' ; foreach ( $ where as $ key => $ val ) { if ( empty ( $ val ) ) { continue ; } else { $ q .= "`$key`=? AND " ; ... | Delete records from table |
47,156 | public function getPDOConstantType ( $ value ) { switch ( true ) { case is_int ( $ value ) : $ type = PDO :: PARAM_INT ; break ; case is_bool ( $ value ) : $ type = PDO :: PARAM_BOOL ; break ; case ( null === $ value ) : $ type = PDO :: PARAM_NULL ; break ; default : $ type = PDO :: PARAM_STR ; } return $ type ; } | Checks the data type of the value that is passed |
47,157 | public static function convertId ( $ id ) { if ( strlen ( $ id ) === 17 ) { $ converted = substr ( $ id , 3 ) - 61197960265728 ; } else { $ converted = '765' . ( $ id + 61197960265728 ) ; } return ( string ) $ converted ; } | Convert DotA2 user id to Steam ID |
47,158 | public function get ( $ name ) { $ name = '_' . ( string ) $ name ; return property_exists ( $ this , $ name ) ? $ this -> $ name : null ; } | Get field value |
47,159 | public function setArray ( array $ data ) { foreach ( $ data as $ name => $ value ) { $ this -> set ( $ name , $ value ) ; } return $ this ; } | Set not - array fields |
47,160 | protected function getTeam ( $ t ) { $ teamInfo = ( array ) $ t ; $ team = new Team ( ) ; $ fields = array_keys ( $ teamInfo ) ; foreach ( $ fields as $ field ) { if ( preg_match ( '/^player_\d+_account_id$/' , $ field ) ) { $ team -> addPlayerId ( $ teamInfo [ $ field ] ) ; continue ; } if ( preg_match ( '/^league_id_... | Map one team |
47,161 | public function parse ( $ parseTo = '' ) { $ parseTo = str_replace ( '.' , '' , $ parseTo ) ; $ p = __DIR__ . '/../../' . self :: PATH . '/' ; $ fullpath = $ p . $ this -> _filename ; $ initData = $ this -> _parseJsonFile ( $ fullpath ) ; if ( $ parseTo ) { $ subdirs = scandir ( $ p ) ; sort ( $ subdirs ) ; foreach ( $... | Parse JSON file |
47,162 | public function getParameter ( $ name ) { $ name = ( string ) $ name ; return array_key_exists ( $ name , $ this -> _params ) ? $ this -> _params [ $ name ] : null ; } | Get request parameter by its name |
47,163 | public function setParameter ( $ name , $ value ) { $ name = ( string ) $ name ; $ value = ( string ) $ value ; $ this -> _params [ $ name ] = $ value ; return $ this ; } | Set parameter by its name and value |
47,164 | public function send ( ) { $ ch = curl_init ( ) ; $ url = $ this -> _url ; $ d = '' ; $ this -> _params [ 'format' ] = 'xml' ; $ this -> _params [ 'key' ] = self :: $ apiKey ; $ this -> _params [ 'language' ] = 'en_us' ; foreach ( $ this -> _params as $ key => $ value ) { $ d .= $ key . '=' . $ value . '&' ; } $ d = rt... | Send request to Valve s servers |
47,165 | public function load ( ) { $ matchesInfo = $ this -> _getMatchesIdsFromMatches ( ) ; $ matchesIds = array ( ) ; foreach ( $ matchesInfo as $ matchInfo ) { array_push ( $ matchesIds , $ matchInfo [ 'match_id' ] ) ; } if ( count ( $ matchesIds ) === 0 ) { return array ( ) ; } $ slotsInfo = $ this -> _loadSlotsInfo ( $ ma... | Load matches from db |
47,166 | public function delete ( array $ ids ) { if ( ! count ( $ ids ) ) { return ; } $ ids_str = implode ( ',' , $ ids ) ; $ db = Db :: obtain ( ) ; $ slots = $ db -> fetchArrayPDO ( 'SELECT id FROM ' . Db :: realTablename ( 'slots' ) . ' WHERE match_id IN (' . $ ids_str . ')' , array ( ) ) ; $ slotsFormatted = array ( ) ; f... | Delete matches info from db |
47,167 | private function _loadSlotsInfo ( array $ matchesIds ) { $ db = Db :: obtain ( ) ; $ slots_query = 'SELECT * FROM ' . Db :: realTablename ( 'slots' ) . ' WHERE match_id IN (' . implode ( ',' , $ matchesIds ) . ')' ; return $ db -> fetchArrayPDO ( $ slots_query , array ( ) ) ; } | Load data about slots from slots table . Array of the matches ids used as filter |
47,168 | private function _getMatchesIdsFromMatches ( ) { $ _matchesIdsFromSlots = $ this -> _getMatchesIdsFromSlots ( ) ; $ db = Db :: obtain ( ) ; $ matchesQuery = 'SELECT * FROM ' . Db :: realTablename ( 'matches' ) . '' ; $ where = '' ; $ data = array ( ) ; if ( null !== $ this -> getLeagueId ( ) ) { $ where .= 'leagueid = ... | Get info about matches from the matches table Use matches ids from slots table as additional filter |
47,169 | public function removeAdditionalUnitItem ( $ item_id ) { foreach ( $ this -> _additional_unit_items as $ k => $ id ) { if ( $ id === $ item_id ) { unset ( $ this -> _additional_unit_items [ $ k ] ) ; break ; } } return $ this ; } | Remove item from additional unit items |
47,170 | public function save ( Player $ player ) { if ( self :: playerExists ( $ player -> get ( 'steamid' ) ) ) { $ this -> update ( $ player ) ; } else { $ this -> insert ( $ player ) ; } } | Determines whether the player should be inserted or updated in the db |
47,171 | public function registerCommands ( string $ namespace , string $ basePath ) : self { $ length = \ strlen ( $ basePath ) + 1 ; $ iterator = Helper :: directoryIterator ( $ basePath , $ this -> getFileFilter ( ) ) ; foreach ( $ iterator as $ file ) { $ class = $ namespace . '\\' . \ substr ( $ file , $ length , - 4 ) ; $... | auto register commands from a dir . |
47,172 | public function registerGroups ( string $ namespace , string $ basePath ) : self { $ length = \ strlen ( $ basePath ) + 1 ; $ iterator = Helper :: directoryIterator ( $ basePath , $ this -> getFileFilter ( ) ) ; foreach ( $ iterator as $ file ) { $ class = $ namespace . '\\' . \ substr ( $ file , $ length , - 4 ) ; $ t... | auto register controllers from a dir . |
47,173 | protected function runCommand ( string $ name , $ handler , array $ options ) { if ( \ is_object ( $ handler ) && \ method_exists ( $ handler , '__invoke' ) ) { if ( $ this -> input -> getSameOpt ( [ 'h' , 'help' ] ) ) { $ desc = $ options [ 'description' ] ?? 'No command description message' ; return $ this -> output ... | run a independent command |
47,174 | public function blockMsgCommand ( ) : int { if ( ! $ this -> output -> supportColor ( ) ) { $ this -> write ( 'Current terminal is not support output color text.' ) ; return 0 ; } $ this -> write ( 'block message:' ) ; foreach ( Show :: getBlockMethods ( ) as $ type ) { $ this -> output -> $ type ( "$type style message... | output block message text |
47,175 | public function highlightCommand ( $ in ) : void { $ file = $ this -> app -> getRootPath ( ) . '/src/Utils/Show.php' ; $ src = \ file_get_contents ( $ file ) ; $ code = Highlighter :: create ( ) -> highlight ( $ src , $ in -> getBoolOpt ( 'ln' ) ) ; $ this -> output -> writeRaw ( $ code ) ; } | a example for highlight code |
47,176 | public static function spinner ( ) { static $ spinner = 0 ; static $ mtime = null ; static $ chars = '-.*.-' ; $ now = microtime ( true ) ; if ( null === $ mtime || ( $ mtime < $ now - 0.1 ) ) { $ mtime = $ now ; self :: clearLine ( ) ; echo $ chars [ $ spinner ] ; $ spinner ++ ; if ( $ spinner > strlen ( $ chars ) - 1... | Spinner that updates every call up to 4 per second |
47,177 | public static function prompt ( $ prompt , $ masked = false , $ limit = 100 ) { echo "$prompt: " ; if ( $ masked ) { `stty -echo` ; } $ buffer = '' ; $ char = "" ; $ f = fopen ( 'php://stdin' , 'r' ) ; while ( strlen ( $ buffer ) < $ limit ) { $ char = fread ( $ f , 1 ) ; if ( $ char === "\n" || $ char === "\r" ) { bre... | Prompts the user for input . Optionally masking it . |
47,178 | protected function findCommand ( ) : void { if ( ! isset ( $ this -> args [ 0 ] ) ) { return ; } $ newArgs = [ ] ; foreach ( $ this -> args as $ key => $ value ) { if ( $ key === 0 ) { $ this -> command = \ trim ( $ value ) ; } elseif ( \ is_int ( $ key ) ) { $ newArgs [ ] = $ value ; } else { $ newArgs [ $ key ] = $ v... | find command name . it is first argument . |
47,179 | public function hasOpt ( string $ name ) : bool { return isset ( $ this -> sOpts [ $ name ] ) || isset ( $ this -> lOpts [ $ name ] ) ; } | check option exists |
47,180 | public static function writeln ( $ message , $ quit = false , array $ opts = [ ] ) : int { return self :: write ( $ message , true , $ quit , $ opts ) ; } | Write data to stdout with newline . |
47,181 | public static function log ( string $ msg , array $ data = [ ] , int $ level = self :: VERB_DEBUG , array $ opts = [ ] ) : void { $ levelName = self :: LEVEL_NAMES [ $ level ] ?? 'INFO' ; $ colorName = self :: LEVEL2TAG [ $ level ] ?? 'info' ; $ taggedName = ColorTag :: add ( $ levelName , $ colorName ) ; $ userOpts = ... | Print log message to console |
47,182 | public static function read ( $ message = null , bool $ nl = false , array $ opts = [ ] ) : string { if ( $ message ) { self :: write ( $ message , $ nl ) ; } $ opts = \ array_merge ( [ 'length' => 1024 , 'stream' => \ STDIN , ] , $ opts ) ; return \ file_get_contents ( $ opts [ 'stream' ] , $ opts [ 'length' ] ) ; } | Read message from STDIN |
47,183 | public static function readSafe ( $ message = null , bool $ nl = false , array $ opts = [ ] ) : string { if ( $ message ) { self :: write ( $ message , $ nl ) ; } $ opts = \ array_merge ( [ 'length' => 1024 , 'stream' => \ STDIN , 'allowTags' => null , ] , $ opts ) ; return \ trim ( \ fgetss ( $ opts [ 'stream' ] , $ o... | Gets line from file pointer and strip HTML tags |
47,184 | public static function readChar ( string $ message = '' , bool $ nl = false ) : string { $ line = self :: readln ( $ message , $ nl ) ; return $ line !== '' ? $ line [ 0 ] : '' ; } | Gets first character from file pointer |
47,185 | public static function readFirst ( string $ message = '' , bool $ nl = false ) : string { return self :: readChar ( $ message , $ nl ) ; } | Read input first char |
47,186 | public static function flushBuffer ( $ nl = false , $ quit = false , array $ opts = [ ] ) : void { self :: stopBuffer ( true , $ nl , $ quit , $ opts ) ; } | Stop buffering and flush buffer text |
47,187 | public function daemonRunCommand ( ) : void { $ ret = ProcessUtil :: daemonRun ( function ( $ pid ) { $ this -> output -> info ( "will running background by new process: $pid" ) ; } ) ; if ( $ ret === 0 ) { $ this -> output -> liteError ( 'current env is not support process create.' ) ; } } | simple process example for daemon run |
47,188 | public function runInBackgroundCommand ( ) : void { $ script = '<?php print_r($_SERVER); ?>' ; $ ret = Sys :: execInBackground ( "php $script" ) ; if ( $ ret === false ) { $ this -> output -> liteError ( 'current env is not support process create.' ) ; } } | simple process example for run In Background |
47,189 | public static function aList ( $ data , string $ title = '' , array $ opts = [ ] ) { return SingleList :: show ( $ data , $ title , $ opts ) ; } | Show a single list |
47,190 | protected function configure ( ) : void { $ method = $ this -> action . 'Configure' ; if ( \ method_exists ( $ this , $ method ) ) { $ this -> $ method ( ) ; } } | Load command configure |
47,191 | final public function execute ( $ input , $ output ) { $ action = $ this -> action ; $ group = static :: getName ( ) ; if ( $ this -> isDisabled ( $ action ) ) { $ output -> liteError ( \ sprintf ( "Sorry, The command '%s' is invalid in the group '%s'!" , $ action , $ group ) ) ; return - 1 ; } $ method = $ this -> act... | Run command action in the group |
47,192 | final public function showCommandList ( ) : void { $ this -> beforeShowCommandList ( ) ; $ ref = new \ ReflectionClass ( $ this ) ; $ sName = \ lcfirst ( self :: getName ( ) ? : $ ref -> getShortName ( ) ) ; if ( ! ( $ classDes = self :: getDescription ( ) ) ) { $ classDes = PhpDoc :: description ( $ ref -> getDocComme... | Display all sub - commands list of the controller class |
47,193 | public function showVersionInfo ( ) : void { $ os = \ PHP_OS ; $ date = \ date ( 'Y.m.d' ) ; $ logo = '' ; $ name = $ this -> getParam ( 'name' , 'Console Application' ) ; $ version = $ this -> getParam ( 'version' , 'Unknown' ) ; $ publishAt = $ this -> getParam ( 'publishAt' , 'Unknown' ) ; $ updateAt = $ this -> get... | Display the application version information |
47,194 | public function showHelpInfo ( string $ command = '' ) : void { $ in = $ this -> input ; if ( $ command ) { $ in -> setCommand ( $ command ) ; $ in -> setSOpt ( 'h' , true ) ; $ in -> clearArgs ( ) ; $ this -> dispatch ( $ command ) ; return ; } $ sep = $ this -> delimiter ; $ script = $ in -> getScript ( ) ; $ out = $... | Display the application help information |
47,195 | public static function findSimilar ( string $ need , $ iterator , int $ similarPercent = 45 ) : array { if ( ! $ need ) { return [ ] ; } $ similar = [ ] ; foreach ( $ iterator as $ name ) { \ similar_text ( $ need , $ name , $ percent ) ; if ( $ similarPercent <= ( int ) $ percent ) { $ similar [ ] = $ name ; } } retur... | find similar text from an array|Iterator |
47,196 | public function addCommand ( string $ name , $ handler = null , array $ options = [ ] ) : RouterInterface { if ( ! $ handler && \ class_exists ( $ name ) ) { $ handler = $ name ; $ name = $ name :: getName ( ) ; } if ( ! $ name || ! $ handler ) { Helper :: throwInvalidArgument ( "Command 'name' and 'handler' cannot be ... | Register a app independent console command |
47,197 | protected function showHelp ( ) : bool { if ( ! $ definition = $ this -> getDefinition ( ) ) { return false ; } $ help = $ definition -> getSynopsis ( ) ; $ help [ 'usage:' ] = \ sprintf ( '%s %s %s' , $ this -> getScriptName ( ) , $ this -> getCommandName ( ) , $ help [ 'usage:' ] ) ; $ help [ 'global options:' ] = Fo... | Display help information |
47,198 | public function getVerbLevel ( ) : int { if ( $ this -> app ) { return $ this -> app -> getVerbLevel ( ) ; } return ( int ) $ this -> input -> getLongOpt ( 'debug' , Console :: VERB_ERROR ) ; } | get current debug level value |
47,199 | public function stderr ( string $ text = '' , $ nl = true ) : int { return Console :: write ( $ text , $ nl , [ 'steam' => $ this -> errorStream , ] ) ; } | Write a message to standard error output stream . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.