예제 #1
0
 public static function getPayload($json)
 {
     $decoded = json_decode($json);
     $events = static::all();
     $event = Objects::property($decoded, 'event');
     if (isset($events[$event])) {
         return call_user_func([$events[$event], 'hydrateFromJson'], $json);
     }
     return null;
 }
 protected function _dataNodeLink($property, $subProperty = null, $displayName = null)
 {
     $fid = $this->{$property . 'Fid'};
     $response = $this->{$property};
     if ($subProperty) {
         $fid = $response->{$subProperty . 'Fid'};
         $response = $response->{$subProperty};
     }
     $text = ValueAs::nonempty($displayName, Objects::property($response, 'displayName'), $fid);
     return '"{' . $text . '[' . $fid . ']}"';
 }
예제 #3
0
 /**
  * Hydrate the public properties
  *
  * @param $data
  */
 public function hydrate($data)
 {
     if ($data && $this->_hydratePublic) {
         foreach ($this->toArray() as $key => $value) {
             if (is_array($data)) {
                 $this->{$key} = Arrays::value($data, $key, $value);
             } else {
                 if (is_object($data)) {
                     $this->{$key} = Objects::property($data, $key, $value);
                 }
             }
         }
     }
 }
예제 #4
0
 /**
  * Hydrate webhook payload based on json payload
  *
  * @param $json
  *
  * @return static
  */
 public static function hydrateFromJson($json)
 {
     $rawPayload = json_decode($json);
     $payload = new static(Objects::property($rawPayload, 'event'));
     $payload->_signature = Objects::property($rawPayload, 'sig');
     $payload->_payloadId = Objects::property($rawPayload, 'uuid');
     $payload->_requestId = Objects::property($rawPayload, 'rqid');
     $data = Objects::property($rawPayload, 'data', new \stdClass());
     $payload->_dataHash = md5(json_encode($rawPayload->data));
     foreach ($payload as $key => $value) {
         $payload->{$key} = isset($data->{$key}) ? $data->{$key} : $value;
     }
     return $payload;
 }
예제 #5
0
 public function view($appId)
 {
     $app = App::firstOrNew(['id' => $appId]);
     // Update database
     if (!$app->exists || $app->updated_at < date('Y-m-d G:i:s', strtotime('-7 days')) || $this->_getRequest()->query->has('u')) {
         $api = new SteamStore($this->_getApi());
         try {
             $response = $api->appDetails($appId);
         } catch (SteamAppNotFoundException $e) {
             return new AppNotFoundView();
         }
         $app->type = $response->type;
         $app->name = $response->name;
         $app->required_age = $response->required_age;
         $app->is_free = $response->is_free;
         $app->detailed_description = $response->detailed_description;
         $app->about_the_game = $response->about_the_game;
         $app->supported_languages = $response->supported_languages;
         $app->header_image = $this->removeQueryString($response->header_image);
         $app->website = $response->website;
         $app->release_date = json_encode(Objects::property($response, 'release_date', []));
         $app->support_info = json_encode(Objects::property($response, 'support_info', []));
         $app->metacritic = json_encode(Objects::property($response, 'metacritic', []));
         $app->categories = json_encode(Objects::property($response, 'categories', []));
         $app->genres = json_encode(Objects::property($response, 'genres', []));
         $app->screenshots = json_encode(Objects::property($response, 'screenshots', []));
         $app->achievements = json_encode(Objects::property($response, 'achievements', []));
         $app->movies = json_encode(Objects::property($response, 'movies', []));
         // Categories
         $ids = [];
         if (is_array($response->categories)) {
             $ids = Arrays::ipull($response->categories, 'id');
         }
         $app->categories()->sync($ids);
         // Genres
         $ids = [];
         if (is_array($response->genres)) {
             $ids = Arrays::ipull($response->genres, 'id');
         }
         $app->genres()->sync($ids);
         // Save
         $app->save();
     }
     $this->layout()->setData('title', $app->name);
     return new AppView($app);
 }
예제 #6
0
 /**
  * Pull an array of properties from the collection
  * optionally keyed by another property
  *
  * @param string[]    $properties
  * @param null|string $keyProperty
  *
  * @return mixed
  */
 public function apull(array $properties, $keyProperty = null)
 {
     $this->_prepareDaos();
     $result = [];
     foreach ((array) $this->_daos as $i => $dao) {
         $key = Objects::property($dao, $keyProperty, $i);
         $result[$key] = [];
         foreach ($properties as $property) {
             $result[$key][$property] = Objects::property($dao, $property, null);
         }
     }
     return $result;
 }
예제 #7
0
 public static function fromJson($json)
 {
     $obj = is_scalar($json) ? json_decode($json) : $json;
     $requestDetail = new static();
     $requestDetail->_url = Objects::property($obj, 'url');
     $requestDetail->_headers = Objects::property($obj, 'headers');
     $requestDetail->_options = Objects::property($obj, 'options');
     $requestDetail->_post = Objects::property($obj, 'post');
     $requestDetail->_query = Objects::property($obj, 'query');
     $requestDetail->_body = Objects::property($obj, 'body');
     $requestDetail->_method = Objects::property($obj, 'method');
     $requestDetail->_isAsync = Objects::property($obj, 'isAsync');
     $requestDetail->_requireAuth = Objects::property($obj, 'requireAuth');
     return $requestDetail;
 }
예제 #8
0
 public function testIdp()
 {
     $object = new stdClass();
     $object->name = "apple";
     $this->assertEquals("apple", Objects::property($object, "name", "pear"));
     $this->assertEquals("orange", Objects::property($object, "noprop", "orange"));
 }
