idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
22,800 | public function setActive ( $ lang ) { if ( $ this -> validate ( $ lang ) ) { $ this -> active = $ lang ; return $ lang ; } return false ; } | Sets active language manually |
22,801 | public function setActiveFromUri ( $ uri ) { $ regex = '/(^\/(' . $ this -> getAvailable ( ) . '))(?:\/|\?|$)/i' ; if ( $ this -> enabled ( ) ) { if ( preg_match ( $ regex , $ uri , $ matches ) ) { $ this -> lang_in_url = true ; $ this -> active = $ matches [ 2 ] ; $ uri = preg_replace ( "/\\" . $ matches [ 1 ] . '/' ,... | Sets the active language based on the first part of the URL |
22,802 | public function getLanguageURLPrefix ( $ lang = null ) { if ( ! $ lang ) { $ lang = $ this -> getLanguage ( ) ; } return $ this -> isIncludeDefaultLanguage ( $ lang ) ? '/' . $ lang : '' ; } | Get s a URL prefix based on configuration |
22,803 | public function isIncludeDefaultLanguage ( $ lang = null ) { if ( ! $ lang ) { $ lang = $ this -> getLanguage ( ) ; } return ! ( $ this -> default === $ lang && $ this -> config -> get ( 'system.languages.include_default_lang' ) === false ) ; } | Test to see if language is default and language should be included in the URL |
22,804 | public function getFallbackPageExtensions ( $ file_ext = null ) { if ( empty ( $ this -> page_extensions ) ) { if ( ! $ file_ext ) { $ file_ext = CONTENT_EXT ; } if ( $ this -> enabled ( ) ) { $ valid_lang_extensions = [ ] ; foreach ( $ this -> languages as $ lang ) { $ valid_lang_extensions [ ] = '.' . $ lang . $ file... | Gets an array of valid extensions with active first then fallback extensions |
22,805 | public function getFallbackLanguages ( ) { if ( empty ( $ this -> fallback_languages ) ) { if ( $ this -> enabled ( ) ) { $ fallback_languages = $ this -> languages ; if ( $ this -> active ) { $ active_extension = $ this -> active ; $ key = \ array_search ( $ active_extension , $ fallback_languages , true ) ; unset ( $... | Gets an array of languages with active first then fallback languages |
22,806 | public function translate ( $ args , array $ languages = null , $ array_support = false , $ html_out = false ) { if ( \ is_array ( $ args ) ) { $ lookup = array_shift ( $ args ) ; } else { $ lookup = $ args ; $ args = [ ] ; } if ( $ this -> config -> get ( 'system.languages.translations' , true ) ) { if ( $ this -> ena... | Translate a key and possibly arguments into a string using current lang and fallbacks |
22,807 | public function getTranslation ( $ lang , $ key , $ array_support = false ) { $ translation = Grav :: instance ( ) [ 'languages' ] -> get ( $ lang . '.' . $ key , null ) ; if ( ! $ array_support && is_array ( $ translation ) ) { return ( string ) array_shift ( $ translation ) ; } return $ translation ; } | Lookup the translation text for a given lang and key |
22,808 | public function getBrowserLanguages ( $ accept_langs = [ ] ) { user_error ( __CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, no longer used' , E_USER_DEPRECATED ) ; if ( empty ( $ this -> http_accept_language ) ) { if ( empty ( $ accept_langs ) && isset ( $ _SERVER [ 'HTTP_ACCEPT_LANGUAGE' ] ) ) { $ ... | Get the browser accepted languages |
22,809 | public static function getCachedMethods ( ) : array { return [ 'getTypePrefix' => true , 'getType' => true , 'getFlexDirectory' => true , 'getCacheKey' => true , 'getCacheChecksum' => true , 'getTimestamp' => true , 'hasProperty' => true , 'getProperty' => true , 'hasNestedProperty' => true , 'getNestedProperty' => tru... | Get list of cached methods . |
22,810 | protected function createFrom ( array $ elements , $ keyField = null ) { $ collection = new static ( $ elements , $ this -> _flexDirectory ) ; $ collection -> setKeyField ( $ keyField ? : $ this -> _keyField ) ; return $ collection ; } | Creates a new instance from the specified elements . |
22,811 | public function addUploadedFile ( UploadedFileInterface $ upload , string $ field = null , array $ crop = null ) : string { $ tmp_dir = $ this -> getTmpDir ( ) ; $ tmp_name = Utils :: generateRandomString ( 12 ) ; $ name = $ upload -> getClientFilename ( ) ; $ data = [ 'name' => $ name , 'type' => $ upload -> getClient... | Add uploaded file to the form flash . |
22,812 | public function addFile ( string $ filename , string $ field , array $ crop = null ) : bool { if ( ! file_exists ( $ filename ) ) { throw new \ RuntimeException ( "File not found: {$filename}" ) ; } $ data = [ 'name' => basename ( $ filename ) , 'type' => Utils :: getMimeByLocalFile ( $ filename ) , 'size' => filesize ... | Add existing file to the form flash . |
22,813 | public function removeFile ( string $ name , string $ field = null ) : bool { if ( ! $ name ) { return false ; } $ field = $ field ? : 'undefined' ; $ upload = $ this -> files [ $ field ] [ $ name ] ?? null ; if ( null !== $ upload ) { $ this -> removeTmpFile ( $ upload [ 'tmp_name' ] ?? '' ) ; } $ upload = $ this -> f... | Remove any file from form flash . |
22,814 | public function clearFiles ( ) { foreach ( $ this -> files as $ field => $ files ) { foreach ( $ files as $ name => $ upload ) { $ this -> removeTmpFile ( $ upload [ 'tmp_name' ] ?? '' ) ; } } $ this -> files = [ ] ; } | Clear form flash from all uploaded files . |
22,815 | public function processTemplate ( $ template , $ vars = [ ] ) { $ this -> grav -> fireEvent ( 'onTwigTemplateVariables' ) ; $ vars += $ this -> twig_vars ; try { $ output = $ this -> twig -> render ( $ template , $ vars ) ; } catch ( \ Twig_Error_Loader $ e ) { throw new \ RuntimeException ( $ e -> getRawMessage ( ) , ... | Process a Twig template directly by using a template name and optional array of variables |
22,816 | public function processString ( $ string , array $ vars = [ ] ) { $ this -> grav -> fireEvent ( 'onTwigStringVariables' ) ; $ vars += $ this -> twig_vars ; $ name = '@Var:' . $ string ; $ this -> setTemplate ( $ name , $ string ) ; try { $ output = $ this -> twig -> render ( $ name , $ vars ) ; } catch ( \ Twig_Error_L... | Process a Twig template directly by using a Twig string and optional array of variables |
22,817 | public function processSite ( $ format = null , array $ vars = [ ] ) { $ this -> grav -> fireEvent ( 'onTwigSiteVariables' ) ; $ pages = $ this -> grav [ 'pages' ] ; $ page = $ this -> grav [ 'page' ] ; $ content = $ page -> content ( ) ; $ twig_vars = $ this -> twig_vars ; $ twig_vars [ 'theme' ] = $ this -> grav [ 'c... | Twig process that renders the site layout . This is the main twig process that renders the overall page and handles all the layout for the site display . |
22,818 | public function setAutoescape ( $ state ) { if ( ! $ state ) { user_error ( __CLASS__ . '::' . __FUNCTION__ . '(false) is deprecated since Grav 1.5' , E_USER_DEPRECATED ) ; } $ this -> autoescape = ( bool ) $ state ; } | Overrides the autoescape setting |
22,819 | public function addDeferJs ( $ asset , $ priority = 10 , $ pipeline = true , $ group = 'head' ) { user_error ( __CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use dynamic method with [\'loading\' => \'defer\']' , E_USER_DEPRECATED ) ; return $ this -> addJs ( $ asset , $ priority , $ pipeline , 'def... | Convenience wrapper for deferred loading of JavaScript |
22,820 | public function minPHPVersion ( ) { if ( null === $ this -> min_php ) { $ this -> min_php = $ this -> remote -> getMinPHPVersion ( ) ; } return $ this -> min_php ; } | Get minimum PHP version from remote |
22,821 | protected function bubble ( $ method , array $ arguments = [ ] , $ testLinked = true ) { if ( ! $ testLinked || $ this -> linked ) { return $ this -> parent ? call_user_func_array ( array ( $ this -> parent , $ method ) , $ arguments ) : $ this ; } return call_user_func_array ( array ( $ this , 'parent::' . $ method ) ... | Bubble a function call up to either the superclass function or the parent Medium instance |
22,822 | public function addTaxonomy ( PageInterface $ page , $ page_taxonomy = null ) { if ( ! $ page_taxonomy ) { $ page_taxonomy = $ page -> taxonomy ( ) ; } if ( empty ( $ page_taxonomy ) || ! $ page -> published ( ) ) { return ; } $ config = $ this -> grav [ 'config' ] ; if ( $ config -> get ( 'site.taxonomies' ) ) { forea... | Takes an individual page and processes the taxonomies configured in its header . It then adds those taxonomies to the map |
22,823 | public function findTaxonomy ( $ taxonomies , $ operator = 'and' ) { $ matches = [ ] ; $ results = [ ] ; foreach ( ( array ) $ taxonomies as $ taxonomy => $ items ) { foreach ( ( array ) $ items as $ item ) { if ( isset ( $ this -> taxonomy_map [ $ taxonomy ] [ $ item ] ) ) { $ matches [ ] = $ this -> taxonomy_map [ $ ... | Returns a new Page object with the sub - pages containing all the values set for a particular taxonomy . |
22,824 | public function getTaxonomyItemKeys ( $ taxonomy ) { return isset ( $ this -> taxonomy_map [ $ taxonomy ] ) ? array_keys ( $ this -> taxonomy_map [ $ taxonomy ] ) : [ ] ; } | Gets item keys per taxonomy |
22,825 | public function initializeWithUrlAndRootPath ( $ url , $ root_path ) { $ this -> initializeWithUrl ( $ url ) ; $ this -> root_path = $ root_path ; return $ this ; } | Initialize the URI class by providing url and root_path arguments |
22,826 | public function paths ( $ id = null ) { if ( $ id !== null ) { return $ this -> paths [ $ id ] ; } return $ this -> paths ; } | Return URI path . |
22,827 | public function route ( $ absolute = false , $ domain = false ) { return ( $ absolute ? $ this -> rootUrl ( $ domain ) : '' ) . '/' . implode ( '/' , $ this -> paths ) ; } | Return route to the current URI . By default route doesn t include base path . |
22,828 | public function query ( $ id = null , $ raw = false ) { if ( $ id !== null ) { return $ this -> queries [ $ id ] ?? null ; } if ( $ raw ) { return $ this -> queries ; } if ( ! $ this -> queries ) { return '' ; } return http_build_query ( $ this -> queries ) ; } | Return full query string or a single query attribute . |
22,829 | public function params ( $ id = null , $ array = false ) { $ config = Grav :: instance ( ) [ 'config' ] ; $ sep = $ config -> get ( 'system.param_sep' ) ; $ params = null ; if ( $ id === null ) { if ( $ array ) { return $ this -> params ; } $ output = [ ] ; foreach ( $ this -> params as $ key => $ value ) { $ output [ ... | Return all or a single query parameter as a URI compatible string . |
22,830 | public function param ( $ id ) { if ( isset ( $ this -> params [ $ id ] ) ) { return html_entity_decode ( rawurldecode ( $ this -> params [ $ id ] ) ) ; } return false ; } | Get URI parameter . |
22,831 | public function url ( $ include_host = false ) { if ( $ include_host ) { return $ this -> url ; } $ url = str_replace ( $ this -> base , '' , rtrim ( $ this -> url , '/' ) ) ; return $ url ? : '/' ; } | Return URL . |
22,832 | public function scheme ( $ raw = false ) { if ( ! $ raw ) { $ scheme = '' ; if ( $ this -> scheme ) { $ scheme = $ this -> scheme . '://' ; } elseif ( $ this -> host ) { $ scheme = '//' ; } return $ scheme ; } return $ this -> scheme ; } | Return the scheme of the URI |
22,833 | public function port ( $ raw = false ) { $ port = $ this -> port ; if ( ! $ raw && $ port === null ) { if ( $ this -> scheme === 'http' ) { $ this -> port = 80 ; } elseif ( $ this -> scheme === 'https' ) { $ this -> port = 443 ; } } return $ this -> port ; } | Return the port number if it can be figured out |
22,834 | public function uri ( $ include_root = true ) { if ( $ include_root ) { return $ this -> uri ; } return str_replace ( $ this -> root_path , '' , $ this -> uri ) ; } | Return the full uri |
22,835 | public function baseIncludingLanguage ( ) { $ grav = Grav :: instance ( ) ; $ pages = $ grav [ 'pages' ] ; return $ pages -> baseUrl ( null , false ) ; } | Return the base relative URL including the language prefix or the base relative url if multi - language is not enabled |
22,836 | public function rootUrl ( $ include_host = false ) { if ( $ include_host ) { return $ this -> root ; } return str_replace ( $ this -> base , '' , $ this -> root ) ; } | Return root URL to the site . |
22,837 | public function referrer ( $ default = null , $ attributes = null ) { $ referrer = $ _SERVER [ 'HTTP_REFERER' ] ?? null ; $ root = $ this -> rootUrl ( true ) ; if ( $ referrer ) { if ( stripos ( $ referrer , $ root ) !== 0 ) { $ referrer = null ; } } if ( ! $ referrer ) { $ referrer = $ default ? : $ this -> route ( tr... | Return relative path to the referrer defaulting to current or given page . |
22,838 | public static function ip ( ) { if ( getenv ( 'HTTP_CLIENT_IP' ) ) { $ ip = getenv ( 'HTTP_CLIENT_IP' ) ; } elseif ( getenv ( 'HTTP_X_FORWARDED_FOR' ) ) { $ ip = getenv ( 'HTTP_X_FORWARDED_FOR' ) ; } elseif ( getenv ( 'HTTP_X_FORWARDED' ) ) { $ ip = getenv ( 'HTTP_X_FORWARDED' ) ; } elseif ( getenv ( 'HTTP_FORWARDED_FO... | Return the IP address of the current user |
22,839 | public static function getCurrentRoute ( ) { if ( ! static :: $ currentRoute ) { $ uri = Grav :: instance ( ) [ 'uri' ] ; static :: $ currentRoute = RouteFactory :: createFromParts ( $ uri -> toArray ( ) ) ; } return static :: $ currentRoute ; } | Returns current route . |
22,840 | public static function addNonce ( $ url , $ action , $ nonceParamName = 'nonce' ) { $ fake = $ url && strpos ( $ url , '/' ) === 0 ; if ( $ fake ) { $ url = 'http://domain.com' . $ url ; } $ uri = new static ( $ url ) ; $ parts = $ uri -> toArray ( ) ; $ nonce = Utils :: getNonce ( $ action ) ; $ parts [ 'params' ] = (... | Adds the nonce to a URL for a specific action |
22,841 | public static function cleanPath ( $ path ) { $ regex = '/(\/)\/+/' ; $ path = str_replace ( [ '\\' , '/ /' ] , '/' , $ path ) ; $ path = preg_replace ( $ regex , '$1' , $ path ) ; return $ path ; } | Removes extra double slashes and fixes back - slashes |
22,842 | public function getContentType ( $ short = true ) { if ( isset ( $ _SERVER [ 'CONTENT_TYPE' ] ) ) { $ content_type = $ _SERVER [ 'CONTENT_TYPE' ] ; if ( $ short ) { return Utils :: substrToString ( $ content_type , ';' ) ; } return $ content_type ; } return null ; } | Get content type from request |
22,843 | public function isValidExtension ( $ extension ) { $ valid_page_types = implode ( '|' , Grav :: instance ( ) [ 'config' ] -> get ( 'system.pages.types' ) ) ; if ( preg_match ( '/(' . $ valid_page_types . ')/' , $ extension ) ) { return true ; } return false ; } | Check if this is a valid Grav extension |
22,844 | private function buildRootPath ( ) { $ scriptPath = str_replace ( '\\' , '/' , $ _SERVER [ 'PHP_SELF' ] ) ; $ rootPath = str_replace ( ' ' , '%20' , rtrim ( substr ( $ scriptPath , 0 , strpos ( $ scriptPath , 'index.php' ) ) , '/' ) ) ; return $ rootPath ; } | Get the Grav Root Path |
22,845 | private function processParams ( $ uri , $ delimiter = ':' ) { if ( strpos ( $ uri , $ delimiter ) !== false ) { preg_match_all ( static :: paramsRegex ( ) , $ uri , $ matches , PREG_SET_ORDER ) ; foreach ( $ matches as $ match ) { $ param = explode ( $ delimiter , $ match [ 1 ] ) ; if ( count ( $ param ) === 2 ) { $ p... | Process any params based in this URL supports any valid delimiter |
22,846 | public function getAllJobs ( ) { list ( $ background , $ foreground ) = $ this -> loadSavedJobs ( ) -> getQueuedJobs ( true ) ; return array_merge ( $ background , $ foreground ) ; } | Get all jobs if they are disabled or not as one array |
22,847 | public function addFunction ( callable $ fn , $ args = [ ] , $ id = null ) { $ job = new Job ( $ fn , $ args , $ id ) ; $ this -> queueJob ( $ job -> configure ( $ this -> config ) ) ; return $ job ; } | Queues a PHP function execution . |
22,848 | public function getCronCommand ( ) { $ phpBinaryFinder = new PhpExecutableFinder ( ) ; $ php = $ phpBinaryFinder -> find ( ) ; $ command = 'cd ' . str_replace ( ' ' , '\ ' , GRAV_ROOT ) . ';' . $ php . ' bin/grav scheduler' ; return "(crontab -l; echo \"* * * * * {$command} 1>> /dev/null 2>&1\") | crontab -" ; } | Helper to get the full Cron command |
22,849 | public function isCrontabSetup ( ) { $ process = new Process ( 'crontab -l' ) ; $ process -> run ( ) ; if ( $ process -> isSuccessful ( ) ) { $ output = $ process -> getOutput ( ) ; return preg_match ( '$bin\/grav schedule$' , $ output ) ? 1 : 0 ; } $ error = $ process -> getErrorOutput ( ) ; return Utils :: startsWith... | Helper to determine if cron job is setup |
22,850 | private function saveJobStates ( ) { $ now = time ( ) ; $ new_states = [ ] ; foreach ( $ this -> jobs_run as $ job ) { if ( $ job -> isSuccessful ( ) ) { $ new_states [ $ job -> getId ( ) ] = [ 'state' => 'success' , 'last-run' => $ now ] ; $ this -> pushExecutedJob ( $ job ) ; } else { $ new_states [ $ job -> getId ( ... | Save job states to statys file |
22,851 | protected static function getRequestSize ( $ header , $ method ) { if ( $ method === 'GET' || $ method === 'OPTIONS' || $ method === 'HEAD' ) { return strlen ( $ header ) + 4 ; } $ match = array ( ) ; if ( preg_match ( "/\r\nContent-Length: ?(\d+)/i" , $ header , $ match ) ) { $ content_length = isset ( $ match [ 1 ] )... | Get whole size of the request includes the request headers and request body . |
22,852 | public static function encode ( $ content , TcpConnection $ connection ) { if ( ! isset ( HttpCache :: $ header [ 'Http-Code' ] ) ) { $ header = "HTTP/1.1 200 OK\r\n" ; } else { $ header = HttpCache :: $ header [ 'Http-Code' ] . "\r\n" ; unset ( HttpCache :: $ header [ 'Http-Code' ] ) ; } if ( ! isset ( HttpCache :: $ ... | Http encode . |
22,853 | public static function tryGcSessions ( ) { if ( HttpCache :: $ sessionGcProbability <= 0 || HttpCache :: $ sessionGcDivisor <= 0 || rand ( 1 , HttpCache :: $ sessionGcDivisor ) > HttpCache :: $ sessionGcProbability ) { return ; } $ time_now = time ( ) ; foreach ( glob ( HttpCache :: $ sessionPath . '/ses*' ) as $ file ... | Try GC sessions . |
22,854 | public function addRoot ( $ domain , $ config ) { if ( is_string ( $ config ) ) { $ config = array ( 'root' => $ config ) ; } $ this -> serverRoot [ $ domain ] = $ config ; } | Add virtual host . |
22,855 | public function run ( ) { $ this -> _onWorkerStart = $ this -> onWorkerStart ; $ this -> onWorkerStart = array ( $ this , 'onWorkerStart' ) ; $ this -> onMessage = array ( $ this , 'onMessage' ) ; parent :: run ( ) ; } | Run webserver instance . |
22,856 | public function onWorkerStart ( ) { if ( empty ( $ this -> serverRoot ) ) { Worker :: safeEcho ( new \ Exception ( 'server root not set, please use WebServer::addRoot($domain, $root_path) to set server root path' ) ) ; exit ( 250 ) ; } $ this -> initMimeTypeMap ( ) ; if ( $ this -> _onWorkerStart ) { try { call_user_fu... | Emit when process start . |
22,857 | public function initMimeTypeMap ( ) { $ mime_file = Http :: getMimeTypesFile ( ) ; if ( ! is_file ( $ mime_file ) ) { $ this -> log ( "$mime_file mime.type file not fond" ) ; return ; } $ items = file ( $ mime_file , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ) ; if ( ! is_array ( $ items ) ) { $ this -> log ( "get ... | Init mime map . |
22,858 | protected function emitError ( $ code , $ msg ) { $ this -> _status = self :: STATUS_CLOSING ; if ( $ this -> onError ) { try { call_user_func ( $ this -> onError , $ this , $ code , $ msg ) ; } catch ( \ Exception $ e ) { Worker :: log ( $ e ) ; exit ( 250 ) ; } catch ( \ Error $ e ) { Worker :: log ( $ e ) ; exit ( 2... | Try to emit onError callback . |
22,859 | protected function tick ( ) { while ( ! $ this -> _scheduler -> isEmpty ( ) ) { $ scheduler_data = $ this -> _scheduler -> top ( ) ; $ timer_id = $ scheduler_data [ 'data' ] ; $ next_run_time = - $ scheduler_data [ 'priority' ] ; $ time_now = microtime ( true ) ; $ this -> _selectTimeout = ( $ next_run_time - $ time_no... | Tick for timer . |
22,860 | public function getRemoteIp ( ) { $ pos = strrpos ( $ this -> _remoteAddress , ':' ) ; if ( $ pos ) { return substr ( $ this -> _remoteAddress , 0 , $ pos ) ; } return '' ; } | Get remote IP . |
22,861 | public function getLocalIp ( ) { $ address = $ this -> getLocalAddress ( ) ; $ pos = strrpos ( $ address , ':' ) ; if ( ! $ pos ) { return '' ; } return substr ( $ address , 0 , $ pos ) ; } | Get local IP . |
22,862 | public function getLocalPort ( ) { $ address = $ this -> getLocalAddress ( ) ; $ pos = strrpos ( $ address , ':' ) ; if ( ! $ pos ) { return 0 ; } return ( int ) substr ( strrchr ( $ address , ':' ) , 1 ) ; } | Get local port . |
22,863 | public function pauseRecv ( ) { Worker :: $ globalEvent -> del ( $ this -> _socket , EventInterface :: EV_READ ) ; $ this -> _isPaused = true ; } | Pauses the reading of data . That is onMessage will not be emitted . Useful to throttle back an upload . |
22,864 | public function resumeRecv ( ) { if ( $ this -> _isPaused === true ) { Worker :: $ globalEvent -> add ( $ this -> _socket , EventInterface :: EV_READ , array ( $ this , 'baseRead' ) ) ; $ this -> _isPaused = false ; $ this -> baseRead ( $ this -> _socket , false ) ; } } | Resumes reading after a call to pauseRecv . |
22,865 | public function baseWrite ( ) { set_error_handler ( function ( ) { } ) ; if ( $ this -> transport === 'ssl' ) { $ len = fwrite ( $ this -> _socket , $ this -> _sendBuffer , 8192 ) ; } else { $ len = fwrite ( $ this -> _socket , $ this -> _sendBuffer ) ; } restore_error_handler ( ) ; if ( $ len === strlen ( $ this -> _s... | Base write handler . |
22,866 | public function doSslHandshake ( $ socket ) { if ( feof ( $ socket ) ) { $ this -> destroy ( ) ; return false ; } $ async = $ this instanceof AsyncTcpConnection ; if ( $ async ) { $ type = STREAM_CRYPTO_METHOD_SSLv2_CLIENT | STREAM_CRYPTO_METHOD_SSLv23_CLIENT ; } else { $ type = STREAM_CRYPTO_METHOD_SSLv2_SERVER | STRE... | SSL handshake . |
22,867 | public function pipe ( $ dest ) { $ source = $ this ; $ this -> onMessage = function ( $ source , $ data ) use ( $ dest ) { $ dest -> send ( $ data ) ; } ; $ this -> onClose = function ( $ source ) use ( $ dest ) { $ dest -> destroy ( ) ; } ; $ dest -> onBufferFull = function ( $ dest ) use ( $ source ) { $ source -> p... | This method pulls all the data out of a readable stream and writes it to the supplied destination . |
22,868 | public function destroy ( ) { if ( $ this -> _status === self :: STATUS_CLOSED ) { return ; } Worker :: $ globalEvent -> del ( $ this -> _socket , EventInterface :: EV_READ ) ; Worker :: $ globalEvent -> del ( $ this -> _socket , EventInterface :: EV_WRITE ) ; set_error_handler ( function ( ) { } ) ; fclose ( $ this ->... | Destroy connection . |
22,869 | protected static function parseHttpHeader ( $ buffer ) { list ( $ http_header , ) = explode ( "\r\n\r\n" , $ buffer , 2 ) ; $ header_data = explode ( "\r\n" , $ http_header ) ; if ( $ _SERVER ) { $ _SERVER = array ( ) ; } list ( $ _SERVER [ 'REQUEST_METHOD' ] , $ _SERVER [ 'REQUEST_URI' ] , $ _SERVER [ 'SERVER_PROTOCOL... | Parse http header . |
22,870 | public static function getSingleLineTotalLength ( ) { $ total_length = 0 ; foreach ( static :: getUiColumns ( ) as $ column_name => $ prop ) { $ key = '_max' . ucfirst ( strtolower ( $ column_name ) ) . 'NameLength' ; $ total_length += static :: $ $ key + static :: UI_SAFE_LENGTH ; } ! defined ( 'LINE_VERSIOIN_LENGTH' ... | Get single line total length for ui |
22,871 | protected static function daemonize ( ) { if ( ! static :: $ daemonize || static :: $ _OS !== OS_TYPE_LINUX ) { return ; } umask ( 0 ) ; $ pid = pcntl_fork ( ) ; if ( - 1 === $ pid ) { throw new Exception ( 'fork fail' ) ; } elseif ( $ pid > 0 ) { exit ( 0 ) ; } if ( - 1 === posix_setsid ( ) ) { throw new Exception ( "... | Run as deamon mode . |
22,872 | public static function resetStd ( ) { if ( ! static :: $ daemonize || static :: $ _OS !== OS_TYPE_LINUX ) { return ; } global $ STDOUT , $ STDERR ; $ handle = fopen ( static :: $ stdoutFile , "a" ) ; if ( $ handle ) { unset ( $ handle ) ; set_error_handler ( function ( ) { } ) ; fclose ( $ STDOUT ) ; fclose ( $ STDERR ... | Redirect standard input and output . |
22,873 | protected static function getAllWorkerPids ( ) { $ pid_array = array ( ) ; foreach ( static :: $ _pidMap as $ worker_pid_array ) { foreach ( $ worker_pid_array as $ worker_pid ) { $ pid_array [ $ worker_pid ] = $ worker_pid ; } } return $ pid_array ; } | Get all pids of worker processes . |
22,874 | public static function getStartFilesForWindows ( ) { global $ argv ; $ files = array ( ) ; foreach ( $ argv as $ file ) { if ( is_file ( $ file ) ) { $ files [ $ file ] = $ file ; } } return $ files ; } | Get start files for windows . |
22,875 | public static function checkWorkerStatusForWindows ( ) { foreach ( static :: $ _processForWindows as $ process_data ) { $ process = $ process_data [ 0 ] ; $ start_file = $ process_data [ 1 ] ; $ timer_id = $ process_data [ 2 ] ; $ status = proc_get_status ( $ process ) ; if ( isset ( $ status [ 'running' ] ) ) { if ( !... | check worker status for windows . |
22,876 | public function setUserAndGroup ( ) { $ user_info = posix_getpwnam ( $ this -> user ) ; if ( ! $ user_info ) { static :: log ( "Warning: User {$this->user} not exsits" ) ; return ; } $ uid = $ user_info [ 'uid' ] ; if ( $ this -> group ) { $ group_info = posix_getgrnam ( $ this -> group ) ; if ( ! $ group_info ) { stat... | Set unix user and group for current process . |
22,877 | public static function checkIfChildRunning ( ) { foreach ( static :: $ _pidMap as $ worker_id => $ worker_pid_array ) { foreach ( $ worker_pid_array as $ pid => $ worker_pid ) { if ( ! posix_kill ( $ pid , 0 ) ) { unset ( static :: $ _pidMap [ $ worker_id ] [ $ pid ] ) ; } } } } | check if child processes is really running |
22,878 | public static function safeEcho ( $ msg , $ decorated = false ) { $ stream = static :: outputStream ( ) ; if ( ! $ stream ) { return false ; } if ( ! $ decorated ) { $ line = $ white = $ green = $ end = '' ; if ( static :: $ _outputDecorated ) { $ line = "\033[1A\n\033[K" ; $ white = "\033[47;30m" ; $ green = "\033[32;... | Safe Echo . |
22,879 | public function pauseAccept ( ) { if ( static :: $ globalEvent && false === $ this -> _pauseAccept && $ this -> _mainSocket ) { static :: $ globalEvent -> del ( $ this -> _mainSocket , EventInterface :: EV_READ ) ; $ this -> _pauseAccept = true ; } } | Pause accept new connections . |
22,880 | public function resumeAccept ( ) { if ( static :: $ globalEvent && true === $ this -> _pauseAccept && $ this -> _mainSocket ) { if ( $ this -> transport !== 'udp' ) { static :: $ globalEvent -> add ( $ this -> _mainSocket , EventInterface :: EV_READ , array ( $ this , 'acceptConnection' ) ) ; } else { static :: $ globa... | Resume accept new connections . |
22,881 | public function acceptConnection ( $ socket ) { set_error_handler ( function ( ) { } ) ; $ new_socket = stream_socket_accept ( $ socket , 0 , $ remote_address ) ; restore_error_handler ( ) ; if ( ! $ new_socket ) { return ; } $ connection = new TcpConnection ( $ new_socket , $ remote_address ) ; $ this -> connections [... | Accept a connection . |
22,882 | public function acceptUdpConnection ( $ socket ) { set_error_handler ( function ( ) { } ) ; $ recv_buffer = stream_socket_recvfrom ( $ socket , static :: MAX_UDP_PACKAGE_SIZE , 0 , $ remote_address ) ; restore_error_handler ( ) ; if ( false === $ recv_buffer || empty ( $ remote_address ) ) { return false ; } $ connecti... | For udp package . |
22,883 | public function create ( string $ account , string $ nickname ) { $ params = [ 'kf_account' => $ account , 'nickname' => $ nickname , ] ; return $ this -> httpPostJson ( 'customservice/kfaccount/add' , $ params ) ; } | Create a staff . |
22,884 | public function update ( string $ account , string $ nickname ) { $ params = [ 'kf_account' => $ account , 'nickname' => $ nickname , ] ; return $ this -> httpPostJson ( 'customservice/kfaccount/update' , $ params ) ; } | Update a staff . |
22,885 | public function invite ( string $ account , string $ wechatId ) { $ params = [ 'kf_account' => $ account , 'invite_wx' => $ wechatId , ] ; return $ this -> httpPostJson ( 'customservice/kfaccount/inviteworker' , $ params ) ; } | Invite a staff . |
22,886 | public function messages ( $ startTime , $ endTime , int $ msgId = 1 , int $ number = 10000 ) { $ params = [ 'starttime' => is_numeric ( $ startTime ) ? $ startTime : strtotime ( $ startTime ) , 'endtime' => is_numeric ( $ endTime ) ? $ endTime : strtotime ( $ endTime ) , 'msgid' => $ msgId , 'number' => $ number , ] ;... | Get messages history . |
22,887 | protected function requestRaw ( $ endpoint , array $ params = [ ] , $ method = 'post' , array $ options = [ ] ) { return $ this -> request ( $ endpoint , $ params , $ method , $ options , true ) ; } | Make a request and return raw response . |
22,888 | public function open ( string $ msgId , int $ index = null ) { $ params = [ 'msg_data_id' => $ msgId , 'index' => $ index , ] ; return $ this -> httpPostJson ( 'cgi-bin/comment/open' , $ params ) ; } | Open article comment . |
22,889 | public function list ( string $ msgId , int $ index , int $ begin , int $ count , int $ type = 0 ) { $ params = [ 'msg_data_id' => $ msgId , 'index' => $ index , 'begin' => $ begin , 'count' => $ count , 'type' => $ type , ] ; return $ this -> httpPostJson ( 'cgi-bin/comment/list' , $ params ) ; } | Get article comments . |
22,890 | public function markElect ( string $ msgId , int $ index , int $ commentId ) { $ params = [ 'msg_data_id' => $ msgId , 'index' => $ index , 'user_comment_id' => $ commentId , ] ; return $ this -> httpPostJson ( 'cgi-bin/comment/markelect' , $ params ) ; } | Mark elect comment . |
22,891 | public function reply ( string $ msgId , int $ index , int $ commentId , string $ content ) { $ params = [ 'msg_data_id' => $ msgId , 'index' => $ index , 'user_comment_id' => $ commentId , 'content' => $ content , ] ; return $ this -> httpPostJson ( 'cgi-bin/comment/reply/add' , $ params ) ; } | Reply to a comment . |
22,892 | public static function getExtBySignature ( $ stream ) { $ prefix = strval ( bin2hex ( mb_strcut ( $ stream , 0 , 10 ) ) ) ; foreach ( self :: $ signatures as $ signature => $ extension ) { if ( 0 === strpos ( $ prefix , strval ( $ signature ) ) ) { return $ extension ; } } return '' ; } | Get file extension by file header signature . |
22,893 | public function get ( string $ openid , string $ lang = 'zh_CN' ) { $ params = [ 'openid' => $ openid , 'lang' => $ lang , ] ; return $ this -> httpGet ( 'cgi-bin/user/info' , $ params ) ; } | Fetch a user by open id . |
22,894 | public function remark ( string $ openid , string $ remark ) { $ params = [ 'openid' => $ openid , 'remark' => $ remark , ] ; return $ this -> httpPostJson ( 'cgi-bin/user/info/updateremark' , $ params ) ; } | Set user remark . |
22,895 | public function update ( array $ deviceIdentifier , string $ comment ) { $ params = [ 'device_identifier' => $ deviceIdentifier , 'comment' => $ comment , ] ; return $ this -> httpPostJson ( 'shakearound/device/update' , $ params ) ; } | Update a device comment . |
22,896 | public function bindPoi ( array $ deviceIdentifier , int $ poiId ) { $ params = [ 'device_identifier' => $ deviceIdentifier , 'poi_id' => $ poiId , ] ; return $ this -> httpPostJson ( 'shakearound/device/bindlocation' , $ params ) ; } | Bind location for device . |
22,897 | public function list ( int $ lastId , int $ count ) { $ params = [ 'type' => 2 , 'last_seen' => $ lastId , 'count' => $ count , ] ; return $ this -> search ( $ params ) ; } | Pagination to get batch of devices . |
22,898 | public function listByApplyId ( int $ applyId , int $ lastId , int $ count ) { $ params = [ 'type' => 3 , 'apply_id' => $ applyId , 'last_seen' => $ lastId , 'count' => $ count , ] ; return $ this -> search ( $ params ) ; } | Fetch batch of devices by applyId . |
22,899 | public function getHttpClient ( ) : ClientInterface { if ( ! ( $ this -> httpClient instanceof ClientInterface ) ) { if ( property_exists ( $ this , 'app' ) && $ this -> app [ 'http_client' ] ) { $ this -> httpClient = $ this -> app [ 'http_client' ] ; } else { $ this -> httpClient = new Client ( [ 'handler' => Handler... | Return GuzzleHttp \ ClientInterface instance . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.