public function hydrate($data)
 {
     parent::hydrate($data);
     $object = Objects::create(ActivityFeedStoryEnum::$storyTypes[$this->story->storyType], []);
     $object->hydrate($this->story);
     $this->story = $object;
 }
Exemplo n.º 2
0
 /**
  * @param ApiCallData $data
  *
  * @return ApiResponseInterface
  *
  * @throws \Exception
  */
 public static function create(ApiCallData $data)
 {
     $type = $data->getResponseType();
     if (!class_exists($type)) {
         throw new \Exception("Type Class '" . $type . "', could not be loaded");
     }
     $interfaces = class_implements($type);
     if ($type == '\\Exception' || $type === '\\Packaged\\Api\\Exceptions\\ApiException' || in_array('\\Packaged\\Api\\Exceptions\\ApiException', $interfaces) || array_key_exists('Exception', class_parents($type))) {
         $code = $data->getStatusCode();
         if (!is_numeric($code)) {
             $code = 500;
         }
         $exception = new $type($data->getStatusMessage(), $code);
         $rawData = $data->getRawResult();
         if (is_object($rawData)) {
             Objects::hydrate($exception, $rawData);
         }
         throw $exception;
     } else {
         if (in_array('Packaged\\Api\\Interfaces\\ApiResponseInterface', $interfaces)) {
             $class = new $type();
             /**
              * @var $class \Packaged\Api\Interfaces\ApiResponseInterface
              */
             $class->setApiCallData($data);
             return $class;
         } else {
             throw new ApiException("An invalid message type was used '" . $type . "'");
         }
     }
 }
Exemplo n.º 3
0
 public function forOutput()
 {
     if (!$this->_definitions) {
         return [];
     }
     $this->_definitions = Objects::msort($this->_definitions, 'getDisplayName');
     return array_values(Objects::mpull($this->_definitions, 'toArray'));
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 protected function _processAlign()
 {
     if (!empty($this->_items)) {
         $counts = Objects::mpull($this->_items, 'getActionCount');
         $maxActions = max($counts);
         foreach ($this->_items as $card) {
             $card->setActionCount($maxActions);
         }
     }
 }
 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 . ']}"';
 }
Exemplo n.º 7
0
 /**
  * Create an instance of this endpoint already bound to the API
  *
  * @param ApiInterface $api
  *
  * @return static
  */
 public static function bound(ApiInterface $api)
 {
     $args = func_get_args();
     array_shift($args);
     $new = Objects::create(get_called_class(), $args);
     /**
      * @var $new ApiAwareInterface
      */
     $api->bind($new);
     return $new;
 }
Exemplo n.º 8
0
 public function hydrate($data)
 {
     parent::hydrate($data);
     $items = [];
     foreach ($this->items as $k => $story) {
         $object = Objects::create(ActivityFeedStoryEnum::$storyTypes[$story->storyType], []);
         $object->hydrate($story);
         $items[$k] = $object;
     }
     $this->items = $items;
 }
Exemplo n.º 9
0
 public static function generate($object, $append = null, $prefix = null, $moreEntropy = false)
 {
     if ($prefix === null) {
         $class = Objects::classShortname($object);
         $short = self::getUppers($class);
         $prefix = strlen($short) > 1 ? $short : substr(strtoupper($class), 0, 3);
     }
     if ($append !== null) {
         $append = self::getUppers($append);
     }
     return uniqid(Path::buildCustom(':', [$prefix, 'PHID', $append]) . ':', $moreEntropy);
 }
 public function hydrate($source)
 {
     if (is_object($source)) {
         $source = Objects::propertyValues($source);
     }
     foreach (Objects::properties($this) as $property) {
         if (isset($source[$property])) {
             $this->{$property} = $source[$property];
         }
     }
     return $this;
 }
Exemplo n.º 11
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;
 }
