idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
52,600
|
public static function formatDate ( \ DateTimeInterface $ dateTime , $ format ) { $ phpFormats = array ( self :: DATE => "Y-m-d" , self :: DATE_AND_TIME => 'Y-m-d\TH:i:s\Z' , ) ; $ phpFormat = $ phpFormats [ $ format ] ; return $ dateTime -> format ( $ phpFormat ) ; }
|
Format DateTime string based on granularity
|
52,601
|
public function createContext ( Registry $ registry ) { $ schemas = array_values ( $ registry -> getSchemas ( ) ) ; foreach ( $ schemas as $ schema ) { $ jsonSchema = $ this -> serializer -> deserialize ( file_get_contents ( $ schema -> getOrigin ( ) ) , 'Joli\Jane\Model\JsonSchema' , 'json' , [ 'document-origin' => $ schema -> getOrigin ( ) ] ) ; $ this -> chainGuesser -> guessClass ( $ jsonSchema , $ schema -> getRootName ( ) , $ schema -> getOrigin ( ) . '#' , $ registry ) ; } foreach ( $ registry -> getSchemas ( ) as $ schema ) { foreach ( $ schema -> getClasses ( ) as $ class ) { $ properties = $ this -> chainGuesser -> guessProperties ( $ class -> getObject ( ) , $ schema -> getRootName ( ) , $ class -> getReference ( ) , $ registry ) ; foreach ( $ properties as $ property ) { $ property -> setType ( $ this -> chainGuesser -> guessType ( $ property -> getObject ( ) , $ property -> getName ( ) , $ property -> getReference ( ) , $ registry ) ) ; } $ class -> setProperties ( $ properties ) ; } } return new Context ( $ registry ) ; }
|
Return a list of class guessed .
|
52,602
|
public function generate ( $ registry ) { $ context = $ this -> createContext ( $ registry ) ; $ prettyPrinter = new Standard ( ) ; $ modelFiles = [ ] ; $ normalizerFiles = [ ] ; foreach ( $ registry -> getSchemas ( ) as $ schema ) { if ( ! file_exists ( ( $ schema -> getDirectory ( ) . DIRECTORY_SEPARATOR . 'Model' ) ) ) { mkdir ( $ schema -> getDirectory ( ) . DIRECTORY_SEPARATOR . 'Model' , 0755 , true ) ; } if ( ! file_exists ( ( $ schema -> getDirectory ( ) . DIRECTORY_SEPARATOR . 'Normalizer' ) ) ) { mkdir ( $ schema -> getDirectory ( ) . DIRECTORY_SEPARATOR . 'Normalizer' , 0755 , true ) ; } $ context -> setCurrentSchema ( $ schema ) ; $ modelFiles = array_merge ( $ modelFiles , $ this -> modelGenerator -> generate ( $ schema , $ schema -> getRootName ( ) , $ context ) ) ; $ normalizerFiles = array_merge ( $ normalizerFiles , $ this -> normalizerGenerator -> generate ( $ schema , $ schema -> getRootName ( ) , $ context ) ) ; } $ generated = [ ] ; foreach ( $ modelFiles as $ file ) { $ generated [ ] = $ file -> getFilename ( ) ; file_put_contents ( $ file -> getFilename ( ) , $ prettyPrinter -> prettyPrintFile ( [ $ file -> getNode ( ) ] ) ) ; } foreach ( $ normalizerFiles as $ file ) { $ generated [ ] = $ file -> getFilename ( ) ; file_put_contents ( $ file -> getFilename ( ) , $ prettyPrinter -> prettyPrintFile ( [ $ file -> getNode ( ) ] ) ) ; } foreach ( $ registry -> getSchemas ( ) as $ schema ) { $ this -> fix ( $ schema -> getDirectory ( ) ) ; } return $ generated ; }
|
Generate code .
|
52,603
|
public function getBasicInformation ( ) { $ data = array ( ) ; $ xml = $ this -> endpoint -> identify ( ) ; $ data [ 'Base URL' ] = $ xml -> Identify -> baseURL ; $ data [ 'Repository Name' ] = $ xml -> Identify -> repositoryName ; $ data [ 'Administrator' ] = $ xml -> Identify -> adminEmail ; return $ data ; }
|
Retrieves the basic information from the endpoint .
|
52,604
|
public function getAvailableMetadataFormats ( ) { $ data = array ( ) ; if ( is_null ( $ this -> metadataIterator ) ) { $ this -> metadataIterator = $ this -> endpoint -> listMetadataFormats ( ) ; } $ data = array ( 'header' => array ( 'Metadata Prefix' , 'Schema' , 'Namespace' ) , 'rows' => array ( ) , ) ; foreach ( $ this -> metadataIterator as $ rec ) { $ data [ 'rows' ] [ ] = array ( $ rec -> metadataPrefix , $ rec -> schema , $ rec -> metadataNamespace ) ; } return $ data ; }
|
Retrieve a list of available metadata format schemas from the endpoint .
|
52,605
|
public function getRecords ( ) { $ data = array ( ) ; if ( empty ( $ this -> metadataIterator ) ) { $ this -> metadataIterator = $ this -> endpoint -> listMetadataFormats ( ) ; } else { $ this -> metadataIterator -> rewind ( ) ; } $ mdPrefix = ( string ) $ this -> metadataIterator -> current ( ) -> metadataPrefix ; $ data = array ( 'header' => array ( 'Identifier' , 'Title' , 'usageDataResourceURL' ) , 'rows' => array ( ) , ) ; $ recordIterator = $ this -> endpoint -> listRecords ( $ mdPrefix ) ; for ( $ i = 0 ; $ i < 10 ; $ i ++ ) { $ rec = $ recordIterator -> next ( ) ; $ data [ 'rows' ] [ ] = array ( $ rec -> header -> identifier , substr ( $ rec -> metadata -> commParadata -> paradataTitle -> string -> __toString ( ) , 0 , 30 ) , $ rec -> metadata -> commParadata -> usageDataResourceURL ) ; } return $ data ; }
|
Get a list of the first 10 records from the first available metadata format .
|
52,606
|
public function tryAnException ( ) { try { $ iterator = $ this -> endpoint -> listRecords ( 'foobardoesnotexist' ) ; $ iterator -> current ( ) ; } catch ( \ Phpoaipmh \ Exception \ OaipmhException $ e ) { throw $ e ; } }
|
Throws a deliberate exception for a non existing schema .
|
52,607
|
public function generate ( $ schema , $ className , Context $ context ) { $ files = [ ] ; $ classes = [ ] ; foreach ( $ schema -> getClasses ( ) as $ class ) { $ methods = [ ] ; $ modelFqdn = $ schema -> getNamespace ( ) . "\\Model\\" . $ class -> getName ( ) ; $ methods [ ] = $ this -> createSupportsDenormalizationMethod ( $ modelFqdn ) ; $ methods [ ] = $ this -> createSupportsNormalizationMethod ( $ modelFqdn ) ; $ methods [ ] = $ this -> createDenormalizeMethod ( $ modelFqdn , $ context , $ class -> getProperties ( ) ) ; $ methods [ ] = $ this -> createNormalizeMethod ( $ modelFqdn , $ context , $ class -> getProperties ( ) ) ; $ normalizerClass = $ this -> createNormalizerClass ( $ class -> getName ( ) . 'Normalizer' , $ methods ) ; $ classes [ ] = $ normalizerClass -> name ; $ namespace = new Stmt \ Namespace_ ( new Name ( $ schema -> getNamespace ( ) . "\\Normalizer" ) , [ new Stmt \ Use_ ( [ new Stmt \ UseUse ( new Name ( 'Joli\Jane\Runtime\Reference' ) ) ] ) , new Stmt \ Use_ ( [ new Stmt \ UseUse ( new Name ( 'Symfony\Component\Serializer\Exception\InvalidArgumentException' ) ) ] ) , new Stmt \ Use_ ( [ new Stmt \ UseUse ( new Name ( 'Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface' ) ) ] ) , new Stmt \ Use_ ( [ new Stmt \ UseUse ( new Name ( 'Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait' ) ) ] ) , new Stmt \ Use_ ( [ new Stmt \ UseUse ( new Name ( 'Symfony\Component\Serializer\Normalizer\DenormalizerInterface' ) ) ] ) , new Stmt \ Use_ ( [ new Stmt \ UseUse ( new Name ( 'Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface' ) ) ] ) , new Stmt \ Use_ ( [ new Stmt \ UseUse ( new Name ( 'Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait' ) ) ] ) , new Stmt \ Use_ ( [ new Stmt \ UseUse ( new Name ( 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' ) ) ] ) , $ normalizerClass ] ) ; $ files [ ] = new File ( $ schema -> getDirectory ( ) . '/Normalizer/' . $ class -> getName ( ) . 'Normalizer.php' , $ namespace , self :: FILE_TYPE_NORMALIZER ) ; } $ files [ ] = new File ( $ schema -> getDirectory ( ) . '/Normalizer/NormalizerFactory.php' , new Stmt \ Namespace_ ( new Name ( $ schema -> getNamespace ( ) . "\\Normalizer" ) , [ $ this -> createNormalizerFactoryClass ( $ classes ) ] ) , self :: FILE_TYPE_NORMALIZER ) ; return $ files ; }
|
Generate a set of files given a schema
|
52,608
|
public function request ( $ url ) { try { $ resp = $ this -> guzzle -> get ( $ url ) ; return ( string ) $ resp -> getBody ( ) ; } catch ( RequestException $ e ) { $ response = $ e -> getResponse ( ) ; throw new HttpException ( $ response ? $ response -> getBody ( ) : null , $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } catch ( TransferException $ e ) { throw new HttpException ( '' , $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } }
|
Do the request with GuzzleAdapter
|
52,609
|
protected function createPath ( Filesystem $ filesystem , $ type ) { $ customPath = $ this -> option ( 'path' ) ; $ defaultPath = config ( "vue-generators.paths.{$type}s" ) ; $ path = $ customPath !== null ? $ customPath : $ defaultPath ; $ this -> buildPathFromArray ( $ path , $ filesystem ) ; return $ path ; }
|
Create path for file .
|
52,610
|
public function setCurlOpts ( array $ opts , $ merge = true ) { $ this -> curlOpts = ( $ merge ) ? array_replace ( $ this -> curlOpts , $ opts ) : $ opts ; }
|
Set cURL Options at runtime
|
52,611
|
public function request ( $ url ) { $ curlOpts = array_replace ( $ this -> curlOpts , [ CURLOPT_URL => $ url ] ) ; $ ch = curl_init ( ) ; foreach ( $ curlOpts as $ opt => $ optVal ) { curl_setopt ( $ ch , $ opt , $ optVal ) ; } $ resp = curl_exec ( $ ch ) ; $ info = ( object ) curl_getinfo ( $ ch ) ; curl_close ( $ ch ) ; $ httpCode = ( string ) $ info -> http_code ; if ( $ httpCode { 0 } != '2' ) { $ msg = sprintf ( 'HTTP Request Failed (code %s): %s' , $ info -> http_code , $ resp ) ; throw new HttpException ( $ resp , $ msg , $ httpCode ) ; } elseif ( strlen ( trim ( $ resp ) ) == 0 ) { throw new HttpException ( $ resp , 'HTTP Response Empty' ) ; } return $ resp ; }
|
Do CURL Request
|
52,612
|
protected function getStub ( Filesystem $ filesystem ) { $ fileName = $ this -> option ( 'empty' ) ? 'EmptyComponent' : 'Component' ; return $ filesystem -> get ( __DIR__ . '/../Stubs/' . $ fileName . '.vue' ) ; }
|
Get and return stub .
|
52,613
|
public function nextItem ( ) { if ( $ this -> batch === null ) { $ this -> batch = [ ] ; } if ( count ( $ this -> batch ) == 0 && ( $ this -> resumptionToken or $ this -> numRequests == 0 ) ) { $ this -> retrieveBatch ( ) ; } if ( count ( $ this -> batch ) > 0 ) { $ this -> numProcessed ++ ; $ item = array_shift ( $ this -> batch ) ; $ this -> currItem = clone $ item ; } else { $ this -> currItem = false ; } return $ this -> currItem ; }
|
Get the next item
|
52,614
|
private function retrieveBatch ( ) { $ params = ( $ this -> resumptionToken ) ? [ 'resumptionToken' => $ this -> resumptionToken ] : $ this -> params ; $ nodeName = $ this -> getItemNodeName ( ) ; $ verb = $ this -> verb ; $ resp = $ this -> oaipmhClient -> request ( $ verb , $ params ) ; $ this -> numRequests ++ ; if ( ! isset ( $ resp -> $ verb -> $ nodeName ) ) { throw new MalformedResponseException ( sprintf ( "Expected XML element list '%s' missing for verb '%s'" , $ nodeName , $ verb ) ) ; } if ( isset ( $ resp -> $ verb -> resumptionToken ) ) { $ this -> resumptionToken = ( string ) $ resp -> $ verb -> resumptionToken ; if ( isset ( $ resp -> $ verb -> resumptionToken [ 'completeListSize' ] ) ) { $ this -> totalRecordsInCollection = ( int ) $ resp -> $ verb -> resumptionToken [ 'completeListSize' ] ; } if ( isset ( $ resp -> $ verb -> resumptionToken [ 'expirationDate' ] ) ) { $ t = $ resp -> $ verb -> resumptionToken [ 'expirationDate' ] ; $ this -> expireDate = \ DateTime :: createFromFormat ( \ DateTime :: ISO8601 , $ t ) ; } } else { $ this -> resumptionToken = null ; } foreach ( $ resp -> $ verb -> $ nodeName as $ node ) { $ this -> batch [ ] = $ node ; } return count ( $ this -> batch ) ; }
|
Do a request to get the next batch of items
|
52,615
|
private function getItemNodeName ( ) { $ mappings = array ( 'ListMetadataFormats' => 'metadataFormat' , 'ListSets' => 'set' , 'ListIdentifiers' => 'header' , 'ListRecords' => 'record' ) ; return ( isset ( $ mappings [ $ this -> verb ] ) ) ? $ mappings [ $ this -> verb ] : false ; }
|
Get Item Node Name
|
52,616
|
public function reset ( ) { $ this -> numRequests = 0 ; $ this -> numProcessed = 0 ; $ this -> currItem = null ; $ this -> resumptionToken = null ; $ this -> totalRecordsInCollection = null ; $ this -> expireDate = null ; $ this -> batch = [ ] ; }
|
Reset the request state
|
52,617
|
protected function createProperty ( $ name , Type $ type , $ namespace , $ default = null ) { $ propertyName = $ this -> getNaming ( ) -> getPropertyName ( $ name ) ; $ property = new Stmt \ PropertyProperty ( $ propertyName ) ; if ( $ default !== null ) { $ property -> default = new Expr \ ConstFetch ( new Name ( $ default ) ) ; } return new Stmt \ Property ( Stmt \ Class_ :: MODIFIER_PROTECTED , [ $ property ] , [ 'comments' => [ $ this -> createPropertyDoc ( $ type , $ namespace ) ] ] ) ; }
|
Return a property stmt
|
52,618
|
protected function buildPathFromArray ( $ path , Filesystem $ filesystem = null ) { $ pathArray = collect ( explode ( '/' , $ path ) ) -> prepend ( 'resources' ) ; if ( is_null ( $ filesystem ) ) { $ filesystem = new Filesystem ( ) ; } $ base = base_path ( ) ; foreach ( $ pathArray as $ path ) { $ base = $ base . '/' . $ path ; if ( ! $ filesystem -> exists ( $ base ) ) { $ filesystem -> makeDirectory ( $ base ) ; } } }
|
Build directory tree from array of paths .
|
52,619
|
protected function createDenormalizeMethod ( $ modelFqdn , Context $ context , $ properties ) { $ context -> refreshScope ( ) ; $ objectVariable = new Expr \ Variable ( 'object' ) ; $ assignStatement = new Expr \ Assign ( $ objectVariable , new Expr \ New_ ( new Name ( '\\' . $ modelFqdn ) ) ) ; $ statements = [ $ assignStatement ] ; if ( $ this -> useReference ) { $ statements = [ new Stmt \ If_ ( new Expr \ Isset_ ( [ new Expr \ PropertyFetch ( new Expr \ Variable ( 'data' ) , "{'\$ref'}" ) ] ) , [ 'stmts' => [ new Stmt \ Return_ ( new Expr \ New_ ( new Name ( 'Reference' ) , [ new Expr \ PropertyFetch ( new Expr \ Variable ( 'data' ) , "{'\$ref'}" ) , new Expr \ ArrayDimFetch ( new Expr \ Variable ( 'context' ) , new Scalar \ String_ ( 'document-origin' ) ) , ] ) ) , ] , ] ) , $ assignStatement , ] ; } array_unshift ( $ statements , new Stmt \ If_ ( new Expr \ BooleanNot ( new Expr \ FuncCall ( new Name ( 'is_object' ) , [ new Arg ( new Expr \ Variable ( 'data' ) ) ] ) ) , [ 'stmts' => [ new Stmt \ Throw_ ( new Expr \ New_ ( new Name ( 'InvalidArgumentException' ) ) ) ] ] ) ) ; foreach ( $ properties as $ property ) { $ propertyVar = new Expr \ PropertyFetch ( new Expr \ Variable ( 'data' ) , sprintf ( "{'%s'}" , $ property -> getName ( ) ) ) ; list ( $ denormalizationStatements , $ outputVar ) = $ property -> getType ( ) -> createDenormalizationStatement ( $ context , $ propertyVar ) ; $ statements [ ] = new Stmt \ If_ ( new Expr \ FuncCall ( new Name ( 'property_exists' ) , [ new Arg ( new Expr \ Variable ( 'data' ) ) , new Arg ( new Scalar \ String_ ( $ property -> getName ( ) ) ) , ] ) , [ 'stmts' => array_merge ( $ denormalizationStatements , [ new Expr \ MethodCall ( $ objectVariable , $ this -> getNaming ( ) -> getPrefixedMethodName ( 'set' , $ property -> getName ( ) ) , [ $ outputVar , ] ) , ] ) , ] ) ; } $ statements [ ] = new Stmt \ Return_ ( $ objectVariable ) ; return new Stmt \ ClassMethod ( 'denormalize' , [ 'type' => Stmt \ Class_ :: MODIFIER_PUBLIC , 'params' => [ new Param ( 'data' ) , new Param ( 'class' ) , new Param ( 'format' , new Expr \ ConstFetch ( new Name ( 'null' ) ) ) , new Param ( 'context' , new Expr \ Array_ ( ) , 'array' ) , ] , 'stmts' => $ statements , ] ) ; }
|
Create the denormalization method .
|
52,620
|
protected function createModel ( $ name , $ properties , $ methods ) { return new Stmt \ Class_ ( new Name ( $ this -> getNaming ( ) -> getClassName ( $ name ) ) , [ 'stmts' => array_merge ( $ properties , $ methods ) ] ) ; }
|
Return a model class
|
52,621
|
public function sortByDesc ( $ callback , int $ options = SORT_REGULAR ) { return $ this -> sortBy ( $ callback , $ options , true ) ; }
|
Sort the collection in descending order using the given callback .
|
52,622
|
public function getCachingIterator ( int $ flags = CachingIterator :: CALL_TOSTRING ) : CachingIterator { return new CachingIterator ( $ this -> getIterator ( ) , $ flags ) ; }
|
Get a CachingIterator instance .
|
52,623
|
public function validateSchema ( ) { $ meta_schema_validator = new SchemaValidator ( ) ; $ json_loader = new JsonLoader ( ) ; $ meta_json = file_get_contents ( __DIR__ . '/../../../data/MetaSchema.json' ) ; $ meta_json = str_replace ( '#' , $ this -> prefix , $ meta_json ) ; $ meta_schema_validator -> validate ( $ json_loader -> load ( $ meta_json ) , $ this -> schema ) ; return true ; }
|
can take up to a second
|
52,624
|
public function getDocumentationForNode ( array $ keys = array ( ) , $ unfold_all = false ) { $ node = $ this -> findNode ( $ this -> schema [ 'root' ] , $ keys , $ unfold_all ) ; return array ( 'name' => end ( $ keys ) ? : 'root' , 'node' => $ node , 'prefix' => $ this -> prefix ) ; }
|
get the documentation
|
52,625
|
public function getPrefixedMethodName ( $ prefix , $ name ) { $ name = $ this -> replaceDollar ( $ name ) ; return sprintf ( "%s%s" , $ prefix , Inflector :: classify ( $ name ) ) ; }
|
Get a method name given a prefix
|
52,626
|
public function getClassName ( $ name ) { $ name = $ this -> replaceDollar ( $ name ) ; $ name = preg_replace_callback ( '#[/\{\}]+(\w)#' , function ( $ matches ) { return ucfirst ( $ matches [ 1 ] ) ; } , $ name ) ; $ name = Inflector :: classify ( $ name ) ; if ( preg_match ( self :: BAD_CLASS_NAME_REGEX , $ name ) ) { $ name = '_' . $ name ; } return $ name ; }
|
Get a class name
|
52,627
|
protected function createGetter ( $ name , Type $ type , $ namespace ) { return new Stmt \ ClassMethod ( $ this -> getNaming ( ) -> getPrefixedMethodName ( 'get' , $ name ) , [ 'type' => Stmt \ Class_ :: MODIFIER_PUBLIC , 'stmts' => [ new Stmt \ Return_ ( new Expr \ PropertyFetch ( new Expr \ Variable ( 'this' ) , $ this -> getNaming ( ) -> getPropertyName ( $ name ) ) ) , ] , ] , [ 'comments' => [ $ this -> createGetterDoc ( $ type , $ namespace ) ] , ] ) ; }
|
Create get method .
|
52,628
|
protected function createSetter ( $ name , Type $ type , $ namespace ) { return new Stmt \ ClassMethod ( $ this -> getNaming ( ) -> getPrefixedMethodName ( 'set' , $ name ) , [ 'type' => Stmt \ Class_ :: MODIFIER_PUBLIC , 'params' => [ new Param ( $ this -> getNaming ( ) -> getPropertyName ( $ name ) , new Expr \ ConstFetch ( new Name ( 'null' ) ) , $ type -> getTypeHint ( $ namespace ) ) , ] , 'stmts' => [ new Expr \ Assign ( new Expr \ PropertyFetch ( new Expr \ Variable ( 'this' ) , $ this -> getNaming ( ) -> getPropertyName ( $ name ) ) , new Expr \ Variable ( $ this -> getNaming ( ) -> getPropertyName ( $ name ) ) ) , new Stmt \ Return_ ( new Expr \ Variable ( 'this' ) ) , ] , ] , [ 'comments' => [ $ this -> createSetterDoc ( $ name , $ type , $ namespace ) ] , ] ) ; }
|
Create set method .
|
52,629
|
protected function createSetterDoc ( $ name , Type $ type , $ namespace ) { return new Doc ( sprintf ( <<<EOD/** * @param %s %s * * @return self */EOD , $ type -> getDocTypeHint ( $ namespace ) , '$' . $ this -> getNaming ( ) -> getPropertyName ( $ name ) ) ) ; }
|
Return doc for set method .
|
52,630
|
public function resolve ( $ reference , $ class ) { $ result = $ reference ; while ( $ result instanceof Reference ) { $ result = $ result -> resolve ( function ( $ data ) use ( $ result , $ class ) { return $ this -> serializer -> denormalize ( $ data , $ class , 'json' , [ 'document-origin' => ( string ) $ result -> getMergedUri ( ) -> withFragment ( '' ) ] ) ; } ) ; } return $ result ; }
|
Resolve a reference with a denormalizer
|
52,631
|
public function listMetadataFormats ( $ identifier = null ) { $ params = ( $ identifier ) ? array ( 'identifier' => $ identifier ) : array ( ) ; return new RecordIterator ( $ this -> client , 'ListMetadataFormats' , $ params ) ; }
|
List Metadata Formats
|
52,632
|
public function listIdentifiers ( $ metadataPrefix , $ from = null , $ until = null , $ set = null , $ resumptionToken = null ) { return $ this -> createRecordIterator ( "ListIdentifiers" , $ metadataPrefix , $ from , $ until , $ set , $ resumptionToken ) ; }
|
List Record identifiers
|
52,633
|
private function createRecordIterator ( $ verb , $ metadataPrefix , $ from , $ until , $ set = null , $ resumptionToken = null ) { $ params = array ( 'metadataPrefix' => $ metadataPrefix ) ; if ( $ from instanceof \ DateTimeInterface ) { $ params [ 'from' ] = Granularity :: formatDate ( $ from , $ this -> getGranularity ( ) ) ; } elseif ( null !== $ from ) { throw new \ InvalidArgumentException ( sprintf ( '%s::%s $from parameter must be an instance of \DateTimeInterface' , get_called_class ( ) , 'createRecordIterator' ) ) ; } if ( $ until instanceof \ DateTimeInterface ) { $ params [ 'until' ] = Granularity :: formatDate ( $ until , $ this -> getGranularity ( ) ) ; } elseif ( null !== $ until ) { throw new \ InvalidArgumentException ( sprintf ( '%s::%s $until parameter must be an instance of \DateTimeInterface' , get_called_class ( ) , 'createRecordIterator' ) ) ; } if ( $ set ) { $ params [ 'set' ] = $ set ; } return new RecordIterator ( $ this -> client , $ verb , $ params , $ resumptionToken ) ; }
|
Create a record iterator
|
52,634
|
private function getGranularity ( ) { if ( $ this -> granularity === null ) { $ response = $ this -> identify ( ) ; return ( isset ( $ response -> Identify -> granularity ) ) ? ( string ) $ response -> Identify -> granularity : Granularity :: DATE ; } return $ this -> granularity ; }
|
Lazy load granularity from Identify if not specified
|
52,635
|
public function merge ( JsonSchema $ left , JsonSchema $ right ) { $ merged = clone $ right ; if ( $ left -> getType ( ) !== null && $ right -> getType ( ) !== null && $ left -> getType ( ) !== $ right -> getType ( ) ) { throw new \ RuntimeException ( "Both types are defined and different, merge is not possible" ) ; } if ( $ right -> getType ( ) === null && $ left -> getType ( ) !== null ) { $ merged -> setType ( $ left -> getType ( ) ) ; } $ merged -> setProperties ( $ this -> arrayMerge ( $ left -> getProperties ( ) , $ right -> getProperties ( ) ) ) ; $ merged -> setRequired ( $ this -> arrayUnique ( $ this -> arrayMerge ( $ left -> getRequired ( ) , $ right -> getRequired ( ) ) ) ) ; return $ merged ; }
|
Create a new JsonSchema based on two merged schema
|
52,636
|
public function generate ( $ schema , $ className , Context $ context ) { $ files = [ ] ; foreach ( $ schema -> getClasses ( ) as $ class ) { $ properties = [ ] ; $ methods = [ ] ; foreach ( $ class -> getProperties ( ) as $ property ) { $ properties [ ] = $ this -> createProperty ( $ property -> getName ( ) , $ property -> getType ( ) , $ schema -> getNamespace ( ) . "\\Model" ) ; $ methods [ ] = $ this -> createGetter ( $ property -> getName ( ) , $ property -> getType ( ) , $ schema -> getNamespace ( ) . "\\Model" ) ; $ methods [ ] = $ this -> createSetter ( $ property -> getName ( ) , $ property -> getType ( ) , $ schema -> getNamespace ( ) . "\\Model" ) ; } $ model = $ this -> createModel ( $ class -> getName ( ) , $ properties , $ methods ) ; $ namespace = new Stmt \ Namespace_ ( new Name ( $ schema -> getNamespace ( ) . "\\Model" ) , [ $ model ] ) ; $ files [ ] = new File ( $ schema -> getDirectory ( ) . '/Model/' . $ class -> getName ( ) . '.php' , $ namespace , self :: FILE_TYPE_MODEL ) ; } return $ files ; }
|
Generate a model given a schema
|
52,637
|
final protected function hhmac ( $ string , $ api_key_secret ) { $ key = base64_decode ( $ api_key_secret ) ; $ hashed = hash_hmac ( 'sha256' , $ string , $ key , true ) ; $ encoded = base64_encode ( $ hashed ) ; $ signature = rtrim ( $ encoded , "\n" ) ; return strval ( $ signature ) ; }
|
Generate HMAC cryptographic hash .
|
52,638
|
final protected function auth ( $ string = '' ) { $ canonical = strtoupper ( $ this -> method ) . $ this -> path ( ) . strval ( $ this -> datetime ) . $ string ; $ signature = $ this -> hhmac ( $ canonical , $ this -> api_key_secret ) ; return sprintf ( 'HHMAC; key=%s; signature=%s; date=%s' , $ this -> api_key_id , $ signature , $ this -> datetime ) ; }
|
Create canonical version of the request as a byte - wise concatenation .
|
52,639
|
protected function path ( ) { $ params = [ ] ; foreach ( $ this -> path_args as $ argument => $ value ) { $ params [ "{{$argument}}" ] = $ value ; } $ path = str_replace ( array_keys ( $ params ) , array_values ( $ params ) , $ this -> path ) ; return $ this -> endpoint . $ path ; }
|
Generate HTTP request URL .
|
52,640
|
protected function initVars ( $ method , $ path , Array $ path_args , Array $ data ) { $ this -> method = $ method ; $ this -> path = $ path ; $ this -> path_args = $ path_args ; }
|
Initialize variables needed to make a request .
|
52,641
|
protected function onErrorResponse ( $ error_code , $ error_message , $ response ) { $ message = print_r ( [ 'code' => $ error_code , 'message' => $ error_message , 'response' => $ response ] , true ) ; $ this -> triggerError ( $ message ) ; }
|
Callback for error HTTP response .
|
52,642
|
private function generateQueryOptions ( array $ options = [ ] ) { if ( isset ( $ options [ 'query' ] ) ) { $ result = $ options [ 'query' ] + $ this -> getDefaultOptions ( ) ; } else { $ result [ 'query' ] = $ options + $ this -> getDefaultOptions ( ) ; } return $ result ; }
|
Generate query options
|
52,643
|
public function setBannerType ( $ bannerType ) { if ( ! in_array ( $ bannerType , [ self :: BANNER_TYPE_ANY , self :: BANNER_TYPE_DOUBLE , self :: BANNER_TYPE_LARGE , self :: BANNER_TYPE_STANDARD , ] ) ) { $ this -> triggerError ( 'Invalid value for bannerType advertisingSettings.' ) ; } else { $ this -> bannerType = $ bannerType ; } return $ this ; }
|
Setting for bannerType .
|
52,644
|
public function setFrequency ( $ frequency ) { if ( $ frequency >= 0 && $ frequency <= 10 ) { $ this -> frequency = $ frequency ; } else { $ this -> triggerError ( 'Invalid value for frequency advertisingSettings.' ) ; } return $ this ; }
|
Setter for frequency .
|
52,645
|
private function run ( $ path , $ options ) { $ method = $ options [ 'method' ] ; $ data = isset ( $ options [ 'data' ] ) ? $ options [ 'data' ] : null ; $ params = isset ( $ options [ 'params' ] ) ? $ options [ 'params' ] : null ; $ headers = isset ( $ options [ 'headers' ] ) ? $ options [ 'headers' ] : array ( ) ; $ body = ! empty ( $ data ) ? json_encode ( $ data ) : null ; $ allowedHeaders = array ( 'If-None-Match' , 'If-Modified-Since' ) ; $ headers = $ this -> filterOptions ( $ headers , $ allowedHeaders ) ; $ headers [ 'User-Agent' ] = $ this -> userAgent ; $ headers [ 'Content-Type' ] = 'application/json' ; if ( ! empty ( $ headers [ 'If-Modified-Since' ] ) && $ headers [ 'If-Modified-Since' ] instanceof DateTime ) { $ headers [ 'If-Modified-Since' ] = gmdate ( 'D, d M Y H:i:s \G\M\T' , $ headers [ 'If-Modified-Since' ] -> getTimestamp ( ) ) ; } $ response = $ this -> requester -> run ( array ( 'url' => self :: URL . $ this -> slug . $ path , 'method' => $ method , 'params' => $ params , 'body' => $ body , 'userpwd' => "$this->email:$this->apiKey" , 'headers' => $ headers ) ) ; return $ response ; }
|
Execute HTTP method on path with data
|
52,646
|
public function setTargetAnchorPosition ( $ value ) { if ( $ this -> validateTargetAnchorPosition ( $ value ) ) { $ this -> targetAnchorPosition = ( string ) $ value ; } return $ this ; }
|
Setter for targetAnchorPosition .
|
52,647
|
public function buildUrl ( $ apiEndPoint ) { if ( is_null ( $ this -> request [ 'url' ] ) ) { return $ apiEndPoint . '/' . $ this -> uri . ( $ this -> queryStr ? '?' . http_build_query ( $ this -> queryStr ) : '' ) ; } if ( strpos ( $ this -> url , $ apiEndPoint ) !== 0 ) { throw new PaysafeException ( 'Unexpected endpoint in url: ' . $ this -> url . ' expected: ' . $ apiEndPoint ) ; } return $ this -> url ; }
|
Build url for the paysafe api client .
|
52,648
|
public function setLayout ( $ layout , Document $ document = NULL ) { $ class = 'ChapterThree\AppleNewsAPI\Document\Layouts\ComponentLayout' ; if ( is_string ( $ layout ) ) { if ( $ document && empty ( $ document -> getComponentLayouts ( ) [ $ layout ] ) ) { $ this -> triggerError ( "No component layout \"${layout}\" found." ) ; return $ this ; } } elseif ( ! $ layout instanceof $ class ) { $ this -> triggerError ( "Layout not of class ${class}." ) ; return $ this ; } $ this -> layout = $ layout ; return $ this ; }
|
Setter for layout .
|
52,649
|
public function setStyle ( $ style , Document $ document = NULL ) { $ class = 'ChapterThree\AppleNewsAPI\Document\Styles\ComponentStyle' ; if ( is_string ( $ style ) ) { if ( $ document && empty ( $ document -> getComponentStyles ( ) [ $ style ] ) ) { $ this -> triggerError ( "No component style \"${style}\" found." ) ; return $ this ; } } elseif ( ! $ style instanceof $ class ) { $ this -> triggerError ( "Style not of class ${class}." ) ; return $ this ; } $ this -> style = $ style ; return $ this ; }
|
Setter for style .
|
52,650
|
public function setItems ( array $ value ) { if ( isset ( $ value [ 0 ] ) && is_object ( $ value [ 0 ] ) && ! $ value [ 0 ] instanceof GalleryItem ) { $ this -> triggerError ( 'Object not of type GalleryItem' ) ; } else { $ this -> items = $ value ; } return $ this ; }
|
Setter for items .
|
52,651
|
public function cancelHeldAuth ( CardPayments \ Authorization $ auth ) { $ auth -> setRequiredFields ( array ( 'id' ) ) ; $ auth -> checkRequiredFields ( ) ; $ tmpAuth = new CardPayments \ Authorization ( array ( 'status' => 'CANCELLED' ) ) ; $ request = new Request ( array ( 'method' => Request :: PUT , 'uri' => $ this -> prepareURI ( "/auths/" . $ auth -> id ) , 'body' => $ tmpAuth ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Authorization ( $ response ) ; }
|
Cancel held authorization .
|
52,652
|
public function reverseAuth ( CardPayments \ AuthorizationReversal $ authReversal ) { $ authReversal -> setRequiredFields ( array ( 'authorizationID' ) ) ; $ authReversal -> checkRequiredFields ( ) ; $ authReversal -> setRequiredFields ( array ( 'merchantRefNum' ) ) ; $ authReversal -> setOptionalFields ( array ( 'amount' , 'dupCheck' ) ) ; $ request = new Request ( array ( 'method' => Request :: POST , 'uri' => $ this -> prepareURI ( "/auths/" . $ authReversal -> authorizationID . "/voidauths" ) , 'body' => $ authReversal ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ AuthorizationReversal ( $ response ) ; }
|
Reverse Authorization .
|
52,653
|
public function cancelSettlement ( CardPayments \ Settlement $ settlement ) { $ settlement -> setRequiredFields ( array ( 'id' ) ) ; $ settlement -> checkRequiredFields ( ) ; $ tmpSettlement = new CardPayments \ Settlement ( array ( 'status' => 'CANCELLED' ) ) ; $ request = new Request ( array ( 'method' => Request :: PUT , 'uri' => $ this -> prepareURI ( "/settlements/" . $ settlement -> id ) , 'body' => $ tmpSettlement ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Settlement ( $ response ) ; }
|
Cancel settlement .
|
52,654
|
public function cancelRefund ( CardPayments \ Refund $ refund ) { $ refund -> setRequiredFields ( array ( 'id' ) ) ; $ refund -> checkRequiredFields ( ) ; $ tmpRefund = new CardPayments \ Refund ( array ( 'status' => 'CANCELLED' ) ) ; $ request = new Request ( array ( 'method' => Request :: PUT , 'uri' => $ this -> prepareURI ( "/refunds/" . $ refund -> id ) , 'body' => $ tmpRefund ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Refund ( $ response ) ; }
|
Cancel Refund .
|
52,655
|
public function getAuth ( CardPayments \ Authorization $ auth ) { $ auth -> setRequiredFields ( array ( 'id' ) ) ; $ auth -> checkRequiredFields ( ) ; $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/auths/" . $ auth -> id ) ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Authorization ( $ response ) ; }
|
Get the authorization .
|
52,656
|
public function getAuthReversal ( CardPayments \ AuthorizationReversal $ authReversal ) { $ authReversal -> setRequiredFields ( array ( 'id' ) ) ; $ authReversal -> checkRequiredFields ( ) ; $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/voidauths/" . $ authReversal -> id ) ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ AuthorizationReversal ( $ response ) ; }
|
Get the authrozation reversal
|
52,657
|
public function getSettlement ( CardPayments \ Settlement $ settlement ) { $ settlement -> setRequiredFields ( array ( 'id' ) ) ; $ settlement -> checkRequiredFields ( ) ; $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/settlements/" . $ settlement -> id ) ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Settlement ( $ response ) ; }
|
Get the settlement .
|
52,658
|
public function getRefund ( CardPayments \ Refund $ refund ) { $ refund -> setRequiredFields ( array ( 'id' ) ) ; $ refund -> checkRequiredFields ( ) ; $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/refunds/" . $ refund -> id ) ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Refund ( $ response ) ; }
|
Get the refund .
|
52,659
|
public function getVerification ( CardPayments \ Verification $ verify ) { $ verify -> setRequiredFields ( array ( 'id' ) ) ; $ verify -> checkRequiredFields ( ) ; $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/verifications/" . $ verify -> id ) ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Verification ( $ response ) ; }
|
Get the verification .
|
52,660
|
public function getAuths ( CardPayments \ Authorization $ auth = null , CardPayments \ Filter $ filter = null ) { $ queryStr = array ( ) ; if ( $ auth && $ auth -> merchantRefNum ) { $ queryStr [ 'merchantRefNum' ] = $ auth -> merchantRefNum ; } if ( $ filter ) { if ( isset ( $ filter -> limit ) ) { $ queryStr [ 'limit' ] = $ filter -> limit ; } if ( isset ( $ filter -> offset ) ) { $ queryStr [ 'offset' ] = $ filter -> offset ; } if ( isset ( $ filter -> startDate ) ) { $ queryStr [ 'startDate' ] = $ filter -> startDate ; } if ( isset ( $ filter -> endDate ) ) { $ queryStr [ 'endDate' ] = $ filter -> endDate ; } } $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/auths" ) , 'queryStr' => $ queryStr ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Pagerator ( $ this -> client , $ response , '\Paysafe\CardPayments\Authorization' ) ; }
|
Get matching authorizations .
|
52,661
|
public function getAuthReversals ( CardPayments \ AuthorizationReversal $ authReversal = null , CardPayments \ Filter $ filter = null ) { $ queryStr = array ( ) ; if ( $ authReversal && $ authReversal -> merchantRefNum ) { $ queryStr [ 'merchantRefNum' ] = $ authReversal -> merchantRefNum ; } if ( $ filter ) { if ( isset ( $ filter -> limit ) ) { $ queryStr [ 'limit' ] = $ filter -> limit ; } if ( isset ( $ filter -> offset ) ) { $ queryStr [ 'offset' ] = $ filter -> offset ; } if ( isset ( $ filter -> startDate ) ) { $ queryStr [ 'startDate' ] = $ filter -> startDate ; } if ( isset ( $ filter -> endDate ) ) { $ queryStr [ 'endDate' ] = $ filter -> endDate ; } } $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/voidauths" ) , 'queryStr' => $ queryStr ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Pagerator ( $ this -> client , $ response , '\Paysafe\CardPayments\AuthorizationReversal' ) ; }
|
Get matching authorization reversals .
|
52,662
|
public function getSettlements ( CardPayments \ Settlement $ settlement = null , CardPayments \ Filter $ filter = null ) { $ queryStr = array ( ) ; if ( $ settlement && $ settlement -> merchantRefNum ) { $ queryStr [ 'merchantRefNum' ] = $ settlement -> merchantRefNum ; } if ( $ filter ) { if ( isset ( $ filter -> limit ) ) { $ queryStr [ 'limit' ] = $ filter -> limit ; } if ( isset ( $ filter -> offset ) ) { $ queryStr [ 'offset' ] = $ filter -> offset ; } if ( isset ( $ filter -> startDate ) ) { $ queryStr [ 'startDate' ] = $ filter -> startDate ; } if ( isset ( $ filter -> endDate ) ) { $ queryStr [ 'endDate' ] = $ filter -> endDate ; } } $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/settlements" ) , 'queryStr' => $ queryStr ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Pagerator ( $ this -> client , $ response , '\Paysafe\CardPayments\Settlement' ) ; }
|
Get matching settlements .
|
52,663
|
public function getRefunds ( CardPayments \ Refund $ refund = null , CardPayments \ Filter $ filter = null ) { $ queryStr = array ( ) ; if ( $ refund && $ refund -> merchantRefNum ) { $ queryStr [ 'merchantRefNum' ] = $ refund -> merchantRefNum ; } if ( $ filter ) { if ( isset ( $ filter -> limit ) ) { $ queryStr [ 'limit' ] = $ filter -> limit ; } if ( isset ( $ filter -> offset ) ) { $ queryStr [ 'offset' ] = $ filter -> offset ; } if ( isset ( $ filter -> startDate ) ) { $ queryStr [ 'startDate' ] = $ filter -> startDate ; } if ( isset ( $ filter -> endDate ) ) { $ queryStr [ 'endDate' ] = $ filter -> endDate ; } } $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/refunds" ) , 'queryStr' => $ queryStr ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Pagerator ( $ this -> client , $ response , '\Paysafe\CardPayments\Refund' ) ; }
|
Get matching refunds .
|
52,664
|
public function getVerifications ( CardPayments \ Verification $ verify = null , CardPayments \ Filter $ filter = null ) { $ queryStr = array ( ) ; if ( $ verify && $ verify -> merchantRefNum ) { $ queryStr [ 'merchantRefNum' ] = $ verify -> merchantRefNum ; } if ( $ filter ) { if ( isset ( $ filter -> limit ) ) { $ queryStr [ 'limit' ] = $ filter -> limit ; } if ( isset ( $ filter -> offset ) ) { $ queryStr [ 'offset' ] = $ filter -> offset ; } if ( isset ( $ filter -> startDate ) ) { $ queryStr [ 'startDate' ] = $ filter -> startDate ; } if ( isset ( $ filter -> endDate ) ) { $ queryStr [ 'endDate' ] = $ filter -> endDate ; } } $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/verifications" ) , 'queryStr' => $ queryStr ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new CardPayments \ Pagerator ( $ this -> client , $ response , '\Paysafe\CardPayments\Verification' ) ; }
|
Get matching verifications .
|
52,665
|
protected function unsetHeaders ( Array $ headers = [ ] ) { foreach ( $ headers as $ property ) { $ this -> client -> unsetHeader ( $ property ) ; } }
|
Remove specified header names from HTTP request .
|
52,666
|
protected function request ( $ data ) { try { if ( $ this -> method == 'delete' ) { $ response = $ this -> client -> { $ this -> method } ( $ this -> path ( ) , [ ] , $ data ) ; } else { $ response = $ this -> client -> { $ this -> method } ( $ this -> path ( ) , $ data ) ; } $ this -> client -> close ( ) ; } catch ( \ Exception $ e ) { $ this -> triggerError ( $ e -> getMessage ( ) ) ; } return $ this -> response ( $ response ) ; }
|
Create HTTP request .
|
52,667
|
protected function response ( $ response ) { if ( $ this -> client -> error ) { $ this -> onErrorResponse ( $ this -> client -> errorCode , $ this -> client -> errorMessage , $ response ) ; } else { $ this -> onSuccessfulResponse ( $ response ) ; } return $ response ; }
|
Preprocess HTTP response .
|
52,668
|
protected function getFileInformation ( $ path ) { $ file = pathinfo ( $ path ) ; $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mimetype = finfo_file ( $ finfo , $ path ) ; if ( ! in_array ( $ mimetype , $ this -> valid_mimes ) ) { if ( $ mimetype == 'text/plain' ) { $ mimetype = 'application/octet-stream' ; } else { $ this -> triggerError ( 'Unsupported mime type: ' . $ mimetype ) ; } } $ contents = file_get_contents ( $ path ) ; return [ 'name' => str_replace ( ' ' , '-' , $ file [ 'filename' ] ) , 'filename' => $ file [ 'basename' ] , 'extension' => $ file [ 'extension' ] , 'mimetype' => $ mimetype , 'contents' => $ contents , 'size' => strlen ( $ contents ) ] ; }
|
Get file information and its contents to upload .
|
52,669
|
protected function multipartPart ( Array $ attributes , $ mimetype = null , $ contents = null ) { $ multipart = '' ; $ headers = [ ] ; foreach ( $ attributes as $ name => $ value ) { $ headers [ ] = $ name . '=' . $ value ; } $ multipart .= '--' . $ this -> boundary . static :: EOL ; $ multipart .= 'Content-Type: ' . $ mimetype . static :: EOL ; $ multipart .= 'Content-Disposition: form-data; ' . join ( '; ' , $ headers ) . static :: EOL ; $ multipart .= static :: EOL . $ contents . static :: EOL ; return $ multipart ; }
|
Generate individual multipart data parts .
|
52,670
|
protected function multipartFinalize ( Array $ multiparts = [ ] ) { $ contents = '' ; foreach ( $ multiparts as $ multipart ) { $ contents .= $ multipart ; } $ contents .= '--' . $ this -> boundary . '--' ; $ contents .= static :: EOL ; return $ contents ; }
|
Finalize multipart data .
|
52,671
|
protected function validateOpacity ( $ value ) { if ( ! is_numeric ( $ value ) || $ value < 0 || $ value > 100 ) { $ this -> triggerError ( 'opacity is not valid' ) ; return FALSE ; } return TRUE ; }
|
Validates the opacity attribute .
|
52,672
|
protected function validateRadius ( $ value ) { if ( ! is_numeric ( $ value ) || $ value < 0 || $ value > 100 ) { $ this -> triggerError ( 'radius is not valid' ) ; return FALSE ; } return TRUE ; }
|
Validates the radius attribute .
|
52,673
|
public function setCaption ( $ value ) { $ class = CaptionDescriptor :: class ; if ( is_object ( $ value ) ) { if ( $ value instanceof $ class ) { $ this -> caption = $ value ; } else { $ this -> triggerError ( "Caption not of class ${class}." ) ; } } else { $ this -> caption = ( string ) $ value ; } return $ this ; }
|
Setter for caption .
|
52,674
|
private function filterHeaders ( ) { $ headers = array ( ) ; foreach ( $ this -> headers as $ name => $ value ) { if ( strtolower ( $ name ) != 'user-agent' ) { $ headers [ ] = "$name: $value" ; } } return $ headers ; }
|
User - Agent header is sent differently .
|
52,675
|
public function current ( ) { if ( array_key_exists ( $ this -> position , $ this -> results ) ) { return $ this -> results [ $ this -> position ] ; } }
|
Get the current element .
|
52,676
|
public function next ( ) { $ this -> position ++ ; if ( ! $ this -> valid ( ) && $ this -> nextPage ) { $ request = new \ Paysafe \ Request ( $ this -> nextPage ) ; $ this -> nextPage = null ; $ response = $ this -> client -> processRequest ( $ request ) ; $ this -> parseResponse ( $ response ) ; } }
|
Go to the next element
|
52,677
|
public function getHeroProfile ( $ battleTag , $ heroId , array $ options = [ ] ) { return $ this -> request ( '/profile/' . ( string ) $ battleTag . '/hero/' . ( int ) $ heroId , $ options ) ; }
|
Get hero profile by battle tag and hero id
|
52,678
|
public function transferDebit ( Transfer $ transfer ) { $ transfer -> setRequiredFields ( array ( 'amount' , 'linkedAccount' , 'merchantRefNum' , ) ) ; $ transfer -> setOptionalFields ( array ( 'detail' , 'dupCheck' , ) ) ; $ request = new Request ( array ( 'method' => Request :: POST , 'uri' => $ this -> prepareURI ( $ this -> debitPath ) , 'body' => $ transfer ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new Transfer ( $ response ) ; }
|
Move funds from the account identified in the API endpoint URI to the linked account in the body of the request
|
52,679
|
public function transferCredit ( Transfer $ transfer ) { $ transfer -> setRequiredFields ( array ( 'amount' , 'linkedAccount' , 'merchantRefNum' , ) ) ; $ transfer -> setOptionalFields ( array ( 'detail' , 'dupCheck' , ) ) ; $ request = new Request ( array ( 'method' => Request :: POST , 'uri' => $ this -> prepareURI ( $ this -> creditPath ) , 'body' => $ transfer ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new Transfer ( $ response ) ; }
|
Move funds from the linked account in the body of the request to the account identified in the API endpoint URI .
|
52,680
|
public function setTop ( $ top ) { if ( ! $ this -> isSupportedUnit ( $ top ) ) { $ this -> triggerError ( "Value \"${top}\" does not use a supported unit." ) ; } else { $ this -> top = $ top ; } return $ this ; }
|
Setter for top .
|
52,681
|
public function setBottom ( $ bottom ) { if ( ! $ this -> isSupportedUnit ( $ bottom ) ) { $ this -> triggerError ( "Value \"${bottom}\" does not use a supported unit." ) ; } else { $ this -> bottom = $ bottom ; } return $ this ; }
|
Setter for bottom .
|
52,682
|
private function updateApiUrl ( $ region ) { $ this -> apiUrl = str_replace ( 'region' , strtolower ( $ region ) , self :: API_URL_PATTERN ) ; return $ this ; }
|
Update API url
|
52,683
|
private function updateApiAccessTokenUrl ( $ region ) { $ this -> apiAccessTokenUrl = str_replace ( 'region' , strtolower ( $ region ) , self :: API_ACCESS_TOKEN_URL_PATTERN ) ; return $ this ; }
|
Update API Access Token url
|
52,684
|
protected function requestAccessToken ( ) { $ options = [ 'form_params' => [ 'grant_type' => 'client_credentials' , 'client_id' => $ this -> getApiKey ( ) , 'client_secret' => $ this -> getApiSecret ( ) , ] , ] ; $ result = ( new Client ( ) ) -> post ( $ this -> getApiAccessTokenUrl ( ) , $ options ) ; if ( 200 === $ result -> getStatusCode ( ) ) { return Access :: fromJson ( json_decode ( $ result -> getBody ( ) -> getContents ( ) ) ) ; } else { throw new \ HttpResponseException ( 'Invalid Response' ) ; } }
|
Request an Access Token from Blizzard
|
52,685
|
public static function setCACertPath ( $ path ) { if ( ! file_exists ( $ path ) ) { throw new PaysafeException ( 'Invalid CA cert path: ' . $ path ) ; } self :: $ caCertPath = realpath ( $ path ) ; }
|
Set the path to the root CA certificate for use with cURL
|
52,686
|
private function getPaysafeException ( $ httpCode , $ message = null , $ code = null ) { if ( ! $ message ) { $ message = "An unknown error has occurred." ; } if ( ! $ code ) { $ code = $ httpCode ; } $ exceptionType = '\Paysafe\PaysafeException' ; switch ( $ httpCode ) { case '400' : $ exceptionType = '\Paysafe\InvalidRequestException' ; break ; case '401' : $ exceptionType = '\Paysafe\InvalidCredentialsException' ; break ; case '402' : $ exceptionType = '\Paysafe\RequestDeclinedException' ; break ; case '403' : $ exceptionType = '\Paysafe\PermissionException' ; break ; case '404' : $ exceptionType = '\Paysafe\EntityNotFoundException' ; break ; case '409' : $ exceptionType = '\Paysafe\RequestConflictException' ; break ; case '406' : case '415' : $ exceptionType = '\Paysafe\APIException' ; break ; default : if ( $ httpCode >= 500 ) { $ exceptionType = '\Paysafe\APIException' ; } break ; } return new $ exceptionType ( $ message , $ code ) ; }
|
Return the correct exception type based on http code
|
52,687
|
public function getSeasonById ( $ id , array $ options = [ ] ) { $ options [ 'access_token' ] = $ this -> blizzardClient -> getAccessToken ( ) ; return $ this -> request ( '/data/d3/season/' . ( int ) $ id , $ options ) ; }
|
Get season by ID
|
52,688
|
public function getSeasonLeaderboardById ( $ id , $ leaderboard , array $ options = [ ] ) { $ options [ 'access_token' ] = $ this -> blizzardClient -> getAccessToken ( ) ; return $ this -> request ( '/data/d3/season/' . ( int ) $ id . '/leaderboard/' . ( string ) $ leaderboard , $ options ) ; }
|
Get season leaderboard by ID and leaderboard
|
52,689
|
public function getEraIndexById ( $ id , array $ options = [ ] ) { $ options [ 'access_token' ] = $ this -> blizzardClient -> getAccessToken ( ) ; return $ this -> request ( '/data/d3/era/' . ( int ) $ id , $ options ) ; }
|
Get era index by ID
|
52,690
|
public function enrollmentChecks ( ThreeDSecure \ ThreeDEnrollment $ enrollmentchecks ) { $ enrollmentchecks -> setRequiredFields ( array ( 'merchantRefNum' , 'amount' , 'currency' , 'card' , 'customerIp' , 'userAgent' , 'acceptHeader' , 'merchantUrl' ) ) ; $ enrollmentchecks -> checkRequiredFields ( ) ; $ request = new Request ( array ( 'method' => Request :: POST , 'uri' => $ this -> prepareURI ( "/enrollmentchecks" ) , 'body' => $ enrollmentchecks ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new ThreeDSecure \ ThreeDEnrollment ( $ response ) ; }
|
Submit an Enrollment lookup Request
|
52,691
|
public function getenrollmentChecks ( ThreeDSecure \ ThreeDEnrollment $ enrollmentchecks ) { $ enrollmentchecks -> setRequiredFields ( array ( 'id' ) ) ; $ enrollmentchecks -> checkRequiredFields ( ) ; $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/enrollmentchecks/" . $ enrollmentchecks -> id ) , 'body' => $ enrollmentchecks ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new ThreeDSecure \ ThreeDEnrollment ( $ response ) ; }
|
Look Up an Enrollment Lookup Using an ID
|
52,692
|
public function authentications ( ThreeDSecure \ Authentications $ authentications ) { $ authentications -> setRequiredFields ( array ( 'merchantRefNum' , 'paRes' ) ) ; $ authentications -> checkRequiredFields ( ) ; $ request = new Request ( array ( 'method' => Request :: POST , 'uri' => $ this -> prepareURI ( "/enrollmentchecks/" . $ authentications -> id . "/authentications" ) , 'body' => $ authentications ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new ThreeDSecure \ Authentications ( $ response ) ; }
|
Submit an Authentications Request
|
52,693
|
public function getAuthentication ( ThreeDSecure \ Authentications $ authentications ) { $ authentications -> checkRequiredFields ( ) ; $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/authentications/" . $ authentications -> id ) , 'body' => $ authentications ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new ThreeDSecure \ Authentications ( $ response ) ; }
|
Look Up an Authentication Using an ID
|
52,694
|
public function getAuthentications ( ThreeDSecure \ Authentications $ authentications , $ enrollmentlookup ) { $ authentications -> setRequiredFields ( array ( 'id' ) ) ; $ authentications -> checkRequiredFields ( ) ; $ fields = array ( ) ; if ( $ enrollmentlookup ) { $ fields [ ] = 'enrollmentchecks' ; } $ queryStr = array ( ) ; if ( $ fields ) { $ queryStr [ 'fields' ] = join ( ',' , $ fields ) ; } $ request = new Request ( array ( 'method' => Request :: GET , 'uri' => $ this -> prepareURI ( "/authentications/" . $ authentications -> id ) , 'queryStr' => $ queryStr ) ) ; $ response = $ this -> client -> processRequest ( $ request ) ; return new ThreeDSecure \ Authentications ( $ response ) ; }
|
Look Up an Authentication and Corresponding Enrollment Check
|
52,695
|
public static function escape ( $ string ) { $ escaped_chars = str_split ( self :: ESCAPED_CHARACTERS ) ; $ escaped_chars_replace = array_map ( function ( $ char ) { return '\\' . $ char ; } , $ escaped_chars ) ; $ string = str_replace ( $ escaped_chars , $ escaped_chars_replace , $ string ) ; return preg_replace ( '/\s+/u' , ' ' , $ string ) ; }
|
Escape Markdown special characters .
|
52,696
|
public function convert ( $ html ) { if ( preg_match ( '/^\s*$/u' , $ html ) ) { return '' ; } $ html = '<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"></head>' . $ html . '</body></html>' ; $ this -> dom = new \ DOMDocument ( ) ; if ( ! $ this -> dom -> loadHTML ( $ html ) ) { return NULL ; } $ xp = new \ DOMXPath ( $ this -> dom ) ; return implode ( self :: BLOCK_DELIMITER , $ this -> getBlocks ( $ xp -> query ( '/html/body' ) -> item ( 0 ) -> childNodes ) ) ; }
|
Convert HTML to Apple News Markdown .
|
52,697
|
protected function getBlocks ( $ nodes ) { $ blocks = array ( ) ; $ block = '' ; $ add_block = function ( $ string = NULL ) use ( & $ blocks , & $ block ) { if ( preg_match ( '/\S/u' , $ block ) ) { $ blocks [ ] = trim ( $ block , " \t" ) ; } if ( preg_match ( '/\S/u' , $ string ) ) { $ blocks [ ] = rtrim ( $ string , " \t" ) ; } $ block = '' ; } ; foreach ( $ nodes as $ node ) { switch ( $ node -> nodeType ) { case XML_ELEMENT_NODE : switch ( $ node -> nodeName ) { case 'p' : case 'pre' : $ add_block ( $ this -> getBlock ( $ node ) ) ; break ; case 'h1' : $ add_block ( '# ' . $ this -> getBlock ( $ node ) ) ; break ; case 'h2' : $ add_block ( '## ' . $ this -> getBlock ( $ node ) ) ; break ; case 'h3' : $ add_block ( '### ' . $ this -> getBlock ( $ node ) ) ; break ; case 'h4' : $ add_block ( '#### ' . $ this -> getBlock ( $ node ) ) ; break ; case 'h5' : $ add_block ( '##### ' . $ this -> getBlock ( $ node ) ) ; break ; case 'h6' : $ add_block ( '###### ' . $ this -> getBlock ( $ node ) ) ; break ; case 'hr' : $ add_block ( '***' ) ; break ; case 'ul' : case 'ol' : case 'dl' : $ add_block ( $ this -> getBlockList ( $ node ) ) ; break ; case 'article' : case 'aside' : case 'blockquote' : case 'dd' : case 'div' : case 'fieldset' : case 'figcaption' : case 'figure' : case 'footer' : case 'form' : case 'header' : case 'hgroup' : case 'main' : case 'nav' : case 'output' : case 'section' : foreach ( $ this -> getBlocks ( $ node -> childNodes ) as $ b ) { $ add_block ( $ b ) ; } break ; case 'canvas' : case 'noscript' : case 'script' : case 'table' : case 'tfoot' : case 'video' : break ; default : $ block .= $ this -> getBlock ( $ node ) ; break ; } break ; case XML_TEXT_NODE : $ block .= self :: escape ( $ node -> textContent ) ; break ; } } $ add_block ( ) ; return $ blocks ; }
|
Converts a \ DOMNodeList into a series of Markdown blocks .
|
52,698
|
protected function getBlock ( \ DOMElement $ element ) { $ block = '' ; foreach ( $ element -> childNodes as $ node ) { switch ( $ node -> nodeType ) { case XML_ELEMENT_NODE : switch ( $ node -> nodeName ) { case 'i' : case 'em' : $ block .= '*' . $ this -> getBlock ( $ node ) . '*' ; break ; case 'b' : case 'strong' : $ block .= '**' . $ this -> getBlock ( $ node ) . '**' ; break ; case 'a' : if ( $ node -> hasAttribute ( 'href' ) ) { $ block .= '[' . $ this -> getBlock ( $ node ) . ']' . '(' . $ node -> getAttribute ( 'href' ) . ')' ; } break ; default : $ block .= $ this -> getBlock ( $ node ) ; break ; } break ; case XML_TEXT_NODE : $ block .= self :: escape ( $ node -> textContent ) ; break ; } } if ( in_array ( $ element -> nodeName , $ this -> white_list ) ) { $ tag = $ element -> cloneNode ( ) ; if ( ! empty ( $ block ) ) { $ tag -> appendChild ( new \ DOMText ( $ block ) ) ; } $ block = $ this -> dom -> saveXML ( $ tag ) ; } return $ block ; }
|
Converts a DOM element into a single Markdown block .
|
52,699
|
protected function getBlockList ( \ DOMElement $ element ) { $ lines = array ( ) ; $ prefix = $ element -> nodeName == 'ol' ? ' 1. ' : ' - ' ; if ( $ element -> nodeName == 'dl' ) { $ newline = TRUE ; foreach ( $ element -> childNodes as $ child ) { switch ( $ child -> nodeName ) { case 'dt' : if ( $ newline ) { $ lines [ ] = $ prefix . $ this -> getBlock ( $ child ) ; } else { $ lines [ count ( $ lines ) - 1 ] .= '<br/>' . $ this -> getBlock ( $ child ) ; } $ newline = FALSE ; break ; case 'dd' : $ lines [ count ( $ lines ) - 1 ] .= '<br/>' . $ this -> getBlock ( $ child ) ; $ newline = TRUE ; break ; } } } else { foreach ( $ element -> childNodes as $ child ) { switch ( $ child -> nodeName ) { case 'li' : $ lines [ ] = $ prefix . $ this -> getBlock ( $ child ) ; break ; } } } return implode ( "\n" , $ lines ) ; }
|
Converts a list - type \ DOMElement into a single Markdown block .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.