PayU integration by Krzysztof Gzocha
  • Namespace
  • Class

Namespaces

  • Team3
    • PayU
      • Annotation
      • Communication
        • CurlRequestBuilder
        • HttpStatusParser
        • Notification
        • Process
          • NotificationProcess
          • ResponseDeserializer
        • Request
          • Model
        • Response
          • Model
        • Sender
      • Configuration
        • Credentials
      • Order
        • Autocomplete
          • Strategy
        • Model
          • Buyer
          • Money
          • Products
          • ShippingMethods
          • Traits
        • Transformer
          • UserOrder
            • Strategy
              • Product
              • ShippingMethod
      • PropertyExtractor
        • Reader
      • Serializer
      • SignatureCalculator
        • Encoder
          • Algorithms
          • Strategy
        • ParametersSorter
        • Validator
      • ValidatorBuilder

Classes

  • Team3\PayU\ValidatorBuilder\ValidatorBuilder

Interfaces

  • Team3\PayU\ValidatorBuilder\ValidatorBuilderInterface
  1 <?php
  2 /**
  3  * @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl>
  4  */
  5 namespace Team3\PayU\PropertyExtractor\Reader;
  6 
  7 use Doctrine\Common\Annotations\Reader;
  8 use Psr\Log\LoggerInterface;
  9 use ReflectionClass;
 10 use ReflectionMethod;
 11 use Team3\PayU\Annotation\PayU;
 12 use Team3\PayU\PropertyExtractor\ExtractorException;
 13 
 14 class AnnotationReader implements ReaderInterface
 15 {
 16     const ANNOTATION_CLASS = 'Team3\PayU\Annotation\PayU';
 17 
 18     /**
 19      * @var Reader
 20      */
 21     private $reader;
 22 
 23     /**
 24      * @var LoggerInterface
 25      */
 26     private $logger;
 27 
 28     /**
 29      * @param Reader          $reader
 30      * @param LoggerInterface $logger
 31      */
 32     public function __construct(
 33         Reader $reader,
 34         LoggerInterface $logger
 35     ) {
 36         $this->reader = $reader;
 37         $this->logger = $logger;
 38     }
 39 
 40     /**
 41      * @inheritdoc
 42      */
 43     public function read($object)
 44     {
 45         try {
 46             $reflectionClass = new ReflectionClass($object);
 47         } catch (\ReflectionException $exception) {
 48             throw new ExtractorException(
 49                 $exception->getMessage(),
 50                 $exception->getCode(),
 51                 $exception
 52             );
 53         }
 54 
 55         $read = [];
 56 
 57         foreach ($this->getMethods($reflectionClass) as $reflectionMethod) {
 58             /** @var PayU $methodAnnotation */
 59             $methodAnnotation = $this
 60                 ->reader
 61                 ->getMethodAnnotation($reflectionMethod, self::ANNOTATION_CLASS);
 62 
 63             if (!is_object($methodAnnotation)) {
 64                 continue;
 65             }
 66 
 67             $readerResult = new ReaderResult(
 68                 $reflectionMethod->getName(),
 69                 $methodAnnotation->getPropertyName()
 70             );
 71             $read[] = $readerResult;
 72             $this->logReaderResult($readerResult, $object);
 73         }
 74 
 75         return $read;
 76     }
 77 
 78     /**
 79      * @param ReflectionClass $reflectionClass
 80      *
 81      * @return ReflectionMethod[]
 82      */
 83     private function getMethods(ReflectionClass $reflectionClass)
 84     {
 85         return $reflectionClass->getMethods();
 86     }
 87 
 88     /**
 89      * @param ReaderResultInterface $readerResult
 90      * @param object                $object
 91      */
 92     private function logReaderResult(
 93         ReaderResultInterface $readerResult,
 94         $object
 95     ) {
 96         $this
 97             ->logger
 98             ->debug(sprintf(
 99                 '%s found result on object %s method %s with property name %s',
100                 get_class($this),
101                 get_class($object),
102                 $readerResult->getMethodName(),
103                 $readerResult->getPropertyName()
104             ));
105     }
106 }
107 
PayU integration by Krzysztof Gzocha API documentation generated by ApiGen