Exemplo n.º 12
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);
                 }
             }
         }
     }
 }
 public function hydrate($data)
 {
     parent::hydrate($data);
     $items = [];
     foreach ($this->items as $item) {
         $raw = DynamicDataNodeResponse::make($item);
         $node = Objects::create($raw->class, []);
         if ($node instanceof DataNodeResponse) {
             $node->hydrate($raw->data);
         }
         $items[] = $node;
     }
     $this->items = $items;
 }
Exemplo n.º 14
0
 /**
  * Retrieve the table name for this DAO
  *
  * @return string
  */
 public function getTableName()
 {
     if ($this->_tableName === null) {
         $class = get_called_class();
         $ns = Objects::getNamespace($class);
         $dirs = $this->getTableNameExcludeDirs();
         foreach ($dirs as $dir) {
             $ns = ltrim(Strings::offset($ns, $dir), '\\');
         }
         $this->_tableName = trim(Inflector::tableize(implode('_', [Strings::stringToUnderScore($ns), Inflector::pluralize(Objects::classShortname($class))])), '_ ');
         $this->_tableName = str_replace('__', '_', $this->_tableName);
     }
     return $this->_tableName;
 }
Exemplo n.º 15
0
 /**
  * @param $class
  * @param $expect
  *
  * @dataProvider tagDataProvider
  */
 public function testTagHtml($class, $expect)
 {
     $tag = Objects::create($class, ['Test']);
     $this->assertInstanceOf('\\Packaged\\Glimpse\\Core\\HtmlTag', $tag);
     /**
      * @var $tag HtmlTag
      */
     $this->assertEquals('<' . $expect . '>Test</' . $expect . '>', $tag->asHtml());
     $tag = $class::create('Test');
     $this->assertInstanceOf('\\Packaged\\Glimpse\\Core\\HtmlTag', $tag);
     /**
      * @var $tag HtmlTag
      */
     $this->assertEquals('<' . $expect . '>Test</' . $expect . '>', $tag->asHtml());
 }
Exemplo n.º 16
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);
 }
Exemplo n.º 17
0
 public function updateApps()
 {
     $apps = new SteamApps($this->_getApi());
     $apps = $apps->getAppList();
     $new = Objects::ppull($apps, 'name', 'appid');
     $current = Manager::table('apps')->lists('id');
     $diff = array_diff(array_keys($new), $current);
     $apps = [];
     foreach ($diff as $appId) {
         $apps[] = ['id' => $appId, 'name' => $new[$appId], 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')];
     }
     Manager::table('apps')->insert($apps);
     // Clear cache
     $cache = new AppsLatestCache();
     $cache->remove();
     error_log('Apps updated');
     die('Apps updated');
 }
Exemplo n.º 18
0
 public function validate(array $properties = null, $throw = true)
 {
     $allValid = true;
     if ($properties === null) {
         $properties = Objects::properties($this->_payload);
     }
     $this->_properties = $properties;
     foreach ($properties as $property) {
         $block = DocBlockParser::fromProperty($this->_payload, $property);
         $nullable = $block->hasTag('nullable');
         $optional = $block->hasTag('optional');
         $val = $this->_payload->{$property};
         if ($val === null && ($nullable || $optional) || $val === '' && $optional) {
             continue;
         }
         foreach ($block->getTags() as $tag => $tags) {
             foreach ($tags as $opt) {
                 if ($this->_repair) {
                     $this->repairValue($tag, $property, $val, $opt);
                 }
                 try {
                     $this->runValidator($tag, $property, $val, $opt);
                 } catch (\Exception $e) {
                     if ($throw) {
                         throw $e;
                     } else {
                         $allValid = false;
                         if (!isset($this->_errors[$property])) {
                             $this->_errors[$property] = [];
                         }
                         $this->_errors[$property][] = $e->getMessage();
                     }
                 }
             }
         }
     }
     return $allValid;
 }
Exemplo n.º 19
0
 /**
  * return the first non-empty property of an object from
  * a specified list of properties
  *
  * @param object $object
  * @param array  $properties
  * @param null   $default
  *
  * @return mixed
  *
  * @deprecated
  */
 function pnonempty($object, array $properties, $default = null)
 {
     return \Packaged\Helpers\Objects::pnonempty($object, $properties, $default);
 }
Exemplo n.º 20
0
 /**
  * @param mixed $default
  *
  * @return PaymentCardRequest[]
  */
 public function getCards($default = [])
 {
     return Objects::property($this->_getResultJson(), 'cards', $default);
 }
Exemplo n.º 21
0
 /**
  * (PHP 5 &gt;= 5.4.0)<br/>
  * Specify data which should be serialized to JSON
  *
  * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  * @return mixed data which can be serialized by <b>json_encode</b>,
  *       which is a value of any type other than a resource.
  */
 public function jsonSerialize()
 {
     return Objects::propertyValues($this);
 }
Exemplo n.º 22
0
 public function sum($property = 'id')
 {
     $this->_prepareDaos();
     if (empty($this->_daos)) {
         return null;
     }
     return array_sum(Objects::ppull($this->_daos, $property));
 }
Exemplo n.º 23
0
 /**
  * @param mixed $default
  *
  * @return InvoiceSubItemRequest[]
  */
 public function getSubItems($default = [])
 {
     return Objects::property($this->_getResultJson(), 'subItems', $default);
 }
Exemplo n.º 24
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;
 }
