idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
9,300
public function removeAttribute ( string $ key ) : void { $ this -> tag -> removeAttribute ( $ key ) ; $ this -> clear ( ) ; }
A wrapper method that simply calls the removeAttribute method on the tag of this node .
9,301
public function confirmMicroTransferAmounts ( $ token , $ amounts ) { try { $ path = $ this -> _config -> merchantPath ( ) . '/us_bank_account_verifications/' . $ token . '/confirm_micro_transfer_amounts' ; $ response = $ this -> _http -> put ( $ path , [ "us_bank_account_verification" => [ "deposit_amounts" => $ amounts ] ] ) ; return $ this -> _verifyGatewayResponse ( $ response ) ; } catch ( Exception \ Unexpected $ e ) { throw new Exception \ Unexpected ( 'Unexpected exception.' ) ; } }
complete micro transfer verification by confirming the transfer amounts
9,302
public function find ( $ token ) { $ this -> _validateId ( $ token ) ; try { $ path = $ this -> _config -> merchantPath ( ) . '/payment_methods/any/' . $ token ; $ response = $ this -> _http -> get ( $ path ) ; return PaymentMethodParser :: parsePaymentMethod ( $ response ) ; } catch ( Exception \ NotFound $ e ) { throw new Exception \ NotFound ( 'payment method with token ' . $ token . ' not found' ) ; } }
find a PaymentMethod by token
9,303
public function _doDelete ( $ subPath ) { $ fullPath = $ this -> _config -> merchantPath ( ) . $ subPath ; $ this -> _http -> delete ( $ fullPath ) ; return new Result \ Successful ( ) ; }
sends the delete request to the gateway
9,304
public function create ( $ params ) { Util :: verifyKeys ( self :: createSignature ( ) , $ params ) ; $ file = $ params [ 'file' ] ; if ( ! is_resource ( $ file ) ) { throw new InvalidArgumentException ( 'file must be a stream resource' ) ; } $ payload = [ 'document_upload[kind]' => $ params [ 'kind' ] ] ; $ path = $ this -> _config -> merchantPath ( ) . '/document_uploads/' ; $ response = $ this -> _http -> postMultipart ( $ path , $ payload , $ file ) ; if ( isset ( $ response [ 'apiErrorResponse' ] ) ) { return new Result \ Error ( $ response [ 'apiErrorResponse' ] ) ; } if ( isset ( $ response [ 'documentUpload' ] ) ) { $ documentUpload = DocumentUpload :: factory ( $ response [ 'documentUpload' ] ) ; return new Result \ Successful ( $ documentUpload ) ; } }
Accepts a dispute given a dispute ID
9,305
public function delete ( $ customerOrId = null , $ addressId = null ) { $ this -> _validateId ( $ addressId ) ; $ customerId = $ this -> _determineCustomerId ( $ customerOrId ) ; $ path = $ this -> _config -> merchantPath ( ) . '/customers/' . $ customerId . '/addresses/' . $ addressId ; $ this -> _http -> delete ( $ path ) ; return new Result \ Successful ( ) ; }
delete an address by id
9,306
public function find ( $ customerOrId , $ addressId ) { $ customerId = $ this -> _determineCustomerId ( $ customerOrId ) ; $ this -> _validateId ( $ addressId ) ; try { $ path = $ this -> _config -> merchantPath ( ) . '/customers/' . $ customerId . '/addresses/' . $ addressId ; $ response = $ this -> _http -> get ( $ path ) ; return Address :: factory ( $ response [ 'address' ] ) ; } catch ( Exception \ NotFound $ e ) { throw new Exception \ NotFound ( 'address for customer ' . $ customerId . ' with id ' . $ addressId . ' not found.' ) ; } }
find an address by id
9,307
public function update ( $ customerOrId , $ addressId , $ attributes ) { $ this -> _validateId ( $ addressId ) ; $ customerId = $ this -> _determineCustomerId ( $ customerOrId ) ; Util :: verifyKeys ( self :: updateSignature ( ) , $ attributes ) ; $ path = $ this -> _config -> merchantPath ( ) . '/customers/' . $ customerId . '/addresses/' . $ addressId ; $ response = $ this -> _http -> put ( $ path , [ 'address' => $ attributes ] ) ; return $ this -> _verifyGatewayResponse ( $ response ) ; }
updates the address record
9,308
public function updateNoValidate ( $ customerOrId , $ addressId , $ attributes ) { $ result = $ this -> update ( $ customerOrId , $ addressId , $ attributes ) ; return Util :: returnObjectOrThrowException ( __CLASS__ , $ result ) ; }
update an address record assuming validations will pass
9,309
private function _validateCustomerId ( $ id = null ) { if ( empty ( $ id ) || trim ( $ id ) == "" ) { throw new InvalidArgumentException ( 'expected customer id to be set' ) ; } if ( ! preg_match ( '/^[0-9A-Za-z_-]+$/' , $ id ) ) { throw new InvalidArgumentException ( $ id . ' is an invalid customer id.' ) ; } }
verifies that a valid customer id is being used
9,310
private function _determineCustomerId ( $ customerOrId ) { $ customerId = ( $ customerOrId instanceof Customer ) ? $ customerOrId -> id : $ customerOrId ; $ this -> _validateCustomerId ( $ customerId ) ; return $ customerId ; }
determines if a string id or Customer object was passed
9,311
private function _doCreate ( $ subPath , $ params ) { $ fullPath = $ this -> _config -> merchantPath ( ) . $ subPath ; $ response = $ this -> _http -> post ( $ fullPath , $ params ) ; return $ this -> _verifyGatewayResponse ( $ response ) ; }
sends the create request to the gateway
9,312
public function saleNoValidate ( $ attribs ) { $ result = $ this -> sale ( $ attribs ) ; return Util :: returnObjectOrThrowException ( __CLASS__ , $ result ) ; }
roughly equivalent to the ruby bang method
9,313
public static function generate ( $ settlement_date , $ groupByCustomField = NULL ) { return Configuration :: gateway ( ) -> settlementBatchSummary ( ) -> generate ( $ settlement_date , $ groupByCustomField ) ; }
static method redirecting to gateway
9,314
private function _getPage ( $ ids ) { $ object = $ this -> _pager [ 'object' ] ; $ method = $ this -> _pager [ 'method' ] ; $ methodArgs = [ ] ; foreach ( $ this -> _pager [ 'methodArgs' ] as $ arg ) { array_push ( $ methodArgs , $ arg ) ; } array_push ( $ methodArgs , $ ids ) ; return call_user_func_array ( [ $ object , $ method ] , $ methodArgs ) ; }
requests the next page of results for the collection
9,315
public function find ( $ idealPaymentId ) { try { $ path = $ this -> _config -> merchantPath ( ) . '/ideal_payments/' . $ idealPaymentId ; $ response = $ this -> _http -> get ( $ path ) ; return IdealPayment :: factory ( $ response [ 'idealPayment' ] ) ; } catch ( Exception \ NotFound $ e ) { throw new Exception \ NotFound ( 'iDEAL Payment with id ' . $ idealPaymentId . ' not found' ) ; } }
find an IdealPayment by id
9,316
public static function arrayFromXml ( $ xml ) { $ document = new DOMDocument ( '1.0' , 'UTF-8' ) ; $ document -> loadXML ( $ xml ) ; $ root = $ document -> documentElement -> nodeName ; return Util :: delimiterToCamelCaseArray ( [ $ root => self :: _nodeToValue ( $ document -> childNodes -> item ( 0 ) ) , ] ) ; }
Converts an XML string into a multidimensional array
9,317
private static function _nodeToArray ( $ node ) { $ type = null ; if ( $ node instanceof DOMElement ) { $ type = $ node -> getAttribute ( 'type' ) ; } switch ( $ type ) { case 'array' : $ array = [ ] ; foreach ( $ node -> childNodes as $ child ) { $ value = self :: _nodeToValue ( $ child ) ; if ( $ value !== null ) { $ array [ ] = $ value ; } } return $ array ; case 'collection' : $ collection = [ ] ; foreach ( $ node -> childNodes as $ child ) { $ value = self :: _nodetoValue ( $ child ) ; if ( $ value !== null ) { if ( ! isset ( $ collection [ $ child -> nodeName ] ) ) { $ collection [ $ child -> nodeName ] = [ ] ; } $ collection [ $ child -> nodeName ] [ ] = self :: _nodeToValue ( $ child ) ; } } return $ collection ; default : $ values = [ ] ; if ( $ node -> childNodes -> length === 1 && $ node -> childNodes -> item ( 0 ) instanceof DOMText ) { return $ node -> childNodes -> item ( 0 ) -> nodeValue ; } else { foreach ( $ node -> childNodes as $ child ) { if ( ! $ child instanceof DOMText ) { $ values [ $ child -> nodeName ] = self :: _nodeToValue ( $ child ) ; } } return $ values ; } } }
Converts a node to an array of values or nodes
9,318
private static function _nodeToValue ( $ node ) { $ type = null ; if ( $ node instanceof DOMElement ) { $ type = $ node -> getAttribute ( 'type' ) ; } switch ( $ type ) { case 'datetime' : return self :: _timestampToUTC ( ( string ) $ node -> nodeValue ) ; case 'date' : return new DateTime ( ( string ) $ node -> nodeValue ) ; case 'integer' : return ( int ) $ node -> nodeValue ; case 'boolean' : $ value = ( string ) $ node -> nodeValue ; if ( is_numeric ( $ value ) ) { return ( bool ) $ value ; } else { return ( $ value !== "true" ) ? false : true ; } case 'array' : case 'collection' : return self :: _nodeToArray ( $ node ) ; default : if ( $ node -> hasChildNodes ( ) ) { return self :: _nodeToArray ( $ node ) ; } elseif ( trim ( $ node -> nodeValue ) === '' ) { return null ; } else { return $ node -> nodeValue ; } } }
Converts a node to a PHP value
9,319
private static function _timestampToUTC ( $ timestamp ) { $ tz = new DateTimeZone ( 'UTC' ) ; $ dateTime = new DateTime ( $ timestamp , $ tz ) ; $ dateTime -> setTimezone ( $ tz ) ; return $ dateTime ; }
Converts XML timestamps into DateTime instances
9,320
public static function init ( ) { self :: $ _createCustomerSignature = [ self :: $ _transparentRedirectKeys , [ 'customer' => CustomerGateway :: createSignature ( ) ] , ] ; self :: $ _updateCustomerSignature = [ self :: $ _transparentRedirectKeys , 'customerId' , [ 'customer' => CustomerGateway :: updateSignature ( ) ] , ] ; self :: $ _transactionSignature = [ self :: $ _transparentRedirectKeys , [ 'transaction' => TransactionGateway :: createSignature ( ) ] , ] ; self :: $ _createCreditCardSignature = [ self :: $ _transparentRedirectKeys , [ 'creditCard' => CreditCardGateway :: createSignature ( ) ] , ] ; self :: $ _updateCreditCardSignature = [ self :: $ _transparentRedirectKeys , 'paymentMethodToken' , [ 'creditCard' => CreditCardGateway :: updateSignature ( ) ] , ] ; }
create signatures for different call types
9,321
public function createCreditCardData ( $ params ) { Util :: verifyKeys ( self :: $ _createCreditCardSignature , $ params ) ; $ params [ "kind" ] = TransparentRedirect :: CREATE_PAYMENT_METHOD ; return $ this -> _data ( $ params ) ; }
returns the trData string for creating a credit card
9,322
public function createCustomerData ( $ params ) { Util :: verifyKeys ( self :: $ _createCustomerSignature , $ params ) ; $ params [ "kind" ] = TransparentRedirect :: CREATE_CUSTOMER ; return $ this -> _data ( $ params ) ; }
returns the trData string for creating a customer .
9,323
public function transactionData ( $ params ) { Util :: verifyKeys ( self :: $ _transactionSignature , $ params ) ; $ params [ "kind" ] = TransparentRedirect :: CREATE_TRANSACTION ; $ transactionType = isset ( $ params [ 'transaction' ] [ 'type' ] ) ? $ params [ 'transaction' ] [ 'type' ] : null ; if ( $ transactionType != Transaction :: SALE && $ transactionType != Transaction :: CREDIT ) { throw new InvalidArgumentException ( 'expected transaction[type] of sale or credit, was: ' . $ transactionType ) ; } return $ this -> _data ( $ params ) ; }
returns the trData string for creating a transaction
9,324
public function updateCreditCardData ( $ params ) { Util :: verifyKeys ( self :: $ _updateCreditCardSignature , $ params ) ; if ( ! isset ( $ params [ 'paymentMethodToken' ] ) ) { throw new InvalidArgumentException ( 'expected params to contain paymentMethodToken.' ) ; } $ params [ "kind" ] = TransparentRedirect :: UPDATE_PAYMENT_METHOD ; return $ this -> _data ( $ params ) ; }
Returns the trData string for updating a credit card .
9,325
public function updateCustomerData ( $ params ) { Util :: verifyKeys ( self :: $ _updateCustomerSignature , $ params ) ; if ( ! isset ( $ params [ 'customerId' ] ) ) { throw new InvalidArgumentException ( 'expected params to contain customerId of customer to update' ) ; } $ params [ "kind" ] = TransparentRedirect :: UPDATE_CUSTOMER ; return $ this -> _data ( $ params ) ; }
Returns the trData string for updating a customer .
9,326
public function set ( $ index , $ value ) { if ( $ index >= $ this -> count ( ) ) throw new OutOfRangeException ( 'Index out of range' ) ; $ this -> _collection [ $ index ] = $ value ; }
Set index s value
9,327
public function remove ( $ index ) { if ( $ index >= $ this -> count ( ) ) throw new OutOfRangeException ( 'Index out of range' ) ; array_splice ( $ this -> _collection , $ index , 1 ) ; }
Remove a value from the collection
9,328
public function isEqual ( $ other ) { return ! ( $ other instanceof self ) ? false : ( $ this -> id === $ other -> id && $ this -> customerId === $ other -> customerId ) ; }
returns false if comparing object is not a Address or is a Address with a different id
9,329
public function find ( $ token ) { $ this -> _validateId ( $ token ) ; try { $ path = $ this -> _config -> merchantPath ( ) . '/payment_methods/paypal_account/' . $ token ; $ response = $ this -> _http -> get ( $ path ) ; return PayPalAccount :: factory ( $ response [ 'paypalAccount' ] ) ; } catch ( Exception \ NotFound $ e ) { throw new Exception \ NotFound ( 'paypal account with token ' . $ token . ' not found' ) ; } }
find a paypalAccount by token
9,330
public function update ( $ token , $ attributes ) { Util :: verifyKeys ( self :: updateSignature ( ) , $ attributes ) ; $ this -> _validateId ( $ token ) ; return $ this -> _doUpdate ( 'put' , '/payment_methods/paypal_account/' . $ token , [ 'paypalAccount' => $ attributes ] ) ; }
updates the paypalAccount record
9,331
public function sale ( $ token , $ transactionAttribs ) { $ this -> _validateId ( $ token ) ; return Transaction :: sale ( array_merge ( $ transactionAttribs , [ 'paymentMethodToken' => $ token ] ) ) ; }
create a new sale for the current PayPal account
9,332
private function _validateId ( $ identifier = null , $ identifierType = 'token' ) { if ( empty ( $ identifier ) ) { throw new InvalidArgumentException ( 'expected paypal account id to be set' ) ; } if ( ! preg_match ( '/^[0-9A-Za-z_-]+$/' , $ identifier ) ) { throw new InvalidArgumentException ( $ identifier . ' is an invalid paypal account ' . $ identifierType . '.' ) ; } }
verifies that a valid paypal account identifier is being used
9,333
public function addFileEvidence ( $ disputeId , $ documentIdOrRequest ) { $ request = is_array ( $ documentIdOrRequest ) ? $ documentIdOrRequest : [ 'documentId' => $ documentIdOrRequest ] ; if ( trim ( $ disputeId ) == "" ) { throw new Exception \ NotFound ( 'dispute with id "' . $ disputeId . '" not found' ) ; } if ( trim ( $ request [ 'documentId' ] ) == "" ) { throw new Exception \ NotFound ( 'document with id "' . $ request [ 'documentId' ] . '" not found' ) ; } try { if ( array_key_exists ( 'category' , $ request ) ) { if ( trim ( $ request [ 'category' ] ) == "" ) { throw new InvalidArgumentException ( 'category cannot be blank' ) ; } } $ request [ 'document_upload_id' ] = $ request [ 'documentId' ] ; unset ( $ request [ 'documentId' ] ) ; $ path = $ this -> _config -> merchantPath ( ) . '/disputes/' . $ disputeId . '/evidence' ; $ response = $ this -> _http -> post ( $ path , [ 'evidence' => $ request ] ) ; if ( isset ( $ response [ 'apiErrorResponse' ] ) ) { return new Result \ Error ( $ response [ 'apiErrorResponse' ] ) ; } if ( isset ( $ response [ 'evidence' ] ) ) { $ evidence = new Dispute \ EvidenceDetails ( $ response [ 'evidence' ] ) ; return new Result \ Successful ( $ evidence ) ; } } catch ( Exception \ NotFound $ e ) { throw new Exception \ NotFound ( 'dispute with id "' . $ disputeId . '" not found' ) ; } }
Adds file evidence to a dispute given a dispute ID and a document ID
9,334
public function addTextEvidence ( $ id , $ contentOrRequest ) { $ request = is_array ( $ contentOrRequest ) ? $ contentOrRequest : [ 'content' => $ contentOrRequest ] ; if ( trim ( $ request [ 'content' ] ) == "" ) { throw new InvalidArgumentException ( 'content cannot be blank' ) ; } try { $ evidence = [ 'comments' => $ request [ 'content' ] , ] ; if ( trim ( $ id ) == "" ) { throw new Exception \ NotFound ( ) ; } if ( array_key_exists ( 'tag' , $ request ) ) { $ evidence [ 'category' ] = $ request [ 'tag' ] ; } if ( array_key_exists ( 'category' , $ request ) ) { if ( trim ( $ request [ 'category' ] ) == "" ) { throw new InvalidArgumentException ( 'category cannot be blank' ) ; } $ evidence [ 'category' ] = $ request [ 'category' ] ; } if ( array_key_exists ( 'sequenceNumber' , $ request ) ) { if ( trim ( $ request [ 'sequenceNumber' ] ) == "" ) { throw new InvalidArgumentException ( 'sequenceNumber cannot be blank' ) ; } else if ( ( string ) ( int ) ( $ request [ 'sequenceNumber' ] ) != $ request [ 'sequenceNumber' ] ) { throw new InvalidArgumentException ( 'sequenceNumber must be an integer' ) ; } $ evidence [ 'sequenceNumber' ] = ( int ) $ request [ 'sequenceNumber' ] ; } $ path = $ this -> _config -> merchantPath ( ) . '/disputes/' . $ id . '/evidence' ; $ response = $ this -> _http -> post ( $ path , [ 'evidence' => $ evidence ] ) ; if ( isset ( $ response [ 'apiErrorResponse' ] ) ) { return new Result \ Error ( $ response [ 'apiErrorResponse' ] ) ; } if ( isset ( $ response [ 'evidence' ] ) ) { $ evidence = new Dispute \ EvidenceDetails ( $ response [ 'evidence' ] ) ; return new Result \ Successful ( $ evidence ) ; } } catch ( Exception \ NotFound $ e ) { throw new Exception \ NotFound ( 'dispute with id "' . $ id . '" not found' ) ; } }
Adds text evidence to a dispute given a dispute ID and content
9,335
public function finalize ( $ id ) { try { if ( trim ( $ id ) == "" ) { throw new Exception \ NotFound ( ) ; } $ path = $ this -> _config -> merchantPath ( ) . '/disputes/' . $ id . '/finalize' ; $ response = $ this -> _http -> put ( $ path ) ; if ( isset ( $ response [ 'apiErrorResponse' ] ) ) { return new Result \ Error ( $ response [ 'apiErrorResponse' ] ) ; } return new Result \ Successful ( ) ; } catch ( Exception \ NotFound $ e ) { throw new Exception \ NotFound ( 'dispute with id "' . $ id . '" not found' ) ; } }
Finalize a dispute given a dispute ID
9,336
public function find ( $ id ) { if ( trim ( $ id ) == "" ) { throw new Exception \ NotFound ( 'dispute with id "' . $ id . '" not found' ) ; } try { $ path = $ this -> _config -> merchantPath ( ) . '/disputes/' . $ id ; $ response = $ this -> _http -> get ( $ path ) ; return Dispute :: factory ( $ response [ 'dispute' ] ) ; } catch ( Exception \ NotFound $ e ) { throw new Exception \ NotFound ( 'dispute with id "' . $ id . '" not found' ) ; } }
Find a dispute given a dispute ID
9,337
public function removeEvidence ( $ disputeId , $ evidenceId ) { try { if ( trim ( $ disputeId ) == "" || trim ( $ evidenceId ) == "" ) { throw new Exception \ NotFound ( ) ; } $ path = $ this -> _config -> merchantPath ( ) . '/disputes/' . $ disputeId . '/evidence/' . $ evidenceId ; $ response = $ this -> _http -> delete ( $ path ) ; if ( isset ( $ response [ 'apiErrorResponse' ] ) ) { return new Result \ Error ( $ response [ 'apiErrorResponse' ] ) ; } return new Result \ Successful ( ) ; } catch ( Exception \ NotFound $ e ) { throw new Exception \ NotFound ( 'evidence with id "' . $ evidenceId . '" for dispute with id "' . $ disputeId . '" not found' ) ; } }
Remove evidence from a dispute given a dispute ID and evidence ID
9,338
public function search ( $ query ) { $ criteria = [ ] ; foreach ( $ query as $ term ) { $ criteria [ $ term -> name ] = $ term -> toparam ( ) ; } $ pager = [ 'object' => $ this , 'method' => 'fetchDisputes' , 'query' => $ criteria ] ; return new PaginatedCollection ( $ pager ) ; }
Search for Disputes given a DisputeSearch query
9,339
public function rewind ( ) { $ this -> _index = 0 ; $ this -> _currentPage = 0 ; $ this -> _pageSize = 0 ; $ this -> _totalItems = 0 ; $ this -> _items = [ ] ; }
rewinds the collection to the first item when iterating with foreach
9,340
public static function timeout ( $ value = null ) { if ( empty ( $ value ) ) { return self :: $ global -> getTimeout ( ) ; } self :: $ global -> setTimeout ( $ value ) ; }
Sets or gets the read timeout to use for making requests .
9,341
public static function proxyHost ( $ value = null ) { if ( empty ( $ value ) ) { return self :: $ global -> getProxyHost ( ) ; } self :: $ global -> setProxyHost ( $ value ) ; }
Sets or gets the proxy host to use for connecting to Braintree
9,342
public static function proxyPort ( $ value = null ) { if ( empty ( $ value ) ) { return self :: $ global -> getProxyPort ( ) ; } self :: $ global -> setProxyPort ( $ value ) ; }
Sets or gets the port of the proxy to use for connecting to Braintree
9,343
public static function proxyType ( $ value = null ) { if ( empty ( $ value ) ) { return self :: $ global -> getProxyType ( ) ; } self :: $ global -> setProxyType ( $ value ) ; }
Sets or gets the proxy type to use for connecting to Braintree . This value can be any of the CURLOPT_PROXYTYPE options in PHP cURL .
9,344
public static function isUsingProxy ( ) { $ proxyHost = self :: $ global -> getProxyHost ( ) ; $ proxyPort = self :: $ global -> getProxyPort ( ) ; return ! empty ( $ proxyHost ) && ! empty ( $ proxyPort ) ; }
Specifies whether or not a proxy is properly configured
9,345
public static function isAuthenticatedProxy ( ) { $ proxyUser = self :: $ global -> getProxyUser ( ) ; $ proxyPwd = self :: $ global -> getProxyPassword ( ) ; return ! empty ( $ proxyUser ) && ! empty ( $ proxyPwd ) ; }
Specified whether or not a username and password have been provided for use with an authenticated proxy
9,346
public static function acceptGzipEncoding ( $ value = null ) { if ( is_null ( $ value ) ) { return self :: $ global -> getAcceptGzipEncoding ( ) ; } self :: $ global -> setAcceptGzipEncoding ( $ value ) ; }
Specify if the HTTP client is able to decode gzipped responses .
9,347
public function caFile ( $ sslPath = NULL ) { $ sslPath = $ sslPath ? $ sslPath : DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'ssl' . DIRECTORY_SEPARATOR ; $ caPath = __DIR__ . $ sslPath . 'api_braintreegateway_com.ca.crt' ; if ( ! file_exists ( $ caPath ) ) { throw new Exception \ SSLCaFileNotFound ( ) ; } return $ caPath ; }
sets the physical path for the location of the CA certs
9,348
protected function getSqlQuery ( $ name , array $ vars = array ( ) ) { $ sql = $ this -> sqlQueries [ $ name ] ; $ vars = array_merge ( array ( 'tablename' => $ this -> tableName ) , $ vars ) ; foreach ( $ vars as $ k => $ v ) { $ sql = str_replace ( "%$k%" , $ v , $ sql ) ; } return $ sql ; }
Get a SQL Query for a task with the variables replaced
9,349
public function addThrowable ( $ e ) { $ this -> exceptions [ ] = $ e ; if ( $ this -> chainExceptions && $ previous = $ e -> getPrevious ( ) ) { $ this -> addThrowable ( $ previous ) ; } }
Adds a Throwable to be profiled in the debug bar
9,350
public function formatThrowableData ( $ e ) { $ filePath = $ e -> getFile ( ) ; if ( $ filePath && file_exists ( $ filePath ) ) { $ lines = file ( $ filePath ) ; $ start = $ e -> getLine ( ) - 4 ; $ lines = array_slice ( $ lines , $ start < 0 ? 0 : $ start , 7 ) ; } else { $ lines = array ( "Cannot open the file ($filePath) in which the exception occurred " ) ; } return array ( 'type' => get_class ( $ e ) , 'message' => $ e -> getMessage ( ) , 'code' => $ e -> getCode ( ) , 'file' => $ filePath , 'line' => $ e -> getLine ( ) , 'stack_trace' => $ e -> getTraceAsString ( ) , 'surrounding_lines' => $ lines , 'xdebug_link' => $ this -> getXdebugLink ( $ filePath , $ e -> getLine ( ) ) ) ; }
Returns Throwable data as an array
9,351
protected function memcachedGetMulti ( $ keys , $ flags ) { if ( $ this -> newGetMultiSignature === null ) { $ this -> newGetMultiSignature = ( new ReflectionMethod ( 'Memcached' , 'getMulti' ) ) -> getNumberOfParameters ( ) === 2 ; } if ( $ this -> newGetMultiSignature ) { return $ this -> memcached -> getMulti ( $ keys , $ flags ) ; } else { $ null = null ; return $ this -> memcached -> getMulti ( $ keys , $ null , $ flags ) ; } }
The memcached getMulti function changed in version 3 . 0 . 0 to only have two parameters .
9,352
public function setRenderSqlWithParams ( $ enabled = true , $ quotationChar = '<>' ) { $ this -> renderSqlWithParams = $ enabled ; $ this -> sqlQuotationChar = $ quotationChar ; }
Renders the SQL of traced statements with params embeded
9,353
public function addConnection ( TraceablePDO $ pdo , $ name = null ) { if ( $ name === null ) { $ name = spl_object_hash ( $ pdo ) ; } $ this -> connections [ $ name ] = $ pdo ; }
Adds a new PDO instance to be collector
9,354
protected function collectPDO ( TraceablePDO $ pdo , TimeDataCollector $ timeCollector = null , $ connectionName = null ) { if ( empty ( $ connectionName ) || $ connectionName == 'default' ) { $ connectionName = 'pdo' ; } else { $ connectionName = 'pdo ' . $ connectionName ; } $ stmts = array ( ) ; foreach ( $ pdo -> getExecutedStatements ( ) as $ stmt ) { $ stmts [ ] = array ( 'sql' => $ this -> renderSqlWithParams ? $ stmt -> getSqlWithParams ( $ this -> sqlQuotationChar ) : $ stmt -> getSql ( ) , 'row_count' => $ stmt -> getRowCount ( ) , 'stmt_id' => $ stmt -> getPreparedId ( ) , 'prepared_stmt' => $ stmt -> getSql ( ) , 'params' => ( object ) $ stmt -> getParameters ( ) , 'duration' => $ stmt -> getDuration ( ) , 'duration_str' => $ this -> getDataFormatter ( ) -> formatDuration ( $ stmt -> getDuration ( ) ) , 'memory' => $ stmt -> getMemoryUsage ( ) , 'memory_str' => $ this -> getDataFormatter ( ) -> formatBytes ( $ stmt -> getMemoryUsage ( ) ) , 'end_memory' => $ stmt -> getEndMemory ( ) , 'end_memory_str' => $ this -> getDataFormatter ( ) -> formatBytes ( $ stmt -> getEndMemory ( ) ) , 'is_success' => $ stmt -> isSuccess ( ) , 'error_code' => $ stmt -> getErrorCode ( ) , 'error_message' => $ stmt -> getErrorMessage ( ) ) ; if ( $ timeCollector !== null ) { $ timeCollector -> addMeasure ( $ stmt -> getSql ( ) , $ stmt -> getStartTime ( ) , $ stmt -> getEndTime ( ) , array ( ) , $ connectionName ) ; } } return array ( 'nb_statements' => count ( $ stmts ) , 'nb_failed_statements' => count ( $ pdo -> getFailedExecutedStatements ( ) ) , 'accumulated_duration' => $ pdo -> getAccumulatedStatementsDuration ( ) , 'accumulated_duration_str' => $ this -> getDataFormatter ( ) -> formatDuration ( $ pdo -> getAccumulatedStatementsDuration ( ) ) , 'memory_usage' => $ pdo -> getMemoryUsage ( ) , 'memory_usage_str' => $ this -> getDataFormatter ( ) -> formatBytes ( $ pdo -> getPeakMemoryUsage ( ) ) , 'peak_memory_usage' => $ pdo -> getPeakMemoryUsage ( ) , 'peak_memory_usage_str' => $ this -> getDataFormatter ( ) -> formatBytes ( $ pdo -> getPeakMemoryUsage ( ) ) , 'statements' => $ stmts ) ; }
Collects data from a single TraceablePDO instance
9,355
protected function getCloner ( ) { if ( ! $ this -> cloner ) { $ clonerOptions = $ this -> getClonerOptions ( ) ; if ( isset ( $ clonerOptions [ 'casters' ] ) ) { $ this -> cloner = new VarCloner ( $ clonerOptions [ 'casters' ] ) ; } else { $ this -> cloner = new VarCloner ( ) ; } if ( isset ( $ clonerOptions [ 'additional_casters' ] ) ) { $ this -> cloner -> addCasters ( $ clonerOptions [ 'additional_casters' ] ) ; } if ( isset ( $ clonerOptions [ 'max_items' ] ) ) { $ this -> cloner -> setMaxItems ( $ clonerOptions [ 'max_items' ] ) ; } if ( isset ( $ clonerOptions [ 'max_string' ] ) ) { $ this -> cloner -> setMaxString ( $ clonerOptions [ 'max_string' ] ) ; } if ( isset ( $ clonerOptions [ 'min_depth' ] ) && method_exists ( $ this -> cloner , 'setMinDepth' ) ) { $ this -> cloner -> setMinDepth ( $ clonerOptions [ 'min_depth' ] ) ; } } return $ this -> cloner ; }
Gets the VarCloner instance with configuration options set .
9,356
protected function getDumper ( ) { if ( ! $ this -> dumper ) { $ this -> dumper = new DebugBarHtmlDumper ( ) ; $ dumperOptions = $ this -> getDumperOptions ( ) ; if ( isset ( $ dumperOptions [ 'styles' ] ) ) { $ this -> dumper -> setStyles ( $ dumperOptions [ 'styles' ] ) ; } } return $ this -> dumper ; }
Gets the DebugBarHtmlDumper instance with configuration options set .
9,357
public function getClonerOptions ( ) { if ( $ this -> clonerOptions === null ) { $ this -> clonerOptions = self :: $ defaultClonerOptions ; } return $ this -> clonerOptions ; }
Gets the array of non - default VarCloner configuration options .
9,358
public function mergeClonerOptions ( $ options ) { $ this -> clonerOptions = $ options + $ this -> getClonerOptions ( ) ; $ this -> cloner = null ; }
Merges an array of non - default VarCloner configuration options with the existing non - default options .
9,359
public function resetClonerOptions ( $ options = null ) { $ this -> clonerOptions = ( $ options ? : array ( ) ) + self :: $ defaultClonerOptions ; $ this -> cloner = null ; }
Resets the array of non - default VarCloner configuration options without retaining any of the existing non - default options .
9,360
public function getDumperOptions ( ) { if ( $ this -> dumperOptions === null ) { $ this -> dumperOptions = self :: $ defaultDumperOptions ; } return $ this -> dumperOptions ; }
Gets the array of non - default HtmlDumper configuration options .
9,361
public function mergeDumperOptions ( $ options ) { $ this -> dumperOptions = $ options + $ this -> getDumperOptions ( ) ; $ this -> dumper = null ; }
Merges an array of non - default HtmlDumper configuration options with the existing non - default options .
9,362
public function resetDumperOptions ( $ options = null ) { $ this -> dumperOptions = ( $ options ? : array ( ) ) + self :: $ defaultDumperOptions ; $ this -> dumper = null ; }
Resets the array of non - default HtmlDumper configuration options without retaining any of the existing non - default options .
9,363
protected function getDisplayOptions ( ) { $ displayOptions = array ( ) ; $ dumperOptions = $ this -> getDumperOptions ( ) ; if ( isset ( $ dumperOptions [ 'expanded_depth' ] ) ) { $ displayOptions [ 'maxDepth' ] = $ dumperOptions [ 'expanded_depth' ] ; } if ( isset ( $ dumperOptions [ 'max_string' ] ) ) { $ displayOptions [ 'maxStringLength' ] = $ dumperOptions [ 'max_string' ] ; } if ( isset ( $ dumperOptions [ 'file_link_format' ] ) ) { $ displayOptions [ 'fileLinkFormat' ] = $ dumperOptions [ 'file_link_format' ] ; } return $ displayOptions ; }
Gets the display options for the HTML dumper .
9,364
public function renderCapturedVar ( $ capturedData , $ seekPath = array ( ) ) { $ data = unserialize ( $ capturedData ) ; if ( ! method_exists ( $ data , 'seek' ) ) { $ data = new SeekingData ( $ data -> getRawData ( ) ) ; } foreach ( $ seekPath as $ key ) { $ data = $ data -> seek ( $ key ) ; } return $ this -> dump ( $ data ) ; }
Renders previously - captured data from captureVar to HTML and returns it as a string .
9,365
protected function dump ( Data $ data ) { $ dumper = $ this -> getDumper ( ) ; $ output = fopen ( 'php://memory' , 'r+b' ) ; $ dumper -> setOutput ( $ output ) ; $ dumper -> setDumpHeader ( '' ) ; $ dumper -> dump ( $ data , null , $ this -> getDisplayOptions ( ) ) ; $ result = stream_get_contents ( $ output , - 1 , 0 ) ; fclose ( $ output ) ; return $ result ; }
Helper function to dump a Data object to HTML .
9,366
public function getVarDumper ( ) { if ( $ this -> varDumper === null ) { $ this -> varDumper = DataCollector :: getDefaultVarDumper ( ) ; } return $ this -> varDumper ; }
Gets the variable dumper instance used by this collector
9,367
protected function sort ( $ data ) { if ( is_string ( $ this -> sort ) ) { $ p = $ this -> sort ; usort ( $ data , function ( $ a , $ b ) use ( $ p ) { if ( $ a [ $ p ] == $ b [ $ p ] ) { return 0 ; } return $ a [ $ p ] < $ b [ $ p ] ? - 1 : 1 ; } ) ; } elseif ( $ this -> sort === true ) { sort ( $ data ) ; } return $ data ; }
Sorts the collected data
9,368
public function setOptions ( array $ options ) { if ( array_key_exists ( 'base_path' , $ options ) ) { $ this -> setBasePath ( $ options [ 'base_path' ] ) ; } if ( array_key_exists ( 'base_url' , $ options ) ) { $ this -> setBaseUrl ( $ options [ 'base_url' ] ) ; } if ( array_key_exists ( 'include_vendors' , $ options ) ) { $ this -> setIncludeVendors ( $ options [ 'include_vendors' ] ) ; } if ( array_key_exists ( 'javascript_class' , $ options ) ) { $ this -> setJavascriptClass ( $ options [ 'javascript_class' ] ) ; } if ( array_key_exists ( 'variable_name' , $ options ) ) { $ this -> setVariableName ( $ options [ 'variable_name' ] ) ; } if ( array_key_exists ( 'initialization' , $ options ) ) { $ this -> setInitialization ( $ options [ 'initialization' ] ) ; } if ( array_key_exists ( 'enable_jquery_noconflict' , $ options ) ) { $ this -> setEnableJqueryNoConflict ( $ options [ 'enable_jquery_noconflict' ] ) ; } if ( array_key_exists ( 'use_requirejs' , $ options ) ) { $ this -> setUseRequireJs ( $ options [ 'use_requirejs' ] ) ; } if ( array_key_exists ( 'controls' , $ options ) ) { foreach ( $ options [ 'controls' ] as $ name => $ control ) { $ this -> addControl ( $ name , $ control ) ; } } if ( array_key_exists ( 'disable_controls' , $ options ) ) { foreach ( ( array ) $ options [ 'disable_controls' ] as $ name ) { $ this -> disableControl ( $ name ) ; } } if ( array_key_exists ( 'ignore_collectors' , $ options ) ) { foreach ( ( array ) $ options [ 'ignore_collectors' ] as $ name ) { $ this -> ignoreCollector ( $ name ) ; } } if ( array_key_exists ( 'ajax_handler_classname' , $ options ) ) { $ this -> setAjaxHandlerClass ( $ options [ 'ajax_handler_classname' ] ) ; } if ( array_key_exists ( 'ajax_handler_bind_to_jquery' , $ options ) ) { $ this -> setBindAjaxHandlerToJquery ( $ options [ 'ajax_handler_bind_to_jquery' ] ) ; } if ( array_key_exists ( 'ajax_handler_auto_show' , $ options ) ) { $ this -> setAjaxHandlerAutoShow ( $ options [ 'ajax_handler_auto_show' ] ) ; } if ( array_key_exists ( 'open_handler_classname' , $ options ) ) { $ this -> setOpenHandlerClass ( $ options [ 'open_handler_classname' ] ) ; } if ( array_key_exists ( 'open_handler_url' , $ options ) ) { $ this -> setOpenHandlerUrl ( $ options [ 'open_handler_url' ] ) ; } }
Sets options from an array
9,369
public function setIncludeVendors ( $ enabled = true ) { if ( is_string ( $ enabled ) ) { $ enabled = array ( $ enabled ) ; } $ this -> includeVendors = $ enabled ; if ( ! $ enabled || ( is_array ( $ enabled ) && ! in_array ( 'js' , $ enabled ) ) ) { $ this -> enableJqueryNoConflict = false ; } return $ this ; }
Whether to include vendor assets
9,370
public function disableVendor ( $ name ) { if ( array_key_exists ( $ name , $ this -> cssVendors ) ) { unset ( $ this -> cssVendors [ $ name ] ) ; } if ( array_key_exists ( $ name , $ this -> jsVendors ) ) { unset ( $ this -> jsVendors [ $ name ] ) ; } }
Disable a specific vendor s assets .
9,371
public function addControl ( $ name , array $ options ) { if ( count ( array_intersect ( array_keys ( $ options ) , array ( 'icon' , 'widget' , 'tab' , 'indicator' ) ) ) === 0 ) { throw new DebugBarException ( "Not enough options for control '$name'" ) ; } $ this -> controls [ $ name ] = $ options ; return $ this ; }
Adds a control to initialize
9,372
public function addAssets ( $ cssFiles , $ jsFiles , $ basePath = null , $ baseUrl = null ) { $ this -> additionalAssets [ ] = array ( 'base_path' => $ basePath , 'base_url' => $ baseUrl , 'css' => ( array ) $ cssFiles , 'js' => ( array ) $ jsFiles ) ; return $ this ; }
Add assets stored in files to render in the head
9,373
public function addInlineAssets ( $ inlineCss , $ inlineJs , $ inlineHead ) { $ this -> additionalAssets [ ] = array ( 'inline_css' => ( array ) $ inlineCss , 'inline_js' => ( array ) $ inlineJs , 'inline_head' => ( array ) $ inlineHead ) ; return $ this ; }
Add inline assets to render inline in the head . Ideally you should store static assets in files that you add with the addAssets function . However adding inline assets is useful when integrating with 3rd - party libraries that require static assets that are only available in an inline format .
9,374
protected function getRelativeRoot ( $ relativeTo , $ basePath , $ baseUrl ) { if ( $ relativeTo === self :: RELATIVE_PATH ) { return $ basePath ; } if ( $ relativeTo === self :: RELATIVE_URL ) { return $ baseUrl ; } return null ; }
Returns the correct base according to the type
9,375
protected function createAsseticCollection ( $ files = null , $ content = null ) { $ assets = array ( ) ; if ( $ files ) { foreach ( $ files as $ file ) { $ assets [ ] = new \ Assetic \ Asset \ FileAsset ( $ file ) ; } } if ( $ content ) { foreach ( $ content as $ item ) { $ assets [ ] = new \ Assetic \ Asset \ StringAsset ( $ item ) ; } } return new \ Assetic \ Asset \ AssetCollection ( $ assets ) ; }
Create an Assetic AssetCollection with the given content . Filenames will be converted to absolute path using the base path .
9,376
public function dumpCssAssets ( $ targetFilename = null ) { $ this -> dumpAssets ( $ this -> getAssets ( 'css' ) , $ this -> getAssets ( 'inline_css' ) , $ targetFilename ) ; }
Write all CSS assets to standard output or in a file
9,377
public function dumpJsAssets ( $ targetFilename = null ) { $ this -> dumpAssets ( $ this -> getAssets ( 'js' ) , $ this -> getAssets ( 'inline_js' ) , $ targetFilename , $ this -> useRequireJs ) ; }
Write all JS assets to standard output or in a file
9,378
public function renderOnShutdown ( $ here = true , $ initialize = true , $ renderStackedData = true , $ head = false ) { register_shutdown_function ( array ( $ this , "replaceTagInBuffer" ) , $ here , $ initialize , $ renderStackedData , $ head ) ; if ( ob_get_level ( ) === 0 ) { ob_start ( ) ; } return ( $ here ) ? self :: REPLACEABLE_TAG : "" ; }
Register shutdown to display the debug bar
9,379
public function render ( $ initialize = true , $ renderStackedData = true ) { $ js = '' ; if ( $ initialize ) { $ js = $ this -> getJsInitializationCode ( ) ; } if ( $ renderStackedData && $ this -> debugBar -> hasStackedData ( ) ) { foreach ( $ this -> debugBar -> getStackedData ( ) as $ id => $ data ) { $ js .= $ this -> getAddDatasetCode ( $ id , $ data , '(stacked)' ) ; } } $ suffix = ! $ initialize ? '(ajax)' : null ; $ js .= $ this -> getAddDatasetCode ( $ this -> debugBar -> getCurrentRequestId ( ) , $ this -> debugBar -> getData ( ) , $ suffix ) ; if ( $ this -> useRequireJs ) { return "<script type=\"text/javascript\">\nrequire(['debugbar'], function(PhpDebugBar){ $js });\n</script>\n" ; } else { return "<script type=\"text/javascript\">\n$js\n</script>\n" ; } }
Returns the code needed to display the debug bar
9,380
protected function getJsControlsDefinitionCode ( $ varname ) { $ js = '' ; $ dataMap = array ( ) ; $ excludedOptions = array ( 'indicator' , 'tab' , 'map' , 'default' , 'widget' , 'position' ) ; $ widgets = array ( ) ; foreach ( $ this -> debugBar -> getCollectors ( ) as $ collector ) { if ( ( $ collector instanceof Renderable ) && ! in_array ( $ collector -> getName ( ) , $ this -> ignoredCollectors ) ) { if ( $ w = $ collector -> getWidgets ( ) ) { $ widgets = array_merge ( $ widgets , $ w ) ; } } } $ controls = array_merge ( $ widgets , $ this -> controls ) ; foreach ( array_filter ( $ controls ) as $ name => $ options ) { $ opts = array_diff_key ( $ options , array_flip ( $ excludedOptions ) ) ; if ( isset ( $ options [ 'tab' ] ) || isset ( $ options [ 'widget' ] ) ) { if ( ! isset ( $ opts [ 'title' ] ) ) { $ opts [ 'title' ] = ucfirst ( str_replace ( '_' , ' ' , $ name ) ) ; } $ js .= sprintf ( "%s.addTab(\"%s\", new %s({%s%s}));\n" , $ varname , $ name , isset ( $ options [ 'tab' ] ) ? $ options [ 'tab' ] : 'PhpDebugBar.DebugBar.Tab' , substr ( json_encode ( $ opts , JSON_FORCE_OBJECT ) , 1 , - 1 ) , isset ( $ options [ 'widget' ] ) ? sprintf ( '%s"widget": new %s()' , count ( $ opts ) ? ', ' : '' , $ options [ 'widget' ] ) : '' ) ; } elseif ( isset ( $ options [ 'indicator' ] ) || isset ( $ options [ 'icon' ] ) ) { $ js .= sprintf ( "%s.addIndicator(\"%s\", new %s(%s), \"%s\");\n" , $ varname , $ name , isset ( $ options [ 'indicator' ] ) ? $ options [ 'indicator' ] : 'PhpDebugBar.DebugBar.Indicator' , json_encode ( $ opts , JSON_FORCE_OBJECT ) , isset ( $ options [ 'position' ] ) ? $ options [ 'position' ] : 'right' ) ; } if ( isset ( $ options [ 'map' ] ) && isset ( $ options [ 'default' ] ) ) { $ dataMap [ $ name ] = array ( $ options [ 'map' ] , $ options [ 'default' ] ) ; } } $ mapJson = array ( ) ; foreach ( $ dataMap as $ name => $ values ) { $ mapJson [ ] = sprintf ( '"%s": ["%s", %s]' , $ name , $ values [ 0 ] , $ values [ 1 ] ) ; } $ js .= sprintf ( "%s.setDataMap({\n%s\n});\n" , $ varname , implode ( ",\n" , $ mapJson ) ) ; $ js .= sprintf ( "%s.restoreState();\n" , $ varname ) ; return $ js ; }
Returns the js code needed to initialized the controls and data mapping of the debug bar
9,381
protected function getAddDatasetCode ( $ requestId , $ data , $ suffix = null ) { $ js = sprintf ( "%s.addDataSet(%s, \"%s\"%s);\n" , $ this -> variableName , json_encode ( $ data ) , $ requestId , $ suffix ? ", " . json_encode ( $ suffix ) : '' ) ; return $ js ; }
Returns the js code needed to add a dataset
9,382
public static function enablePropelProfiling ( PropelConfiguration $ config = null ) { if ( $ config === null ) { $ config = Propel :: getConfiguration ( PropelConfiguration :: TYPE_OBJECT ) ; } $ config -> setParameter ( 'debugpdo.logging.details.method.enabled' , true ) ; $ config -> setParameter ( 'debugpdo.logging.details.time.enabled' , true ) ; $ config -> setParameter ( 'debugpdo.logging.details.mem.enabled' , true ) ; $ allMethods = array ( 'PropelPDO::__construct' , 'PropelPDO::__destruct' , 'PropelPDO::exec' , 'PropelPDO::query' , 'PropelPDO::beginTransaction' , 'PropelPDO::commit' , 'PropelPDO::rollBack' , 'DebugPDOStatement::execute' , ) ; $ config -> setParameter ( 'debugpdo.logging.methods' , $ allMethods , false ) ; }
Sets the needed configuration option in propel to enable query logging
9,383
public function handle ( $ request = null , $ echo = true , $ sendHeader = true ) { if ( $ request === null ) { $ request = $ _REQUEST ; } $ op = 'find' ; if ( isset ( $ request [ 'op' ] ) ) { $ op = $ request [ 'op' ] ; if ( ! in_array ( $ op , array ( 'find' , 'get' , 'clear' ) ) ) { throw new DebugBarException ( "Invalid operation '{$request['op']}'" ) ; } } if ( $ sendHeader ) { $ this -> debugBar -> getHttpDriver ( ) -> setHeaders ( array ( 'Content-Type' => 'application/json' ) ) ; } $ response = json_encode ( call_user_func ( array ( $ this , $ op ) , $ request ) ) ; if ( $ echo ) { echo $ response ; } return $ response ; }
Handles the current request
9,384
public function getVarDumper ( ) { if ( $ this -> varDumper === null ) { $ this -> varDumper = self :: getDefaultVarDumper ( ) ; } return $ this -> varDumper ; }
Gets the variable dumper instance used by this collector ; note that collectors using this instance need to be sure to return the static assets provided by the variable dumper .
9,385
public function getCollector ( $ name ) { if ( ! isset ( $ this -> collectors [ $ name ] ) ) { throw new DebugBarException ( "'$name' is not a registered collector" ) ; } return $ this -> collectors [ $ name ] ; }
Returns a data collector
9,386
public function getCurrentRequestId ( ) { if ( $ this -> requestId === null ) { $ this -> requestId = $ this -> getRequestIdGenerator ( ) -> generate ( ) ; } return $ this -> requestId ; }
Returns the id of the current request
9,387
public function getDataAsHeaders ( $ headerName = 'phpdebugbar' , $ maxHeaderLength = 4096 , $ maxTotalHeaderLength = 250000 ) { $ data = rawurlencode ( json_encode ( array ( 'id' => $ this -> getCurrentRequestId ( ) , 'data' => $ this -> getData ( ) ) ) ) ; if ( strlen ( $ data ) > $ maxTotalHeaderLength ) { $ data = rawurlencode ( json_encode ( array ( 'error' => 'Maximum header size exceeded' ) ) ) ; } $ chunks = array ( ) ; while ( strlen ( $ data ) > $ maxHeaderLength ) { $ chunks [ ] = substr ( $ data , 0 , $ maxHeaderLength ) ; $ data = substr ( $ data , $ maxHeaderLength ) ; } $ chunks [ ] = $ data ; $ headers = array ( ) ; for ( $ i = 0 , $ c = count ( $ chunks ) ; $ i < $ c ; $ i ++ ) { $ name = $ headerName . ( $ i > 0 ? "-$i" : '' ) ; $ headers [ $ name ] = $ chunks [ $ i ] ; } return $ headers ; }
Returns an array of HTTP headers containing the data
9,388
public function sendDataInHeaders ( $ useOpenHandler = null , $ headerName = 'phpdebugbar' , $ maxHeaderLength = 4096 ) { if ( $ useOpenHandler === null ) { $ useOpenHandler = self :: $ useOpenHandlerWhenSendingDataHeaders ; } if ( $ useOpenHandler && $ this -> storage !== null ) { $ this -> getData ( ) ; $ headerName .= '-id' ; $ headers = array ( $ headerName => $ this -> getCurrentRequestId ( ) ) ; } else { $ headers = $ this -> getDataAsHeaders ( $ headerName , $ maxHeaderLength ) ; } $ this -> getHttpDriver ( ) -> setHeaders ( $ headers ) ; return $ this ; }
Sends the data through the HTTP headers
9,389
public function stackData ( ) { $ http = $ this -> initStackSession ( ) ; $ data = null ; if ( ! $ this -> isDataPersisted ( ) || $ this -> stackAlwaysUseSessionStorage ) { $ data = $ this -> getData ( ) ; } elseif ( $ this -> data === null ) { $ this -> collect ( ) ; } $ stack = $ http -> getSessionValue ( $ this -> stackSessionNamespace ) ; $ stack [ $ this -> getCurrentRequestId ( ) ] = $ data ; $ http -> setSessionValue ( $ this -> stackSessionNamespace , $ stack ) ; return $ this ; }
Stacks the data in the session for later rendering
9,390
public function hasStackedData ( ) { try { $ http = $ this -> initStackSession ( ) ; } catch ( DebugBarException $ e ) { return false ; } return count ( $ http -> getSessionValue ( $ this -> stackSessionNamespace ) ) > 0 ; }
Checks if there is stacked data in the session
9,391
public function getStackedData ( $ delete = true ) { $ http = $ this -> initStackSession ( ) ; $ stackedData = $ http -> getSessionValue ( $ this -> stackSessionNamespace ) ; if ( $ delete ) { $ http -> deleteSessionValue ( $ this -> stackSessionNamespace ) ; } $ datasets = array ( ) ; if ( $ this -> isDataPersisted ( ) && ! $ this -> stackAlwaysUseSessionStorage ) { foreach ( $ stackedData as $ id => $ data ) { $ datasets [ $ id ] = $ this -> getStorage ( ) -> get ( $ id ) ; } } else { $ datasets = $ stackedData ; } return $ datasets ; }
Returns the data stacked in the session
9,392
public static function create ( ContainerInterface $ container , Request $ request = null ) { if ( ! isset ( $ request ) ) { $ request = $ container [ 'request' ] ; } $ view = new Smarty ( __DIR__ . '/../templates/' ) ; if ( in_array ( 'https' , $ request -> getHeader ( 'X-Forwarded-Proto' ) ) ) { $ request = $ request -> withUri ( $ request -> getUri ( ) -> withScheme ( 'https' ) -> withPort ( 443 ) ) ; } $ smartyPlugins = new SmartyPlugins ( $ container [ 'router' ] , $ request -> getUri ( ) -> withUserInfo ( null ) ) ; $ view -> registerPlugin ( 'function' , 'path_for' , [ $ smartyPlugins , 'pathFor' ] ) ; $ view -> registerPlugin ( 'function' , 'base_url' , [ $ smartyPlugins , 'baseUrl' ] ) ; return $ view ; }
Create Smarty view object .
9,393
private static function getProcess ( array $ arguments ) { $ config = Config :: getInstance ( ) ; return new Process ( array_merge ( [ $ config -> python , $ config -> youtubedl ] , $ config -> params , $ arguments ) ) ; }
Return a youtube - dl process with the specified arguments .
9,394
private static function callYoutubedl ( array $ arguments ) { $ config = Config :: getInstance ( ) ; $ process = self :: getProcess ( $ arguments ) ; $ process -> setEnv ( [ 'PATH' => $ config -> phantomjsDir ] ) ; $ process -> inheritEnvironmentVariables ( ) ; $ process -> run ( ) ; if ( ! $ process -> isSuccessful ( ) ) { $ errorOutput = trim ( $ process -> getErrorOutput ( ) ) ; $ exitCode = $ process -> getExitCode ( ) ; if ( $ errorOutput == 'ERROR: This video is protected by a password, use the --video-password option' ) { throw new PasswordException ( $ errorOutput , $ exitCode ) ; } elseif ( substr ( $ errorOutput , 0 , 21 ) == 'ERROR: Wrong password' ) { throw new Exception ( _ ( 'Wrong password' ) , $ exitCode ) ; } else { throw new Exception ( $ errorOutput , $ exitCode ) ; } } else { return trim ( $ process -> getOutput ( ) ) ; } }
Call youtube - dl .
9,395
private function getProp ( $ prop = 'dump-json' ) { $ arguments = [ '--' . $ prop ] ; if ( isset ( $ this -> webpageUrl ) ) { $ arguments [ ] = $ this -> webpageUrl ; } if ( isset ( $ this -> requestedFormat ) ) { $ arguments [ ] = '-f' ; $ arguments [ ] = $ this -> requestedFormat ; } if ( isset ( $ this -> password ) ) { $ arguments [ ] = '--video-password' ; $ arguments [ ] = $ this -> password ; } return $ this :: callYoutubedl ( $ arguments ) ; }
Get a property from youtube - dl .
9,396
public function getJson ( ) { if ( ! isset ( $ this -> json ) ) { $ this -> json = json_decode ( $ this -> getProp ( 'dump-single-json' ) ) ; } return $ this -> json ; }
Get all information about a video .
9,397
public function getUrl ( ) { if ( ! isset ( $ this -> urls ) ) { $ this -> urls = explode ( "\n" , $ this -> getProp ( 'get-url' ) ) ; if ( empty ( $ this -> urls [ 0 ] ) ) { throw new EmptyUrlException ( _ ( 'youtube-dl returned an empty URL.' ) ) ; } } return $ this -> urls ; }
Get URL of video from URL of page .
9,398
private function getRtmpArguments ( ) { $ arguments = [ ] ; if ( $ this -> protocol == 'rtmp' ) { foreach ( [ 'url' => '-rtmp_tcurl' , 'webpage_url' => '-rtmp_pageurl' , 'player_url' => '-rtmp_swfverify' , 'flash_version' => '-rtmp_flashver' , 'play_path' => '-rtmp_playpath' , 'app' => '-rtmp_app' , ] as $ property => $ option ) { if ( isset ( $ this -> { $ property } ) ) { $ arguments [ ] = $ option ; $ arguments [ ] = $ this -> { $ property } ; } } if ( isset ( $ this -> rtmp_conn ) ) { foreach ( $ this -> rtmp_conn as $ conn ) { $ arguments [ ] = '-rtmp_conn' ; $ arguments [ ] = $ conn ; } } } return $ arguments ; }
Return arguments used to run rtmp for a specific video .
9,399
private function getAvconvProcess ( $ audioBitrate , $ filetype = 'mp3' , $ audioOnly = true , $ from = null , $ to = null ) { if ( ! $ this -> checkCommand ( [ $ this -> config -> avconv , '-version' ] ) ) { throw new Exception ( _ ( 'Can\'t find avconv or ffmpeg at ' ) . $ this -> config -> avconv . '.' ) ; } $ durationRegex = '/(\d+:)?(\d+:)?(\d+)/' ; $ afterArguments = [ ] ; if ( $ audioOnly ) { $ afterArguments [ ] = '-vn' ; } if ( ! empty ( $ from ) ) { if ( ! preg_match ( $ durationRegex , $ from ) ) { throw new Exception ( _ ( 'Invalid start time: ' ) . $ from . '.' ) ; } $ afterArguments [ ] = '-ss' ; $ afterArguments [ ] = $ from ; } if ( ! empty ( $ to ) ) { if ( ! preg_match ( $ durationRegex , $ to ) ) { throw new Exception ( _ ( 'Invalid end time: ' ) . $ to . '.' ) ; } $ afterArguments [ ] = '-to' ; $ afterArguments [ ] = $ to ; } $ urls = $ this -> getUrl ( ) ; $ arguments = array_merge ( [ $ this -> config -> avconv , '-v' , $ this -> config -> avconvVerbosity , ] , $ this -> getRtmpArguments ( ) , [ '-i' , $ urls [ 0 ] , '-f' , $ filetype , '-b:a' , $ audioBitrate . 'k' , ] , $ afterArguments , [ 'pipe:1' , ] ) ; $ arguments [ ] = '-user_agent' ; $ arguments [ ] = $ this -> getProp ( 'dump-user-agent' ) ; return new Process ( $ arguments ) ; }
Get a process that runs avconv in order to convert a video .