/** * @param IQuarkRESTServiceDescriptor $descriptor * @param string $endpoint * @param string $source */ public function __construct(IQuarkRESTServiceDescriptor $descriptor = null, $endpoint = '', $source = '') { if (func_num_args() == 1) { $endpoint = Quark::WebHost(); } if (strlen(trim($source)) == 0) { $source = QuarkObject::ClassOf($descriptor); } $this->_descriptor = $descriptor; $this->_endpoint = $endpoint; $this->_source = $source; }
/** * @param IQuarkModel $model * * @return string */ private static function _class(IQuarkModel $model) { return strtolower(QuarkObject::ClassOf($model)); }
/** * @param IQuarkModel $model * @param $options * * @return mixed * @throws QuarkArchException */ private function _collection($model, $options) { $collection = isset($options[QuarkModel::OPTION_COLLECTION]) ? $options[QuarkModel::OPTION_COLLECTION] : QuarkObject::ClassOf($model); if ($this->_connection == null) { throw new QuarkArchException('MongoDB connection not pooled'); } return $this->_connection->{$collection}; }
/** * @param string $family * @param array $options */ public function __construct($family, $options = []) { $this->_family = $family; $this->_sizes = isset($options[self::OPTION_SIZES]) && is_array($options[self::OPTION_SIZES]) && !QuarkObject::isAssociative($options[self::OPTION_SIZES]) ? $options[self::OPTION_SIZES] : $this->_sizes; $this->_subsets = isset($options[self::OPTION_SUBSETS]) && is_array($options[self::OPTION_SUBSETS]) && !QuarkObject::isAssociative($options[self::OPTION_SUBSETS]) ? $options[self::OPTION_SUBSETS] : $this->_subsets; }
/** * @param string $name * @param IQuarkAuthorizableModel $user * @param QuarkDTO $input * @param bool $http * * @return bool */ public function Input($name, IQuarkAuthorizableModel $user, QuarkDTO $input, $http) { $this->_name = $name; $session = $http ? $input->GetCookieByName($this->_cookie) : ($input->AuthorizationProvider() != null ? $input->AuthorizationProvider()->ToCookie() : null); if (!$session) { return false; } $session->value = trim($session->value); if (!$session->value) { return false; } $storage = self::_storage($name, $session->value); try { $json = json_decode($storage->Load()->Content()); if (!$json || QuarkObject::isIterative($json)) { return false; } $this->_sid = $session->value; $this->_user = $json->user; $this->_signature = $json->signature; $this->_ttl = $json->ttl; $this->_output = new QuarkDTO(); $this->_output->AuthorizationProvider(new QuarkKeyValuePair($this->_name, $this->_sid)); return true; } catch (\Exception $e) { return false; } }
/** * @param IQuarkModel $model * @param $criteria * @param array $options * * @return array */ public function Find(IQuarkModel $model, $criteria, $options = []) { $buffer = self::_find($criteria, $options); if (isset($options[QuarkModel::OPTION_SORT]) && QuarkObject::isAssociative($options[QuarkModel::OPTION_SORT])) { $sort = $options[QuarkModel::OPTION_SORT]; foreach ($sort as $key => $rule) { usort($buffer, function ($a, $b) use($key) { if (!isset($a[$key]) || !isset($b[$key])) { return 0; } if (is_bool($a[$key]) || is_bool($b[$key])) { return self::_cmp($a[$key], $b[$key]); } if (is_string($a[$key]) || is_string($b[$key])) { return strnatcmp($a[$key], $b[$key]); } return 0; }); if ($rule == -1) { $buffer = array_reverse($buffer); } } } return $buffer; }