Exemplo n.º 25
0
 /**
  * Retrieve the name for this endpoint
  *
  * @return string
  */
 public function getName()
 {
     return Strings::titleize(Objects::classShortname(get_called_class()));
 }
Exemplo n.º 26
0
 public function publicVars()
 {
     return Objects::propertyValues($this);
 }
Exemplo n.º 27
0
 /**
  * Invokes the "new" operator with a vector of arguments. There is no way to
  * call_user_func_array() on a class constructor, so you can instead use this
  * function:
  *
  *   $obj = newv($class_name, $argv);
  *
  * That is, these two statements are equivalent:
  *
  *   $pancake = new Pancake('Blueberry', 'Maple Syrup', true);
  *   $pancake = newv('Pancake', array('Blueberry', 'Maple Syrup', true));
  *
  * DO NOT solve this problem in other, more creative ways! Three popular
  * alternatives are:
  *
  *   - Build a fake serialized object and unserialize it.
  *   - Invoke the constructor twice.
  *   - just use eval() lol
  *
  * These are really bad solutions to the problem because they can have side
  * effects (e.g., __wakeup()) and give you an object in an otherwise impossible
  * state. Please endeavor to keep your objects in possible states.
  *
  * If you own the classes you're doing this for, you should consider whether
  * or not restructuring your code (for instance, by creating static
  * construction methods) might make it cleaner before using newv(). Static
  * constructors can be invoked with call_user_func_array(), and may give your
  * class a cleaner and more descriptive API.
  *
  * @param  $className string  The name of a class.
  * @param  $argv      array Array of arguments to pass to its constructor.
  *
  * @return object     A new object of the specified class, constructed by
  *                  passing the argument vector to its constructor.
  * @group util
  *
  * @deprecated
  */
 function newv($className, array $argv)
 {
     return \Packaged\Helpers\Objects::create($className, $argv);
 }
Exemplo n.º 28
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;
 }
Exemplo n.º 29
0
 /**
  * @param bool $default
  *
  * @return boolean
  */
 public function isRestrictive($default = false)
 {
     return Objects::property($this->_getResultJson(), 'restrictive', $default);
 }
Exemplo n.º 30
0
 /**
  * @param mixed $default
  *
  * @return ProductRequest[]
  */
 public function getProducts($default = [])
 {
     return Objects::property($this->_getResultJson(), 'products', $default);
 }