@@ -31,72 +31,72 @@ |
||
| 31 | 31 | class FacebookPageTabHelper extends FacebookCanvasLoginHelper |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var array|null |
|
| 36 | - */ |
|
| 37 | - protected $pageData; |
|
| 34 | + /** |
|
| 35 | + * @var array|null |
|
| 36 | + */ |
|
| 37 | + protected $pageData; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Initialize the helper and process available signed request data. |
|
| 41 | - * |
|
| 42 | - * @param string|null $appId |
|
| 43 | - * @param string|null $appSecret |
|
| 44 | - */ |
|
| 45 | - public function __construct($appId = null, $appSecret = null) |
|
| 46 | - { |
|
| 39 | + /** |
|
| 40 | + * Initialize the helper and process available signed request data. |
|
| 41 | + * |
|
| 42 | + * @param string|null $appId |
|
| 43 | + * @param string|null $appSecret |
|
| 44 | + */ |
|
| 45 | + public function __construct($appId = null, $appSecret = null) |
|
| 46 | + { |
|
| 47 | 47 | parent::__construct($appId, $appSecret); |
| 48 | 48 | |
| 49 | 49 | if (!$this->signedRequest) { |
| 50 | - return; |
|
| 50 | + return; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | $this->pageData = $this->signedRequest->get('page'); |
| 54 | - } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Returns a value from the page data. |
|
| 58 | - * |
|
| 59 | - * @param string $key |
|
| 60 | - * @param mixed|null $default |
|
| 61 | - * |
|
| 62 | - * @return mixed|null |
|
| 63 | - */ |
|
| 64 | - public function getPageData($key, $default = null) |
|
| 65 | - { |
|
| 56 | + /** |
|
| 57 | + * Returns a value from the page data. |
|
| 58 | + * |
|
| 59 | + * @param string $key |
|
| 60 | + * @param mixed|null $default |
|
| 61 | + * |
|
| 62 | + * @return mixed|null |
|
| 63 | + */ |
|
| 64 | + public function getPageData($key, $default = null) |
|
| 65 | + { |
|
| 66 | 66 | if (isset($this->pageData[$key])) { |
| 67 | - return $this->pageData[$key]; |
|
| 67 | + return $this->pageData[$key]; |
|
| 68 | 68 | } |
| 69 | 69 | return $default; |
| 70 | - } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Returns true if the page is liked by the user. |
|
| 74 | - * |
|
| 75 | - * @return boolean |
|
| 76 | - */ |
|
| 77 | - public function isLiked() |
|
| 78 | - { |
|
| 72 | + /** |
|
| 73 | + * Returns true if the page is liked by the user. |
|
| 74 | + * |
|
| 75 | + * @return boolean |
|
| 76 | + */ |
|
| 77 | + public function isLiked() |
|
| 78 | + { |
|
| 79 | 79 | return $this->getPageData('liked') === true; |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Returns true if the user is an admin. |
|
| 84 | - * |
|
| 85 | - * @return boolean |
|
| 86 | - */ |
|
| 87 | - public function isAdmin() |
|
| 88 | - { |
|
| 82 | + /** |
|
| 83 | + * Returns true if the user is an admin. |
|
| 84 | + * |
|
| 85 | + * @return boolean |
|
| 86 | + */ |
|
| 87 | + public function isAdmin() |
|
| 88 | + { |
|
| 89 | 89 | return $this->getPageData('admin') === true; |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Returns the page id if available. |
|
| 94 | - * |
|
| 95 | - * @return string|null |
|
| 96 | - */ |
|
| 97 | - public function getPageId() |
|
| 98 | - { |
|
| 92 | + /** |
|
| 93 | + * Returns the page id if available. |
|
| 94 | + * |
|
| 95 | + * @return string|null |
|
| 96 | + */ |
|
| 97 | + public function getPageId() |
|
| 98 | + { |
|
| 99 | 99 | return $this->getPageData('id'); |
| 100 | - } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | } |
@@ -32,84 +32,84 @@ |
||
| 32 | 32 | class GraphSessionInfo extends GraphObject |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Returns the application id the token was issued for. |
|
| 37 | - * |
|
| 38 | - * @return string|null |
|
| 39 | - */ |
|
| 40 | - public function getAppId() |
|
| 41 | - { |
|
| 35 | + /** |
|
| 36 | + * Returns the application id the token was issued for. |
|
| 37 | + * |
|
| 38 | + * @return string|null |
|
| 39 | + */ |
|
| 40 | + public function getAppId() |
|
| 41 | + { |
|
| 42 | 42 | return $this->getProperty('app_id'); |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Returns the application name the token was issued for. |
|
| 47 | - * |
|
| 48 | - * @return string|null |
|
| 49 | - */ |
|
| 50 | - public function getApplication() |
|
| 51 | - { |
|
| 45 | + /** |
|
| 46 | + * Returns the application name the token was issued for. |
|
| 47 | + * |
|
| 48 | + * @return string|null |
|
| 49 | + */ |
|
| 50 | + public function getApplication() |
|
| 51 | + { |
|
| 52 | 52 | return $this->getProperty('application'); |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Returns the date & time that the token expires. |
|
| 57 | - * |
|
| 58 | - * @return \DateTime|null |
|
| 59 | - */ |
|
| 60 | - public function getExpiresAt() |
|
| 61 | - { |
|
| 55 | + /** |
|
| 56 | + * Returns the date & time that the token expires. |
|
| 57 | + * |
|
| 58 | + * @return \DateTime|null |
|
| 59 | + */ |
|
| 60 | + public function getExpiresAt() |
|
| 61 | + { |
|
| 62 | 62 | $stamp = $this->getProperty('expires_at'); |
| 63 | 63 | if ($stamp) { |
| 64 | - return (new \DateTime())->setTimestamp($stamp); |
|
| 64 | + return (new \DateTime())->setTimestamp($stamp); |
|
| 65 | 65 | } else { |
| 66 | - return null; |
|
| 66 | + return null; |
|
| 67 | + } |
|
| 67 | 68 | } |
| 68 | - } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Returns whether the token is valid. |
|
| 72 | - * |
|
| 73 | - * @return boolean |
|
| 74 | - */ |
|
| 75 | - public function isValid() |
|
| 76 | - { |
|
| 70 | + /** |
|
| 71 | + * Returns whether the token is valid. |
|
| 72 | + * |
|
| 73 | + * @return boolean |
|
| 74 | + */ |
|
| 75 | + public function isValid() |
|
| 76 | + { |
|
| 77 | 77 | return $this->getProperty('is_valid'); |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Returns the date & time the token was issued at. |
|
| 82 | - * |
|
| 83 | - * @return \DateTime|null |
|
| 84 | - */ |
|
| 85 | - public function getIssuedAt() |
|
| 86 | - { |
|
| 80 | + /** |
|
| 81 | + * Returns the date & time the token was issued at. |
|
| 82 | + * |
|
| 83 | + * @return \DateTime|null |
|
| 84 | + */ |
|
| 85 | + public function getIssuedAt() |
|
| 86 | + { |
|
| 87 | 87 | $stamp = $this->getProperty('issued_at'); |
| 88 | 88 | if ($stamp) { |
| 89 | - return (new \DateTime())->setTimestamp($stamp); |
|
| 89 | + return (new \DateTime())->setTimestamp($stamp); |
|
| 90 | 90 | } else { |
| 91 | - return null; |
|
| 91 | + return null; |
|
| 92 | + } |
|
| 92 | 93 | } |
| 93 | - } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Returns the scope permissions associated with the token. |
|
| 97 | - * |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - public function getScopes() |
|
| 101 | - { |
|
| 95 | + /** |
|
| 96 | + * Returns the scope permissions associated with the token. |
|
| 97 | + * |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + public function getScopes() |
|
| 101 | + { |
|
| 102 | 102 | return $this->getPropertyAsArray('scopes'); |
| 103 | - } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Returns the login id of the user associated with the token. |
|
| 107 | - * |
|
| 108 | - * @return string|null |
|
| 109 | - */ |
|
| 110 | - public function getId() |
|
| 111 | - { |
|
| 105 | + /** |
|
| 106 | + * Returns the login id of the user associated with the token. |
|
| 107 | + * |
|
| 108 | + * @return string|null |
|
| 109 | + */ |
|
| 110 | + public function getId() |
|
| 111 | + { |
|
| 112 | 112 | return $this->getProperty('user_id'); |
| 113 | - } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | } |
| 116 | 116 | \ No newline at end of file |
@@ -32,175 +32,175 @@ |
||
| 32 | 32 | class FacebookResponse |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var FacebookRequest The request which produced this response |
|
| 37 | - */ |
|
| 38 | - private $request; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array The decoded response from the Graph API |
|
| 42 | - */ |
|
| 43 | - private $responseData; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string The raw response from the Graph API |
|
| 47 | - */ |
|
| 48 | - private $rawResponse; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var bool Indicates whether sent ETag matched the one on the FB side |
|
| 52 | - */ |
|
| 53 | - private $etagHit; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var string ETag received with the response. `null` in case of ETag hit. |
|
| 57 | - */ |
|
| 58 | - private $etag; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Creates a FacebookResponse object for a given request and response. |
|
| 62 | - * |
|
| 63 | - * @param FacebookRequest $request |
|
| 64 | - * @param array $responseData JSON Decoded response data |
|
| 65 | - * @param string $rawResponse Raw string response |
|
| 66 | - * @param bool $etagHit Indicates whether sent ETag matched the one on the FB side |
|
| 67 | - * @param string|null $etag ETag received with the response. `null` in case of ETag hit. |
|
| 68 | - */ |
|
| 69 | - public function __construct($request, $responseData, $rawResponse, $etagHit = false, $etag = null) |
|
| 70 | - { |
|
| 35 | + /** |
|
| 36 | + * @var FacebookRequest The request which produced this response |
|
| 37 | + */ |
|
| 38 | + private $request; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array The decoded response from the Graph API |
|
| 42 | + */ |
|
| 43 | + private $responseData; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string The raw response from the Graph API |
|
| 47 | + */ |
|
| 48 | + private $rawResponse; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var bool Indicates whether sent ETag matched the one on the FB side |
|
| 52 | + */ |
|
| 53 | + private $etagHit; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var string ETag received with the response. `null` in case of ETag hit. |
|
| 57 | + */ |
|
| 58 | + private $etag; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Creates a FacebookResponse object for a given request and response. |
|
| 62 | + * |
|
| 63 | + * @param FacebookRequest $request |
|
| 64 | + * @param array $responseData JSON Decoded response data |
|
| 65 | + * @param string $rawResponse Raw string response |
|
| 66 | + * @param bool $etagHit Indicates whether sent ETag matched the one on the FB side |
|
| 67 | + * @param string|null $etag ETag received with the response. `null` in case of ETag hit. |
|
| 68 | + */ |
|
| 69 | + public function __construct($request, $responseData, $rawResponse, $etagHit = false, $etag = null) |
|
| 70 | + { |
|
| 71 | 71 | $this->request = $request; |
| 72 | 72 | $this->responseData = $responseData; |
| 73 | 73 | $this->rawResponse = $rawResponse; |
| 74 | 74 | $this->etagHit = $etagHit; |
| 75 | 75 | $this->etag = $etag; |
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Returns the request which produced this response. |
|
| 80 | - * |
|
| 81 | - * @return FacebookRequest |
|
| 82 | - */ |
|
| 83 | - public function getRequest() |
|
| 84 | - { |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Returns the request which produced this response. |
|
| 80 | + * |
|
| 81 | + * @return FacebookRequest |
|
| 82 | + */ |
|
| 83 | + public function getRequest() |
|
| 84 | + { |
|
| 85 | 85 | return $this->request; |
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Returns the decoded response data. |
|
| 90 | - * |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - public function getResponse() |
|
| 94 | - { |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Returns the decoded response data. |
|
| 90 | + * |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + public function getResponse() |
|
| 94 | + { |
|
| 95 | 95 | return $this->responseData; |
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Returns the raw response |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - public function getRawResponse() |
|
| 104 | - { |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Returns the raw response |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + public function getRawResponse() |
|
| 104 | + { |
|
| 105 | 105 | return $this->rawResponse; |
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Returns true if ETag matched the one sent with a request |
|
| 110 | - * |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function isETagHit() |
|
| 114 | - { |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Returns true if ETag matched the one sent with a request |
|
| 110 | + * |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function isETagHit() |
|
| 114 | + { |
|
| 115 | 115 | return $this->etagHit; |
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Returns the ETag |
|
| 120 | - * |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function getETag() |
|
| 124 | - { |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Returns the ETag |
|
| 120 | + * |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function getETag() |
|
| 124 | + { |
|
| 125 | 125 | return $this->etag; |
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Gets the result as a GraphObject. If a type is specified, returns the |
|
| 130 | - * strongly-typed subclass of GraphObject for the data. |
|
| 131 | - * |
|
| 132 | - * @param string $type |
|
| 133 | - * |
|
| 134 | - * @return mixed |
|
| 135 | - */ |
|
| 136 | - public function getGraphObject($type = 'Facebook\GraphObject') { |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Gets the result as a GraphObject. If a type is specified, returns the |
|
| 130 | + * strongly-typed subclass of GraphObject for the data. |
|
| 131 | + * |
|
| 132 | + * @param string $type |
|
| 133 | + * |
|
| 134 | + * @return mixed |
|
| 135 | + */ |
|
| 136 | + public function getGraphObject($type = 'Facebook\GraphObject') { |
|
| 137 | 137 | return (new GraphObject($this->responseData))->cast($type); |
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns an array of GraphObject returned by the request. If a type is |
|
| 142 | - * specified, returns the strongly-typed subclass of GraphObject for the data. |
|
| 143 | - * |
|
| 144 | - * @param string $type |
|
| 145 | - * |
|
| 146 | - * @return mixed |
|
| 147 | - */ |
|
| 148 | - public function getGraphObjectList($type = 'Facebook\GraphObject') { |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns an array of GraphObject returned by the request. If a type is |
|
| 142 | + * specified, returns the strongly-typed subclass of GraphObject for the data. |
|
| 143 | + * |
|
| 144 | + * @param string $type |
|
| 145 | + * |
|
| 146 | + * @return mixed |
|
| 147 | + */ |
|
| 148 | + public function getGraphObjectList($type = 'Facebook\GraphObject') { |
|
| 149 | 149 | $out = array(); |
| 150 | 150 | $data = $this->responseData->data; |
| 151 | 151 | $dataLength = count($data); |
| 152 | 152 | for ($i = 0; $i < $dataLength; $i++) { |
| 153 | - $out[] = (new GraphObject($data[$i]))->cast($type); |
|
| 153 | + $out[] = (new GraphObject($data[$i]))->cast($type); |
|
| 154 | 154 | } |
| 155 | 155 | return $out; |
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * If this response has paginated data, returns the FacebookRequest for the |
|
| 160 | - * next page, or null. |
|
| 161 | - * |
|
| 162 | - * @return FacebookRequest|null |
|
| 163 | - */ |
|
| 164 | - public function getRequestForNextPage() |
|
| 165 | - { |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * If this response has paginated data, returns the FacebookRequest for the |
|
| 160 | + * next page, or null. |
|
| 161 | + * |
|
| 162 | + * @return FacebookRequest|null |
|
| 163 | + */ |
|
| 164 | + public function getRequestForNextPage() |
|
| 165 | + { |
|
| 166 | 166 | return $this->handlePagination('next'); |
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * If this response has paginated data, returns the FacebookRequest for the |
|
| 171 | - * previous page, or null. |
|
| 172 | - * |
|
| 173 | - * @return FacebookRequest|null |
|
| 174 | - */ |
|
| 175 | - public function getRequestForPreviousPage() |
|
| 176 | - { |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * If this response has paginated data, returns the FacebookRequest for the |
|
| 171 | + * previous page, or null. |
|
| 172 | + * |
|
| 173 | + * @return FacebookRequest|null |
|
| 174 | + */ |
|
| 175 | + public function getRequestForPreviousPage() |
|
| 176 | + { |
|
| 177 | 177 | return $this->handlePagination('previous'); |
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Returns the FacebookRequest for the previous or next page, or null. |
|
| 182 | - * |
|
| 183 | - * @param string $direction |
|
| 184 | - * |
|
| 185 | - * @return FacebookRequest|null |
|
| 186 | - */ |
|
| 187 | - private function handlePagination($direction) { |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Returns the FacebookRequest for the previous or next page, or null. |
|
| 182 | + * |
|
| 183 | + * @param string $direction |
|
| 184 | + * |
|
| 185 | + * @return FacebookRequest|null |
|
| 186 | + */ |
|
| 187 | + private function handlePagination($direction) { |
|
| 188 | 188 | if (isset($this->responseData->paging->$direction)) { |
| 189 | - $url = parse_url($this->responseData->paging->$direction); |
|
| 190 | - parse_str($url['query'], $params); |
|
| 189 | + $url = parse_url($this->responseData->paging->$direction); |
|
| 190 | + parse_str($url['query'], $params); |
|
| 191 | 191 | |
| 192 | - if (isset($params['type']) && strpos($this->request->getPath(), $params['type']) !== false){ |
|
| 192 | + if (isset($params['type']) && strpos($this->request->getPath(), $params['type']) !== false){ |
|
| 193 | 193 | unset($params['type']); |
| 194 | - } |
|
| 195 | - return new FacebookRequest( |
|
| 194 | + } |
|
| 195 | + return new FacebookRequest( |
|
| 196 | 196 | $this->request->getSession(), |
| 197 | 197 | $this->request->getMethod(), |
| 198 | 198 | $this->request->getPath(), |
| 199 | 199 | $params |
| 200 | - ); |
|
| 200 | + ); |
|
| 201 | 201 | } else { |
| 202 | - return null; |
|
| 202 | + return null; |
|
| 203 | + } |
|
| 203 | 204 | } |
| 204 | - } |
|
| 205 | 205 | |
| 206 | 206 | } |
@@ -189,7 +189,7 @@ |
||
| 189 | 189 | $url = parse_url($this->responseData->paging->$direction); |
| 190 | 190 | parse_str($url['query'], $params); |
| 191 | 191 | |
| 192 | - if (isset($params['type']) && strpos($this->request->getPath(), $params['type']) !== false){ |
|
| 192 | + if (isset($params['type']) && strpos($this->request->getPath(), $params['type']) !== false) { |
|
| 193 | 193 | unset($params['type']); |
| 194 | 194 | } |
| 195 | 195 | return new FacebookRequest( |
@@ -32,58 +32,58 @@ discard block |
||
| 32 | 32 | class FacebookRequestException extends FacebookSDKException |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var int Status code for the response causing the exception |
|
| 37 | - */ |
|
| 38 | - private $statusCode; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string Raw response |
|
| 42 | - */ |
|
| 43 | - private $rawResponse; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var array Decoded response |
|
| 47 | - */ |
|
| 48 | - private $responseData; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Creates a FacebookRequestException. |
|
| 52 | - * |
|
| 53 | - * @param string $rawResponse The raw response from the Graph API |
|
| 54 | - * @param array $responseData The decoded response from the Graph API |
|
| 55 | - * @param int $statusCode |
|
| 56 | - */ |
|
| 57 | - public function __construct($rawResponse, $responseData, $statusCode) |
|
| 58 | - { |
|
| 35 | + /** |
|
| 36 | + * @var int Status code for the response causing the exception |
|
| 37 | + */ |
|
| 38 | + private $statusCode; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string Raw response |
|
| 42 | + */ |
|
| 43 | + private $rawResponse; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var array Decoded response |
|
| 47 | + */ |
|
| 48 | + private $responseData; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Creates a FacebookRequestException. |
|
| 52 | + * |
|
| 53 | + * @param string $rawResponse The raw response from the Graph API |
|
| 54 | + * @param array $responseData The decoded response from the Graph API |
|
| 55 | + * @param int $statusCode |
|
| 56 | + */ |
|
| 57 | + public function __construct($rawResponse, $responseData, $statusCode) |
|
| 58 | + { |
|
| 59 | 59 | $this->rawResponse = $rawResponse; |
| 60 | 60 | $this->statusCode = $statusCode; |
| 61 | 61 | $this->responseData = self::convertToArray($responseData); |
| 62 | 62 | parent::__construct( |
| 63 | - $this->get('message', 'Unknown Exception'), $this->get('code', -1), null |
|
| 63 | + $this->get('message', 'Unknown Exception'), $this->get('code', -1), null |
|
| 64 | 64 | ); |
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Process an error payload from the Graph API and return the appropriate |
|
| 69 | - * exception subclass. |
|
| 70 | - * |
|
| 71 | - * @param string $raw the raw response from the Graph API |
|
| 72 | - * @param array $data the decoded response from the Graph API |
|
| 73 | - * @param int $statusCode the HTTP response code |
|
| 74 | - * |
|
| 75 | - * @return FacebookRequestException |
|
| 76 | - */ |
|
| 77 | - public static function create($raw, $data, $statusCode) |
|
| 78 | - { |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Process an error payload from the Graph API and return the appropriate |
|
| 69 | + * exception subclass. |
|
| 70 | + * |
|
| 71 | + * @param string $raw the raw response from the Graph API |
|
| 72 | + * @param array $data the decoded response from the Graph API |
|
| 73 | + * @param int $statusCode the HTTP response code |
|
| 74 | + * |
|
| 75 | + * @return FacebookRequestException |
|
| 76 | + */ |
|
| 77 | + public static function create($raw, $data, $statusCode) |
|
| 78 | + { |
|
| 79 | 79 | $data = self::convertToArray($data); |
| 80 | 80 | if (!isset($data['error']['code']) && isset($data['code'])) { |
| 81 | - $data = array('error' => $data); |
|
| 81 | + $data = array('error' => $data); |
|
| 82 | 82 | } |
| 83 | 83 | $code = (isset($data['error']['code']) ? $data['error']['code'] : null); |
| 84 | 84 | |
| 85 | 85 | if (isset($data['error']['error_subcode'])) { |
| 86 | - switch ($data['error']['error_subcode']) { |
|
| 86 | + switch ($data['error']['error_subcode']) { |
|
| 87 | 87 | // Other authentication issues |
| 88 | 88 | case 458: |
| 89 | 89 | case 459: |
@@ -92,131 +92,131 @@ discard block |
||
| 92 | 92 | case 464: |
| 93 | 93 | case 467: |
| 94 | 94 | return new FacebookAuthorizationException($raw, $data, $statusCode); |
| 95 | - break; |
|
| 96 | - } |
|
| 95 | + break; |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | switch ($code) { |
| 100 | - // Login status or token expired, revoked, or invalid |
|
| 101 | - case 100: |
|
| 100 | + // Login status or token expired, revoked, or invalid |
|
| 101 | + case 100: |
|
| 102 | 102 | case 102: |
| 103 | 103 | case 190: |
| 104 | 104 | return new FacebookAuthorizationException($raw, $data, $statusCode); |
| 105 | 105 | break; |
| 106 | 106 | |
| 107 | - // Server issue, possible downtime |
|
| 108 | - case 1: |
|
| 107 | + // Server issue, possible downtime |
|
| 108 | + case 1: |
|
| 109 | 109 | case 2: |
| 110 | 110 | return new FacebookServerException($raw, $data, $statusCode); |
| 111 | 111 | break; |
| 112 | 112 | |
| 113 | - // API Throttling |
|
| 114 | - case 4: |
|
| 113 | + // API Throttling |
|
| 114 | + case 4: |
|
| 115 | 115 | case 17: |
| 116 | 116 | case 341: |
| 117 | 117 | return new FacebookThrottleException($raw, $data, $statusCode); |
| 118 | 118 | break; |
| 119 | 119 | |
| 120 | - // Duplicate Post |
|
| 121 | - case 506: |
|
| 120 | + // Duplicate Post |
|
| 121 | + case 506: |
|
| 122 | 122 | return new FacebookClientException($raw, $data, $statusCode); |
| 123 | 123 | break; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // Missing Permissions |
| 127 | 127 | if ($code == 10 || ($code >= 200 && $code <= 299)) { |
| 128 | - return new FacebookPermissionException($raw, $data, $statusCode); |
|
| 128 | + return new FacebookPermissionException($raw, $data, $statusCode); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // OAuth authentication error |
| 132 | 132 | if (isset($data['error']['type']) |
| 133 | 133 | and $data['error']['type'] === 'OAuthException') { |
| 134 | - return new FacebookAuthorizationException($raw, $data, $statusCode); |
|
| 134 | + return new FacebookAuthorizationException($raw, $data, $statusCode); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // All others |
| 138 | 138 | return new FacebookOtherException($raw, $data, $statusCode); |
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Checks isset and returns that or a default value. |
|
| 143 | - * |
|
| 144 | - * @param string $key |
|
| 145 | - * @param mixed $default |
|
| 146 | - * |
|
| 147 | - * @return mixed |
|
| 148 | - */ |
|
| 149 | - private function get($key, $default = null) |
|
| 150 | - { |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Checks isset and returns that or a default value. |
|
| 143 | + * |
|
| 144 | + * @param string $key |
|
| 145 | + * @param mixed $default |
|
| 146 | + * |
|
| 147 | + * @return mixed |
|
| 148 | + */ |
|
| 149 | + private function get($key, $default = null) |
|
| 150 | + { |
|
| 151 | 151 | if (isset($this->responseData['error'][$key])) { |
| 152 | - return $this->responseData['error'][$key]; |
|
| 152 | + return $this->responseData['error'][$key]; |
|
| 153 | 153 | } |
| 154 | 154 | return $default; |
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Returns the HTTP status code |
|
| 159 | - * |
|
| 160 | - * @return int |
|
| 161 | - */ |
|
| 162 | - public function getHttpStatusCode() |
|
| 163 | - { |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Returns the HTTP status code |
|
| 159 | + * |
|
| 160 | + * @return int |
|
| 161 | + */ |
|
| 162 | + public function getHttpStatusCode() |
|
| 163 | + { |
|
| 164 | 164 | return $this->statusCode; |
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Returns the sub-error code |
|
| 169 | - * |
|
| 170 | - * @return int |
|
| 171 | - */ |
|
| 172 | - public function getSubErrorCode() |
|
| 173 | - { |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Returns the sub-error code |
|
| 169 | + * |
|
| 170 | + * @return int |
|
| 171 | + */ |
|
| 172 | + public function getSubErrorCode() |
|
| 173 | + { |
|
| 174 | 174 | return $this->get('error_subcode', -1); |
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Returns the error type |
|
| 179 | - * |
|
| 180 | - * @return string |
|
| 181 | - */ |
|
| 182 | - public function getErrorType() |
|
| 183 | - { |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Returns the error type |
|
| 179 | + * |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 182 | + public function getErrorType() |
|
| 183 | + { |
|
| 184 | 184 | return $this->get('type', ''); |
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Returns the raw response used to create the exception. |
|
| 189 | - * |
|
| 190 | - * @return string |
|
| 191 | - */ |
|
| 192 | - public function getRawResponse() |
|
| 193 | - { |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Returns the raw response used to create the exception. |
|
| 189 | + * |
|
| 190 | + * @return string |
|
| 191 | + */ |
|
| 192 | + public function getRawResponse() |
|
| 193 | + { |
|
| 194 | 194 | return $this->rawResponse; |
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Returns the decoded response used to create the exception. |
|
| 199 | - * |
|
| 200 | - * @return array |
|
| 201 | - */ |
|
| 202 | - public function getResponse() |
|
| 203 | - { |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Returns the decoded response used to create the exception. |
|
| 199 | + * |
|
| 200 | + * @return array |
|
| 201 | + */ |
|
| 202 | + public function getResponse() |
|
| 203 | + { |
|
| 204 | 204 | return $this->responseData; |
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Converts a stdClass object to an array |
|
| 209 | - * |
|
| 210 | - * @param mixed $object |
|
| 211 | - * |
|
| 212 | - * @return array |
|
| 213 | - */ |
|
| 214 | - private static function convertToArray($object) |
|
| 215 | - { |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Converts a stdClass object to an array |
|
| 209 | + * |
|
| 210 | + * @param mixed $object |
|
| 211 | + * |
|
| 212 | + * @return array |
|
| 213 | + */ |
|
| 214 | + private static function convertToArray($object) |
|
| 215 | + { |
|
| 216 | 216 | if ($object instanceof \stdClass) { |
| 217 | - return get_object_vars($object); |
|
| 217 | + return get_object_vars($object); |
|
| 218 | 218 | } |
| 219 | 219 | return $object; |
| 220 | - } |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | 222 | } |
| 223 | 223 | \ No newline at end of file |
@@ -32,14 +32,14 @@ |
||
| 32 | 32 | class FacebookJavaScriptLoginHelper extends FacebookSignedRequestFromInputHelper |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Get raw signed request from the cookie. |
|
| 37 | - * |
|
| 38 | - * @return string|null |
|
| 39 | - */ |
|
| 40 | - public function getRawSignedRequest() |
|
| 41 | - { |
|
| 35 | + /** |
|
| 36 | + * Get raw signed request from the cookie. |
|
| 37 | + * |
|
| 38 | + * @return string|null |
|
| 39 | + */ |
|
| 40 | + public function getRawSignedRequest() |
|
| 41 | + { |
|
| 42 | 42 | return $this->getRawSignedRequestFromCookie(); |
| 43 | - } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | } |
@@ -30,39 +30,39 @@ |
||
| 30 | 30 | interface FacebookHttpable |
| 31 | 31 | { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The headers we want to send with the request |
|
| 35 | - * |
|
| 36 | - * @param string $key |
|
| 37 | - * @param string $value |
|
| 38 | - */ |
|
| 39 | - public function addRequestHeader($key, $value); |
|
| 33 | + /** |
|
| 34 | + * The headers we want to send with the request |
|
| 35 | + * |
|
| 36 | + * @param string $key |
|
| 37 | + * @param string $value |
|
| 38 | + */ |
|
| 39 | + public function addRequestHeader($key, $value); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The headers returned in the response |
|
| 43 | - * |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - public function getResponseHeaders(); |
|
| 41 | + /** |
|
| 42 | + * The headers returned in the response |
|
| 43 | + * |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + public function getResponseHeaders(); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * The HTTP status response code |
|
| 50 | - * |
|
| 51 | - * @return int |
|
| 52 | - */ |
|
| 53 | - public function getResponseHttpStatusCode(); |
|
| 48 | + /** |
|
| 49 | + * The HTTP status response code |
|
| 50 | + * |
|
| 51 | + * @return int |
|
| 52 | + */ |
|
| 53 | + public function getResponseHttpStatusCode(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Sends a request to the server |
|
| 57 | - * |
|
| 58 | - * @param string $url The endpoint to send the request to |
|
| 59 | - * @param string $method The request method |
|
| 60 | - * @param array $parameters The key value pairs to be sent in the body |
|
| 61 | - * |
|
| 62 | - * @return string Raw response from the server |
|
| 63 | - * |
|
| 64 | - * @throws \Facebook\FacebookSDKException |
|
| 65 | - */ |
|
| 66 | - public function send($url, $method = 'GET', $parameters = array()); |
|
| 55 | + /** |
|
| 56 | + * Sends a request to the server |
|
| 57 | + * |
|
| 58 | + * @param string $url The endpoint to send the request to |
|
| 59 | + * @param string $method The request method |
|
| 60 | + * @param array $parameters The key value pairs to be sent in the body |
|
| 61 | + * |
|
| 62 | + * @return string Raw response from the server |
|
| 63 | + * |
|
| 64 | + * @throws \Facebook\FacebookSDKException |
|
| 65 | + */ |
|
| 66 | + public function send($url, $method = 'GET', $parameters = array()); |
|
| 67 | 67 | |
| 68 | 68 | } |
@@ -32,48 +32,48 @@ |
||
| 32 | 32 | class FacebookStream |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var resource Context stream resource instance |
|
| 37 | - */ |
|
| 38 | - protected $stream; |
|
| 35 | + /** |
|
| 36 | + * @var resource Context stream resource instance |
|
| 37 | + */ |
|
| 38 | + protected $stream; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var array Response headers from the stream wrapper |
|
| 42 | - */ |
|
| 43 | - protected $responseHeaders; |
|
| 40 | + /** |
|
| 41 | + * @var array Response headers from the stream wrapper |
|
| 42 | + */ |
|
| 43 | + protected $responseHeaders; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Make a new context stream reference instance |
|
| 47 | - * |
|
| 48 | - * @param array $options |
|
| 49 | - */ |
|
| 50 | - public function streamContextCreate(array $options) |
|
| 51 | - { |
|
| 45 | + /** |
|
| 46 | + * Make a new context stream reference instance |
|
| 47 | + * |
|
| 48 | + * @param array $options |
|
| 49 | + */ |
|
| 50 | + public function streamContextCreate(array $options) |
|
| 51 | + { |
|
| 52 | 52 | $this->stream = stream_context_create($options); |
| 53 | - } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * The response headers from the stream wrapper |
|
| 57 | - * |
|
| 58 | - * @return array|null |
|
| 59 | - */ |
|
| 60 | - public function getResponseHeaders() |
|
| 61 | - { |
|
| 55 | + /** |
|
| 56 | + * The response headers from the stream wrapper |
|
| 57 | + * |
|
| 58 | + * @return array|null |
|
| 59 | + */ |
|
| 60 | + public function getResponseHeaders() |
|
| 61 | + { |
|
| 62 | 62 | return $this->responseHeaders; |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Send a stream wrapped request |
|
| 67 | - * |
|
| 68 | - * @param string $url |
|
| 69 | - * |
|
| 70 | - * @return mixed |
|
| 71 | - */ |
|
| 72 | - public function fileGetContents($url) |
|
| 73 | - { |
|
| 65 | + /** |
|
| 66 | + * Send a stream wrapped request |
|
| 67 | + * |
|
| 68 | + * @param string $url |
|
| 69 | + * |
|
| 70 | + * @return mixed |
|
| 71 | + */ |
|
| 72 | + public function fileGetContents($url) |
|
| 73 | + { |
|
| 74 | 74 | $rawResponse = file_get_contents($url, false, $this->stream); |
| 75 | 75 | $this->responseHeaders = $http_response_header; |
| 76 | 76 | return $rawResponse; |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | } |
@@ -32,98 +32,98 @@ |
||
| 32 | 32 | class FacebookCurl |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var resource Curl resource instance |
|
| 37 | - */ |
|
| 38 | - protected $curl; |
|
| 35 | + /** |
|
| 36 | + * @var resource Curl resource instance |
|
| 37 | + */ |
|
| 38 | + protected $curl; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Make a new curl reference instance |
|
| 42 | - */ |
|
| 43 | - public function init() |
|
| 44 | - { |
|
| 40 | + /** |
|
| 41 | + * Make a new curl reference instance |
|
| 42 | + */ |
|
| 43 | + public function init() |
|
| 44 | + { |
|
| 45 | 45 | $this->curl = curl_init(); |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Set a curl option |
|
| 50 | - * |
|
| 51 | - * @param $key |
|
| 52 | - * @param $value |
|
| 53 | - */ |
|
| 54 | - public function setopt($key, $value) |
|
| 55 | - { |
|
| 48 | + /** |
|
| 49 | + * Set a curl option |
|
| 50 | + * |
|
| 51 | + * @param $key |
|
| 52 | + * @param $value |
|
| 53 | + */ |
|
| 54 | + public function setopt($key, $value) |
|
| 55 | + { |
|
| 56 | 56 | curl_setopt($this->curl, $key, $value); |
| 57 | - } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Set an array of options to a curl resource |
|
| 61 | - * |
|
| 62 | - * @param array $options |
|
| 63 | - */ |
|
| 64 | - public function setopt_array(array $options) |
|
| 65 | - { |
|
| 59 | + /** |
|
| 60 | + * Set an array of options to a curl resource |
|
| 61 | + * |
|
| 62 | + * @param array $options |
|
| 63 | + */ |
|
| 64 | + public function setopt_array(array $options) |
|
| 65 | + { |
|
| 66 | 66 | curl_setopt_array($this->curl, $options); |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Send a curl request |
|
| 71 | - * |
|
| 72 | - * @return mixed |
|
| 73 | - */ |
|
| 74 | - public function exec() |
|
| 75 | - { |
|
| 69 | + /** |
|
| 70 | + * Send a curl request |
|
| 71 | + * |
|
| 72 | + * @return mixed |
|
| 73 | + */ |
|
| 74 | + public function exec() |
|
| 75 | + { |
|
| 76 | 76 | return curl_exec($this->curl); |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Return the curl error number |
|
| 81 | - * |
|
| 82 | - * @return int |
|
| 83 | - */ |
|
| 84 | - public function errno() |
|
| 85 | - { |
|
| 79 | + /** |
|
| 80 | + * Return the curl error number |
|
| 81 | + * |
|
| 82 | + * @return int |
|
| 83 | + */ |
|
| 84 | + public function errno() |
|
| 85 | + { |
|
| 86 | 86 | return curl_errno($this->curl); |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Return the curl error message |
|
| 91 | - * |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function error() |
|
| 95 | - { |
|
| 89 | + /** |
|
| 90 | + * Return the curl error message |
|
| 91 | + * |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function error() |
|
| 95 | + { |
|
| 96 | 96 | return curl_error($this->curl); |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Get info from a curl reference |
|
| 101 | - * |
|
| 102 | - * @param $type |
|
| 103 | - * |
|
| 104 | - * @return mixed |
|
| 105 | - */ |
|
| 106 | - public function getinfo($type) |
|
| 107 | - { |
|
| 99 | + /** |
|
| 100 | + * Get info from a curl reference |
|
| 101 | + * |
|
| 102 | + * @param $type |
|
| 103 | + * |
|
| 104 | + * @return mixed |
|
| 105 | + */ |
|
| 106 | + public function getinfo($type) |
|
| 107 | + { |
|
| 108 | 108 | return curl_getinfo($this->curl, $type); |
| 109 | - } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Get the currently installed curl version |
|
| 113 | - * |
|
| 114 | - * @return array |
|
| 115 | - */ |
|
| 116 | - public function version() |
|
| 117 | - { |
|
| 111 | + /** |
|
| 112 | + * Get the currently installed curl version |
|
| 113 | + * |
|
| 114 | + * @return array |
|
| 115 | + */ |
|
| 116 | + public function version() |
|
| 117 | + { |
|
| 118 | 118 | return curl_version(); |
| 119 | - } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Close the resource connection to curl |
|
| 123 | - */ |
|
| 124 | - public function close() |
|
| 125 | - { |
|
| 121 | + /** |
|
| 122 | + * Close the resource connection to curl |
|
| 123 | + */ |
|
| 124 | + public function close() |
|
| 125 | + { |
|
| 126 | 126 | curl_close($this->curl); |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | } |
@@ -32,122 +32,122 @@ discard block |
||
| 32 | 32 | class FacebookCurlHttpClient implements FacebookHttpable |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var array The headers to be sent with the request |
|
| 37 | - */ |
|
| 38 | - protected $requestHeaders = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array The headers received from the response |
|
| 42 | - */ |
|
| 43 | - protected $responseHeaders = array(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var int The HTTP status code returned from the server |
|
| 47 | - */ |
|
| 48 | - protected $responseHttpStatusCode = 0; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var string The client error message |
|
| 52 | - */ |
|
| 53 | - protected $curlErrorMessage = ''; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var int The curl client error code |
|
| 57 | - */ |
|
| 58 | - protected $curlErrorCode = 0; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var string|boolean The raw response from the server |
|
| 62 | - */ |
|
| 63 | - protected $rawResponse; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var FacebookCurl Procedural curl as object |
|
| 67 | - */ |
|
| 68 | - protected static $facebookCurl; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var boolean If IPv6 should be disabled |
|
| 72 | - */ |
|
| 73 | - protected static $disableIPv6; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @const Curl Version which is unaffected by the proxy header length error. |
|
| 77 | - */ |
|
| 78 | - const CURL_PROXY_QUIRK_VER = 0x071E00; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @const "Connection Established" header text |
|
| 82 | - */ |
|
| 83 | - const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n"; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param FacebookCurl|null Procedural curl as object |
|
| 87 | - */ |
|
| 88 | - public function __construct(FacebookCurl $facebookCurl = null) |
|
| 89 | - { |
|
| 35 | + /** |
|
| 36 | + * @var array The headers to be sent with the request |
|
| 37 | + */ |
|
| 38 | + protected $requestHeaders = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array The headers received from the response |
|
| 42 | + */ |
|
| 43 | + protected $responseHeaders = array(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var int The HTTP status code returned from the server |
|
| 47 | + */ |
|
| 48 | + protected $responseHttpStatusCode = 0; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var string The client error message |
|
| 52 | + */ |
|
| 53 | + protected $curlErrorMessage = ''; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var int The curl client error code |
|
| 57 | + */ |
|
| 58 | + protected $curlErrorCode = 0; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var string|boolean The raw response from the server |
|
| 62 | + */ |
|
| 63 | + protected $rawResponse; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var FacebookCurl Procedural curl as object |
|
| 67 | + */ |
|
| 68 | + protected static $facebookCurl; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var boolean If IPv6 should be disabled |
|
| 72 | + */ |
|
| 73 | + protected static $disableIPv6; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @const Curl Version which is unaffected by the proxy header length error. |
|
| 77 | + */ |
|
| 78 | + const CURL_PROXY_QUIRK_VER = 0x071E00; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @const "Connection Established" header text |
|
| 82 | + */ |
|
| 83 | + const CONNECTION_ESTABLISHED = "HTTP/1.0 200 Connection established\r\n\r\n"; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param FacebookCurl|null Procedural curl as object |
|
| 87 | + */ |
|
| 88 | + public function __construct(FacebookCurl $facebookCurl = null) |
|
| 89 | + { |
|
| 90 | 90 | self::$facebookCurl = $facebookCurl ?: new FacebookCurl(); |
| 91 | 91 | self::$disableIPv6 = self::$disableIPv6 ?: false; |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Disable IPv6 resolution |
|
| 96 | - */ |
|
| 97 | - public function disableIPv6() |
|
| 98 | - { |
|
| 94 | + /** |
|
| 95 | + * Disable IPv6 resolution |
|
| 96 | + */ |
|
| 97 | + public function disableIPv6() |
|
| 98 | + { |
|
| 99 | 99 | self::$disableIPv6 = true; |
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * The headers we want to send with the request |
|
| 104 | - * |
|
| 105 | - * @param string $key |
|
| 106 | - * @param string $value |
|
| 107 | - */ |
|
| 108 | - public function addRequestHeader($key, $value) |
|
| 109 | - { |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * The headers we want to send with the request |
|
| 104 | + * |
|
| 105 | + * @param string $key |
|
| 106 | + * @param string $value |
|
| 107 | + */ |
|
| 108 | + public function addRequestHeader($key, $value) |
|
| 109 | + { |
|
| 110 | 110 | $this->requestHeaders[$key] = $value; |
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * The headers returned in the response |
|
| 115 | - * |
|
| 116 | - * @return array |
|
| 117 | - */ |
|
| 118 | - public function getResponseHeaders() |
|
| 119 | - { |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * The headers returned in the response |
|
| 115 | + * |
|
| 116 | + * @return array |
|
| 117 | + */ |
|
| 118 | + public function getResponseHeaders() |
|
| 119 | + { |
|
| 120 | 120 | return $this->responseHeaders; |
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * The HTTP status response code |
|
| 125 | - * |
|
| 126 | - * @return int |
|
| 127 | - */ |
|
| 128 | - public function getResponseHttpStatusCode() |
|
| 129 | - { |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * The HTTP status response code |
|
| 125 | + * |
|
| 126 | + * @return int |
|
| 127 | + */ |
|
| 128 | + public function getResponseHttpStatusCode() |
|
| 129 | + { |
|
| 130 | 130 | return $this->responseHttpStatusCode; |
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Sends a request to the server |
|
| 135 | - * |
|
| 136 | - * @param string $url The endpoint to send the request to |
|
| 137 | - * @param string $method The request method |
|
| 138 | - * @param array $parameters The key value pairs to be sent in the body |
|
| 139 | - * |
|
| 140 | - * @return string Raw response from the server |
|
| 141 | - * |
|
| 142 | - * @throws \Facebook\FacebookSDKException |
|
| 143 | - */ |
|
| 144 | - public function send($url, $method = 'GET', $parameters = array()) |
|
| 145 | - { |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Sends a request to the server |
|
| 135 | + * |
|
| 136 | + * @param string $url The endpoint to send the request to |
|
| 137 | + * @param string $method The request method |
|
| 138 | + * @param array $parameters The key value pairs to be sent in the body |
|
| 139 | + * |
|
| 140 | + * @return string Raw response from the server |
|
| 141 | + * |
|
| 142 | + * @throws \Facebook\FacebookSDKException |
|
| 143 | + */ |
|
| 144 | + public function send($url, $method = 'GET', $parameters = array()) |
|
| 145 | + { |
|
| 146 | 146 | $this->openConnection($url, $method, $parameters); |
| 147 | 147 | $this->tryToSendRequest(); |
| 148 | 148 | |
| 149 | 149 | if ($this->curlErrorCode) { |
| 150 | - throw new FacebookSDKException($this->curlErrorMessage, $this->curlErrorCode); |
|
| 150 | + throw new FacebookSDKException($this->curlErrorMessage, $this->curlErrorCode); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Separate the raw headers from the raw body |
@@ -158,114 +158,114 @@ discard block |
||
| 158 | 158 | $this->closeConnection(); |
| 159 | 159 | |
| 160 | 160 | return $rawBody; |
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Opens a new curl connection |
|
| 165 | - * |
|
| 166 | - * @param string $url The endpoint to send the request to |
|
| 167 | - * @param string $method The request method |
|
| 168 | - * @param array $parameters The key value pairs to be sent in the body |
|
| 169 | - */ |
|
| 170 | - public function openConnection($url, $method = 'GET', $parameters = array()) |
|
| 171 | - { |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Opens a new curl connection |
|
| 165 | + * |
|
| 166 | + * @param string $url The endpoint to send the request to |
|
| 167 | + * @param string $method The request method |
|
| 168 | + * @param array $parameters The key value pairs to be sent in the body |
|
| 169 | + */ |
|
| 170 | + public function openConnection($url, $method = 'GET', $parameters = array()) |
|
| 171 | + { |
|
| 172 | 172 | $options = array( |
| 173 | - CURLOPT_URL => $url, |
|
| 174 | - CURLOPT_CONNECTTIMEOUT => 10, |
|
| 175 | - CURLOPT_TIMEOUT => 60, |
|
| 176 | - CURLOPT_RETURNTRANSFER => true, // Follow 301 redirects |
|
| 177 | - CURLOPT_HEADER => true, // Enable header processing |
|
| 178 | - CURLOPT_SSL_VERIFYHOST => 2, |
|
| 179 | - CURLOPT_SSL_VERIFYPEER => true, |
|
| 180 | - CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
| 173 | + CURLOPT_URL => $url, |
|
| 174 | + CURLOPT_CONNECTTIMEOUT => 10, |
|
| 175 | + CURLOPT_TIMEOUT => 60, |
|
| 176 | + CURLOPT_RETURNTRANSFER => true, // Follow 301 redirects |
|
| 177 | + CURLOPT_HEADER => true, // Enable header processing |
|
| 178 | + CURLOPT_SSL_VERIFYHOST => 2, |
|
| 179 | + CURLOPT_SSL_VERIFYPEER => true, |
|
| 180 | + CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
| 181 | 181 | ); |
| 182 | 182 | |
| 183 | 183 | if ($method !== "GET") { |
| 184 | - $options[CURLOPT_POSTFIELDS] = $parameters; |
|
| 184 | + $options[CURLOPT_POSTFIELDS] = $parameters; |
|
| 185 | 185 | } |
| 186 | 186 | if ($method === 'DELETE' || $method === 'PUT') { |
| 187 | - $options[CURLOPT_CUSTOMREQUEST] = $method; |
|
| 187 | + $options[CURLOPT_CUSTOMREQUEST] = $method; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | if (!empty($this->requestHeaders)) { |
| 191 | - $options[CURLOPT_HTTPHEADER] = $this->compileRequestHeaders(); |
|
| 191 | + $options[CURLOPT_HTTPHEADER] = $this->compileRequestHeaders(); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | if (self::$disableIPv6) { |
| 195 | - $options[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; |
|
| 195 | + $options[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | self::$facebookCurl->init(); |
| 199 | 199 | self::$facebookCurl->setopt_array($options); |
| 200 | - } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Closes an existing curl connection |
|
| 204 | - */ |
|
| 205 | - public function closeConnection() |
|
| 206 | - { |
|
| 202 | + /** |
|
| 203 | + * Closes an existing curl connection |
|
| 204 | + */ |
|
| 205 | + public function closeConnection() |
|
| 206 | + { |
|
| 207 | 207 | self::$facebookCurl->close(); |
| 208 | - } |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Try to send the request |
|
| 212 | - */ |
|
| 213 | - public function tryToSendRequest() |
|
| 214 | - { |
|
| 210 | + /** |
|
| 211 | + * Try to send the request |
|
| 212 | + */ |
|
| 213 | + public function tryToSendRequest() |
|
| 214 | + { |
|
| 215 | 215 | $this->sendRequest(); |
| 216 | 216 | $this->curlErrorMessage = self::$facebookCurl->error(); |
| 217 | 217 | $this->curlErrorCode = self::$facebookCurl->errno(); |
| 218 | 218 | $this->responseHttpStatusCode = self::$facebookCurl->getinfo(CURLINFO_HTTP_CODE); |
| 219 | - } |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Send the request and get the raw response from curl |
|
| 223 | - */ |
|
| 224 | - public function sendRequest() |
|
| 225 | - { |
|
| 221 | + /** |
|
| 222 | + * Send the request and get the raw response from curl |
|
| 223 | + */ |
|
| 224 | + public function sendRequest() |
|
| 225 | + { |
|
| 226 | 226 | $this->rawResponse = self::$facebookCurl->exec(); |
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Compiles the request headers into a curl-friendly format |
|
| 231 | - * |
|
| 232 | - * @return array |
|
| 233 | - */ |
|
| 234 | - public function compileRequestHeaders() |
|
| 235 | - { |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Compiles the request headers into a curl-friendly format |
|
| 231 | + * |
|
| 232 | + * @return array |
|
| 233 | + */ |
|
| 234 | + public function compileRequestHeaders() |
|
| 235 | + { |
|
| 236 | 236 | $return = array(); |
| 237 | 237 | |
| 238 | 238 | foreach ($this->requestHeaders as $key => $value) { |
| 239 | - $return[] = $key . ': ' . $value; |
|
| 239 | + $return[] = $key . ': ' . $value; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | return $return; |
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Extracts the headers and the body into a two-part array |
|
| 247 | - * |
|
| 248 | - * @return array |
|
| 249 | - */ |
|
| 250 | - public function extractResponseHeadersAndBody() |
|
| 251 | - { |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Extracts the headers and the body into a two-part array |
|
| 247 | + * |
|
| 248 | + * @return array |
|
| 249 | + */ |
|
| 250 | + public function extractResponseHeadersAndBody() |
|
| 251 | + { |
|
| 252 | 252 | $headerSize = self::getHeaderSize(); |
| 253 | 253 | |
| 254 | 254 | $rawHeaders = mb_substr($this->rawResponse, 0, $headerSize); |
| 255 | 255 | $rawBody = mb_substr($this->rawResponse, $headerSize); |
| 256 | 256 | |
| 257 | 257 | return array(trim($rawHeaders), trim($rawBody)); |
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Converts raw header responses into an array |
|
| 262 | - * |
|
| 263 | - * @param string $rawHeaders |
|
| 264 | - * |
|
| 265 | - * @return array |
|
| 266 | - */ |
|
| 267 | - public static function headersToArray($rawHeaders) |
|
| 268 | - { |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Converts raw header responses into an array |
|
| 262 | + * |
|
| 263 | + * @param string $rawHeaders |
|
| 264 | + * |
|
| 265 | + * @return array |
|
| 266 | + */ |
|
| 267 | + public static function headersToArray($rawHeaders) |
|
| 268 | + { |
|
| 269 | 269 | $headers = array(); |
| 270 | 270 | |
| 271 | 271 | // Normalize line breaks |
@@ -279,51 +279,51 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | $headerComponents = explode("\n", $rawHeader); |
| 281 | 281 | foreach ($headerComponents as $line) { |
| 282 | - if (strpos($line, ': ') === false) { |
|
| 282 | + if (strpos($line, ': ') === false) { |
|
| 283 | 283 | $headers['http_code'] = $line; |
| 284 | - } else { |
|
| 284 | + } else { |
|
| 285 | 285 | list ($key, $value) = explode(': ', $line); |
| 286 | 286 | $headers[$key] = $value; |
| 287 | - } |
|
| 287 | + } |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | return $headers; |
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Return proper header size |
|
| 295 | - * |
|
| 296 | - * @return integer |
|
| 297 | - */ |
|
| 298 | - private function getHeaderSize() |
|
| 299 | - { |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Return proper header size |
|
| 295 | + * |
|
| 296 | + * @return integer |
|
| 297 | + */ |
|
| 298 | + private function getHeaderSize() |
|
| 299 | + { |
|
| 300 | 300 | $headerSize = self::$facebookCurl->getinfo(CURLINFO_HEADER_SIZE); |
| 301 | 301 | // This corrects a Curl bug where header size does not account |
| 302 | 302 | // for additional Proxy headers. |
| 303 | 303 | if ( self::needsCurlProxyFix() ) { |
| 304 | - // Additional way to calculate the request body size. |
|
| 305 | - if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { |
|
| 306 | - $headerSize = mb_strlen($this->rawResponse) - $m[1]; |
|
| 307 | - } elseif (stripos($this->rawResponse, self::CONNECTION_ESTABLISHED) !== false) { |
|
| 308 | - $headerSize += mb_strlen(self::CONNECTION_ESTABLISHED); |
|
| 309 | - } |
|
| 304 | + // Additional way to calculate the request body size. |
|
| 305 | + if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { |
|
| 306 | + $headerSize = mb_strlen($this->rawResponse) - $m[1]; |
|
| 307 | + } elseif (stripos($this->rawResponse, self::CONNECTION_ESTABLISHED) !== false) { |
|
| 308 | + $headerSize += mb_strlen(self::CONNECTION_ESTABLISHED); |
|
| 309 | + } |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | return $headerSize; |
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Detect versions of Curl which report incorrect header lengths when |
|
| 317 | - * using Proxies. |
|
| 318 | - * |
|
| 319 | - * @return boolean |
|
| 320 | - */ |
|
| 321 | - private static function needsCurlProxyFix() |
|
| 322 | - { |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Detect versions of Curl which report incorrect header lengths when |
|
| 317 | + * using Proxies. |
|
| 318 | + * |
|
| 319 | + * @return boolean |
|
| 320 | + */ |
|
| 321 | + private static function needsCurlProxyFix() |
|
| 322 | + { |
|
| 323 | 323 | $ver = self::$facebookCurl->version(); |
| 324 | 324 | $version = $ver['version_number']; |
| 325 | 325 | |
| 326 | 326 | return $version < self::CURL_PROXY_QUIRK_VER; |
| 327 | - } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | 329 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | CURLOPT_HEADER => true, // Enable header processing |
| 178 | 178 | CURLOPT_SSL_VERIFYHOST => 2, |
| 179 | 179 | CURLOPT_SSL_VERIFYPEER => true, |
| 180 | - CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
| 180 | + CURLOPT_CAINFO => __DIR__.'/certs/DigiCertHighAssuranceEVRootCA.pem', |
|
| 181 | 181 | ); |
| 182 | 182 | |
| 183 | 183 | if ($method !== "GET") { |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $return = array(); |
| 237 | 237 | |
| 238 | 238 | foreach ($this->requestHeaders as $key => $value) { |
| 239 | - $return[] = $key . ': ' . $value; |
|
| 239 | + $return[] = $key.': '.$value; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | return $return; |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | $headerSize = self::$facebookCurl->getinfo(CURLINFO_HEADER_SIZE); |
| 301 | 301 | // This corrects a Curl bug where header size does not account |
| 302 | 302 | // for additional Proxy headers. |
| 303 | - if ( self::needsCurlProxyFix() ) { |
|
| 303 | + if (self::needsCurlProxyFix()) { |
|
| 304 | 304 | // Additional way to calculate the request body size. |
| 305 | 305 | if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { |
| 306 | 306 | $headerSize = mb_strlen($this->rawResponse) - $m[1]; |