idx int64 0 241k | question stringlengths 64 6.21k | target stringlengths 5 803 |
|---|---|---|
6,300 | public function move ( $ x , $ y ) { $ this -> driver -> manage ( ) -> window ( ) -> setPosition ( new WebDriverPoint ( $ x , $ y ) ) ; return $ this ; } | Move the browser window . |
6,301 | public function screenshot ( $ name ) { $ this -> driver -> takeScreenshot ( sprintf ( '%s/%s.png' , rtrim ( static :: $ storeScreenshotsAt , '/' ) , $ name ) ) ; return $ this ; } | Take a screenshot and store it with the given name . |
6,302 | public function storeConsoleLog ( $ name ) { if ( in_array ( $ this -> driver -> getCapabilities ( ) -> getBrowserName ( ) , static :: $ supportsRemoteLogs ) ) { $ console = $ this -> driver -> manage ( ) -> getLog ( 'browser' ) ; if ( ! empty ( $ console ) ) { file_put_contents ( sprintf ( '%s/%s.log' , rtrim ( static :: $ storeConsoleLogAt , '/' ) , $ name ) , json_encode ( $ console , JSON_PRETTY_PRINT ) ) ; } } return $ this ; } | Store the console output with the given name . |
6,303 | public function withinFrame ( $ selector , Closure $ callback ) { $ this -> driver -> switchTo ( ) -> frame ( $ this -> resolver -> findOrFail ( $ selector ) ) ; $ callback ( $ this ) ; $ this -> driver -> switchTo ( ) -> defaultContent ( ) ; return $ this ; } | Switch to a specified frame in the browser and execute the given callback . |
6,304 | public function with ( $ selector , Closure $ callback ) { $ browser = new static ( $ this -> driver , new ElementResolver ( $ this -> driver , $ this -> resolver -> format ( $ selector ) ) ) ; if ( $ this -> page ) { $ browser -> onWithoutAssert ( $ this -> page ) ; } if ( $ selector instanceof Component ) { $ browser -> onComponent ( $ selector , $ this -> resolver ) ; } call_user_func ( $ callback , $ browser ) ; return $ this ; } | Execute a Closure with a scoped browser instance . |
6,305 | public function onComponent ( $ component , $ parentResolver ) { $ this -> component = $ component ; $ this -> resolver -> pageElements ( $ component -> elements ( ) + $ parentResolver -> elements ) ; $ component -> assert ( $ this ) ; $ this -> resolver -> prefix = $ this -> resolver -> format ( $ component -> selector ( ) ) ; } | Set the current component state . |
6,306 | public function resolveForTyping ( $ field ) { if ( ! is_null ( $ element = $ this -> findById ( $ field ) ) ) { return $ element ; } return $ this -> firstOrFail ( [ $ field , "input[name='{$field}']" , "textarea[name='{$field}']" , ] ) ; } | Resolve the element for a given input field . |
6,307 | public function resolveForSelection ( $ field ) { if ( ! is_null ( $ element = $ this -> findById ( $ field ) ) ) { return $ element ; } return $ this -> firstOrFail ( [ $ field , "select[name='{$field}']" , ] ) ; } | Resolve the element for a given select field . |
6,308 | public function resolveSelectOptions ( $ field , array $ values ) { $ options = $ this -> resolveForSelection ( $ field ) -> findElements ( WebDriverBy :: tagName ( 'option' ) ) ; if ( empty ( $ options ) ) { return [ ] ; } return array_filter ( $ options , function ( $ option ) use ( $ values ) { return in_array ( $ option -> getAttribute ( 'value' ) , $ values ) ; } ) ; } | Resolve all the options with the given value on the select field . |
6,309 | public function resolveForChecking ( $ field , $ value = null ) { if ( ! is_null ( $ element = $ this -> findById ( $ field ) ) ) { return $ element ; } $ selector = 'input[type=checkbox]' ; if ( ! is_null ( $ field ) ) { $ selector .= "[name='{$field}']" ; } if ( ! is_null ( $ value ) ) { $ selector .= "[value='{$value}']" ; } return $ this -> firstOrFail ( [ $ field , $ selector , ] ) ; } | Resolve the element for a given checkbox field . |
6,310 | public function resolveForAttachment ( $ field ) { if ( ! is_null ( $ element = $ this -> findById ( $ field ) ) ) { return $ element ; } return $ this -> firstOrFail ( [ $ field , "input[type=file][name='{$field}']" , ] ) ; } | Resolve the element for a given file field . |
6,311 | public function resolveForField ( $ field ) { if ( ! is_null ( $ element = $ this -> findById ( $ field ) ) ) { return $ element ; } return $ this -> firstOrFail ( [ $ field , "input[name='{$field}']" , "textarea[name='{$field}']" , "select[name='{$field}']" , "button[name='{$field}']" , ] ) ; } | Resolve the element for a given field . |
6,312 | public function resolveForButtonPress ( $ button ) { foreach ( $ this -> buttonFinders as $ method ) { if ( ! is_null ( $ element = $ this -> { $ method } ( $ button ) ) ) { return $ element ; } } throw new InvalidArgumentException ( "Unable to locate button [{$button}]." ) ; } | Resolve the element for a given button . |
6,313 | protected function findButtonByName ( $ button ) { if ( ! is_null ( $ element = $ this -> find ( "input[type=submit][name='{$button}']" ) ) || ! is_null ( $ element = $ this -> find ( "input[type=button][value='{$button}']" ) ) || ! is_null ( $ element = $ this -> find ( "button[name='{$button}']" ) ) ) { return $ element ; } } | Resolve the element for a given button by name . |
6,314 | protected function findButtonByValue ( $ button ) { foreach ( $ this -> all ( 'input[type=submit]' ) as $ element ) { if ( $ element -> getAttribute ( 'value' ) === $ button ) { return $ element ; } } } | Resolve the element for a given button by value . |
6,315 | protected function findButtonByText ( $ button ) { foreach ( $ this -> all ( 'button' ) as $ element ) { if ( Str :: contains ( $ element -> getText ( ) , $ button ) ) { return $ element ; } } } | Resolve the element for a given button by text . |
6,316 | protected function findById ( $ selector ) { if ( preg_match ( '/^#[\w\-:]+$/' , $ selector ) ) { return $ this -> driver -> findElement ( WebDriverBy :: id ( substr ( $ selector , 1 ) ) ) ; } } | Attempt to find the selector by ID . |
6,317 | public function firstOrFail ( $ selectors ) { foreach ( ( array ) $ selectors as $ selector ) { try { return $ this -> findOrFail ( $ selector ) ; } catch ( Exception $ e ) { } } throw $ e ; } | Get the first element matching the given selectors . |
6,318 | public function findOrFail ( $ selector ) { if ( ! is_null ( $ element = $ this -> findById ( $ selector ) ) ) { return $ element ; } return $ this -> driver -> findElement ( WebDriverBy :: cssSelector ( $ this -> format ( $ selector ) ) ) ; } | Find an element by the given selector or throw an exception . |
6,319 | public function all ( $ selector ) { try { return $ this -> driver -> findElements ( WebDriverBy :: cssSelector ( $ this -> format ( $ selector ) ) ) ; } catch ( Exception $ e ) { } return [ ] ; } | Find the elements by the given selector or return an empty array . |
6,320 | public function format ( $ selector ) { $ sortedElements = collect ( $ this -> elements ) -> sortByDesc ( function ( $ element , $ key ) { return strlen ( $ key ) ; } ) -> toArray ( ) ; $ selector = str_replace ( array_keys ( $ sortedElements ) , array_values ( $ sortedElements ) , $ originalSelector = $ selector ) ; if ( Str :: startsWith ( $ selector , '@' ) && $ selector === $ originalSelector ) { $ selector = '[dusk="' . explode ( '@' , $ selector ) [ 1 ] . '"]' ; } return trim ( $ this -> prefix . ' ' . $ selector ) ; } | Format the given selector with the current prefix . |
6,321 | public function script ( $ scripts ) { return collect ( ( array ) $ scripts ) -> map ( function ( $ script ) { return $ this -> driver -> executeScript ( $ script ) ; } ) -> all ( ) ; } | Execute JavaScript within the browser . |
6,322 | public function cookie ( $ name , $ value = null , $ expiry = null , array $ options = [ ] ) { if ( ! is_null ( $ value ) ) { return $ this -> addCookie ( $ name , $ value , $ expiry , $ options ) ; } if ( $ cookie = $ this -> driver -> manage ( ) -> getCookieNamed ( $ name ) ) { return decrypt ( rawurldecode ( $ cookie [ 'value' ] ) , $ unserialize = false ) ; } } | Get or set an encrypted cookie s value . |
6,323 | public function addCookie ( $ name , $ value , $ expiry = null , array $ options = [ ] , $ encrypt = true ) { if ( $ encrypt ) { $ value = encrypt ( $ value , $ serialize = false ) ; } if ( $ expiry instanceof DateTimeInterface ) { $ expiry = $ expiry -> getTimestamp ( ) ; } $ this -> driver -> manage ( ) -> addCookie ( array_merge ( $ options , compact ( 'expiry' , 'name' , 'value' ) ) ) ; return $ this ; } | Add the given cookie . |
6,324 | public function assertUrlIs ( $ url ) { $ pattern = str_replace ( '\*' , '.*' , preg_quote ( $ url , '/' ) ) ; $ segments = parse_url ( $ this -> driver -> getCurrentURL ( ) ) ; $ currentUrl = sprintf ( '%s://%s%s%s' , $ segments [ 'scheme' ] , $ segments [ 'host' ] , Arr :: get ( $ segments , 'port' , '' ) ? ':' . $ segments [ 'port' ] : '' , Arr :: get ( $ segments , 'path' , '' ) ) ; PHPUnit :: assertRegExp ( '/^' . $ pattern . '$/u' , $ currentUrl , "Actual URL [{$this->driver->getCurrentURL()}] does not equal expected URL [{$url}]." ) ; return $ this ; } | Assert that the current URL matches the given URL . |
6,325 | public function assertSchemeIs ( $ scheme ) { $ pattern = str_replace ( '\*' , '.*' , preg_quote ( $ scheme , '/' ) ) ; $ actual = parse_url ( $ this -> driver -> getCurrentURL ( ) , PHP_URL_SCHEME ) ?? '' ; PHPUnit :: assertRegExp ( '/^' . $ pattern . '$/u' , $ actual , "Actual scheme [{$actual}] does not equal expected scheme [{$pattern}]." ) ; return $ this ; } | Assert that the current scheme matches the given scheme . |
6,326 | public function assertSchemeIsNot ( $ scheme ) { $ actual = parse_url ( $ this -> driver -> getCurrentURL ( ) , PHP_URL_SCHEME ) ?? '' ; PHPUnit :: assertNotEquals ( $ scheme , $ actual , "Scheme [{$scheme}] should not equal the actual value." ) ; return $ this ; } | Assert that the current scheme does not match the given scheme . |
6,327 | public function assertHostIs ( $ host ) { $ pattern = str_replace ( '\*' , '.*' , preg_quote ( $ host , '/' ) ) ; $ actual = parse_url ( $ this -> driver -> getCurrentURL ( ) , PHP_URL_HOST ) ?? '' ; PHPUnit :: assertRegExp ( '/^' . $ pattern . '$/u' , $ actual , "Actual host [{$actual}] does not equal expected host [{$pattern}]." ) ; return $ this ; } | Assert that the current host matches the given host . |
6,328 | public function assertPortIs ( $ port ) { $ pattern = str_replace ( '\*' , '.*' , preg_quote ( $ port , '/' ) ) ; $ actual = parse_url ( $ this -> driver -> getCurrentURL ( ) , PHP_URL_PORT ) ?? '' ; PHPUnit :: assertRegExp ( '/^' . $ pattern . '$/u' , $ actual , "Actual port [{$actual}] does not equal expected port [{$pattern}]." ) ; return $ this ; } | Assert that the current port matches the given port . |
6,329 | public function assertPathIs ( $ path ) { $ pattern = str_replace ( '\*' , '.*' , preg_quote ( $ path , '/' ) ) ; $ actualPath = parse_url ( $ this -> driver -> getCurrentURL ( ) , PHP_URL_PATH ) ?? '' ; PHPUnit :: assertRegExp ( '/^' . $ pattern . '$/u' , $ actualPath , "Actual path [{$actualPath}] does not equal expected path [{$path}]." ) ; return $ this ; } | Assert that the current URL path matches the given pattern . |
6,330 | public function assertPathBeginsWith ( $ path ) { $ actualPath = parse_url ( $ this -> driver -> getCurrentURL ( ) , PHP_URL_PATH ) ?? '' ; PHPUnit :: assertStringStartsWith ( $ path , $ actualPath , "Actual path [{$actualPath}] does not begin with expected path [{$path}]." ) ; return $ this ; } | Assert that the current URL path begins with given path . |
6,331 | public function assertPathIsNot ( $ path ) { $ actualPath = parse_url ( $ this -> driver -> getCurrentURL ( ) , PHP_URL_PATH ) ?? '' ; PHPUnit :: assertNotEquals ( $ path , $ actualPath , "Path [{$path}] should not equal the actual value." ) ; return $ this ; } | Assert that the current URL path does not match the given path . |
6,332 | public function assertFragmentIs ( $ fragment ) { $ pattern = preg_quote ( $ fragment , '/' ) ; $ actualFragment = ( string ) parse_url ( $ this -> driver -> executeScript ( 'return window.location.href;' ) , PHP_URL_FRAGMENT ) ; PHPUnit :: assertRegExp ( '/^' . str_replace ( '\*' , '.*' , $ pattern ) . '$/u' , $ actualFragment , "Actual fragment [{$actualFragment}] does not equal expected fragment [{$fragment}]." ) ; return $ this ; } | Assert that the current URL fragment matches the given pattern . |
6,333 | public function assertFragmentBeginsWith ( $ fragment ) { $ actualFragment = ( string ) parse_url ( $ this -> driver -> executeScript ( 'return window.location.href;' ) , PHP_URL_FRAGMENT ) ; PHPUnit :: assertStringStartsWith ( $ fragment , $ actualFragment , "Actual fragment [$actualFragment] does not begin with expected fragment [$fragment]." ) ; return $ this ; } | Assert that the current URL fragment begins with given fragment . |
6,334 | public function assertFragmentIsNot ( $ fragment ) { $ actualFragment = ( string ) parse_url ( $ this -> driver -> executeScript ( 'return window.location.href;' ) , PHP_URL_FRAGMENT ) ; PHPUnit :: assertNotEquals ( $ fragment , $ actualFragment , "Fragment [{$fragment}] should not equal the actual value." ) ; return $ this ; } | Assert that the current URL fragment does not match the given fragment . |
6,335 | public function assertQueryStringHas ( $ name , $ value = null ) { $ output = $ this -> assertHasQueryStringParameter ( $ name ) ; if ( is_null ( $ value ) ) { return $ this ; } $ parsedOutputName = is_array ( $ output [ $ name ] ) ? implode ( ',' , $ output [ $ name ] ) : $ output [ $ name ] ; $ parsedValue = is_array ( $ value ) ? implode ( ',' , $ value ) : $ value ; PHPUnit :: assertEquals ( $ value , $ output [ $ name ] , "Query string parameter [{$name}] had value [{$parsedOutputName}], but expected [{$parsedValue}]." ) ; return $ this ; } | Assert that a query string parameter is present and has a given value . |
6,336 | public function assertQueryStringMissing ( $ name ) { $ parsedUrl = parse_url ( $ this -> driver -> getCurrentURL ( ) ) ; if ( ! array_key_exists ( 'query' , $ parsedUrl ) ) { PHPUnit :: assertTrue ( true ) ; return $ this ; } parse_str ( $ parsedUrl [ 'query' ] , $ output ) ; PHPUnit :: assertArrayNotHasKey ( $ name , $ output , "Found unexpected query string parameter [{$name}] in [" . $ this -> driver -> getCurrentURL ( ) . '].' ) ; return $ this ; } | Assert that the given query string parameter is missing . |
6,337 | protected function assertHasQueryStringParameter ( $ name ) { $ parsedUrl = parse_url ( $ this -> driver -> getCurrentURL ( ) ) ; PHPUnit :: assertArrayHasKey ( 'query' , $ parsedUrl , 'Did not see expected query string in [' . $ this -> driver -> getCurrentURL ( ) . '].' ) ; parse_str ( $ parsedUrl [ 'query' ] , $ output ) ; PHPUnit :: assertArrayHasKey ( $ name , $ output , "Did not see expected query string parameter [{$name}] in [" . $ this -> driver -> getCurrentURL ( ) . '].' ) ; return $ output ; } | Assert that the given query string parameter is present . |
6,338 | public function setUserAgent ( $ userAgent ) { if ( is_null ( $ userAgent ) ) { foreach ( $ this -> getUaHttpHeaders ( ) as $ altHeader ) { if ( isset ( $ this -> httpHeaders [ $ altHeader ] ) ) { $ userAgent .= $ this -> httpHeaders [ $ altHeader ] . ' ' ; } } } return $ this -> userAgent = $ userAgent ; } | Set the user agent . |
6,339 | public function isCrawler ( $ userAgent = null ) { $ agent = trim ( preg_replace ( "/{$this->compiledExclusions}/i" , '' , $ userAgent ? : $ this -> userAgent ) ) ; if ( $ agent == '' ) { return false ; } $ result = preg_match ( "/{$this->compiledRegex}/i" , $ agent , $ matches ) ; if ( $ matches ) { $ this -> matches = $ matches ; } return ( bool ) $ result ; } | Check user agent string against the regex . |
6,340 | protected function triggerCommand ( $ command , $ arguments = null ) { return $ this -> getCommandBus ( ) -> execute ( $ command , $ arguments ? : $ this -> arguments , $ this -> update ) ; } | Helper to Trigger other Commands . |
6,341 | public function row ( ) { $ property = 'keyboard' ; if ( $ this -> isInlineKeyboard ( ) ) { $ property = 'inline_keyboard' ; } $ this -> items [ $ property ] [ ] = func_get_args ( ) ; return $ this ; } | Create a new row in keyboard to add buttons . |
6,342 | protected function buildDependencyInjectedAnswer ( $ answerClass ) { if ( ! method_exists ( $ answerClass , '__construct' ) ) { return new $ answerClass ( ) ; } $ constructorReflector = new \ ReflectionMethod ( $ answerClass , '__construct' ) ; $ params = $ constructorReflector -> getParameters ( ) ; if ( empty ( $ params ) ) { return new $ answerClass ( ) ; } $ container = $ this -> telegram -> getContainer ( ) ; $ dependencies = [ ] ; foreach ( $ params as $ param ) { $ dependencies [ ] = $ container -> make ( $ param -> getClass ( ) -> name ) ; } $ classReflector = new \ ReflectionClass ( $ answerClass ) ; return $ classReflector -> newInstanceArgs ( $ dependencies ) ; } | Use PHP Reflection and Laravel Container to instantiate the answer with type hinted dependencies . |
6,343 | private function getOptions ( array $ headers , $ body , $ options , $ timeOut , $ isAsyncRequest = false , $ connectTimeOut = 10 ) { $ default_options = [ RequestOptions :: HEADERS => $ headers , RequestOptions :: BODY => $ body , RequestOptions :: TIMEOUT => $ timeOut , RequestOptions :: CONNECT_TIMEOUT => $ connectTimeOut , RequestOptions :: SYNCHRONOUS => ! $ isAsyncRequest , ] ; return array_merge ( $ default_options , $ options ) ; } | Prepares and returns request options . |
6,344 | public function getBotConfig ( $ name = null ) { $ name = $ name ? : $ this -> getDefaultBot ( ) ; $ bots = $ this -> getConfig ( 'bots' ) ; if ( ! is_array ( $ config = array_get ( $ bots , $ name ) ) && ! $ config ) { throw new InvalidArgumentException ( "Bot [$name] not configured." ) ; } $ config [ 'bot' ] = $ name ; return $ config ; } | Get the configuration for a bot . |
6,345 | public function bot ( $ name = null ) { $ name = $ name ? : $ this -> getDefaultBot ( ) ; if ( ! isset ( $ this -> bots [ $ name ] ) ) { $ this -> bots [ $ name ] = $ this -> makeBot ( $ name ) ; } return $ this -> bots [ $ name ] ; } | Get a bot instance . |
6,346 | public function reconnect ( $ name = null ) { $ name = $ name ? : $ this -> getDefaultBot ( ) ; $ this -> disconnect ( $ name ) ; return $ this -> bot ( $ name ) ; } | Reconnect to the given bot . |
6,347 | public function disconnect ( $ name = null ) { $ name = $ name ? : $ this -> getDefaultBot ( ) ; unset ( $ this -> bots [ $ name ] ) ; } | Disconnect from the given bot . |
6,348 | protected function parseBotCommands ( array $ commands ) { $ globalCommands = $ this -> getConfig ( 'commands' , [ ] ) ; $ parsedCommands = $ this -> parseCommands ( $ commands ) ; return $ this -> deduplicateArray ( array_merge ( $ globalCommands , $ parsedCommands ) ) ; } | Builds the list of commands for the given commands array . |
6,349 | protected function parseCommands ( array $ commands ) { if ( ! is_array ( $ commands ) ) { return $ commands ; } $ commandGroups = $ this -> getConfig ( 'command_groups' ) ; $ sharedCommands = $ this -> getConfig ( 'shared_commands' ) ; $ results = [ ] ; foreach ( $ commands as $ command ) { if ( isset ( $ commandGroups [ $ command ] ) ) { $ results = array_merge ( $ results , $ this -> parseCommands ( $ commandGroups [ $ command ] ) ) ; continue ; } if ( isset ( $ sharedCommands [ $ command ] ) ) { $ command = $ sharedCommands [ $ command ] ; } if ( ! in_array ( $ command , $ results ) ) { $ results [ ] = $ command ; } } return $ results ; } | Parse an array of commands and build a list . |
6,350 | public function sendSticker ( array $ params ) { if ( is_file ( $ params [ 'sticker' ] ) && ( pathinfo ( $ params [ 'sticker' ] , PATHINFO_EXTENSION ) !== 'webp' ) ) { throw new TelegramSDKException ( 'Invalid Sticker Provided. Supported Format: Webp' ) ; } $ response = $ this -> uploadFile ( 'sendSticker' , $ params ) ; return new Message ( $ response -> getDecodedBody ( ) ) ; } | Send . webp stickers . |
6,351 | public function sendChatAction ( array $ params ) { $ validActions = [ 'typing' , 'upload_photo' , 'record_video' , 'upload_video' , 'record_audio' , 'upload_audio' , 'upload_document' , 'find_location' , ] ; if ( isset ( $ params [ 'action' ] ) && in_array ( $ params [ 'action' ] , $ validActions ) ) { $ this -> post ( 'sendChatAction' , $ params ) ; return true ; } throw new TelegramSDKException ( 'Invalid Action! Accepted value: ' . implode ( ', ' , $ validActions ) ) ; } | Broadcast a Chat Action . |
6,352 | public function getChatAdministrators ( array $ params ) { $ response = $ this -> post ( 'getChatAdministrators' , $ params ) ; return collect ( $ response -> getResult ( ) ) -> map ( function ( $ admin ) { return new ChatMember ( $ admin ) ; } ) -> all ( ) ; } | Get a list of administrators in a chat . |
6,353 | public function answerInlineQuery ( array $ params = [ ] ) { if ( is_array ( $ params [ 'results' ] ) ) { $ params [ 'results' ] = json_encode ( $ params [ 'results' ] ) ; } $ this -> post ( 'answerInlineQuery' , $ params ) ; return true ; } | Use this method to send answers to an inline query . |
6,354 | public function setWebhook ( array $ params ) { if ( filter_var ( $ params [ 'url' ] , FILTER_VALIDATE_URL ) === false ) { throw new TelegramSDKException ( 'Invalid URL Provided' ) ; } if ( parse_url ( $ params [ 'url' ] , PHP_URL_SCHEME ) !== 'https' ) { throw new TelegramSDKException ( 'Invalid URL, should be a HTTPS url.' ) ; } return $ this -> uploadFile ( 'setWebhook' , $ params ) ; } | Set a Webhook to receive incoming updates via an outgoing webhook . |
6,355 | public function getWebhookUpdate ( $ shouldEmitEvent = true ) { $ body = json_decode ( file_get_contents ( 'php://input' ) , true ) ; $ update = new Update ( $ body ) ; if ( $ shouldEmitEvent ) { $ this -> emitEvent ( new UpdateWasReceived ( $ update , $ this ) ) ; } return $ update ; } | Returns a webhook update sent by Telegram . Works only if you set a webhook . |
6,356 | public function commandsHandler ( $ webhook = false , array $ params = [ ] ) { if ( $ webhook ) { $ update = $ this -> getWebhookUpdate ( ) ; $ this -> processCommand ( $ update ) ; return $ update ; } $ updates = $ this -> getUpdates ( $ params ) ; $ highestId = - 1 ; foreach ( $ updates as $ update ) { $ highestId = $ update -> getUpdateId ( ) ; $ this -> processCommand ( $ update ) ; } if ( $ highestId != - 1 ) { $ params = [ ] ; $ params [ 'offset' ] = $ highestId + 1 ; $ params [ 'limit' ] = 1 ; $ this -> markUpdateAsRead ( $ params ) ; } return $ updates ; } | Processes Inbound Commands . |
6,357 | public function triggerCommand ( $ name , Update $ update ) { return $ this -> getCommandBus ( ) -> execute ( $ name , $ update -> getMessage ( ) -> getText ( ) , $ update ) ; } | Helper to Trigger Commands . |
6,358 | protected function get ( $ endpoint , $ params = [ ] ) { if ( array_key_exists ( 'reply_markup' , $ params ) ) { $ params [ 'reply_markup' ] = ( string ) $ params [ 'reply_markup' ] ; } return $ this -> sendRequest ( 'GET' , $ endpoint , $ params ) ; } | Sends a GET request to Telegram Bot API and returns the result . |
6,359 | protected function post ( $ endpoint , array $ params = [ ] , $ fileUpload = false ) { if ( $ fileUpload ) { $ params = [ 'multipart' => $ params ] ; } else { if ( array_key_exists ( 'reply_markup' , $ params ) ) { $ params [ 'reply_markup' ] = ( string ) $ params [ 'reply_markup' ] ; } $ params = [ 'form_params' => $ params ] ; } return $ this -> sendRequest ( 'POST' , $ endpoint , $ params ) ; } | Sends a POST request to Telegram Bot API and returns the result . |
6,360 | protected function sendRequest ( $ method , $ endpoint , array $ params = [ ] ) { $ request = $ this -> request ( $ method , $ endpoint , $ params ) ; return $ this -> lastResponse = $ this -> client -> sendRequest ( $ request ) ; } | Sends a request to Telegram Bot API and returns the result . |
6,361 | protected function request ( $ method , $ endpoint , array $ params = [ ] ) { return new TelegramRequest ( $ this -> getAccessToken ( ) , $ method , $ endpoint , $ params , $ this -> isAsyncRequest ( ) , $ this -> getTimeOut ( ) , $ this -> getConnectTimeOut ( ) ) ; } | Instantiates a new TelegramRequest entity . |
6,362 | protected function isValidFileOrUrl ( $ name , $ contents ) { if ( $ name == 'url' ) { return false ; } if ( $ name == 'certificate' ) { return true ; } if ( is_readable ( $ contents ) ) { return true ; } return filter_var ( $ contents , FILTER_VALIDATE_URL ) ; } | Determines if the string passed to be uploaded is a valid file on the local file system or a valid remote URL . |
6,363 | protected function wordToEmojiReplace ( $ line , $ replace , $ delimiter ) { foreach ( $ replace as $ key => $ value ) { $ line = str_replace ( $ delimiter . $ key . $ delimiter , $ value , $ line ) ; } return $ line ; } | Finds words enclosed by the delimiter and converts them to the appropriate emoji character . |
6,364 | protected function emojiToWordReplace ( $ line , $ replace , $ delimiter ) { foreach ( $ replace as $ key => $ value ) { $ line = str_replace ( $ key , $ delimiter . $ value . $ delimiter , $ line ) ; } return $ line ; } | Finds emojis and replaces them with text enclosed by the delimiter |
6,365 | protected function getEmojiMap ( ) { if ( ! isset ( $ this -> emojiMapFile ) ) { $ this -> emojiMapFile = realpath ( __DIR__ . self :: DEFAULT_EMOJI_MAP_FILE ) ; } if ( ! file_exists ( $ this -> emojiMapFile ) ) { throw new TelegramEmojiMapFileNotFoundException ( ) ; } return json_decode ( file_get_contents ( $ this -> emojiMapFile ) , true ) ; } | Get Emoji Map Array . |
6,366 | protected function setupEmojiMaps ( ) { $ this -> emojiMap = $ this -> getEmojiMap ( ) ; $ this -> wordMap = array_flip ( $ this -> emojiMap ) ; } | Setup Emoji Maps . |
6,367 | public function decodeBody ( ) { $ this -> decodedBody = json_decode ( $ this -> body , true ) ; if ( $ this -> decodedBody === null ) { $ this -> decodedBody = [ ] ; parse_str ( $ this -> body , $ this -> decodedBody ) ; } if ( ! is_array ( $ this -> decodedBody ) ) { $ this -> decodedBody = [ ] ; } if ( $ this -> isError ( ) ) { $ this -> makeException ( ) ; } } | Converts raw API response to proper decoded response . |
6,368 | public function isType ( $ type ) { if ( $ this -> has ( strtolower ( $ type ) ) ) { return true ; } return $ this -> detectType ( ) === $ type ; } | Determine if the message is of given type |
6,369 | public static function create ( TelegramResponse $ response ) { $ data = $ response -> getDecodedBody ( ) ; $ code = null ; $ message = null ; if ( isset ( $ data [ 'ok' ] , $ data [ 'error_code' ] ) && $ data [ 'ok' ] === false ) { $ code = $ data [ 'error_code' ] ; $ message = isset ( $ data [ 'description' ] ) ? $ data [ 'description' ] : 'Unknown error from API.' ; } throw new static ( $ response , new TelegramOtherException ( $ message , $ code ) ) ; } | A factory for creating the appropriate exception based on the response from Telegram . |
6,370 | public function open ( ) { if ( is_resource ( $ this -> path ) ) { return $ this -> path ; } if ( ! $ this -> isRemoteFile ( ) && ! is_readable ( $ this -> path ) ) { throw new TelegramSDKException ( 'Failed to create InputFile entity. Unable to read resource: ' . $ this -> path . '.' ) ; } return Psr7 \ try_fopen ( $ this -> path , 'r' ) ; } | Opens file stream . |
6,371 | public function prepareRequest ( TelegramRequest $ request ) { $ url = $ this -> getBaseBotUrl ( ) . $ request -> getAccessToken ( ) . '/' . $ request -> getEndpoint ( ) ; return [ $ url , $ request -> getMethod ( ) , $ request -> getHeaders ( ) , $ request -> isAsyncRequest ( ) , ] ; } | Prepares the API request for sending to the client handler . |
6,372 | public function sendRequest ( TelegramRequest $ request ) { list ( $ url , $ method , $ headers , $ isAsyncRequest ) = $ this -> prepareRequest ( $ request ) ; $ timeOut = $ request -> getTimeOut ( ) ; $ connectTimeOut = $ request -> getConnectTimeOut ( ) ; $ options = $ this -> getOptions ( $ request , $ method ) ; $ rawResponse = $ this -> httpClientHandler -> send ( $ url , $ method , $ headers , $ options , $ timeOut , $ isAsyncRequest , $ connectTimeOut ) ; $ returnResponse = $ this -> getResponse ( $ request , $ rawResponse ) ; if ( $ returnResponse -> isError ( ) ) { throw $ returnResponse -> getThrownException ( ) ; } return $ returnResponse ; } | Send an API request and process the result . |
6,373 | public static function run ( array & $ config ) { self :: $ config = $ config ; self :: startTemplateEngine ( $ config ) ; if ( isset ( $ config [ 'sessionName' ] ) ) USession :: start ( $ config [ 'sessionName' ] ) ; self :: forward ( $ _GET [ 'c' ] ) ; } | Handles the request |
6,374 | public static function forward ( $ url , $ initialize = true , $ finalize = true ) { $ u = self :: parseUrl ( $ url ) ; if ( is_array ( Router :: getRoutes ( ) ) && ( $ ru = Router :: getRoute ( $ url ) ) !== false ) { if ( \ is_array ( $ ru ) ) { if ( is_callable ( $ ru [ 0 ] ) ) { self :: runCallable ( $ ru ) ; } else { self :: _preRunAction ( $ ru , $ initialize , $ finalize ) ; } } else { echo $ ru ; } } else { self :: setCtrlNS ( ) ; $ u [ 0 ] = self :: $ ctrlNS . $ u [ 0 ] ; self :: _preRunAction ( $ u , $ initialize , $ finalize ) ; } } | Forwards to url |
6,375 | public static function runAction ( array & $ u , $ initialize = true , $ finalize = true ) { $ ctrl = $ u [ 0 ] ; self :: $ controller = $ ctrl ; self :: $ action = "index" ; self :: $ actionParams = [ ] ; if ( \ sizeof ( $ u ) > 1 ) self :: $ action = $ u [ 1 ] ; if ( \ sizeof ( $ u ) > 2 ) self :: $ actionParams = array_slice ( $ u , 2 ) ; $ controller = new $ ctrl ( ) ; if ( ! $ controller instanceof Controller ) { print "`{$u[0]}` isn't a controller instance.`<br/>" ; return ; } self :: injectDependences ( $ controller ) ; if ( ! $ controller -> isValid ( self :: $ action ) ) { $ controller -> onInvalidControl ( ) ; } else { if ( $ initialize ) $ controller -> initialize ( ) ; self :: callController ( $ controller , $ u ) ; if ( $ finalize ) $ controller -> finalize ( ) ; } } | Runs an action on a controller |
6,376 | public static function runCallable ( array & $ u ) { self :: $ actionParams = [ ] ; if ( \ sizeof ( $ u ) > 1 ) { self :: $ actionParams = array_slice ( $ u , 1 ) ; } if ( isset ( self :: $ config [ 'di' ] ) ) { $ di = self :: $ config [ 'di' ] ; if ( \ is_array ( $ di ) ) { self :: $ actionParams = array_merge ( self :: $ actionParams , $ di ) ; } } call_user_func_array ( $ u [ 0 ] , self :: $ actionParams ) ; } | Runs a callback |
6,377 | public static function runAsString ( array & $ u , $ initialize = true , $ finalize = true ) { \ ob_start ( ) ; self :: runAction ( $ u , $ initialize , $ finalize ) ; return \ ob_get_clean ( ) ; } | Runs an action on a controller and returns a string |
6,378 | public function noAccess ( $ urlParts ) { if ( ! is_array ( $ urlParts ) ) { $ urlParts = explode ( "." , $ urlParts ) ; } USession :: set ( "urlParts" , $ urlParts ) ; $ fMessage = $ this -> _noAccessMsg ; $ this -> noAccessMessage ( $ fMessage ) ; $ message = $ this -> fMessage ( $ fMessage -> parseContent ( [ "url" => implode ( "/" , $ urlParts ) ] ) ) ; $ this -> authLoadView ( $ this -> _getFiles ( ) -> getViewNoAccess ( ) , [ "_message" => $ message , "authURL" => $ this -> getBaseUrl ( ) , "bodySelector" => $ this -> _getBodySelector ( ) , "_loginCaption" => $ this -> _loginCaption ] ) ; } | Action called when the user does not have access rights to a requested resource |
6,379 | public function connect ( ) { if ( URequest :: isPost ( ) ) { if ( $ connected = $ this -> _connect ( ) ) { if ( isset ( $ _POST [ "ck-remember" ] ) ) { $ this -> rememberMe ( $ connected ) ; } if ( USession :: exists ( $ this -> _attemptsSessionKey ) ) { USession :: delete ( $ this -> _attemptsSessionKey ) ; } $ this -> onConnect ( $ connected ) ; } else { $ this -> onBadCreditentials ( ) ; } } } | Override to implement the complete connection procedure |
6,380 | public function badLogin ( ) { $ fMessage = new FlashMessage ( "Invalid creditentials!" , "Connection problem" , "warning" , "warning circle" ) ; $ this -> badLoginMessage ( $ fMessage ) ; $ attemptsMessage = "" ; if ( ( $ nbAttempsMax = $ this -> attemptsNumber ( ) ) !== null ) { $ nb = USession :: getTmp ( $ this -> _attemptsSessionKey , $ nbAttempsMax ) ; $ nb -- ; if ( $ nb < 0 ) $ nb = 0 ; if ( $ nb == 0 ) { $ fAttemptsNumberMessage = $ this -> noAttempts ( ) ; } else { $ fAttemptsNumberMessage = new FlashMessage ( "<i class='ui warning icon'></i> You still have {_attemptsCount} attempts to log in." , null , "bottom attached warning" , "" ) ; } USession :: setTmp ( $ this -> _attemptsSessionKey , $ nb , $ this -> attemptsTimeout ( ) ) ; $ this -> attemptsNumberMessage ( $ fAttemptsNumberMessage , $ nb ) ; $ fAttemptsNumberMessage -> parseContent ( [ "_attemptsCount" => $ nb , "_timer" => "<span id='timer'></span>" ] ) ; $ attemptsMessage = $ this -> fMessage ( $ fAttemptsNumberMessage , "timeout-message" ) ; $ fMessage -> addType ( "attached" ) ; } $ message = $ this -> fMessage ( $ fMessage , "bad-login" ) . $ attemptsMessage ; $ this -> authLoadView ( $ this -> _getFiles ( ) -> getViewNoAccess ( ) , [ "_message" => $ message , "authURL" => $ this -> getBaseUrl ( ) , "bodySelector" => $ this -> _getBodySelector ( ) , "_loginCaption" => $ this -> _loginCaption ] ) ; } | Default Action for invalid creditentials |
6,381 | public function terminate ( ) { USession :: terminate ( ) ; $ fMessage = new FlashMessage ( "You have been properly disconnected!" , "Logout" , "success" , "checkmark" ) ; $ this -> terminateMessage ( $ fMessage ) ; $ message = $ this -> fMessage ( $ fMessage ) ; $ this -> authLoadView ( $ this -> _getFiles ( ) -> getViewNoAccess ( ) , [ "_message" => $ message , "authURL" => $ this -> getBaseUrl ( ) , "bodySelector" => $ this -> _getBodySelector ( ) , "_loginCaption" => $ this -> _loginCaption ] ) ; } | Logout action Terminate the session and display a logout message |
6,382 | public function info ( $ force = null ) { if ( isset ( $ force ) ) { $ displayInfoAsString = ( $ force === true ) ? true : false ; } else { $ displayInfoAsString = $ this -> _displayInfoAsString ( ) ; } return $ this -> loadView ( $ this -> _getFiles ( ) -> getViewInfo ( ) , [ "connected" => USession :: get ( $ this -> _getUserSessionKey ( ) ) , "authURL" => $ this -> getBaseUrl ( ) , "bodySelector" => $ this -> _getBodySelector ( ) ] , $ displayInfoAsString ) ; } | Action displaying the logged user information if _displayInfoAsString returns true use _infoUser var in views to display user info |
6,383 | public function _autoConnect ( ) { $ cookie = $ this -> getCookieUser ( ) ; if ( isset ( $ cookie ) ) { $ user = $ this -> fromCookie ( $ cookie ) ; if ( isset ( $ user ) ) { USession :: set ( $ this -> _getUserSessionKey ( ) , $ user ) ; } } } | Auto connect the user |
6,384 | public static function start ( ) { $ transformers = [ ] ; if ( CacheManager :: $ cache -> exists ( self :: $ key ) ) { $ transformers = CacheManager :: $ cache -> fetch ( self :: $ key ) ; } self :: $ transformers = array_merge ( self :: $ transformers , $ transformers ) ; } | Do not use at runtime ! |
6,385 | public static function start ( & $ config ) { self :: $ cacheDirectory = self :: initialGetCacheDirectory ( $ config ) ; $ cacheDirectory = \ ROOT . \ DS . self :: $ cacheDirectory ; Annotations :: $ config [ 'cache' ] = new AnnotationCache ( $ cacheDirectory . '/annotations' ) ; self :: register ( Annotations :: getManager ( ) ) ; self :: getCacheInstance ( $ config , $ cacheDirectory , ".cache" ) ; } | Starts the cache in dev mode for generating the other caches Do not use in production |
6,386 | public static function startProd ( & $ config ) { self :: $ cacheDirectory = self :: initialGetCacheDirectory ( $ config ) ; $ cacheDirectory = \ ROOT . \ DS . self :: $ cacheDirectory ; self :: getCacheInstance ( $ config , $ cacheDirectory , ".cache" ) ; } | Starts the cache for production |
6,387 | public static function checkCache ( & $ config , $ silent = false ) { $ dirs = self :: getCacheDirectories ( $ config , $ silent ) ; foreach ( $ dirs as $ dir ) { self :: safeMkdir ( $ dir ) ; } return $ dirs ; } | Checks the existence of cache subdirectories and returns an array of cache folders |
6,388 | public static function clearCache ( & $ config , $ type = "all" ) { $ cacheDirectories = self :: checkCache ( $ config ) ; $ cacheDirs = [ "annotations" , "controllers" , "models" , "queries" , "views" , "contents" ] ; foreach ( $ cacheDirs as $ typeRef ) { self :: _clearCache ( $ cacheDirectories , $ type , $ typeRef ) ; } } | Deletes files from a cache type |
6,389 | public function getModifiedFiles ( ) { try { return $ this -> extractFromCommand ( 'git diff --name-status HEAD' , function ( $ array ) { $ array = trim ( preg_replace ( '!\s+!' , ' ' , $ array ) ) ; return explode ( ' ' , $ array ) ; } ) ; } catch ( \ Cz \ Git \ GitException $ e ) { return [ ] ; } } | Returns list of modified files in repo . |
6,390 | public function getRemoteUrl ( ) { try { $ values = $ this -> extractFromCommand ( 'git config --get remote.origin.url' , function ( $ str ) { return trim ( $ str ) ; } ) ; if ( isset ( $ values ) ) { return implode ( " " , $ values ) ; } } catch ( \ Cz \ Git \ GitException $ e ) { return "" ; } return "" ; } | Returns the remote URL |
6,391 | public function _get ( $ condition = "1=1" , $ include = false , $ useCache = false ) { try { $ condition = $ this -> getCondition ( $ condition ) ; $ include = $ this -> getInclude ( $ include ) ; $ useCache = UString :: isBooleanTrue ( $ useCache ) ; $ datas = DAO :: getAll ( $ this -> model , $ condition , $ include , null , $ useCache ) ; echo $ this -> _getResponseFormatter ( ) -> get ( $ datas ) ; } catch ( \ Exception $ e ) { $ this -> _setResponseCode ( 500 ) ; echo $ this -> _getResponseFormatter ( ) -> formatException ( $ e ) ; } } | Returns a list of objects from the server . |
6,392 | public static function getUrl ( $ resource , $ absolute = false ) { if ( strpos ( $ resource , '//' ) !== false ) { return $ resource ; } if ( $ absolute ) { return self :: $ siteURL . self :: ASSETS_FOLDER . $ resource ; } return ltrim ( self :: ASSETS_FOLDER , '/' ) . $ resource ; } | Returns the absolute or relative url to the resource . |
6,393 | public static function getThemeUrl ( $ theme , $ resource , $ absolute = false ) { if ( $ absolute ) { return self :: $ siteURL . self :: ASSETS_FOLDER . $ theme . '/' . $ resource ; } return ltrim ( self :: ASSETS_FOLDER , '/' ) . $ theme . '/' . $ resource ; } | Returns the absolute or relative url for a resource in a theme . |
6,394 | public static function js ( $ resource , $ attributes = [ ] , $ absolute = false ) { return self :: script ( self :: getUrl ( $ resource , $ absolute ) , $ attributes ) ; } | Returns the script inclusion for a javascript resource . |
6,395 | public static function css ( $ resource , $ attributes = [ ] , $ absolute = false ) { return self :: stylesheet ( self :: getUrl ( $ resource , $ absolute ) , $ attributes ) ; } | Returns the css inclusion for a stylesheet resource . |
6,396 | public function connect ( ) { if ( ! isset ( $ this -> apiTokens ) ) { $ this -> apiTokens = $ this -> _loadApiTokens ( ) ; } $ token = $ this -> apiTokens -> addToken ( ) ; $ this -> _addHeaderToken ( $ token ) ; return [ "access_token" => $ token , "token_type" => "Bearer" , "expires_in" => $ this -> apiTokens -> getDuration ( ) ] ; } | Establishes the connection with the server returns an added token in the Authorization header of the request |
6,397 | public function redirectToRoute ( $ routeName , $ parameters = [ ] , $ initialize = false , $ finalize = false ) { $ path = Router :: getRouteByName ( $ routeName , $ parameters ) ; if ( $ path !== false ) { $ route = Router :: getRoute ( $ path , false ) ; if ( $ route !== false ) { $ this -> forward ( $ route [ 0 ] , $ route [ 1 ] , \ array_slice ( $ route , 2 ) , $ initialize , $ finalize ) ; } else { throw new RouterException ( "Route {$routeName} not found" , 404 ) ; } } else { throw new RouterException ( "Route {$routeName} not found" , 404 ) ; } } | Redirect to a route by its name |
6,398 | public function connect ( ) { try { $ this -> _connect ( ) ; return true ; } catch ( \ PDOException $ e ) { throw new DBException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e -> getPrevious ( ) ) ; } } | Creates the PDO instance and realize a safe connection . |
6,399 | public function get ( $ condition = "1=1" , $ included = false , $ useCache = false ) { $ this -> _get ( $ condition , $ included , $ useCache ) ; } | Returns a list of objects from the server |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.