vendor/facebook/graph-sdk/src/Facebook/FacebookApp.php line 29

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright 2017 Facebook, Inc.
  4.  *
  5.  * You are hereby granted a non-exclusive, worldwide, royalty-free license to
  6.  * use, copy, modify, and distribute this software in source code or binary
  7.  * form for use in connection with the web services and APIs provided by
  8.  * Facebook.
  9.  *
  10.  * As with any software that integrates with the Facebook platform, your use
  11.  * of this software is subject to the Facebook Developer Principles and
  12.  * Policies [http://developers.facebook.com/policy/]. This copyright notice
  13.  * shall be included in all copies or substantial portions of the software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21.  * DEALINGS IN THE SOFTWARE.
  22.  *
  23.  */
  24. namespace Facebook;
  25. use Facebook\Authentication\AccessToken;
  26. use Facebook\Exceptions\FacebookSDKException;
  27. class FacebookApp implements \Serializable
  28. {
  29.     /**
  30.      * @var string The app ID.
  31.      */
  32.     protected $id;
  33.     /**
  34.      * @var string The app secret.
  35.      */
  36.     protected $secret;
  37.     /**
  38.      * @param string $id
  39.      * @param string $secret
  40.      *
  41.      * @throws FacebookSDKException
  42.      */
  43.     public function __construct($id$secret)
  44.     {
  45.         if (!is_string($id)
  46.           // Keeping this for BC. Integers greater than PHP_INT_MAX will make is_int() return false
  47.           && !is_int($id)) {
  48.             throw new FacebookSDKException('The "app_id" must be formatted as a string since many app ID\'s are greater than PHP_INT_MAX on some systems.');
  49.         }
  50.         // We cast as a string in case a valid int was set on a 64-bit system and this is unserialised on a 32-bit system
  51.         $this->id = (string) $id;
  52.         $this->secret $secret;
  53.     }
  54.     /**
  55.      * Returns the app ID.
  56.      *
  57.      * @return string
  58.      */
  59.     public function getId()
  60.     {
  61.         return $this->id;
  62.     }
  63.     /**
  64.      * Returns the app secret.
  65.      *
  66.      * @return string
  67.      */
  68.     public function getSecret()
  69.     {
  70.         return $this->secret;
  71.     }
  72.     /**
  73.      * Returns an app access token.
  74.      *
  75.      * @return AccessToken
  76.      */
  77.     public function getAccessToken()
  78.     {
  79.         return new AccessToken($this->id '|' $this->secret);
  80.     }
  81.     /**
  82.      * Serializes the FacebookApp entity as a string.
  83.      *
  84.      * @return string
  85.      */
  86.     public function serialize()
  87.     {
  88.         return implode('|', [$this->id$this->secret]);
  89.     }
  90.     /**
  91.      * Unserializes a string as a FacebookApp entity.
  92.      *
  93.      * @param string $serialized
  94.      */
  95.     public function unserialize($serialized)
  96.     {
  97.         list($id$secret) = explode('|'$serialized);
  98.         $this->__construct($id$secret);
  99.     }
  100. }