Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Renderforest\ProjectData;
  4.  
  5. use Renderforest\Base\ApiEntityBase;
  6.  
  7. /**
  8.  * Class ProjectDataStyles
  9.  * @package Renderforest\ProjectData
  10.  */
  11. class ProjectDataStyles extends ApiEntityBase
  12. {
  13.     /**
  14.      *  Example JSON
  15.      *  {
  16.      *      "transition": "3",
  17.      *      "theme": "1"
  18.      *  }
  19.      */
  20.  
  21.     const KEY_THEME = 'theme';
  22.     const KEY_TRANSITION = 'transition';
  23.  
  24.     /** @var string */
  25.     protected $theme;
  26.  
  27.     /** @var string */
  28.     protected $transition;
  29.  
  30.     /**
  31.      * @return string
  32.      */
  33.     public function getTheme(): string
  34.     {
  35.         return $this->theme || '';
  36.     }
  37.  
  38.     /**
  39.      * @param string $theme
  40.      * @return ProjectDataStyles
  41.      */
  42.     public function setTheme(string $theme): ProjectDataStyles
  43.     {
  44.         $this->theme = $theme;
  45.  
  46.         return $this;
  47.     }
  48.  
  49.     /**
  50.      * @return string
  51.      */
  52.     public function getTransition(): string
  53.     {
  54.         return $this->transition || '';
  55.     }
  56.  
  57.     /**
  58.      * @param string $transition
  59.      * @return ProjectDataStyles
  60.      */
  61.     public function setTransition(string $transition): ProjectDataStyles
  62.     {
  63.         $this->transition = $transition;
  64.  
  65.         return $this;
  66.     }
  67.  
  68.     /**
  69.      * @param array $projectDataStylesArrayData
  70.      */
  71.     public function exchangeArray(array $projectDataStylesArrayData)
  72.     {
  73.         if (true === array_key_exists(self::KEY_THEME, $projectDataStylesArrayData)) {
  74.             $projectDataStylesTheme = $projectDataStylesArrayData[self::KEY_THEME];
  75.             $this->setTheme($projectDataStylesTheme);
  76.         }
  77.  
  78.         if (true === array_key_exists(self::KEY_TRANSITION, $projectDataStylesArrayData)) {
  79.             $projectDataStylesTransition = $projectDataStylesArrayData[self::KEY_TRANSITION];
  80.             $this->setTransition($projectDataStylesTransition);
  81.         }
  82.     }
  83.  
  84.     /**
  85.      * @return array
  86.      */
  87.     public function getArrayCopy(): array
  88.     {
  89.         $theme = $this->getTheme();
  90.         $transition = $this->getTransition();
  91.         $arrayCopy = [];
  92.         if ($theme !== '') {
  93.             $arrayCopy[self::KEY_THEME] = $theme;
  94.         }
  95.  
  96.         if ($transition) {
  97.             $arrayCopy[self::KEY_TRANSITION] = $transition;
  98.         }
  99.  
  100.         return $arrayCopy;
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement