## Paynetics Bundle Documentation

### Configuration
   
    paynetics:
        service:              ''
        cache:
            enable:               false
            driver:               paynetics.cache.adapter.redis
            expiration:           0
            key:                  token
            fallbackKey:          id
            extend:               15
            depth:                1
        kernel_exception:
            enable:               false
            type:                 api
            codes_location:       App\Exception\ExceptionCodes
            entity_location:      App\Entity
        serializer:
            snake_case:           true
            disable_type_enforcement: true
            allow_extra_attributes: true
            skip_null_values:     true
            datetime_format:      'Y-m-d H:i:s'
      

### Controller

#### AbstractApiController 

    Extends Symfony AbstractControlle
        
    Methods:
    
    protected function response($data, array $groups = [], int $code = 0, array $headers)
    
    - $data: any serializable object,array etc.
    - $groups: symfony serialzier serialization groups
    - $code: internal response code
    - $headers: array of headers to be sent with response
    
    protected function success($data, array $groups = [], array $headers)
    
        Alias for response with response code always 0
        
    protected function error($data, int $code = -1, array $headers)
    
        Alias for response for errors if not using AppException
      
    protected function normalizeFilters(string $data, string $type)
    
    - $data: POST request body to be normalized to array
    - $type: Model of filters that are allowed
    
    Additional:
    
    SerializationTrait
    ValidationTrait

    
#### AbstractWebController 

    Extends Symfony AbstractControlle
    
   
    Methods:
    
    protected function generateForm(string $type,$model,Request $request,string $redirect,callable $action,array $extra = [],array $parameters = [])
    
    - $type: Symfony Form Type
    - $model: Model for the Type
    - $request: Symfony Request
    - $redirect: Where to redirect after success (route name)
    - $action: Anonymous function to be called if form is submited and valid
    - $extra: Extra parameters to be passeed to Type (AbstractController::createForm($type,$model,$options = $extra))
    - $parameters: Parameters to be passed to redirectToRoute after success
    
    - return: Either symfony form view or RedirectResponse
    
    protected function redirectOrRender($form, ?string $view = null, array $data = [])
    
    - $form: Pass the result from the function above
    - $view: Twig view to be rendered
    - $data: Additional data to be passed to the view
    
    - return: Either redirect to new page or render view
    
    Addtional:
    
    TranslationTrait
    SerializationTrait
    PaginatorTrait


### DTOs

    ListDto
    
        Used for pagination
        
        Properties:
            - $items: array|Collection|ArrayCollection of items
            - $totalItems: count of all items
            
### BaseEntity
    
    Properties:
        - $id
        - $createdAt
        - $updatedOn
        - $isDeleted
        
### EntityInterface
    
    Marker interface
    
### Events

    EntityCacheEvent
        
        Dispatched when getting data with BaseRepository class
        
### EventSubscriber

    DoctrineEventSubscriber
        
        Subscribes to doctrine persist, flush and remove events
        Used for set, update, delete from cache
    
    EntityCacheLoadSubscriber
        
        Same as abovee only when selecting from DB
    
    KernelExceptionSubscriber
    
        Handle and format Excеptions
        
        
### Exception

    AppException 
    
        Custom exception used in the bundle
        
    ExceptionCodes
        
        Array of exception codes used in response when exception occures
        
### Extractor
    
    AnnotationExtractor
    
        Used to extract data from entity 
        
        Annotations : Settings, Cache
        
### FileManager
    
    S3FileManager:
    
        Aws read/write file manager

### Helpers

    use *Trait in your class to use it.
   
    Keep in mind that your service have to be created
    by symfony DI. Otherwise you have to pass dependacies
    to each trait.
    
#### AuditLogTrait

    Using monolog to log to elastic search
    Logging create, update, delete for each entity
    Can be used for any data such as user loggin action etc
    
    
     public function log(string $data): void
      - string $data: Pass json data to be logged

#### DispatcherTrait

    Symfony dispatcher interface
    
    public function dispatch(Event $event, ?string $name = null): void
        - Event $event: instance of build in or custom event
        - string $name: name of the event -- legacy for event dispatcher before 4.3

#### PaginatorTrait
    
    Knp paginator
    
    public function paginate(?array $data, int $page = 1, int $limit = 20): PaginationInterface
        - array $data: Data to be paginated
        - int $page: current page
        - int $limit: current limit

#### SerializationTrait

    Symfony serializer:
    
   [Context Options](SERIALIZER.md)
    
    public function serialize($data, array $context = [], string $format = 'json'): string

    public function deserialize(string $data,string $type,array $context = [],EntityInterface $existing = null,string $format = 'json')

    public function normalize($data, array $context = ['skip_null_values' => true])

#### TranslationTrait

#### URLParser

#### ValidationTrait


### BaseManager

    CRUD Doctrine manager
    
    Methods:
    
    repository:
    
    create:
    update:
    delete:
    
    Hooks:
    
    preCreate
    preUpdate
    preDelete
    preFlush
    
### BaseRepository


### Request

#### Http


#### Cache



### Validator

    EitherOrValidator
