rpicms

A CMS for the Raspberry Pi
git clone git://archive.git.mtrnord.blog/RpicmsTeam/rpicms.git
Log | Files | Refs | README | LICENSE

State.php (1501B)


      1 <?php
      2 
      3 /**
      4  *  This program is free software: you can redistribute it and/or modify
      5  *  it under the terms of the GNU Lesser General Public License as published by
      6  *  the Free Software Foundation, either version 3 of the License, or
      7  *  (at your option) any later version.
      8  *
      9  *  This program is distributed in the hope that it will be useful,
     10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12  *  GNU Lesser General Public License for more details.
     13  *
     14  *  You should have received a copy of the GNU Lesser General Public License
     15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
     16  */
     17 
     18 namespace fkooman\OAuth\Client;
     19 
     20 use fkooman\OAuth\Client\Exception\TokenException;
     21 
     22 class State extends Token
     23 {
     24     /** state VARCHAR(255) NOT NULL */
     25     protected $state;
     26 
     27     public function __construct(array $data)
     28     {
     29         parent::__construct($data);
     30 
     31         foreach (array('state') as $key) {
     32             if (!array_key_exists($key, $data)) {
     33                 throw new TokenException(sprintf("missing field '%s'", $key));
     34             }
     35         }
     36 
     37         $this->setState($data['state']);
     38     }
     39 
     40     public function setState($state)
     41     {
     42         if (!is_string($state) || 0 >= strlen($state)) {
     43             throw new TokenException("state needs to be a non-empty string");
     44         }
     45         $this->state = $state;
     46     }
     47 
     48     public function getState()
     49     {
     50         return $this->state;
     51     }
     52 }