Overview
  • Namespace
  • Class

Namespaces

  • PayPal
    • Api
    • Auth
    • Cache
    • Common
    • Converter
    • Core
    • Exception
    • Handler
    • Log
    • Rest
    • Security
    • Transport
    • Validation

Classes

  • PayPal\Api\Address
  • PayPal\Api\Agreement
  • PayPal\Api\AgreementDetails
  • PayPal\Api\AgreementStateDescriptor
  • PayPal\Api\AgreementTransaction
  • PayPal\Api\AgreementTransactions
  • PayPal\Api\AlternatePayment
  • PayPal\Api\Amount
  • PayPal\Api\Authorization
  • PayPal\Api\BankAccount
  • PayPal\Api\BankAccountsList
  • PayPal\Api\BankToken
  • PayPal\Api\BaseAddress
  • PayPal\Api\Billing
  • PayPal\Api\BillingAgreementToken
  • PayPal\Api\BillingInfo
  • PayPal\Api\CancelNotification
  • PayPal\Api\Capture
  • PayPal\Api\CarrierAccount
  • PayPal\Api\CarrierAccountToken
  • PayPal\Api\CartBase
  • PayPal\Api\ChargeModel
  • PayPal\Api\Cost
  • PayPal\Api\CountryCode
  • PayPal\Api\CreateProfileResponse
  • PayPal\Api\Credit
  • PayPal\Api\CreditCard
  • PayPal\Api\CreditCardHistory
  • PayPal\Api\CreditCardList
  • PayPal\Api\CreditCardToken
  • PayPal\Api\CreditFinancingOffered
  • PayPal\Api\Currency
  • PayPal\Api\CurrencyConversion
  • PayPal\Api\CustomAmount
  • PayPal\Api\DetailedRefund
  • PayPal\Api\Details
  • PayPal\Api\Error
  • PayPal\Api\ErrorDetails
  • PayPal\Api\ExtendedBankAccount
  • PayPal\Api\ExternalFunding
  • PayPal\Api\FileAttachment
  • PayPal\Api\FlowConfig
  • PayPal\Api\FmfDetails
  • PayPal\Api\FundingDetail
  • PayPal\Api\FundingInstrument
  • PayPal\Api\FundingOption
  • PayPal\Api\FundingSource
  • PayPal\Api\FuturePayment
  • PayPal\Api\HyperSchema
  • PayPal\Api\Image
  • PayPal\Api\Incentive
  • PayPal\Api\InputFields
  • PayPal\Api\InstallmentInfo
  • PayPal\Api\InstallmentOption
  • PayPal\Api\Invoice
  • PayPal\Api\InvoiceAddress
  • PayPal\Api\InvoiceItem
  • PayPal\Api\InvoiceNumber
  • PayPal\Api\InvoiceSearchResponse
  • PayPal\Api\Item
  • PayPal\Api\ItemList
  • PayPal\Api\Links
  • PayPal\Api\Measurement
  • PayPal\Api\MerchantInfo
  • PayPal\Api\MerchantPreferences
  • PayPal\Api\Metadata
  • PayPal\Api\NameValuePair
  • PayPal\Api\Notification
  • PayPal\Api\OpenIdAddress
  • PayPal\Api\OpenIdError
  • PayPal\Api\OpenIdSession
  • PayPal\Api\OpenIdTokeninfo
  • PayPal\Api\OpenIdUserinfo
  • PayPal\Api\Order
  • PayPal\Api\OverrideChargeModel
  • PayPal\Api\Participant
  • PayPal\Api\Patch
  • PayPal\Api\PatchRequest
  • PayPal\Api\Payee
  • PayPal\Api\Payer
  • PayPal\Api\PayerInfo
  • PayPal\Api\Payment
  • PayPal\Api\PaymentCard
  • PayPal\Api\PaymentCardToken
  • PayPal\Api\PaymentDefinition
  • PayPal\Api\PaymentDetail
  • PayPal\Api\PaymentExecution
  • PayPal\Api\PaymentHistory
  • PayPal\Api\PaymentInstruction
  • PayPal\Api\PaymentOptions
  • PayPal\Api\PaymentSummary
  • PayPal\Api\PaymentTerm
  • PayPal\Api\Payout
  • PayPal\Api\PayoutBatch
  • PayPal\Api\PayoutBatchHeader
  • PayPal\Api\PayoutItem
  • PayPal\Api\PayoutItemDetails
  • PayPal\Api\PayoutSenderBatchHeader
  • PayPal\Api\Phone
  • PayPal\Api\Plan
  • PayPal\Api\PlanList
  • PayPal\Api\PotentialPayerInfo
  • PayPal\Api\Presentation
  • PayPal\Api\PrivateLabelCard
  • PayPal\Api\ProcessorResponse
  • PayPal\Api\RecipientBankingInstruction
  • PayPal\Api\RedirectUrls
  • PayPal\Api\Refund
  • PayPal\Api\RefundDetail
  • PayPal\Api\RefundRequest
  • PayPal\Api\RelatedResources
  • PayPal\Api\Sale
  • PayPal\Api\Search
  • PayPal\Api\ShippingAddress
  • PayPal\Api\ShippingCost
  • PayPal\Api\ShippingInfo
  • PayPal\Api\Tax
  • PayPal\Api\Template
  • PayPal\Api\TemplateData
  • PayPal\Api\Templates
  • PayPal\Api\TemplateSettings
  • PayPal\Api\TemplateSettingsMetadata
  • PayPal\Api\Terms
  • PayPal\Api\Transaction
  • PayPal\Api\TransactionBase
  • PayPal\Api\Transactions
  • PayPal\Api\VerifyWebhookSignature
  • PayPal\Api\VerifyWebhookSignatureResponse
  • PayPal\Api\Webhook
  • PayPal\Api\WebhookEvent
  • PayPal\Api\WebhookEventList
  • PayPal\Api\WebhookEventType
  • PayPal\Api\WebhookEventTypeList
  • PayPal\Api\WebhookList
  • PayPal\Api\WebProfile
  • PayPal\Auth\OAuthTokenCredential
  • PayPal\Cache\AuthorizationCache
  • PayPal\Common\ArrayUtil
  • PayPal\Common\PayPalModel
  • PayPal\Common\PayPalResourceModel
  • PayPal\Common\PayPalUserAgent
  • PayPal\Common\ReflectionUtil
  • PayPal\Converter\FormatConverter
  • PayPal\Core\PayPalConfigManager
  • PayPal\Core\PayPalConstants
  • PayPal\Core\PayPalCredentialManager
  • PayPal\Core\PayPalHttpConfig
  • PayPal\Core\PayPalHttpConnection
  • PayPal\Core\PayPalLoggingManager
  • PayPal\Handler\OauthHandler
  • PayPal\Handler\RestHandler
  • PayPal\Log\PayPalDefaultLogFactory
  • PayPal\Log\PayPalLogger
  • PayPal\Rest\ApiContext
  • PayPal\Security\Cipher
  • PayPal\Transport\PayPalRestCall
  • PayPal\Validation\ArgumentValidator
  • PayPal\Validation\JsonValidator
  • PayPal\Validation\NumericValidator
  • PayPal\Validation\UrlValidator

