idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
18,300 | public function fetchPermanentVideo ( $ mediaID , $ into = null ) { $ stream = $ this -> doPermanentFetchToStream ( $ mediaID , null ) ; $ json = json_decode ( stream_get_contents ( $ stream ) ) ; $ body = $ this -> client -> send ( new Request ( 'GET' , $ json -> down_url ) , [ RequestOptions :: SINK => $ this -> crea... | Downloads the given video into the specified file . |
18,301 | public function storePermanentNews ( News $ news ) { $ json = $ this -> storeNews ( 'https://api.weixin.qq.com/cgi-bin/material/add_news' , $ news ) ; return new Uploaded \ News ( $ json -> media_id ) ; } | Upload a news item for permanent storage . |
18,302 | public function storeTemporaryNews ( News $ news ) { $ json = $ this -> storeNews ( 'https://api.weixin.qq.com/cgi-bin/media/uploadnews' , $ news ) ; return ( new Uploaded \ News ( $ json -> media_id ) ) -> withExpiresDate ( $ this -> createExpiryDate ( $ json -> created_at ) ) ; } | Upload a news item for temporary storage . It will expire after 3 days but we ll set the expiry to 2 days to be safe when it comes to time zones . |
18,303 | public function storePermanentVideo ( Video $ video ) { if ( $ video -> getTitle ( ) === null || $ video -> getDescription ( ) === null ) { throw new InvalidArgumentException ( "permanent videos must have a title and description" ) ; } return $ this -> storeVideo ( true , $ video ) ; } | Uploads a video for permanent storage to the WeChat servers . The video supplied must have had the title and description populated . |
18,304 | public function storeTemporaryVideo ( Video $ video ) { return $ this -> storeVideo ( false , $ video ) -> withExpiresDate ( new \ DateTime ( '@' . ( time ( ) + 172800 ) ) ) ; } | Uploads a video item for temporary storage on the WeChat servers . |
18,305 | public function storePermanentImage ( Image $ image ) { $ json = $ this -> storeGenericMedia ( MediaType :: IMAGE , true , $ image ) ; return ( new Uploaded \ Image ( $ json -> media_id ) ) -> withURL ( $ json -> url ) ; } | Uploads an image for permanent storage on the WeChat servers . |
18,306 | public function storeTemporaryImage ( Image $ image ) { $ json = $ this -> storeGenericMedia ( MediaType :: IMAGE , false , $ image ) ; return ( new Uploaded \ Image ( $ json -> media_id ) ) -> withExpiresDate ( $ this -> createExpiryDate ( $ json -> created_at ) ) ; } | Uploads an image for temporary storage on the WeChat servers . |
18,307 | public function storePermanentThumbnail ( Thumbnail $ thumbnail ) { $ json = $ this -> storeGenericMedia ( MediaType :: THUMBNAIL , true , $ thumbnail ) ; return new Uploaded \ Thumbnail ( $ json -> media_id ) ; } | Uploads a thumbnail for permanent storage on the WeChat servers . |
18,308 | public function storeTemporaryThumbnail ( Thumbnail $ thumbnail ) { $ json = $ this -> storeGenericMedia ( MediaType :: THUMBNAIL , false , $ thumbnail ) ; return ( new Uploaded \ Thumbnail ( $ json -> thumb_media_id ) ) -> withExpiresDate ( $ this -> createExpiryDate ( $ json -> created_at ) ) ; } | Uploads a thumbnail for temporary storage on the WeChat servers . |
18,309 | public function storePermanentAudio ( Audio $ audio ) { $ json = $ this -> storeGenericMedia ( MediaType :: AUDIO , true , $ audio ) ; return new Uploaded \ Audio ( $ json -> media_id ) ; } | Uploads an audio item for permanent storage on the WeChat servers . |
18,310 | public function storeTemporaryAudio ( Audio $ audio ) { $ json = $ this -> storeGenericMedia ( MediaType :: AUDIO , false , $ audio ) ; return ( new Uploaded \ Audio ( $ json -> media_id ) ) -> withExpiresDate ( $ this -> createExpiryDate ( $ json -> created_at ) ) ; } | Uploads an audio item for temporary storage on the WeChat servers . |
18,311 | private function expandNews ( array $ rawNewsItems , Paginated \ News $ news ) { foreach ( $ rawNewsItems as $ rawNewsItem ) { $ newsItem = new Downloaded \ NewsItem ( $ rawNewsItem -> title , $ rawNewsItem -> content , $ rawNewsItem -> thumb_media_id ) ; if ( strlen ( $ rawNewsItem -> author ) > 0 ) { $ newsItem = $ n... | Expands the given news media with its items into an object . |
18,312 | public function paginateImages ( $ offset = 0 , $ count = 20 ) { $ json = $ this -> paginate ( MediaType :: IMAGE , $ offset , $ count ) ; $ resultSet = [ ] ; foreach ( $ json -> item as $ item ) { $ image = new Paginated \ Image ( $ item -> media_id , $ item -> name , $ item -> update_time ) ; if ( isset ( $ item -> u... | Paginates through images stored on the WeChat servers . |
18,313 | public function paginateVideos ( $ offset = 0 , $ count = 20 ) { $ json = $ this -> paginate ( MediaType :: VIDEO , $ offset , $ count ) ; $ resultSet = [ ] ; foreach ( $ json -> item as $ item ) { $ resultSet [ ] = new Paginated \ Video ( $ item -> media_id , $ item -> update_time ) ; } return new Paginated \ VideoRes... | Paginates through videos stored on the WeChat servers . |
18,314 | public function paginateAudio ( $ offset = 0 , $ count = 20 ) { $ json = $ this -> paginate ( MediaType :: AUDIO , $ offset , $ count ) ; $ resultSet = [ ] ; foreach ( $ json -> item as $ item ) { $ resultSet = new Paginated \ Audio ( $ item -> media_id , $ item -> update_time ) ; } return new Paginated \ AudioResultSe... | Paginates through audio items stored on the WeChat servers . |
18,315 | public function paginateNews ( $ offset = 0 , $ count = 20 ) { $ json = $ this -> paginate ( MediaType :: ARTICLE , $ offset , $ count ) ; $ resultSet = [ ] ; foreach ( $ json -> item as $ item ) { $ resultSet [ ] = $ this -> expandNews ( $ item -> content -> news_item , new Paginated \ News ( $ item -> media_id , $ it... | Paginates through news items stored on the WeChat servers . |
18,316 | private function paginate ( $ type , $ offset , $ limit ) { if ( $ limit < 1 ) { $ limit = 1 ; } elseif ( $ limit > 20 ) { $ limit = 20 ; } $ json = json_decode ( $ this -> client -> send ( new Request ( 'POST' , 'https://api.weixin.qq.com/cgi-bin/material/batchget_material' , [ ] , json_encode ( [ 'type' => $ type , '... | Performs the actual pagination request for the given item type . |
18,317 | private function doPermanentFetchToStream ( $ mediaID , $ into ) { $ body = $ this -> client -> send ( new Request ( 'POST' , 'https://api.weixin.qq.com/cgi-bin/material/get_material' , [ ] , json_encode ( [ 'media_id' => $ mediaID , ] ) ) , [ RequestOptions :: SINK => $ this -> createWritableStream ( $ into ) , ] ) ->... | Downloads the generic permanent media item into the given destination . |
18,318 | private function storeNews ( $ endpoint , News $ news ) { $ jsonBody = [ 'articles' => [ ] ] ; foreach ( $ news -> getItems ( ) as $ newsArticle ) { $ jsonArticle = [ 'title' => $ newsArticle -> getTitle ( ) , 'content' => $ newsArticle -> getContent ( ) , 'thumb_media_id' => $ newsArticle -> getThumbnailMediaID ( ) , ... | Handles the uploading of a news item to the WeChat servers . |
18,319 | private function doUpload ( $ endpoint , $ type , $ body ) { return json_decode ( $ this -> client -> send ( new Request ( 'POST' , Uri :: withQueryValue ( new Uri ( $ endpoint ) , 'type' , $ type ) , [ ] , $ body ) ) -> getBody ( ) ) ; } | Uploads a simple string body to the WeChat servers . |
18,320 | private function doMultipartUpload ( $ endpoint , $ type , $ stream , array $ extra = [ ] ) { return json_decode ( $ this -> client -> send ( new Request ( 'POST' , Uri :: withQueryValue ( new Uri ( $ endpoint ) , 'type' , $ type ) , [ ] , new MultipartStream ( array_merge ( [ [ 'name' => 'media' , 'contents' => $ stre... | Performs a multipart upload to the WeChat API . Additional multipart fields can be added in if required . |
18,321 | public function withAccessToken ( AccessToken $ token ) { $ config = $ this -> getConfig ( ) ; $ this -> configureHandlers ( $ config [ 'handler' ] ) ; $ config [ 'wechat.accessToken' ] = $ token ; $ config [ 'wechat.developerMode' ] = $ this -> developerMode ; return new static ( $ config ) ; } | Sets the access token to be used and returns the cloned client with the token being used . |
18,322 | public function pushNote ( $ title , $ body ) { self :: checkPushable ( ) ; $ data = [ ] ; $ data [ $ this -> recipientType ] = $ this -> recipient ; $ data [ 'type' ] = 'note' ; $ data [ 'title' ] = $ title ; $ data [ 'body' ] = $ body ; return new Push ( Connection :: sendCurlRequest ( Connection :: URL_PUSHES , "POS... | Push a note . |
18,323 | public function pushFile ( $ filePath , $ mimeType = null , $ title = null , $ body = null , $ altFileName = null ) { self :: checkPushable ( ) ; $ fullFilePath = realpath ( $ filePath ) ; if ( ! is_readable ( $ fullFilePath ) ) { throw new Exceptions \ NotFoundException ( 'File does not exist or is unreadable.' ) ; } ... | Push a file . |
18,324 | public function createPermanentCode ( $ value ) { $ str = is_string ( $ value ) ; $ args = $ this -> createCode ( [ 'action_name' => $ str ? 'QR_LIMIT_STR_SCENE' : 'QR_LIMIT_SCENE' , 'action_info' => [ 'scene' => [ ( $ str ? 'scene_str' : 'scene_id' ) => $ value , ] , ] , ] ) ; return new Code \ Permanent ( $ args [ 0 ... | Creates and returns an instance of a new permanent QR code . This code can be used to download the code contents . |
18,325 | private function createCode ( array $ body ) { $ json = json_decode ( $ this -> client -> send ( new Request ( 'POST' , 'https://api.weixin.qq.com/cgi-bin/qrcode/create' , [ ] , json_encode ( $ body ) ) ) -> getBody ( ) ) ; if ( in_array ( $ body [ 'action_name' ] , [ 'QR_LIMIT_SCENE' , 'QR_LIMIT_STR_SCENE' ] ) ) { if ... | Method responsible for the actual interaction with the WeChat API and returns the arguments used for creating a GroupService code . |
18,326 | public function withURL ( $ url ) { if ( filter_var ( $ url , FILTER_VALIDATE_URL ) === false ) { throw new InvalidArgumentException ( "invalid url `{$url}` given for news item" ) ; } $ new = clone $ this ; $ new -> url = $ url ; return $ new ; } | Populates the URL to be used when clicking on View more in an article . |
18,327 | public function shortenAll ( array $ urls , callable $ callback = null ) { $ urls = array_values ( $ urls ) ; $ shortened = [ ] ; $ requests = function ( $ urls ) { foreach ( $ urls as $ url ) { yield new Request ( 'POST' , 'https://api.weixin.qq.com/cgi-bin/shorturl' , [ ] , json_encode ( [ 'action' => 'long2short' , ... | Shortens all the given URLs . |
18,328 | public function shorten ( $ url ) { $ shortened = null ; $ this -> shortenAll ( [ $ url ] , function ( $ error , $ short , $ long ) use ( & $ shortened ) { $ shortened = $ short ; } ) ; return $ shortened ; } | Returns a shorter representation of the given URL . Similar to URL shortening services like bit . ly etc . |
18,329 | public function expandAll ( array $ urls , callable $ callback = null ) { $ urls = array_values ( $ urls ) ; $ expanded = [ ] ; $ requests = function ( $ urls ) { foreach ( $ urls as $ url ) { yield new Request ( 'HEAD' , $ url ) ; } } ; if ( ! is_callable ( $ callback ) ) { $ expanded = array_combine ( $ urls , array_... | Expands the given URLs into their long version . This is done dirtily by issuing a HEAD request to the given short URL and using the contents of the Location header . |
18,330 | public function expand ( $ url ) { $ expanded = null ; $ this -> expandAll ( [ $ url ] , function ( $ error , $ long ) use ( & $ expanded ) { $ expanded = $ long ; } ) ; return $ expanded ; } | Expands the given URL and will return the long version of the provided shortened URL . This is done by issuing a HEAD request on the given URL . |
18,331 | public function getAllGroups ( ) { $ request = new Request ( "GET" , "https://api.weixin.qq.com/cgi-bin/groups/get" ) ; $ response = $ this -> client -> send ( $ request ) ; $ json = json_decode ( $ response -> getBody ( ) ) ; $ groups = [ ] ; if ( isset ( $ json -> groups ) ) { foreach ( $ json -> groups as $ group ) ... | Retrieves a list of all the groups that have been created in this OA . |
18,332 | public function getGroup ( $ groupID ) { $ groups = $ this -> getAllGroups ( ) ; foreach ( $ groups as $ group ) { if ( $ group -> getID ( ) == $ groupID ) { return $ group ; } } return null ; } | Returns the details for a single group . If no group with the given ID is found null will be returned . |
18,333 | public function updateGroup ( Group $ group ) { $ json = [ 'group' => [ 'id' => $ group -> getID ( ) , 'name' => $ group -> getName ( ) , ] , ] ; $ request = new Request ( "POST" , "https://api.weixin.qq.com/cgi-bin/groups/update" , [ ] , json_encode ( $ json ) ) ; $ this -> client -> send ( $ request ) ; } | Allows the updating of a group . |
18,334 | public function changeGroup ( $ userOpenID , $ groupID ) { $ failed = $ this -> changeAllGroups ( [ $ userOpenID ] , $ groupID ) ; if ( count ( $ failed ) <= 0 ) { return true ; } return false ; } | Changes the group for the specified user to the specified group s ID . |
18,335 | public function changeAllGroups ( array $ userOpenIDs , $ groupID ) { if ( count ( $ userOpenIDs ) < 1 ) { throw new InvalidArgumentException ( "At least one user is required." ) ; } $ requests = function ( $ users ) use ( $ groupID ) { foreach ( array_chunk ( $ users , 50 ) as $ chunk ) { yield new Request ( "POST" , ... | Changes the group for all the specified users . Returns an array containing the OpenID s of the users that failed to have their group changed . |
18,336 | public function getAllUsers ( array $ userOpenIDs , callable $ callback = null , $ lang = 'en' ) { if ( count ( $ userOpenIDs ) < 1 ) { throw new InvalidArgumentException ( "At least one user is required." ) ; } else { $ userOpenIDs = array_unique ( array_values ( $ userOpenIDs ) ) ; } $ requestBuilder = function ( $ o... | Retrieves the profiles of all the specified WeChat user IDs . |
18,337 | public function paginateUsers ( $ nextOpenID = null ) { $ json = json_decode ( $ this -> client -> send ( new Request ( 'GET' , Uri :: withQueryValue ( new Uri ( 'https://api.weixin.qq.com/cgi-bin/user/get' ) , 'next_openid' , $ nextOpenID ) ) ) -> getBody ( ) ) ; if ( ! isset ( $ json -> total ) ) { return new Paginat... | Allows pagination through the entire list of followers . |
18,338 | public function sendSms ( $ message ) { if ( empty ( $ this -> phone ) ) { throw new Exceptions \ InvalidRecipientException ( "Phonebook entry doesn't have a phone number." ) ; } return $ this -> deviceParent -> sendSms ( $ this -> phone , $ message ) ; } | Send an SMS message to the contact . |
18,339 | public function withoutItem ( MenuItem $ item ) { $ cloned = clone $ this ; foreach ( $ cloned -> items as $ storedIndex => $ storedItem ) { if ( $ storedItem === $ item ) { unset ( $ cloned -> items [ $ storedIndex ] ) ; break ; } } return $ cloned ; } | Removes the specified item from the menu . Ensures the menu item remains immutable . |
18,340 | protected function handleTypeView ( $ url ) { if ( filter_var ( $ url , FILTER_VALIDATE_URL ) === false ) { throw new InvalidArgumentException ( "Invalid URL." ) ; } $ this -> key = $ url ; } | Validates the URL that will be visited when clicking the menu item . |
18,341 | protected function buildMessage ( array $ message ) { $ doc = new DOMDocument ( ) ; $ root = $ doc -> createElement ( 'xml' ) ; $ doc -> appendChild ( $ root ) ; $ message = array_merge ( $ message , [ 'FromUserName' => $ this -> sender , 'ToUserName' => $ this -> recipient , 'CreateTime' => time ( ) ] ) ; $ this -> fi... | Receives an array representation of the message and converts it into its XML representation . |
18,342 | private function sendReply ( $ reply , array $ headers = [ ] ) { if ( $ this -> sent ) { throw new Exception \ AlreadySentException ( ) ; } $ headers = array_merge ( [ 'Connection: close' , 'Content-Length: ' . strlen ( $ reply ) , ] , $ headers ) ; $ hasContentType = false ; foreach ( $ headers as $ headerLine ) { if ... | Handles the sending of the reply . Throws an exception if a reply has previously been sent . |
18,343 | public function sendText ( Type \ Text $ message ) { $ this -> sendReply ( $ this -> buildMessage ( [ 'MsgType' => $ message -> getType ( ) , 'Content' => $ message -> getContent ( ) , ] ) ) ; } | Sends a text reply . |
18,344 | public function sendImage ( Type \ Image $ message ) { $ this -> sendReply ( $ this -> buildMessage ( [ 'MsgType' => $ message -> getType ( ) , ucfirst ( $ message -> getType ( ) ) => [ 'MediaId' => $ message -> getMediaID ( ) , ] , ] ) ) ; } | Sends an image reply . |
18,345 | public function sendAudio ( Type \ Audio $ audioMessage ) { $ this -> sendReply ( $ this -> buildMessage ( [ 'MsgType' => $ audioMessage -> getType ( ) , ucfirst ( $ audioMessage -> getType ( ) ) => [ 'MediaId' => $ audioMessage -> getMediaID ( ) , ] , ] ) ) ; } | Sends an audio reply . |
18,346 | public function sendVideo ( Type \ Video $ videoMessage ) { $ this -> sendReply ( $ this -> buildMessage ( [ 'MsgType' => $ videoMessage -> getType ( ) , ucfirst ( $ videoMessage -> getType ( ) ) => [ 'MediaId' => $ videoMessage -> getMediaID ( ) , 'ThumbMediaId' => $ videoMessage -> getThumbnailID ( ) , ] , ] ) ) ; } | Sends a video reply . |
18,347 | public function sendMusic ( Type \ Music $ musicMessage ) { $ this -> sendReply ( $ this -> buildMessage ( [ 'MsgType' => $ musicMessage -> getType ( ) , ucfirst ( $ musicMessage -> getType ( ) ) => [ 'Title' => $ musicMessage -> getTitle ( ) , 'Description' => $ musicMessage -> getDescription ( ) , 'MusicUrl' => $ mus... | Sends a music reply . |
18,348 | public function sendNews ( Type \ News $ newsMessage ) { $ items = [ ] ; foreach ( $ newsMessage -> getItems ( ) as $ newsItem ) { $ items [ ] = [ 'Title' => $ newsItem -> getTitle ( ) , 'Description' => $ newsItem -> getDescription ( ) , 'PicUrl' => $ newsItem -> getImageURL ( ) , 'Url' => $ newsItem -> getURL ( ) , ]... | Sends a new message reply . |
18,349 | public static function sendCurlRequest ( $ url , $ method , $ data = null , $ sendAsJSON = true , $ apiKey = null ) { $ curl = curl_init ( ) ; if ( $ method == 'GET' && ! empty ( $ data ) ) { $ url .= '?' . http_build_query ( $ data ) ; } curl_setopt ( $ curl , CURLOPT_URL , $ url ) ; if ( ! empty ( $ apiKey ) ) { curl... | Send a request to a remote server using cURL . |
18,350 | public function on ( $ type , callable $ listener ) { $ args = array_slice ( func_get_args ( ) , 2 ) ; $ this -> emitter -> addListener ( $ type , function ( EventInterface $ event , Input \ Input $ input , Reply \ Handler $ replyHandler ) use ( $ args , $ listener ) { call_user_func_array ( $ listener , array_merge ( ... | Adds an event listener for the given input type . |
18,351 | public function formatMessageForPush ( TypeInterface $ message , $ openID ) { $ json = [ ] ; $ json [ 'touser' ] = $ openID ; $ json [ 'msgtype' ] = $ message -> getType ( ) ; $ methodName = 'format' . ucfirst ( $ message -> getType ( ) ) . 'ForPush' ; if ( method_exists ( $ this , $ methodName ) ) { $ json [ $ message... | Formats the provided message for sending as a push message to the specified recipient . |
18,352 | public function formatTemplateMessage ( $ templateID , $ openID , $ url , array $ data , array $ options = [ ] ) { $ json = [ 'touser' => ( string ) $ openID , 'template_id' => ( string ) $ templateID , 'url' => ( string ) $ url , 'data' => [ ] , ] ; if ( isset ( $ options [ 'color' ] ) ) { $ json [ 'topcolor' ] = '#' ... | Formats the given data to be used in a template message . Returns an array that can be sent to the API . |
18,353 | public function authenticate ( $ appId , $ secretKey , StorageInterface $ storage = null ) { if ( ! $ storage ) { $ storage = new File ( sys_get_temp_dir ( ) ) ; } $ hash = $ storage -> hash ( $ appId , $ secretKey ) ; $ cached = $ storage -> retrieve ( $ hash ) ; if ( $ cached instanceof AccessToken && $ cached -> val... | Authenticates against the WeChat API . If authentication is successful a modified copy of the client is returned with the access token in use . |
18,354 | public function changeName ( $ name ) { return new Contact ( Connection :: sendCurlRequest ( Connection :: URL_CONTACTS . '/' . $ this -> iden , 'POST' , [ 'name' => $ name ] , true , $ this -> apiKey ) , $ this -> apiKey ) ; } | Change the contact s name . |
18,355 | public function withItem ( MenuItem $ item ) { if ( count ( $ this -> items ) >= 3 ) { throw new LengthException ( "Maximum of 3 items allowed in a menu." ) ; } $ cloned = clone $ this ; $ cloned -> items [ ] = $ item ; return $ cloned ; } | Adds a new item to the menu . Ensures the menu remains immutable . |
18,356 | public function sendPushMessageToUser ( TypeInterface $ message , $ openID ) { $ this -> client -> send ( new Request ( "POST" , "https://api.weixin.qq.com/cgi-bin/message/custom/send" , [ ] , json_encode ( ( new Formatter ( ) ) -> formatMessageForPush ( $ message , $ openID ) ) ) ) ; } | Sends the given message to the specified user . |
18,357 | public function sendBroadcastMessageToGroup ( TypeInterface $ message , $ groupID ) { $ json = ( new Formatter ( ) ) -> formatMessageForBroadcast ( $ message ) ; $ json [ 'filter' ] [ 'group_id' ] = ( int ) $ groupID ; $ json = json_decode ( $ this -> client -> send ( new Request ( "POST" , "https://api.weixin.qq.com/c... | Sends the given messages as a broadcast to the specified group . Returns the ID of the broadcast message in order to query the status of the message at a later stage . |
18,358 | public function queryBroadcastMessageStatus ( $ broadcastMessageID ) { $ json = json_decode ( $ this -> client -> send ( new Request ( "POST" , "https://api.weixin.qq.com/cgi-bin/message/mass/get" , [ ] , json_encode ( [ "msg_id" => ( int ) $ broadcastMessageID , ] ) ) ) -> getBody ( ) ) ; return strtolower ( $ json ->... | Returns a string that contains the status of the specified broadcast message . |
18,359 | public function sendTemplateMessageToUser ( $ templateID , $ openID , $ url , array $ data , array $ options = [ ] ) { if ( ! filter_var ( $ url , FILTER_VALIDATE_URL ) ) { throw new InvalidArgumentException ( '$url must be a valid URL.' ) ; } $ json = json_decode ( $ this -> client -> send ( new Request ( "POST" , "ht... | Sends the templated message with the given template id to to specified user . |
18,360 | public function getPushes ( $ modifiedAfter = 0 , $ cursor = null , $ limit = null ) { $ data = self :: initData ( $ modifiedAfter , $ cursor , $ limit ) ; $ pushes = Connection :: sendCurlRequest ( Connection :: URL_PUSHES , 'GET' , $ data , false , $ this -> apiKey ) -> pushes ; $ objPushes = [ ] ; foreach ( $ pushes... | Get push history . |
18,361 | public function push ( $ iden ) { $ response = Connection :: sendCurlRequest ( Connection :: URL_PUSHES . '/' . $ iden , 'GET' , null , false , $ this -> apiKey ) ; return new Push ( $ response , $ this -> apiKey ) ; } | Returns a Push object with the specified iden . |
18,362 | public function getDevices ( $ modifiedAfter = 0 , $ cursor = null , $ limit = null ) { $ data = self :: initData ( $ modifiedAfter , $ cursor , $ limit ) ; $ devices = Connection :: sendCurlRequest ( Connection :: URL_DEVICES , 'GET' , $ data , true , $ this -> apiKey ) -> devices ; $ objDevices = [ ] ; foreach ( $ de... | Get a list of available devices . |
18,363 | public function device ( $ idenOrNickname ) { if ( $ this -> devices === null ) { $ this -> getDevices ( ) ; } foreach ( $ this -> devices as $ d ) { if ( $ d -> iden == $ idenOrNickname || $ d -> nickname == $ idenOrNickname ) { return $ d ; } } throw new Exceptions \ NotFoundException ( "Device not found." ) ; } | Target a device by its iden or nickname . |
18,364 | public function createContact ( $ name , $ email ) { if ( filter_var ( $ email , FILTER_VALIDATE_EMAIL ) === false ) { throw new Exceptions \ InvalidRecipientException ( 'Invalid email address.' ) ; } $ data = [ 'name' => $ name , 'email' => $ email ] ; return new Contact ( Connection :: sendCurlRequest ( Connection ::... | Create a new contact . |
18,365 | public function getContacts ( $ modifiedAfter = 0 , $ cursor = null , $ limit = null ) { $ data = self :: initData ( $ modifiedAfter , $ cursor , $ limit ) ; $ contacts = Connection :: sendCurlRequest ( Connection :: URL_CONTACTS , 'GET' , $ data , false , $ this -> apiKey ) -> contacts ; $ objContacts = [ ] ; foreach ... | Get a list of contacts . |
18,366 | public function contact ( $ nameOrEmail ) { if ( $ this -> contacts === null ) { $ this -> getContacts ( ) ; } foreach ( $ this -> contacts as $ c ) { if ( $ c -> name == $ nameOrEmail || $ c -> email == $ nameOrEmail ) { return $ c ; } } throw new Exceptions \ NotFoundException ( "Contact not found." ) ; } | Target a contact by its name or email . |
18,367 | public function updateUserPreferences ( $ preferences ) { return Connection :: sendCurlRequest ( Connection :: URL_USERS . '/me' , 'POST' , [ 'preferences' => $ preferences ] , true , $ this -> apiKey ) ; } | Update preferences for the current user . |
18,368 | public function channel ( $ tag ) { if ( $ this -> channels === null ) { $ this -> getChannelSubscriptions ( ) ; } if ( $ this -> myChannels === null ) { $ this -> getMyChannels ( ) ; } foreach ( $ this -> myChannels as $ c ) { if ( $ tag == $ c -> tag ) { $ c -> myChannel = true ; return $ c ; } } foreach ( $ this -> ... | Target a channel to create subscribe to unsubscribe from or get information . |
18,369 | public function getChannelSubscriptions ( $ modifiedAfter = 0 , $ cursor = null , $ limit = null ) { $ data = self :: initData ( $ modifiedAfter , $ cursor , $ limit ) ; $ subscriptions = Connection :: sendCurlRequest ( Connection :: URL_SUBSCRIPTIONS , 'GET' , $ data , false , $ this -> apiKey ) -> subscriptions ; $ o... | Get a list of the channels the current user is subscribed to . |
18,370 | public function getMyChannels ( $ modifiedAfter = 0 , $ cursor = null , $ limit = null ) { $ data = self :: initData ( $ modifiedAfter , $ cursor , $ limit ) ; $ myChannels = Connection :: sendCurlRequest ( Connection :: URL_CHANNELS , 'GET' , $ data , false , $ this -> apiKey ) -> channels ; $ objChannels = [ ] ; fore... | Get a list of channels created by the current user . |
18,371 | private static function initData ( $ modifiedAfter , $ cursor , $ limit ) { $ data = [ ] ; $ data [ 'modified_after' ] = $ modifiedAfter ; $ data [ 'cursor' ] = $ cursor ; $ data [ 'limit' ] = $ limit ; return $ data ; } | Initialize data to be sent . |
18,372 | public function dismiss ( ) { return new Push ( Connection :: sendCurlRequest ( Connection :: URL_PUSHES . '/' . $ this -> iden , 'POST' , [ 'dismissed' => true ] , true , $ this -> apiKey ) , $ this -> apiKey ) ; } | Dismiss the push notification . |
18,373 | public function subscribe ( ) { if ( $ this -> type == "subscription" ) { throw new Exceptions \ ChannelException ( "Already subscribed to this channel." ) ; } if ( ! empty ( $ this -> myChannel ) ) { throw new Exceptions \ ChannelException ( "Cannot subscribe to own channel." ) ; } try { return new Channel ( Connectio... | Subscribe to the channel . |
18,374 | public function unsubscribe ( ) { if ( $ this -> type != "subscription" ) { throw new Exceptions \ ChannelException ( "The current user is not subscribed to this channel." ) ; } Connection :: sendCurlRequest ( Connection :: URL_SUBSCRIPTIONS . '/' . $ this -> iden , 'DELETE' , null , false , $ this -> apiKey ) ; } | Unsubscribe from the channel . |
18,375 | public function getChannelInformation ( ) { try { return new Channel ( Connection :: sendCurlRequest ( Connection :: URL_CHANNEL_INFO , 'GET' , [ 'tag' => $ this -> channelTag ] , false , $ this -> apiKey ) , $ this -> apiKey ) ; } catch ( Exceptions \ ConnectionException $ e ) { if ( $ e -> getCode ( ) === 400 ) { thr... | Get information about the channel . |
18,376 | protected function createWritableStream ( $ filePath ) { if ( is_resource ( $ filePath ) ) { $ stream = $ filePath ; } elseif ( is_string ( $ filePath ) ) { $ stream = fopen ( $ filePath , 'wb' ) ; if ( ! $ stream ) { throw new InvalidArgumentException ( "Can't open file `{$filePath}` for writing." ) ; } } else { $ str... | Creates a writable stream that downloaded contents can be stored in . |
18,377 | public function sendSms ( $ toNumber , $ message ) { if ( empty ( $ this -> has_sms ) ) { throw new Exceptions \ NoSmsException ( "Device cannot send SMS messages." ) ; } $ data = [ 'type' => 'push' , 'push' => [ 'type' => 'messaging_extension_reply' , 'package_name' => 'com.pushbullet.android' , 'source_user_iden' => ... | Send an SMS message from the device . |
18,378 | public function getPhonebook ( ) { $ entries = Connection :: sendCurlRequest ( Connection :: URL_PHONEBOOK . '_' . $ this -> iden , 'GET' , null , false , $ this -> apiKey ) -> phonebook ; $ objEntries = [ ] ; foreach ( $ entries as $ e ) { $ objEntries [ ] = new PhonebookEntry ( $ e , $ this ) ; } return $ objEntries ... | Get the device s phonebook . |
18,379 | public function delete ( ) { Connection :: sendCurlRequest ( Connection :: URL_DEVICES . '/' . $ this -> iden , 'DELETE' , null , false , $ this -> apiKey ) ; } | Delete the device . |
18,380 | public function patch ( $ selection , $ operations = null ) { $ isPatch = $ selection instanceof Patch ; $ patch = $ isPatch ? $ selection : null ; if ( $ isPatch ) { $ this -> operations [ ] = [ 'patch' => $ patch -> serialize ( ) ] ; return $ this ; } if ( ! is_array ( $ operations ) ) { throw new InvalidArgumentExce... | Patch the given document or selection |
18,381 | public function fetch ( $ query , $ params = null , $ options = [ ] ) { $ unfilteredResponse = isset ( $ options [ 'filterResponse' ] ) && $ options [ 'filterResponse' ] === false ; $ serializedParams = $ params ? ParameterSerializer :: serialize ( $ params ) : [ ] ; $ queryParams = array_merge ( [ 'query' => $ query ]... | Query for documents |
18,382 | public function getDocument ( $ id ) { $ body = $ this -> request ( [ 'url' => '/data/doc/' . $ this -> clientConfig [ 'dataset' ] . '/' . $ id , 'cdnAllowed' => true ] ) ; return $ body [ 'documents' ] [ 0 ] ; } | Fetch a single document by ID |
18,383 | public function create ( $ document , $ options = null ) { $ this -> assertProperties ( $ document , [ '_type' ] , 'create' ) ; return $ this -> createDocument ( $ document , 'create' , $ options ) ; } | Create a new document in the configured dataset |
18,384 | public function createIfNotExists ( $ document , $ options = null ) { $ this -> assertProperties ( $ document , [ '_id' , '_type' ] , 'createIfNotExists' ) ; return $ this -> createDocument ( $ document , 'createIfNotExists' , $ options ) ; } | Create a new document if the document ID does not already exist |
18,385 | public function createOrReplace ( $ document , $ options = null ) { $ this -> assertProperties ( $ document , [ '_id' , '_type' ] , 'createOrReplace' ) ; return $ this -> createDocument ( $ document , 'createOrReplace' , $ options ) ; } | Create or replace a document with the given ID |
18,386 | public function mutate ( $ mutations , $ options = null ) { $ mut = $ mutations ; if ( $ mut instanceof Patch ) { $ mut = [ 'patch' => $ mut -> serialize ( ) ] ; } elseif ( $ mut instanceof Transaction ) { $ mut = $ mut -> serialize ( ) ; } $ body = [ 'mutations' => ! isset ( $ mut [ 0 ] ) ? [ $ mut ] : $ mut ] ; $ que... | Send a set of mutations to the API for processing |
18,387 | public function config ( $ newConfig = null ) { if ( $ newConfig === null ) { return $ this -> clientConfig ; } $ this -> clientConfig = $ this -> initConfig ( $ newConfig ) ; $ this -> httpClient = new HttpClient ( [ 'base_uri' => $ this -> clientConfig [ 'url' ] , 'timeout' => $ this -> clientConfig [ 'timeout' ] , '... | Sets or gets the client configuration . |
18,388 | public function request ( $ options ) { $ request = $ this -> getRequest ( $ options ) ; $ requestOptions = isset ( $ options [ 'query' ] ) ? [ 'query' => $ options [ 'query' ] ] : [ ] ; try { $ response = $ this -> httpClient -> send ( $ request , $ requestOptions ) ; } catch ( GuzzleRequestException $ err ) { $ hasRe... | Performs a request against the Sanity API based on the passed options . |
18,389 | private function createDocument ( $ document , $ operation , $ options = [ ] ) { $ mutation = [ $ operation => $ document ] ; $ opts = array_replace ( [ 'returnFirst' => true , 'returnDocuments' => true ] , $ options ? : [ ] ) ; return $ this -> mutate ( [ $ mutation ] , $ opts ) ; } | Creates a document using the given operation type |
18,390 | private function getRequest ( $ options ) { $ headers = isset ( $ options [ 'headers' ] ) ? $ options [ 'headers' ] : [ ] ; $ headers [ 'User-Agent' ] = 'sanity-php ' . Version :: VERSION ; if ( ! empty ( $ this -> clientConfig [ 'token' ] ) ) { $ headers [ 'Authorization' ] = 'Bearer ' . $ this -> clientConfig [ 'toke... | Returns an instance of Request based on the given options and client configuration . |
18,391 | private function initConfig ( $ config ) { $ specifiedConfig = array_replace_recursive ( $ this -> clientConfig , $ config ) ; if ( ! isset ( $ specifiedConfig [ 'apiVersion' ] ) ) { trigger_error ( Client :: NO_API_VERSION_WARNING , E_USER_DEPRECATED ) ; } $ newConfig = array_replace_recursive ( $ this -> defaultConfi... | Initialize a new client configuration |
18,392 | private function getMutationQueryParams ( $ options = [ ] ) { $ query = [ 'returnIds' => 'true' ] ; if ( ! isset ( $ options [ 'returnDocuments' ] ) || $ options [ 'returnDocuments' ] ) { $ query [ 'returnDocuments' ] = 'true' ; } if ( isset ( $ options [ 'visibility' ] ) && $ options [ 'visibility' ] !== 'sync' ) { $ ... | Get a reduced and normalized set of query params for a mutation based on the given options |
18,393 | public static function dirtyDecode ( $ access_token , $ claims = [ ] ) { $ now = time ( ) ; $ expecting = false ; $ incorrect = false ; $ expired = false ; $ error = false ; $ errors = array ( ) ; $ decodedToken = array ( ) ; $ token_segments = explode ( '.' , $ access_token ) ; $ body = ( isset ( $ token_segments [ 1 ... | Decode a Access Token |
18,394 | public function sign ( HttpRequest $ request ) { if ( $ this -> developerKey ) { $ requestUrl = $ request -> getUrl ( ) ; $ requestUrl .= ( strpos ( $ request -> getUrl ( ) , '?' ) === false ) ? '?' : '&' ; $ requestUrl .= 'key=' . urlencode ( $ this -> developerKey ) ; $ request -> setUrl ( $ requestUrl ) ; } if ( nul... | Include an accessToken in a given HttpRequest . |
18,395 | private function normalize ( $ selection ) { if ( isset ( $ selection [ 'query' ] ) ) { return [ 'query' => $ selection [ 'query' ] ] ; } if ( is_string ( $ selection ) || ( is_array ( $ selection ) && isset ( $ selection [ 0 ] ) ) ) { return [ 'id' => $ selection ] ; } $ selectionOpts = implode ( PHP_EOL , [ '' , '* D... | Validates and normalizes a selection |
18,396 | public function registerClientScript ( ) { $ view = $ this -> getView ( ) ; CropperAsset :: register ( $ view ) ; $ options = Json :: encode ( $ this -> pluginOptions ) ; $ selector = "#$this->id .crop-image-container > img" ; if ( $ this -> modal ) { $ ajaxOptions = Json :: encode ( $ this -> ajaxOptions ) ; $ view ->... | Registers required script for the plugin to work as jQuery image cropping |
18,397 | private function validateInsert ( $ at , $ selector , $ items ) { $ insertLocations = [ 'before' , 'after' , 'replace' ] ; $ signature = 'insert(at, selector, items)' ; $ index = array_search ( $ at , $ insertLocations ) ; if ( $ index === false ) { $ valid = implode ( ', ' , array_map ( function ( $ loc ) { return '"'... | Validates parameters for an insert operation |
18,398 | private function assertProperties ( $ doc , $ required , $ method ) { $ keys = array_keys ( $ doc ) ; $ diff = array_diff ( $ required , $ keys ) ; if ( empty ( $ diff ) ) { return ; } $ err = $ method . ': the following required properties are missing: ' ; $ err .= implode ( ', ' , $ diff ) ; throw new InvalidArgument... | Assert that the given document contains the required properties |
18,399 | public function listModels ( $ optParams = array ( ) ) { $ data = $ this -> __call ( 'list' , array ( $ optParams ) ) ; if ( $ this -> useObjects ( ) ) { return new ListModel ( $ data ) ; } else { return $ data ; } } | Executes list api method . list is a php saved keyword and therefore it can t be used as method name |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.