public function __construct() { $schema = new Schema('Watch'); $schema->addString('value', false); $this->store = new Store($schema); $this->store->setEntityClass(Watch::class); }
public function __construct() { $schema = new Schema('Credential'); $schema->addString('email'); $schema->addString('service'); $schema->addString('value', false); $this->store = new Store($schema); $this->store->setEntityClass(Credential::class); }
/** * Process the WHERE clause * * @param $arr * @return string * @throws GQL */ private function recordWhere($arr) { $arr_conditions = explode('AND', $arr['where']); $str_regex = '/(?<lhs>[^\\s<>=]*)\\s*(?<comp>=|<|<=|>|>=|IN|CONTAINS|HAS ANCESTOR|HAS DESCENDANT)\\s*(?<rhs>[^\\s<>=]+)/i'; foreach ($arr_conditions as $str_condition) { $arr_matches = []; if (preg_match($str_regex, trim($str_condition), $arr_matches)) { $str_comp = strtoupper($arr_matches['comp']); if (isset($this->arr_operators[$str_comp])) { $int_operator = $this->arr_operators[$str_comp]; } else { throw new GQL("Unsupported operator in condition: [{$arr_matches['comp']}] [{$str_condition}]"); } // If schema is set and its properties is not empty, then we use it to test the validity if (isset($this->obj_schema) && !empty($this->obj_schema->getProperties())) { // Check left hand side's type $arr_properties = $this->obj_schema->getProperties(); if (isset($arr_properties[$arr_matches['lhs']])) { $int_current_type = $arr_properties[$arr_matches['lhs']]['type']; switch ($int_current_type) { case \GDS\Schema::PROPERTY_STRING: if ('@' !== $arr_matches['rhs'][0]) { // Skip named parameters if (substr($arr_matches['rhs'], 0, strlen(self::TOKEN_PREFIX)) != self::TOKEN_PREFIX) { // If the right hand side has not been tokenized throw new GQL("Invalid string representation in: [{$str_condition}]"); } } break; // @todo Add support for other type's validity here } } else { // We have a Schema, but it does not contain a definition for this property. // So, skip validation checks (we must support onl-the-fly Schemas) } } $this->arr_conditions[] = ['lhs' => $arr_matches['lhs'], 'comp' => $str_comp, 'op' => $int_operator, 'rhs' => $this->lookupToken($arr_matches['rhs'])]; } else { throw new GQL("Failed to parse condition: [{$str_condition}]"); } } return ''; }
public function getSchema() { static $schema = false; if ($schema === false) { $schema = new Schema($this->getKind()); $schema_def = $this->getDefinition(); foreach ($schema_def as $name => $field) { if (!isset($field['type'])) { throw new Exception('Error, type not set in field deffinition'); } $func = 'add' . ucwords($field['type']); $index = isset($field['index']) ? $field['index'] : false; $schema->{$func}($name, $index); $schema->setEntityClass(get_called_class()); } } return $schema; }