Interfaces

  • PayPal\Handler\IPayPalHandler
  • PayPal\Log\PayPalLogFactory
  • PayPal\Rest\IResource

Exceptions

  • PayPal\Exception\PayPalConfigurationException
  • PayPal\Exception\PayPalConnectionException
  • PayPal\Exception\PayPalInvalidCredentialException
  • PayPal\Exception\PayPalMissingCredentialException
  1 <?php
  2 
  3 namespace PayPal\Common;
  4 
  5 use PayPal\Exception\PayPalConfigurationException;
  6 
  7 /**
  8  * Class ReflectionUtil
  9  *
 10  * @package PayPal\Common
 11  */
 12 class ReflectionUtil
 13 {
 14 
 15     /**
 16      * Reflection Methods
 17      *
 18      * @var \ReflectionMethod[]
 19      */
 20     private static $propertiesRefl = array();
 21 
 22     /**
 23      * Properties Type
 24      *
 25      * @var string[]
 26      */
 27     private static $propertiesType = array();
 28 
 29 
 30     /**
 31      * Gets Property Class of the given property.
 32      * If the class is null, it returns null.
 33      * If the property is not found, it returns null.
 34      *
 35      * @param $class
 36      * @param $propertyName
 37      * @return null|string
 38      * @throws PayPalConfigurationException
 39      */
 40     public static function getPropertyClass($class, $propertyName)
 41     {
 42         if ($class == get_class(new PayPalModel())) {
 43             // Make it generic if PayPalModel is used for generating this
 44             return get_class(new PayPalModel());
 45         }
 46 
 47         // If the class doesn't exist, or the method doesn't exist, return null.
 48         if (!class_exists($class) || !method_exists($class, self::getter($class, $propertyName))) {
 49             return null;
 50         }
 51 
 52         if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {
 53             $param = $annotations['return'];
 54         }
 55 
 56         if (isset($param)) {
 57             $anno = preg_split("/[\s\[\]]+/", $param);
 58             return $anno[0];
 59         } else {
 60             throw new PayPalConfigurationException("Getter function for '$propertyName' in '$class' class should have a proper return type.");
 61         }
 62     }
 63 
 64     /**
 65      * Checks if the Property is of type array or an object
 66      *
 67      * @param $class
 68      * @param $propertyName
 69      * @return null|boolean
 70      * @throws PayPalConfigurationException
 71      */
 72     public static function isPropertyClassArray($class, $propertyName)
 73     {
 74         // If the class doesn't exist, or the method doesn't exist, return null.
 75         if (!class_exists($class) || !method_exists($class, self::getter($class, $propertyName))) {
 76             return null;
 77         }
 78 
 79         if (($annotations = self::propertyAnnotations($class, $propertyName)) && isset($annotations['return'])) {
 80             $param = $annotations['return'];
 81         }
 82 
 83         if (isset($param)) {
 84             return substr($param, -strlen('[]'))==='[]';
 85         } else {
 86             throw new PayPalConfigurationException("Getter function for '$propertyName' in '$class' class should have a proper return type.");
 87         }
 88     }
 89 
 90     /**
 91      * Retrieves Annotations of each property
 92      *
 93      * @param $class
 94      * @param $propertyName
 95      * @throws \RuntimeException
 96      * @return mixed
 97      */
 98     public static function propertyAnnotations($class, $propertyName)
 99     {
100         $class = is_object($class) ? get_class($class) : $class;
101         if (!class_exists('ReflectionProperty')) {
102             throw new \RuntimeException("Property type of " . $class . "::{$propertyName} cannot be resolved");
103         }
104 
105         if ($annotations =& self::$propertiesType[$class][$propertyName]) {
106             return $annotations;
107         }
108 
109         if (!($refl =& self::$propertiesRefl[$class][$propertyName])) {
110             $getter = self::getter($class, $propertyName);
111             $refl = new \ReflectionMethod($class, $getter);
112             self::$propertiesRefl[$class][$propertyName] = $refl;
113         }
114 
115         // todo: smarter regexp
116         if (!preg_match_all(
117             '~\@([^\s@\(]+)[\t ]*(?:\(?([^\n@]+)\)?)?~i',
118             $refl->getDocComment(),
119             $annots,
120             PREG_PATTERN_ORDER)) {
121             return null;
122         }
123         foreach ($annots[1] as $i => $annot) {
124             $annotations[strtolower($annot)] = empty($annots[2][$i]) ? true : rtrim($annots[2][$i], " \t\n\r)");
125         }
126 
127         return $annotations;
128     }
129 
130     /**
131      * preg_replace_callback callback function
132      *
133      * @param $match
134      * @return string
135      */
136     private static function replace_callback($match)
137     {
138         return ucwords($match[2]);
139     }
140 
141     /**
142      * Returns the properly formatted getter function name based on class name and property
143      * Formats the property name to a standard getter function
144      *
145      * @param string $class
146      * @param string $propertyName
147      * @return string getter function name
148      */
149     public static function getter($class, $propertyName)
150     {
151         return method_exists($class, "get" . ucfirst($propertyName)) ?
152             "get" . ucfirst($propertyName) :
153             "get" . preg_replace_callback("/([_\-\s]?([a-z0-9]+))/", "self::replace_callback", $propertyName);
154     }
155 }
156 
API documentation generated by ApiGen