public function hydrate($data) { parent::hydrate($data); $object = Objects::create(ActivityFeedStoryEnum::$storyTypes[$this->story->storyType], []); $object->hydrate($this->story); $this->story = $object; }
/** * @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 . "'"); } } }
public function forOutput() { if (!$this->_definitions) { return []; } $this->_definitions = Objects::msort($this->_definitions, 'getDisplayName'); return array_values(Objects::mpull($this->_definitions, 'toArray')); }
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 _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 . ']}"'; }
/** * 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; }
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; }
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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * @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()); }
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); }
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'); }
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; }
/** * 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); }
/** * @param mixed $default * * @return PaymentCardRequest[] */ public function getCards($default = []) { return Objects::property($this->_getResultJson(), 'cards', $default); }
/** * (PHP 5 >= 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); }
public function sum($property = 'id') { $this->_prepareDaos(); if (empty($this->_daos)) { return null; } return array_sum(Objects::ppull($this->_daos, $property)); }
/** * @param mixed $default * * @return InvoiceSubItemRequest[] */ public function getSubItems($default = []) { return Objects::property($this->_getResultJson(), 'subItems', $default); }
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; }
/** * Retrieve the name for this endpoint * * @return string */ public function getName() { return Strings::titleize(Objects::classShortname(get_called_class())); }
public function publicVars() { return Objects::propertyValues($this); }
/** * 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); }
/** * 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; }
/** * @param bool $default * * @return boolean */ public function isRestrictive($default = false) { return Objects::property($this->_getResultJson(), 'restrictive', $default); }
/** * @param mixed $default * * @return ProductRequest[] */ public function getProducts($default = []) { return Objects::property($this->_getResultJson(), 'products', $default); }