예제 #9
0
 /**
  * @param mixed $default
  *
  * @return ProductRequest[]
  */
 public function getProducts($default = [])
 {
     return Objects::property($this->_getResultJson(), 'products', $default);
 }
예제 #10
0
 /**
  * @param mixed $default
  *
  * @return InvoiceSubItemRequest[]
  */
 public function getSubItems($default = [])
 {
     return Objects::property($this->_getResultJson(), 'subItems', $default);
 }
예제 #11
0
 /**
  * RSA Public Key
  * 
  * @param mixed $default
  * @param bool $trim Trim Value
  *
  * @return string
  */
 public function getKey($default = null, $trim = true)
 {
     $value = Objects::property($this->_getResultJson(), 'key', $default);
     return $trim ? Strings::ntrim($value) : $value;
 }
예제 #12
0
 /**
  * @param IApiConnection     $connection
  * @param SecurityDefinition $definition
  *
  * @return IToken
  */
 public function getToken(IApiConnection $connection, SecurityDefinition $definition)
 {
     if ($definition->getType() !== 'oauth2') {
         throw new \InvalidArgumentException('The security definition provided is not a valid oAuth2 definition');
     }
     $params = [];
     $params['grant_type'] = $this->getGrantType();
     $params['api_user'] = $this->getApiUser();
     $params['api_key'] = $this->getApiSecret();
     $request = new ApiRequest();
     $request->setConnection($connection);
     $detail = new ApiRequestDetail();
     $detail->setMethod('POST');
     $detail->setUrl($definition->getTokenUrl());
     $detail->setPostFields($params);
     $request->setRequestDetail($detail);
     $connection->load($request);
     $tokenResponse = $request->getDecodedResponse();
     $token = new AccessToken();
     $token->setToken(Objects::property($tokenResponse, 'access_token'));
     $token->setType(Objects::property($tokenResponse, 'token_type', 'Bearer'));
     $token->setExpirySeconds(Objects::property($tokenResponse, 'expires_in'));
     $token->setExpiryTime(Objects::property($tokenResponse, 'expiry_time'));
     $token->setUserId(Objects::property($tokenResponse, 'uid'));
     $token->setSessionSecret(Objects::property($tokenResponse, 'session_secret'));
     return $token;
 }
예제 #13
0
 /**
  * @param mixed $default
  *
  * @return ProductOfferRequest[]
  */
 public function getOffers($default = [])
 {
     return Objects::property($this->_getResultJson(), 'offers', $default);
 }
예제 #14
0
 /**
  * @param mixed $default
  *
  * @return PaymentCardRequest[]
  */
 public function getCards($default = [])
 {
     return Objects::property($this->_getResultJson(), 'cards', $default);
 }
예제 #15
0
 /**
  * @param mixed $default
  * @param bool $trim Trim Value
  *
  * @return string
  */
 public function getExternalReference($default = null, $trim = true)
 {
     $value = Objects::property($this->_getResultJson(), 'externalReference', $default);
     return $trim ? Strings::ntrim($value) : $value;
 }
예제 #16
0
 /**
  * @param mixed $default
  *
  * @return InvoiceSummaryRequest[]
  */
 public function getInvoices($default = [])
 {
     return Objects::property($this->_getResultJson(), 'invoices', $default);
 }
예제 #17
0
 /**
  * @param mixed $default
  *
  * @return OrderRequest
  */
 public function getOrder($default = null)
 {
     return Objects::property($this->_getResultJson(), 'order', $default);
 }
예제 #18
0
 /**
  * @param mixed $default
  *
  * @return integer
  */
 public function getTotalItems($default = null)
 {
     return Objects::property($this->_getResultJson(), 'totalItems', $default);
 }
예제 #19
0
 /**
  * @param mixed $default
  *
  * @return AddressRequest[]
  */
 public function getAddresses($default = [])
 {
     return Objects::property($this->_getResultJson(), 'addresses', $default);
 }
예제 #20
0
 /**
  * Access an object property, retrieving the value stored there
  * if it exists or a default if it does not.
  *
  * @param object $object   Source object
  * @param string $property Property name to pull from the object
  * @param mixed  $default  Default value if the property does not exist
  *
  * @return mixed
  *
  * @deprecated
  */
 function idp($object, $property, $default = null)
 {
     return \Packaged\Helpers\Objects::property($object, $property, $default);
 }
예제 #21
0
 /**
  * @param mixed $default
  *
  * @return integer
  */
 public function getQuantity($default = null)
 {
     return Objects::property($this->_getResultJson(), 'quantity', $default);
 }
예제 #22
0
 /**
  * @param bool $default
  *
  * @return boolean
  */
 public function isRestrictive($default = false)
 {
     return Objects::property($this->_getResultJson(), 'restrictive', $default);
 }
예제 #23
0
 /**
  * @param             $response
  * @param AccessToken $token
  *
  * @return OAuthUser
  */
 public function userDetails($response, AccessToken $token)
 {
     $user = new OAuthUser();
     $result = Objects::property($response, 'result', $response);
     /**
      * @var $result AuthUserDetailsResponse
      */
     if (!$result instanceof AuthUserDetailsResponse) {
         $result = AuthUserDetailsResponse::make($result);
     }
     $user->setAuthUserDetails($result);
     $user->exchangeArray(['uid' => $result->userFid, 'nickname' => ValueAs::nonempty($result->displayName, $result->firstName, $result->lastName, $result->username, $result->userFid), 'locale' => $result->language, 'location' => $result->timezone, 'name' => $result->displayName, 'imageUrl' => $result->avatarUrl, 'firstName' => $result->firstName, 'lastName' => $result->lastName, 'description' => $result->description, 'email' => $result->username]);
     return $user;
 }