idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
47,700 | public function removeSignatureRequestAccess ( $ request_id ) { $ response = $ this -> rest -> post ( static :: SIGNATURE_REQUEST_REMOVE_PATH . '/' . $ request_id ) ; $ this -> checkResponse ( $ response , false ) ; return true ; } | Removes your access to a completed SignatureRequest . Note that this action is NOT reversible . |
47,701 | public function getFiles ( $ request_id , $ dest_path = null , $ type = null ) { if ( $ dest_path ) { $ response = $ this -> rest -> get ( static :: SIGNATURE_REQUEST_FILES_PATH . '/' . $ request_id , $ type ? array ( 'file_type' => $ type ) : null ) ; $ this -> checkResponse ( $ response , false ) ; file_put_contents ( $ dest_path , $ response ) ; } else { $ response = $ this -> rest -> get ( static :: SIGNATURE_REQUEST_FILES_PATH . '/' . $ request_id , array ( 'get_url' => true ) ) ; return new FileResponse ( $ response ) ; } return $ response ; } | Retrieves a link or copy of the files associated with a signature request |
47,702 | public function getTemplate ( $ id ) { $ response = $ this -> rest -> get ( static :: TEMPLATE_PATH . '/' . $ id ) ; $ this -> checkResponse ( $ response ) ; return new Template ( $ response ) ; } | Retrieves the specified Template |
47,703 | public function getTemplates ( $ page = 1 , $ page_size = null , $ account_id = null ) { $ response = $ this -> rest -> get ( static :: TEMPLATE_LIST_PATH , array ( 'account_id' => $ account_id , 'page' => $ page , 'page_size' => $ page_size ) ) ; $ this -> checkResponse ( $ response ) ; $ list = new TemplateList ( $ response ) ; if ( $ page > $ list -> getNumPages ( ) ) { throw new Error ( 'page_not_found' , 'Page not found' ) ; } return $ list ; } | Retrieves a list of Templates that are accessible by this account |
47,704 | public function addTemplateUser ( $ template_id , $ id_or_email ) { $ key = strpos ( $ id_or_email , '@' ) ? 'email_address' : 'account_id' ; $ response = $ this -> rest -> post ( static :: TEMPLATE_ADD_USER_PATH . '/' . $ template_id , array ( $ key => $ id_or_email ) ) ; $ this -> checkResponse ( $ response ) ; return new Template ( $ response ) ; } | Gives the specified Account access to the specified Template . The user can be designated using their account ID or email address . |
47,705 | public function removeTemplateUser ( $ template_id , $ id_or_email ) { $ key = strpos ( $ id_or_email , '@' ) ? 'email_address' : 'account_id' ; $ response = $ this -> rest -> post ( static :: TEMPLATE_REMOVE_USER_PATH . '/' . $ template_id , array ( $ key => $ id_or_email ) ) ; $ this -> checkResponse ( $ response ) ; return new Template ( $ response ) ; } | Removes the specified Account access to the specified Template . The user can be designated using their account ID or email . |
47,706 | public function createEmbeddedDraft ( Template $ request ) { $ response = $ this -> rest -> post ( static :: TEMPLATE_CREATE_EMBEDDED_DRAFT , $ request -> toEmbeddedDraftParams ( ) ) ; $ this -> checkResponse ( $ response ) ; return new Template ( $ response ) ; } | The first step in an EmbeddedTemplate workflow . Creates a draft template that can then be further set up in the template edit stage . |
47,707 | public function deleteTemplate ( $ template_id ) { $ response = $ this -> rest -> post ( static :: TEMPLATE_DELETE_PATH . '/' . $ template_id ) ; $ this -> checkResponse ( $ response , false ) ; return true ; } | Deletes the specified Template from the Account . |
47,708 | public function getTemplateFiles ( $ template_id , $ dest_path = null , $ type = 'pdf' ) { if ( $ dest_path ) { $ response = $ this -> rest -> get ( static :: TEMPLATE_FILES_PATH . '/' . $ template_id , $ type ? array ( 'file_type' => $ type ) : null ) ; $ this -> checkResponse ( $ response , false ) ; file_put_contents ( $ dest_path , $ response ) ; } else { $ response = $ this -> rest -> get ( static :: TEMPLATE_FILES_PATH . '/' . $ template_id , array ( 'get_url' => true ) ) ; } return $ response ; } | Retrieves a link or copy of the files associated with a template |
47,709 | public function updateTemplateFiles ( $ template_id , Template $ request ) { $ params = $ request -> toUpdateParams ( ) ; $ response = $ this -> rest -> post ( static :: TEMPLATE_UPDATE_FILES_PATH . '/' . $ template_id , $ params ) ; return new Template ( $ response ) ; } | Creates a new Template using the overlay of specified Template |
47,710 | public function sendTemplateSignatureRequest ( TemplateSignatureRequest $ request ) { $ params = $ request -> toParams ( ) ; $ response = $ this -> rest -> post ( static :: TEMPLATE_SIGNATURE_REQUEST_PATH , $ params ) ; $ this -> checkResponse ( $ response ) ; return new SignatureRequest ( $ response ) ; } | Creates a new Signature Request based on the Template provided |
47,711 | public function getSignatureRequest ( $ id ) { $ response = $ this -> rest -> get ( static :: SIGNATURE_REQUEST_PATH . '/' . $ id ) ; $ this -> checkResponse ( $ response ) ; return new SignatureRequest ( $ response ) ; } | Retrieves a SignatureRequest with the given ID |
47,712 | public function getSignatureRequests ( $ page = 1 ) { $ params = array ( 'page' => $ page ) ; $ response = $ this -> rest -> get ( static :: SIGNATURE_REQUEST_LIST_PATH , $ params ) ; $ this -> checkResponse ( $ response ) ; $ list = new SignatureRequestList ( $ response ) ; if ( $ page > $ list -> getNumPages ( ) ) { throw new Error ( 'page_not_found' , 'Page not found' ) ; } return $ list ; } | Retrieves the current user s signature requests . The resulting object represents a paged query result . |
47,713 | public function createEmbeddedSignatureRequest ( EmbeddedSignatureRequest $ request ) { $ params = $ request -> toParams ( ) ; $ url = $ request -> isUsingTemplate ( ) ? static :: SIGNATURE_REQUEST_EMBEDDED_TEMPLATE_PATH : static :: SIGNATURE_REQUEST_EMBEDDED_PATH ; $ response = $ this -> rest -> post ( $ url , $ params ) ; $ this -> checkResponse ( $ response ) ; return new SignatureRequest ( $ response ) ; } | Creates a SignatureRequest that can be embedded within your website |
47,714 | public function getEmbeddedSignUrl ( $ id ) { $ response = $ this -> rest -> get ( static :: EMBEDDED_SIGN_URL_PATH . '/' . $ id ) ; $ this -> checkResponse ( $ response ) ; return new EmbeddedResponse ( $ response ) ; } | Retrieves an embedded object containing a signature URL that can be opened in an iFrame . |
47,715 | public function getEmbeddedEditUrl ( $ id , Template $ request = null ) { if ( $ request !== null ) { $ params = $ request -> toParams ( ) ; $ response = $ this -> rest -> post ( static :: EMBEDDED_EDIT_URL_PATH . '/' . $ id , $ params ) ; } else { $ response = $ this -> rest -> get ( static :: EMBEDDED_EDIT_URL_PATH . '/' . $ id ) ; } $ this -> checkResponse ( $ response ) ; return new EmbeddedResponse ( $ response ) ; } | Retrieves an embedded object containing an edit URL that can be opened in an iFrame to edit an EmbeddedTemplate . |
47,716 | public function unclaimedDraftEditAndResend ( $ id , UnclaimedDraft $ draft ) { $ response = $ this -> rest -> post ( static :: UNCLAIMED_DRAFT_EDIT_AND_RESEND_PATH . '/' . $ id , $ draft -> toEditParams ( ) ) ; $ this -> checkResponse ( $ response ) ; return $ draft -> fromResponse ( $ response ) ; } | Creates a new SignatureRequest from another request that can be edited prior to being sent to the recipients . |
47,717 | public function requestOAuthToken ( OAuthTokenRequest $ request , $ auto_set_request_token = false ) { $ rest = new REST ( array ( 'server' => $ this -> oauth_token_url , 'debug_mode' => $ this -> debug_mode ) ) ; if ( $ this -> oauth_token_url != self :: OAUTH_TOKEN_URL ) { $ this -> disableCertificateCheck ( $ rest ) ; } $ response = $ rest -> post ( '' , $ request -> toParams ( ) ) ; $ this -> checkResponse ( $ response ) ; $ this -> checkOAuthTokenResponse ( $ response ) ; $ token = new OAuthToken ( $ response ) ; if ( $ auto_set_request_token ) { $ this -> rest = $ this -> createREST ( $ token ) ; } return $ token ; } | Performs an OAuth request and returns the OAuthToken object for authorizing an API App and will automatically set the access token for making authenticated requests with this client . |
47,718 | public function refreshOAuthToken ( OAuthToken $ token , $ auto_set_request_token = false ) { $ rest = new REST ( array ( 'server' => $ this -> oauth_token_url , 'debug_mode' => $ this -> debug_mode ) ) ; if ( $ this -> oauth_token_url != self :: OAUTH_TOKEN_URL ) { $ this -> disableCertificateCheck ( $ rest ) ; } $ response = $ rest -> post ( '' , $ token -> toParams ( ) ) ; $ this -> checkResponse ( $ response ) ; $ this -> checkOAuthTokenResponse ( $ response ) ; $ token -> fromObject ( $ response ) ; if ( $ auto_set_request_token ) { $ this -> rest = $ this -> createREST ( $ token ) ; } return $ token ; } | Refresh OAuth token and will automatically set the access token for making authenticated requests with this client . |
47,719 | public function getAccount ( ) { $ response = $ this -> rest -> get ( static :: ACCOUNT_PATH ) ; $ this -> checkResponse ( $ response ) ; return new Account ( $ response ) ; } | Returns the current user s HelloSign account information |
47,720 | public function isAccountValid ( $ email ) { $ response = $ this -> rest -> post ( static :: ACCOUNT_VALIDATE_PATH , array ( 'email_address' => $ email ) ) ; $ this -> checkResponse ( $ response ) ; return property_exists ( $ response , 'account' ) ; } | Returns true if an Account exists with the provided email address . Note this is limited to the visibility of the currently authenticated user . |
47,721 | public function createAccount ( Account $ account , $ client_id = null , $ client_secret = null ) { $ post = $ account -> toCreateParams ( ) ; if ( $ client_id ) { $ post += array ( 'client_id' => $ client_id , 'client_secret' => $ client_secret ) ; } $ response = $ this -> rest -> post ( static :: ACCOUNT_CREATE_PATH , $ post ) ; $ this -> checkResponse ( $ response ) ; return $ account -> fromResponse ( $ response ) ; } | Creates a new HelloSign account |
47,722 | public function updateAccount ( Account $ account ) { $ response = $ this -> rest -> post ( static :: ACCOUNT_PATH , $ account -> toUpdateParams ( ) ) ; $ this -> checkResponse ( $ response ) ; return $ account -> fromResponse ( $ response ) ; } | Updates your Account s settings |
47,723 | public function getTeam ( ) { $ response = $ this -> rest -> get ( static :: TEAM_PATH ) ; $ this -> checkResponse ( $ response ) ; return new Team ( $ response ) ; } | Retrieves the Team for the current Account |
47,724 | public function createTeam ( Team $ team ) { $ response = $ this -> rest -> post ( static :: TEAM_CREATE_PATH , $ team -> toCreateParams ( ) ) ; $ this -> checkResponse ( $ response ) ; return $ team -> fromResponse ( $ response ) ; } | Creates a new Team for the current Account |
47,725 | public function updateTeamName ( $ name ) { $ response = $ this -> rest -> post ( static :: TEAM_PATH , array ( 'name' => $ name ) ) ; $ this -> checkResponse ( $ response ) ; return new Team ( $ response ) ; } | Updates the current Account s Team name |
47,726 | public function destroyTeam ( ) { $ response = $ this -> rest -> post ( static :: TEAM_DESTROY_PATH ) ; $ this -> checkResponse ( $ response , false ) ; return true ; } | Deletes the current Account s Team |
47,727 | public function inviteTeamMember ( $ id_or_email ) { $ key = strpos ( $ id_or_email , '@' ) ? 'email_address' : 'account_id' ; $ response = $ this -> rest -> post ( static :: TEAM_ADD_MEMBER_PATH , array ( $ key => $ id_or_email ) ) ; $ this -> checkResponse ( $ response ) ; return new Team ( $ response ) ; } | Adds the specified Account to the current Team |
47,728 | public function removeTeamMember ( $ id_or_email ) { $ key = strpos ( $ id_or_email , '@' ) ? 'email_address' : 'account_id' ; $ response = $ this -> rest -> post ( static :: TEAM_REMOVE_MEMBER_PATH , array ( $ key => $ id_or_email ) ) ; $ this -> checkResponse ( $ response ) ; return new Team ( $ response ) ; } | Removes the specified Account from the current Team |
47,729 | public function removeAllTeamMembers ( ) { $ team = $ this -> getTeam ( ) ; $ last_team = $ team ; foreach ( $ team -> getAccounts ( ) as $ account ) { if ( ! $ account -> isTeamAdmin ( ) ) { $ last_team = $ this -> removeTeamMember ( $ account -> getId ( ) ) ; } } return $ last_team ; } | Removes all team members from current Team |
47,730 | protected function createREST ( $ first , $ last = null , $ api_url = self :: API_URL ) { if ( $ first instanceof OAuthToken ) { $ rest = new REST ( array ( 'server' => $ api_url , 'debug_mode' => $ this -> debug_mode ) ) ; $ auth = $ first -> getTokenType ( ) . ' ' . $ first -> getAccessToken ( ) ; $ rest -> setHeader ( 'Authorization' , $ auth ) ; return $ rest ; } return new REST ( array ( 'server' => $ api_url , 'user' => $ first , 'pass' => $ last , 'debug_mode' => $ this -> debug_mode ) ) ; } | Creates REST object |
47,731 | public function createApiApp ( ApiApp $ apiApp ) { $ post = $ apiApp -> toCreateParams ( ) ; $ response = $ this -> rest -> post ( static :: APIAPP_PATH , $ post ) ; $ this -> checkResponse ( $ response ) ; return $ apiApp -> fromResponse ( $ response ) ; } | Creates a new API App |
47,732 | public function updateApiApp ( $ client_id , ApiApp $ app ) { $ response = $ this -> rest -> post ( static :: APIAPP_PATH . '/' . $ client_id , $ app -> toUpdateParams ( ) ) ; $ this -> checkResponse ( $ response ) ; return $ app -> fromResponse ( $ response ) ; } | Updates your API App s settings |
47,733 | public function getApiApp ( $ id ) { $ params = array ( ) ; $ response = $ this -> rest -> get ( static :: APIAPP_PATH . '/' . $ id , $ params ) ; $ this -> checkResponse ( $ response ) ; return new ApiApp ( $ response ) ; } | Retrieves an API App with the given Client ID |
47,734 | public function deleteApiApp ( $ client_id ) { $ response = $ this -> rest -> delete ( static :: APIAPP_PATH . '/' . $ client_id ) ; $ this -> checkResponse ( $ response , false ) ; return true ; } | Completely deletes the API app specified from the account . |
47,735 | public function getApiApps ( $ page = 1 , $ page_size = 20 ) { $ response = $ this -> rest -> get ( static :: APIAPP_LIST_PATH , array ( 'page' => $ page , 'page_size' => $ page_size ) ) ; $ this -> checkResponse ( $ response ) ; $ list = new ApiAppList ( $ response ) ; if ( $ page > $ list -> getNumPages ( ) ) { throw new Error ( 'page_not_found' , 'Page not found' ) ; } return $ list ; } | Retrieves a list of API Apps for account |
47,736 | public function sendBulkSendJobWithTemplate ( BulkSendJob $ request ) { $ params = $ request -> toParams ( ) ; $ response = $ this -> rest -> post ( static :: SIGNATURE_REQUEST_BULK_SEND_PATH , $ params ) ; $ this -> checkResponse ( $ response ) ; return new BulkSendJob ( $ response ) ; } | Creates a new Bulk Send Job using the specified Template |
47,737 | public function sendEmbeddedBulkSendJobWithTemplate ( EmbeddedBulkSendJob $ request ) { $ params = $ request -> toParams ( ) ; $ response = $ this -> rest -> post ( static :: SIGNATURE_REQUEST_EMBEDDED_BULK_SEND_PATH , $ params ) ; $ this -> checkResponse ( $ response ) ; return new BulkSendJob ( $ response ) ; } | Creates a new embedded Bulk Send Job using the specified Template |
47,738 | public function getBulkSendJob ( $ id ) { $ params = array ( ) ; $ response = $ this -> rest -> get ( static :: BULK_SEND_JOB_PATH . '/' . $ id , $ params ) ; $ this -> checkResponse ( $ response ) ; return new BulkSendJob ( $ response ) ; } | Retrieves a Bulk Send Job with the given Bulk Send Job ID |
47,739 | public function getBulkSendJobs ( $ page = 1 , $ page_size = 20 ) { $ response = $ this -> rest -> get ( static :: BULK_SEND_JOB_LIST_PATH , array ( 'page' => $ page , 'page_size' => $ page_size ) ) ; $ this -> checkResponse ( $ response ) ; $ list = new BulkSendJobList ( $ response ) ; if ( $ page > $ list -> getNumPages ( ) ) { throw new Error ( 'page_not_found' , 'Page not found' ) ; } return $ list ; } | Retrieves a list of Bulk Send Jobs for account |
47,740 | public function withAttributes ( array $ attributes ) { $ serverRequest = $ this -> serverRequest ; foreach ( $ attributes as $ attribute => $ value ) { $ serverRequest = $ serverRequest -> withAttribute ( $ attribute , $ value ) ; } return new static ( $ serverRequest ) ; } | Create a new instance with the specified derived request attributes . |
47,741 | public function getServerParam ( $ key , $ default = null ) { $ serverParams = $ this -> serverRequest -> getServerParams ( ) ; return isset ( $ serverParams [ $ key ] ) ? $ serverParams [ $ key ] : $ default ; } | Retrieve a server parameter . |
47,742 | public static function get ( $ key ) { $ key = strtoupper ( $ key ) ; $ list = static :: loadConstants ( ) ; if ( array_key_exists ( $ key , $ list ) ) return static :: loadConstants ( ) [ $ key ] ; if ( static :: exist ( $ key ) ) return $ key ; static :: invalidType ( ) ; } | Get the constant value from a passed report type . |
47,743 | public static function exist ( $ value ) { $ list = static :: loadConstants ( ) ; return in_array ( $ value , $ list ) || in_array ( strtoupper ( $ value ) , $ list ) ; } | Check if a passed value is available as report type . |
47,744 | private function setService ( $ service ) { try { $ this -> service = $ this -> adWordsServices -> get ( $ this -> session , $ service ) ; } catch ( \ Exception $ e ) { throw new \ Edujugon \ GoogleAds \ Exceptions \ Service ( "The service '$service' is not available. Please pass a valid service" ) ; } } | Set the service |
47,745 | public function of ( $ reportType ) { $ this -> validateReportType ( $ reportType ) ; $ this -> reportDefinitionFields = $ this -> reportDefinitionService -> getReportFields ( $ reportType ) ; $ this -> obj = $ this -> createObj ( $ this -> reportDefinitionFields ) ; return $ this ; } | Load the fields of the passed reportType |
47,746 | public function except ( array $ list ) { foreach ( $ list as $ field ) { if ( property_exists ( $ this -> obj , $ field ) ) unset ( $ this -> obj -> $ field ) ; } return $ this ; } | Pull fields from the list . |
47,747 | private function createObj ( $ reportDefinitionFields ) { $ obj = new \ stdClass ( ) ; foreach ( $ reportDefinitionFields as $ reportDefinitionField ) { $ name = $ reportDefinitionField -> getFieldName ( ) ; $ obj -> $ name = [ 'type' => $ reportDefinitionField -> getFieldType ( ) , 'values' => ( $ reportDefinitionField -> getEnumValues ( ) !== null ) ? $ reportDefinitionField -> getEnumValues ( ) : null , ] ; } return $ obj ; } | Create a stdClass object with filter data . |
47,748 | public function handle ( ) { $ oAth2 = ( new OAuth2 ( ) ) -> build ( ) ; $ authorizationUrl = $ oAth2 -> buildFullAuthorizationUri ( ) ; $ this -> line ( sprintf ( "Log into the Google account you use for AdWords and visit the following URL:\n%s" , $ authorizationUrl ) ) ; $ accessToken = $ this -> ask ( 'After approving the token enter the authorization code here:' ) ; $ oAth2 -> setCode ( $ accessToken ) ; $ authToken = $ oAth2 -> fetchAuthToken ( ) ; if ( ! array_key_exists ( 'refresh_token' , $ authToken ) ) { $ this -> error ( 'Couldn\'t find refresh_token key in the response.' ) ; $ this -> comment ( 'Below you can check the whole response:' ) ; $ this -> line ( json_encode ( $ authToken ) ) ; return ; } $ this -> comment ( 'Copy the refresh token in your googleads configuration file (config/google-ads.php)' ) ; $ this -> line ( sprintf ( 'Refresh token: "%s"' , $ authToken [ 'refresh_token' ] ) ) ; } | Generate refresh token |
47,749 | public function userCredentials ( array $ data = [ ] ) { $ data = $ this -> mergeData ( $ data ) ; $ refreshCredentials = new OAuth2TokenBuilder ( ) ; return $ refreshCredentials -> withClientId ( $ data [ 'clientId' ] ) -> withClientSecret ( $ data [ 'clientSecret' ] ) -> withRefreshToken ( $ data [ 'refreshToken' ] ) -> build ( ) ; } | UserRefreshCredentials Generate a refreshable OAuth2 credential for authentication . |
47,750 | public function where ( $ field , $ value , $ opposite = false ) { return $ this -> filter ( function ( $ item ) use ( $ field , $ value , $ opposite ) { $ method = $ this -> concatGet ( $ field ) ; $ pass = $ item -> $ method ( ) == $ value ; return $ opposite ? ! $ pass : $ pass ; } ) ; } | search the value in the collection in a specific field . |
47,751 | public function set ( $ field , $ value ) { return $ this -> map ( function ( $ item ) use ( $ field , $ value ) { $ method = $ this -> concatSet ( $ field ) ; return $ item -> $ method ( $ value ) ; } ) ; } | Set the value in the specific field . |
47,752 | public function save ( ) { $ operations = [ ] ; $ this -> items -> each ( function ( $ item ) use ( & $ operations ) { $ operation = $ this -> setOperator ( ) ; $ operation -> setOperand ( $ item ) ; $ operation -> setOperator ( 'SET' ) ; $ operations [ ] = $ operation ; } ) ; if ( empty ( $ operations ) ) return false ; return $ this -> adWordsServices -> mutate ( $ operations ) -> getValue ( ) ; } | Persist values in google . |
47,753 | public function service ( $ service , $ session = null ) { $ this -> service = ( new Service ( $ service , $ session ? : $ this -> session ) ) ; return $ this -> service ; } | Set the google adwords service . |
47,754 | private function loadData ( $ my_std_class , $ property , $ subProperty ) { if ( property_exists ( $ my_std_class , $ property ) ) { return $ my_std_class -> $ property -> { '@attributes' } -> $ subProperty ; } } | Load the report name . |
47,755 | private function loadFields ( $ my_std_class ) { if ( property_exists ( $ my_std_class -> table , 'columns' ) ) { foreach ( $ my_std_class -> table -> columns -> column as $ column ) { $ this -> fields -> push ( $ this -> convertToStdClass ( $ column ) ) ; } } } | Load the report columns |
47,756 | private function loadResults ( $ my_std_class ) { if ( property_exists ( $ my_std_class -> table , 'row' ) ) { foreach ( $ my_std_class -> table -> row as $ row ) { $ this -> result -> push ( $ this -> convertToStdClass ( $ row ) ) ; } } } | Load the report rows |
47,757 | public function format ( $ format ) { if ( Format :: exist ( $ format ) ) $ this -> format = Format :: get ( $ format ) ; else Format :: invalidType ( ) ; return $ this ; } | Set the format for the report . |
47,758 | public function from ( $ reportType ) { if ( ! ReportTypes :: exist ( $ reportType ) ) ReportTypes :: invalidType ( ) ; $ this -> type = ReportTypes :: get ( $ reportType ) ; return $ this ; } | Set the report type |
47,759 | public function during ( $ starting , $ ending ) { if ( ! is_numeric ( $ starting ) || ! is_numeric ( $ ending ) ) throw new \ Edujugon \ GoogleAds \ Exceptions \ Report ( 'During clause only accepts the following date format: "Ymd" => e.g. 20170112' ) ; $ this -> during = [ $ starting , $ ending ] ; return $ this ; } | Set the starting and ending dates for the report . |
47,760 | public function getAsSimpleXMLObj ( ) { $ this -> format ( Format :: get ( 'xml' ) ) ; $ this -> run ( ) ; return simplexml_load_string ( $ this -> data -> getAsString ( ) ) ; } | Get the report as a SimpleXMLObj |
47,761 | public function getAsObj ( ) { $ this -> format ( Format :: get ( 'xml' ) ) ; $ this -> run ( ) ; return ( new MyReport ( simplexml_load_string ( $ this -> data -> getAsString ( ) ) ) ) ; } | Get the report as an object |
47,762 | public function saveToFile ( $ filePath , $ format = 'csvforexcel' ) { $ this -> format ( Format :: get ( $ format ) ) ; $ this -> run ( ) ; $ this -> data -> saveToFile ( $ filePath ) ; return true ; } | Save the report in a file . |
47,763 | private function run ( ) { if ( $ this -> magicSelect ) { $ this -> selectAllFields ( ) ; $ this -> magicRun ( ) ; } $ query = $ this -> createQuery ( ) ; $ this -> data = $ this -> reportDownloader -> downloadReportWithAwql ( $ query , $ this -> format ) ; } | Run the AWQL |
47,764 | private function magicRun ( ) { $ query = $ this -> createQuery ( ) ; try { $ this -> data = $ this -> reportDownloader -> downloadReportWithAwql ( $ query , $ this -> format ) ; } catch ( ApiException $ e ) { $ field = $ e -> getErrors ( ) [ 0 ] -> getFieldPath ( ) ; if ( ! empty ( $ field ) ) { $ this -> except ( $ field ) ; $ this -> magicRun ( ) ; } else var_dump ( $ e -> getMessage ( ) ) ; } } | Magic Run the AWQL |
47,765 | public function except ( $ excepts ) { $ excepts = is_array ( $ excepts ) ? $ excepts : func_get_args ( ) ; $ this -> fields = array_filter ( $ this -> fields , function ( $ field ) use ( $ excepts ) { return ! in_array ( $ field , $ excepts ) ; } ) ; return $ this ; } | Pull fields out of fields list . |
47,766 | public function oAuth ( $ env = null , $ data = [ ] ) { $ this -> oAuth2Credential = ( new OAuth2 ( $ env ) ) -> userCredentials ( $ data ) ; return $ this ; } | Create OAuth2 credential |
47,767 | public function build ( array $ data = [ ] ) { if ( ! $ this -> oAuth2Credential ) $ this -> oAuth ( ) ; $ data = $ this -> mergeData ( $ data ) ; $ adwordsSession = new AdWordsSessionBuilder ( ) ; return $ adwordsSession -> withDeveloperToken ( $ data [ 'developerToken' ] ) -> withClientCustomerId ( $ data [ 'clientCustomerId' ] ) -> withOAuth2Credential ( $ this -> oAuth2Credential ) -> build ( ) ; } | Construct an API session configured from global config data file or passed data |
47,768 | public function buildWithOAuth ( $ developerToken , $ oAuth2Credential ) { $ adwordsSession = new AdWordsSessionBuilder ( ) ; return $ adwordsSession -> withDeveloperToken ( $ developerToken ) -> withOAuth2Credential ( $ oAuth2Credential ) -> build ( ) ; } | Construct an API session from OAuth2 |
47,769 | public function setProtection ( $ permissions , $ userPass = '' , $ ownerPass = null , $ revision = 3 ) { if ( $ revision < 2 || $ revision > 3 ) { throw new \ InvalidArgumentException ( 'Only revision 2 or 3 are supported.' ) ; } if ( $ revision === 3 ) { $ this -> setMinPdfVersion ( '1.4' ) ; } $ this -> pValue = $ this -> sanitizePermissionsValue ( $ permissions , $ revision ) ; if ( $ ownerPass === null || $ ownerPass === '' ) { $ ownerPass = function_exists ( 'random_bytes' ) ? \ random_bytes ( 32 ) : uniqid ( rand ( ) ) ; } $ this -> encrypted = true ; $ this -> revision = $ revision ; $ this -> keyLength = $ revision === 3 ? 16 : 5 ; $ this -> padding = "\x28\xBF\x4E\x5E\x4E\x75\x8A\x41\x64\x00\x4E\x56\xFF\xFA\x01\x08" . "\x2E\x2E\x00\xB6\xD0\x68\x3E\x80\x2F\x0C\xA9\xFE\x64\x53\x69\x7A" ; $ this -> oValue = $ this -> computeOValue ( $ userPass , $ ownerPass ) ; $ this -> encryptionKey = $ this -> computeEncryptionKey ( $ userPass ) ; $ this -> uValue = $ this -> computeUValue ( $ this -> encryptionKey ) ; return $ ownerPass ; } | Set permissions as well as user and owner passwords |
47,770 | public function sanitizePermissionsValue ( $ permissions , $ revision ) { if ( is_array ( $ permissions ) ) { $ legacyOptions = [ 'print' => 4 , 'modify' => 8 , 'copy' => 16 , 'annot-forms' => 32 ] ; foreach ( $ permissions as $ key => $ value ) { if ( isset ( $ legacyOptions [ $ value ] ) ) { $ permissions [ $ key ] = $ legacyOptions [ $ value ] ; } elseif ( ! is_int ( $ value ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid permission value: %s' , $ value ) ) ; } } $ permissions = array_sum ( $ permissions ) ; } $ permissions = ( int ) $ permissions ; $ allowed = self :: PERM_PRINT | self :: PERM_MODIFY | self :: PERM_COPY | self :: PERM_ANNOT ; if ( $ revision > 2 ) { $ allowed |= self :: PERM_FILL_FORM | self :: PERM_ACCESSIBILITY | self :: PERM_ASSEMBLE | self :: PERM_DIGITAL_PRINT ; } if ( ( $ allowed & $ permissions ) !== $ permissions ) { throw new \ InvalidArgumentException ( sprintf ( 'Permission flags (%s) are not allowed for this security handler revision %s.' , $ permissions , $ revision ) ) ; } $ permissions = 61632 | 0xFFFF0000 | $ permissions ; if ( $ revision < 3 ) { $ permissions |= 3840 ; } if ( PHP_INT_SIZE === 4 || ( $ permissions ) < ( 2147483647 ) ) { return $ permissions ; } return ( $ permissions | ( 4294967295 << 32 ) ) ; } | Ensures a valid permission value . |
47,771 | protected function computeOValue ( $ userPassword , $ ownerPassword = '' ) { $ revision = $ this -> revision ; if ( '' === $ ownerPassword ) $ ownerPassword = $ userPassword ; $ s = substr ( $ ownerPassword . $ this -> padding , 0 , 32 ) ; $ s = md5 ( $ s , true ) ; if ( $ revision >= 3 ) { for ( $ i = 0 ; $ i < 50 ; $ i ++ ) $ s = md5 ( $ s , true ) ; } $ encryptionKey = substr ( $ s , 0 , $ this -> keyLength ) ; $ s = substr ( $ userPassword . $ this -> padding , 0 , 32 ) ; $ s = $ this -> arcfour ( $ encryptionKey , $ s ) ; if ( $ revision >= 3 ) { for ( $ i = 1 ; $ i <= 19 ; $ i ++ ) { $ tmp = array ( ) ; for ( $ j = 0 ; $ j < $ this -> keyLength ; $ j ++ ) { $ tmp [ $ j ] = ord ( $ encryptionKey [ $ j ] ) ^ $ i ; $ tmp [ $ j ] = chr ( $ tmp [ $ j ] ) ; } $ s = $ this -> arcfour ( join ( '' , $ tmp ) , $ s ) ; } } return $ s ; } | Compute the O value . |
47,772 | protected function computeEncryptionKey ( $ password = '' ) { $ revision = $ this -> revision ; $ s = substr ( $ password . $ this -> padding , 0 , 32 ) ; $ s .= $ this -> oValue ; $ pValue = ( int ) ( float ) $ this -> pValue ; $ s .= pack ( "V" , $ pValue ) ; $ s .= $ this -> fileIdentifier ; $ s = md5 ( $ s , true ) ; if ( $ revision >= 3 ) { for ( $ i = 0 ; $ i < 50 ; $ i ++ ) $ s = md5 ( substr ( $ s , 0 , $ this -> keyLength ) , true ) ; } return substr ( $ s , 0 , $ this -> keyLength ) ; } | Compute the encryption key based on a password . |
47,773 | protected function computeUValue ( $ encryptionKey ) { $ revision = $ this -> revision ; if ( $ revision < 3 ) { return $ this -> arcfour ( $ encryptionKey , $ this -> padding ) ; } $ s = $ this -> padding ; $ s .= $ this -> fileIdentifier ; $ s = md5 ( $ s , true ) ; $ s = $ this -> arcfour ( $ encryptionKey , $ s ) ; $ length = strlen ( $ encryptionKey ) ; for ( $ i = 1 ; $ i <= 19 ; $ i ++ ) { $ tmp = array ( ) ; for ( $ j = 0 ; $ j < $ length ; $ j ++ ) { $ tmp [ $ j ] = ord ( $ encryptionKey [ $ j ] ) ^ $ i ; $ tmp [ $ j ] = chr ( $ tmp [ $ j ] ) ; } $ s = $ this -> arcfour ( join ( '' , $ tmp ) , $ s ) ; } return $ s . str_repeat ( "\0" , 16 ) ; } | Compute the U value . |
47,774 | protected function getEncryptionKeyByObjectNumber ( $ objectNumber ) { return substr ( substr ( md5 ( $ this -> encryptionKey . pack ( 'VXxx' , $ objectNumber ) , true ) , 0 , $ this -> keyLength + 5 ) , 0 , 16 ) ; } | Computes the encryption key by an object number |
47,775 | protected function _putencryption ( ) { $ this -> _put ( '/Filter /Standard' ) ; $ this -> _put ( '/V ' . ( $ this -> revision === 3 ? '2' : '1' ) ) ; $ this -> _put ( '/R ' . ( $ this -> revision === 3 ? '3' : '2' ) ) ; if ( $ this -> revision === 3 ) { $ this -> _put ( '/Length 128' ) ; } $ this -> _put ( '/O (' . $ this -> _escape ( $ this -> oValue ) . ')' ) ; $ this -> _put ( '/U (' . $ this -> _escape ( $ this -> uValue ) . ')' ) ; $ this -> _put ( '/P ' . $ this -> pValue ) ; } | Writes the values of the encryption dictionary . |
47,776 | public function filesToOverwrite ( ) { $ files = new Filesystem ; $ stubs = array_map ( function ( SplFileInfo $ file ) { return $ file -> getRelativePathname ( ) ; } , $ files -> allFiles ( "{$this->sageRoot}/resources/assets" ) ) ; return array_intersect ( $ stubs , $ this -> getFileList ( ) ) ; } | List of files that will be overwritten |
47,777 | public function getFileList ( ) { $ files = new Filesystem ; return array_map ( function ( SplFileInfo $ file ) { return $ file -> getRelativePathname ( ) ; } , $ files -> allFiles ( $ this -> stubDirectory ) ) ; } | List of files to be copied |
47,778 | protected function copyFiles ( ) { $ files = new Filesystem ; array_map ( function ( $ file ) use ( $ files ) { $ files -> copy ( "{$this->stubDirectory}/{$file}" , "{$this->sageRoot}/resources/assets/{$file}" ) ; } , $ this -> getFileList ( ) ) ; } | Copy files from stubs directory to theme |
47,779 | protected function updatePackages ( $ packagesFile = '' ) { $ packagesFile = $ packagesFile ? : "{$this->sageRoot}/package.json" ; $ packages = json_decode ( file_get_contents ( $ packagesFile ) , true ) ; if ( ! $ this -> addOn ) { $ packages = $ this -> removePresetsFromPackagesArray ( $ packages ) ; } $ packages = $ this -> updatePackagesArray ( $ packages ) ; ksort ( $ packages [ 'devDependencies' ] ) ; ksort ( $ packages [ 'dependencies' ] ) ; file_put_contents ( $ packagesFile , preg_replace_callback ( '/^ +/m' , function ( $ matches ) { return str_repeat ( ' ' , strlen ( $ matches [ 0 ] ) / 2 ) ; } , json_encode ( $ packages , JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) . PHP_EOL ) ) ; } | Update package . json |
47,780 | protected function confirmOverwrite ( array $ files = [ ] ) { if ( ! $ files || $ this -> option ( 'overwrite' ) ) { return true ; } $ files = implode ( "\n - " , $ files ) ; return $ this -> confirm ( "Are you sure you want to overwrite the following files?\n<comment> - {$files}</comment>\n\n" ) ; } | Confirm overwriting files |
47,781 | public static function getModules ( ) { $ req = new GetModulesRequest ( ) ; $ resp = new GetModulesResponse ( ) ; ApiProxy :: makeSyncCall ( 'modules' , 'GetModules' , $ req , $ resp ) ; return $ resp -> getModuleList ( ) ; } | Gets an array of all the modules for the application . |
47,782 | public static function getVersions ( $ module = null ) { $ req = new GetVersionsRequest ( ) ; $ resp = new GetVersionsResponse ( ) ; if ( $ module !== null ) { if ( ! is_string ( $ module ) ) { throw new \ InvalidArgumentException ( '$module must be a string. Actual type: ' . gettype ( $ module ) ) ; } $ req -> setModule ( $ module ) ; } try { ApiProxy :: makeSyncCall ( 'modules' , 'GetVersions' , $ req , $ resp ) ; } catch ( ApplicationError $ e ) { throw errorCodeToException ( $ e -> getApplicationError ( ) ) ; } return $ resp -> getVersionList ( ) ; } | Get an array of all versions associated with a module . |
47,783 | public static function getDefaultVersion ( $ module = null ) { $ req = new GetDefaultVersionRequest ( ) ; $ resp = new GetDefaultVersionResponse ( ) ; if ( $ module !== null ) { if ( ! is_string ( $ module ) ) { throw new \ InvalidArgumentException ( '$module must be a string. Actual type: ' . gettype ( $ module ) ) ; } $ req -> setModule ( $ module ) ; } try { ApiProxy :: makeSyncCall ( 'modules' , 'GetDefaultVersion' , $ req , $ resp ) ; } catch ( ApplicationError $ e ) { throw errorCodeToException ( $ e -> getApplicationError ( ) ) ; } return $ resp -> getVersion ( ) ; } | Get the default version of a module . |
47,784 | public static function getNumInstances ( $ module = null , $ version = null ) { $ req = new GetNumInstancesRequest ( ) ; $ resp = new GetNumInstancesResponse ( ) ; if ( $ module !== null ) { if ( ! is_string ( $ module ) ) { throw new \ InvalidArgumentException ( '$module must be a string. Actual type: ' . gettype ( $ module ) ) ; } $ req -> setModule ( $ module ) ; } if ( $ version !== null ) { if ( ! is_string ( $ version ) ) { throw new \ InvalidArgumentException ( '$version must be a string. Actual type: ' . gettype ( $ version ) ) ; } $ req -> setVersion ( $ version ) ; } try { ApiProxy :: makeSyncCall ( 'modules' , 'GetNumInstances' , $ req , $ resp ) ; } catch ( ApplicationError $ e ) { throw self :: errorCodeToException ( $ e -> getApplicationError ( ) ) ; } return ( int ) $ resp -> getInstances ( ) ; } | Get the number of instances set for a version of a module . |
47,785 | public static function setNumInstances ( $ instances , $ module = null , $ version = null ) { $ req = new SetNumInstancesRequest ( ) ; $ resp = new SetNumInstancesResponse ( ) ; if ( ! is_int ( $ instances ) ) { throw new \ InvalidArgumentException ( '$instances must be an integer. Actual type: ' . gettype ( $ instances ) ) ; } $ req -> setInstances ( $ instances ) ; if ( $ module !== null ) { if ( ! is_string ( $ module ) ) { throw new \ InvalidArgumentException ( '$module must be a string. Actual type: ' . gettype ( $ module ) ) ; } $ req -> setModule ( $ module ) ; } if ( $ version !== null ) { if ( ! is_string ( $ version ) ) { throw new \ InvalidArgumentException ( '$version must be a string. Actual type: ' . gettype ( $ version ) ) ; } $ req -> setVersion ( $ version ) ; } try { ApiProxy :: makeSyncCall ( 'modules' , 'SetNumInstances' , $ req , $ resp ) ; } catch ( ApplicationError $ e ) { throw self :: errorCodeToException ( $ e -> getApplicationError ( ) ) ; } } | Set the number of instances for a version of a module . |
47,786 | public function stat ( ) { $ prefix = $ this -> prefix ; if ( StringUtil :: endsWith ( $ prefix , parent :: DELIMITER ) ) { $ prefix = substr ( $ prefix , 0 , strlen ( $ prefix ) - 1 ) ; } if ( ini_get ( "google_app_engine.enable_gcs_stat_cache" ) && $ this -> tryGetFromStatCache ( $ stat_result ) ) { return $ stat_result ; } if ( isset ( $ prefix ) ) { $ result = $ this -> headObject ( $ prefix ) ; if ( $ result !== false ) { $ mode = parent :: S_IFREG ; $ mtime = $ result [ 'mtime' ] ; $ size = $ result [ 'size' ] ; } else { do { $ results = $ this -> listBucket ( $ prefix ) ; if ( false === $ results ) { return false ; } if ( empty ( $ results ) ) { return false ; } $ object_name_folder = $ prefix . parent :: FOLDER_SUFFIX ; $ object_name_delimiter = $ prefix . parent :: DELIMITER ; foreach ( $ results as $ result ) { if ( $ result [ 'name' ] === $ object_name_folder || $ result [ 'name' ] === $ object_name_delimiter ) { $ mode = parent :: S_IFDIR ; break ; } } } while ( ! isset ( $ mode ) && isset ( $ this -> next_marker ) ) ; } } else { $ results = $ this -> listBucket ( ) ; if ( $ results !== false ) { $ mode = parent :: S_IFDIR ; } else { return false ; } } if ( ! isset ( $ mode ) ) { return false ; } $ mode |= parent :: S_IRUSR | parent :: S_IRGRP | parent :: S_IROTH ; if ( $ this -> isBucketWritable ( $ this -> bucket_name ) ) { $ mode |= parent :: S_IWUSR | parent :: S_IWGRP | parent :: S_IWOTH ; } $ stat_args [ "mode" ] = $ mode ; if ( isset ( $ mtime ) ) { $ unix_time = strtotime ( $ mtime ) ; if ( $ unix_time !== false ) { $ stat_args [ "mtime" ] = $ unix_time ; } } if ( isset ( $ size ) ) { $ stat_args [ "size" ] = intval ( $ size ) ; } $ stat_result = $ this -> createStatArray ( $ stat_args ) ; $ this -> addToStatCache ( $ stat_result ) ; return $ stat_result ; } | The stat function uses GET requests to the bucket to try and determine if the object is a file or a directory by listing the contents of the bucket and then matching the results against the supplied object name . |
47,787 | private function headObject ( $ object_name ) { $ headers = $ this -> getOAuthTokenHeader ( parent :: READ_SCOPE ) ; if ( $ headers === false ) { if ( ! $ this -> quiet ) { trigger_error ( "Unable to acquire OAuth token." , E_USER_WARNING ) ; } return false ; } $ url = $ this -> createObjectUrl ( $ this -> bucket_name , $ object_name ) ; $ http_response = $ this -> makeHttpRequest ( $ url , "HEAD" , $ headers ) ; if ( $ http_response === false ) { if ( ! $ this -> quiet ) { trigger_error ( 'Unable to connect to the Cloud Storage Service.' , E_USER_WARNING ) ; } return false ; } $ status_code = $ http_response [ 'status_code' ] ; if ( HttpResponse :: OK !== $ status_code ) { if ( ! $ this -> quiet && HttpResponse :: NOT_FOUND !== $ status_code ) { trigger_error ( $ this -> getErrorMessage ( $ http_response [ 'status_code' ] , $ http_response [ 'body' ] ) , E_USER_WARNING ) ; } return false ; } $ headers = $ http_response [ 'headers' ] ; return [ 'size' => $ this -> getHeaderValue ( 'x-goog-stored-content-length' , $ headers ) , 'mtime' => $ this -> getHeaderValue ( 'Last-Modified' , $ headers ) ] ; } | Perform a HEAD request on an object to get size & mtime info . |
47,788 | private function isBucketWritable ( $ bucket ) { $ cache_key_name = sprintf ( parent :: WRITABLE_MEMCACHE_KEY_FORMAT , $ bucket ) ; $ memcache = new \ Memcache ( ) ; $ result = $ memcache -> get ( $ cache_key_name ) ; if ( $ result ) { return $ result [ 'is_writable' ] ; } $ token_header = $ this -> getOAuthTokenHeader ( parent :: WRITE_SCOPE ) ; if ( $ token_header === false ) { return false ; } $ headers = array_merge ( parent :: $ upload_start_header , $ token_header ) ; $ url = parent :: createObjectUrl ( $ bucket , parent :: WRITABLE_TEMP_FILENAME ) ; $ http_response = $ this -> makeHttpRequest ( $ url , "POST" , $ headers ) ; if ( $ http_response === false ) { return false ; } $ status_code = $ http_response [ 'status_code' ] ; $ is_writable = $ status_code == HttpResponse :: CREATED ; $ memcache -> set ( $ cache_key_name , [ 'is_writable' => $ is_writable ] , null , $ this -> context_options [ 'writable_cache_expiry_seconds' ] ) ; return $ is_writable ; } | Test if a given bucket is writable . We will cache results in memcache as this is an expensive operation . This might lead to incorrect results being returned for this call for a short period while the result remains in the cache . |
47,789 | public static function getImageServingUrl ( $ gs_filename , $ options = [ ] ) { $ blob_key = self :: createGsKey ( $ gs_filename ) ; if ( ! is_array ( $ options ) ) { throw new \ InvalidArgumentException ( '$options must be an array. ' . 'Actual type: ' . gettype ( $ options ) ) ; } $ extra_options = array_diff ( array_keys ( $ options ) , array_keys ( self :: $ get_image_serving_url_default_options ) ) ; if ( ! empty ( $ extra_options ) ) { throw new \ InvalidArgumentException ( 'Invalid options supplied: ' . htmlspecialchars ( implode ( ',' , $ extra_options ) ) ) ; } $ options = array_merge ( self :: $ get_image_serving_url_default_options , $ options ) ; if ( ! is_bool ( $ options [ 'crop' ] ) ) { throw new \ InvalidArgumentException ( '$options[\'crop\'] must be a boolean. ' . 'Actual type: ' . gettype ( $ options [ 'crop' ] ) ) ; } if ( $ options [ 'crop' ] && is_null ( $ options [ 'size' ] ) ) { throw new \ InvalidArgumentException ( '$options[\'size\'] must be set because $options[\'crop\'] is true.' ) ; } if ( ! is_null ( $ options [ 'size' ] ) ) { $ size = $ options [ 'size' ] ; if ( ! is_int ( $ size ) ) { throw new \ InvalidArgumentException ( '$options[\'size\'] must be an integer. ' . 'Actual type: ' . gettype ( $ size ) ) ; } if ( $ size < 0 || $ size > self :: MAX_IMAGE_SERVING_SIZE ) { throw new \ InvalidArgumentException ( '$options[\'size\'] must be >= 0 and <= ' . self :: MAX_IMAGE_SERVING_SIZE . '. Actual value: ' . $ size ) ; } } if ( ! is_bool ( $ options [ 'secure_url' ] ) ) { throw new \ InvalidArgumentException ( '$options[\'secure_url\'] must be a boolean. ' . 'Actual type: ' . gettype ( $ options [ 'secure_url' ] ) ) ; } $ req = new ImagesGetUrlBaseRequest ( ) ; $ resp = new ImagesGetUrlBaseResponse ( ) ; $ req -> setBlobKey ( $ blob_key ) ; $ req -> setCreateSecureUrl ( $ options [ 'secure_url' ] ) ; try { ApiProxy :: makeSyncCall ( 'images' , 'GetUrlBase' , $ req , $ resp ) ; } catch ( ApplicationError $ e ) { throw self :: imagesApplicationErrorToException ( $ e ) ; } $ url = $ resp -> getUrl ( ) ; if ( ! is_null ( $ options [ 'size' ] ) ) { $ url .= ( '=s' . $ options [ 'size' ] ) ; if ( $ options [ 'crop' ] ) { $ url .= '-c' ; } } return $ url ; } | Returns a URL that serves an image . |
47,790 | public static function deleteImageServingUrl ( $ gs_filename ) { $ blob_key = self :: createGsKey ( $ gs_filename ) ; $ req = new ImagesDeleteUrlBaseRequest ( ) ; $ resp = new ImagesDeleteUrlBaseResponse ( ) ; $ req -> setBlobKey ( $ blob_key ) ; try { ApiProxy :: makeSyncCall ( 'images' , 'DeleteUrlBase' , $ req , $ resp ) ; } catch ( ApplicationError $ e ) { throw self :: imagesApplicationErrorToException ( $ e ) ; } } | Deletes an image serving URL that was created using getImageServingUrl . |
47,791 | public static function getPublicUrl ( $ gs_filename , $ use_https ) { if ( ! is_bool ( $ use_https ) ) { throw new \ InvalidArgumentException ( 'Parameter $use_https must be boolean but was ' . typeOrClass ( $ use_https ) ) ; } if ( ! self :: parseFilename ( $ gs_filename , $ bucket , $ object ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid Google Cloud Storage filename: %s' , htmlspecialchars ( $ gs_filename ) ) ) ; } if ( self :: isDevelServer ( ) ) { $ scheme = 'http' ; $ host = getenv ( 'HTTP_HOST' ) ; $ path = sprintf ( '%s/%s%s' , self :: LOCAL_ENDPOINT , $ bucket , $ object ) ; } else { if ( $ use_https && strpos ( $ bucket , '.' ) !== false ) { $ host = self :: PRODUCTION_HOST_PATH_FORMAT ; $ path = sprintf ( '/%s%s' , $ bucket , $ object ) ; } else { $ host = sprintf ( self :: PRODUCTION_HOST_SUBDOMAIN_FORMAT , $ bucket ) ; $ path = strlen ( $ object ) > 0 ? $ object : '/' ; } $ scheme = $ use_https ? 'https' : 'http' ; } return sprintf ( '%s://%s%s' , $ scheme , $ host , strtr ( $ path , self :: $ url_path_translation_map ) ) ; } | Get the public URL for a Google Cloud Storage filename . |
47,792 | public static function getFilename ( $ bucket , $ object ) { if ( self :: validateBucketName ( $ bucket ) === false ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid cloud storage bucket name \'%s\'' , htmlspecialchars ( $ bucket ) ) ) ; } if ( self :: validateObjectName ( $ object ) === false ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid cloud storage object name \'%s\'' , htmlspecialchars ( $ object ) ) ) ; } return sprintf ( self :: GS_FILENAME_FORMAT , $ bucket , $ object ) ; } | Get the filename of a Google Cloud Storage object . |
47,793 | public static function parseFilename ( $ filename , & $ bucket , & $ object ) { $ bucket = null ; $ object = null ; $ gs_prefix_len = strlen ( self :: GS_PREFIX ) ; if ( ! StringUtil :: startsWith ( $ filename , self :: GS_PREFIX ) ) { return false ; } $ first_slash_pos = strpos ( $ filename , '/' , $ gs_prefix_len ) ; if ( $ first_slash_pos === false ) { $ bucket = substr ( $ filename , $ gs_prefix_len ) ; } else { $ bucket = substr ( $ filename , $ gs_prefix_len , $ first_slash_pos - $ gs_prefix_len ) ; if ( $ first_slash_pos != strlen ( $ filename ) - 1 ) { $ object = substr ( $ filename , $ first_slash_pos ) ; } } if ( strlen ( $ bucket ) == 0 ) { return false ; } if ( ini_get ( 'google_app_engine.gcs_default_keyword' ) ) { if ( $ bucket === self :: GS_DEFAULT_BUCKET_KEYWORD ) { $ bucket = self :: getDefaultGoogleStorageBucketName ( ) ; if ( ! $ bucket ) { throw new \ InvalidArgumentException ( 'Application does not have a default Cloud Storage Bucket, ' . 'must specify a bucket name' ) ; } } } if ( self :: validateBucketName ( $ bucket ) === false ) { trigger_error ( sprintf ( 'Invalid cloud storage bucket name \'%s\'' , $ bucket ) , E_USER_ERROR ) ; return false ; } if ( isset ( $ object ) && self :: validateObjectName ( $ object ) === false ) { trigger_error ( sprintf ( 'Invalid cloud storage object name \'%s\'' , $ object ) , E_USER_ERROR ) ; return false ; } return true ; } | Parse and extract the bucket and object names from the supplied filename . |
47,794 | private static function createGsKey ( $ filename ) { if ( ! self :: parseFilename ( $ filename , $ bucket , $ object ) || ! $ object ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid Google Cloud Storage filename: %s' , htmlspecialchars ( $ filename ) ) ) ; } $ gs_filename = sprintf ( '/gs/%s%s' , $ bucket , $ object ) ; $ request = new CreateEncodedGoogleStorageKeyRequest ( ) ; $ response = new CreateEncodedGoogleStorageKeyResponse ( ) ; $ request -> setFilename ( $ gs_filename ) ; try { ApiProxy :: makeSyncCall ( 'blobstore' , 'CreateEncodedGoogleStorageKey' , $ request , $ response ) ; } catch ( ApplicationError $ e ) { throw self :: applicationErrorToException ( $ e ) ; } return $ response -> getBlobKey ( ) ; } | Create a blob key for a Google Cloud Storage file . |
47,795 | public static function serve ( $ gs_filename , $ options = [ ] ) { $ extra_options = array_diff ( array_keys ( $ options ) , self :: $ serve_options ) ; if ( ! empty ( $ extra_options ) ) { throw new \ InvalidArgumentException ( 'Invalid options supplied: ' . htmlspecialchars ( implode ( ',' , $ extra_options ) ) ) ; } $ start = ArrayUtil :: findByKeyOrNull ( $ options , "start" ) ; $ end = ArrayUtil :: findByKeyOrNull ( $ options , "end" ) ; $ use_range = ArrayUtil :: findByKeyOrNull ( $ options , "use_range" ) ; $ request_range_header = ArrayUtil :: findByKeyOrNull ( $ _SERVER , "HTTP_RANGE" ) ; $ range_header = self :: checkRanges ( $ start , $ end , $ use_range , $ request_range_header ) ; $ save_as = ArrayUtil :: findByKeyOrNull ( $ options , "save_as" ) ; if ( isset ( $ save_as ) && ! is_string ( $ save_as ) ) { throw new \ InvalidArgumentException ( "Unexpected value for save_as." ) ; } $ blob_key = self :: createGsKey ( $ gs_filename ) ; self :: sendHeader ( self :: BLOB_KEY_HEADER , $ blob_key ) ; if ( isset ( $ range_header ) ) { self :: sendHeader ( self :: BLOB_RANGE_HEADER , $ range_header ) ; } $ content_type = ArrayUtil :: findByKeyOrNull ( $ options , "content_type" ) ; if ( isset ( $ content_type ) ) { self :: sendHeader ( "Content-Type" , $ content_type ) ; } if ( isset ( $ save_as ) ) { self :: sendHeader ( "Content-Disposition" , sprintf ( "attachment; filename=%s" , $ save_as ) ) ; } } | Serve a Google Cloud Storage file as the response . |
47,796 | public static function getDefaultGoogleStorageBucketName ( ) { $ success = false ; $ default_bucket_name = apc_fetch ( self :: GS_DEFAULT_BUCKET_APC_KEY , $ success ) ; if ( $ success ) { return $ default_bucket_name ; } $ request = new GetDefaultGcsBucketNameRequest ( ) ; $ response = new GetDefaultGcsBucketNameResponse ( ) ; ApiProxy :: makeSyncCall ( 'app_identity_service' , 'GetDefaultGcsBucketName' , $ request , $ response ) ; $ default_bucket_name = $ response -> getDefaultGcsBucketName ( ) ; if ( $ default_bucket_name ) { apc_store ( self :: GS_DEFAULT_BUCKET_APC_KEY , $ default_bucket_name ) ; } return $ default_bucket_name ; } | Return the name of the default Google Cloud Storage bucket for the application if one has been configured . |
47,797 | private static function applicationErrorToException ( $ error ) { switch ( $ error -> getApplicationError ( ) ) { case ErrorCode :: URL_TOO_LONG : $ result = new \ InvalidArgumentException ( 'The upload URL supplied was too long.' ) ; break ; case ErrorCode :: PERMISSION_DENIED : $ result = new CloudStorageException ( 'Permission Denied' ) ; break ; case ErrorCode :: ARGUMENT_OUT_OF_RANGE : $ result = new \ InvalidArgumentException ( $ error -> getMessage ( ) ) ; break ; default : $ result = new CloudStorageException ( 'Error Code: ' . $ error -> getApplicationError ( ) ) ; } return $ result ; } | Convert an BlobstoreServiceError returned from an RPC call to an exception . |
47,798 | private static function imagesApplicationErrorToException ( $ error ) { switch ( $ error -> getApplicationError ( ) ) { case ImagesServiceError \ ErrorCode :: UNSPECIFIED_ERROR : $ result = new CloudStorageException ( 'Unspecified error with image.' ) ; break ; case ImagesServiceError \ ErrorCode :: BAD_TRANSFORM_DATA : $ result = new CloudStorageException ( 'Bad image transform data.' ) ; break ; case ImagesServiceError \ ErrorCode :: NOT_IMAGE : $ result = new CloudStorageException ( 'Not an image.' ) ; break ; case ImagesServiceError \ ErrorCode :: BAD_IMAGE_DATA : $ result = new CloudStorageException ( 'Bad image data.' ) ; break ; case ImagesServiceError \ ErrorCode :: IMAGE_TOO_LARGE : $ result = new CloudStorageException ( 'Image too large.' ) ; break ; case ImagesServiceError \ ErrorCode :: INVALID_BLOB_KEY : $ result = new CloudStorageException ( 'Invalid blob key for image.' ) ; break ; case ImagesServiceError \ ErrorCode :: ACCESS_DENIED : $ result = new CloudStorageException ( 'Access denied to image.' ) ; break ; case ImagesServiceError \ ErrorCode :: OBJECT_NOT_FOUND : $ result = new CloudStorageException ( 'Image object not found.' ) ; break ; default : $ result = new CloudStorageException ( 'Images Error Code: ' . $ error -> getApplicationError ( ) ) ; } return $ result ; } | Convert an ImagesServiceError returned from an RPC call to an exception . |
47,799 | private static function serializeRange ( $ start , $ end ) { if ( $ start < 0 ) { $ range_str = sprintf ( '%d' , $ start ) ; } else if ( ! isset ( $ end ) ) { $ range_str = sprintf ( "%d-" , $ start ) ; } else { $ range_str = sprintf ( "%d-%d" , $ start , $ end ) ; } return sprintf ( "bytes=%s" , $ range_str ) ; } | Create the value for a range header from start and end byte values . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.