Skip to content

Commit

Permalink
added index capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
esokullu committed Jan 17, 2018
1 parent e5cb23f commit 55a54c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/Pho/Kernel/Foundation/Handlers/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ protected static function saveField(
}
elseif($helper->withIndex()) {
// check if there is an index
// see: https://github.com/phonetworks/pho-microkernel/issues/12
if($kernel->live()) {
$kernel->index()->createIndex($particle->label(), $field_name);
}
}
parent::saveField($particle, $field_name, $field_value, $defer_persist, $helper);

/*if(!$defer_persist) {
$particle->attributes()->$field_name = $field_value;
return;
}
$particle->attributes()->quietSet($field_name, $field_value);
*/
}

}
14 changes: 14 additions & 0 deletions src/Pho/Kernel/Services/Index/IndexInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,18 @@ public function checkNodeUniqueness(
string $label = ""
): bool;


/**
* Creates an index
*
* May be run over and over with no effect if it's duplicate
* Although not recommended.
*
* @param string $label Node label
* @param string $field_name Field name (not value!)
*
* @return void
*/
public function createIndex(string $label, string $field_name): void;

}
2 changes: 1 addition & 1 deletion tests/assets/compiled/UserWithUniqueFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class UserWithUniqueFeatures extends User {
const DEFAULT_MASK = 0xfffff;

// added username with 3 chars min, 20 chars max, and must be unique!
const FIELDS = "{\"username\":{\"constraints\":{\"minLength\":3,\"maxLength\":20,\"uuid\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null},\"directives\":{\"unique\":true, \"md5\":false,\"now\":false,\"default\":\"|_~_~NO!-!VALUE!-!SET~_~_|\"}},\"password\":{\"constraints\":{\"minLength\":null,\"maxLength\":null,\"uuid\":null,\"regex\":\"^[a-zA-Z0-9_]{4,12}$\",\"greaterThan\":null,\"lessThan\":null},\"directives\":{\"md5\":true,\"now\":false,\"default\":\"|_~_~NO!-!VALUE!-!SET~_~_|\"}},\"join_time\":{\"constraints\":{\"minLength\":null,\"maxLength\":null,\"uuid\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null},\"directives\":{\"md5\":false,\"now\":true,\"default\":\"|_~_~NO!-!VALUE!-!SET~_~_|\"}},\"birthday\":{\"constraints\":{\"minLength\":null,\"maxLength\":null,\"uuid\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null},\"directives\":{\"md5\":false,\"now\":false,\"default\":411436800}},\"about\":{\"constraints\":{\"minLength\":null,\"maxLength\":\"255\",\"uuid\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null},\"directives\":{ \"md5\":false,\"now\":false,\"default\":\"\"}}}";
const FIELDS = "{\"username\":{\"constraints\":{\"minLength\":3,\"maxLength\":20,\"uuid\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null},\"directives\":{\"unique\":true, \"md5\":false,\"now\":false,\"default\":\"|_~_~NO!-!VALUE!-!SET~_~_|\"}},\"password\":{\"constraints\":{\"minLength\":null,\"maxLength\":null,\"uuid\":null,\"regex\":\"^[a-zA-Z0-9_]{4,12}$\",\"greaterThan\":null,\"lessThan\":null},\"directives\":{\"md5\":true,\"now\":false,\"default\":\"|_~_~NO!-!VALUE!-!SET~_~_|\"}},\"join_time\":{\"constraints\":{\"minLength\":null,\"maxLength\":null,\"uuid\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null},\"directives\":{\"md5\":false,\"now\":true,\"default\":\"|_~_~NO!-!VALUE!-!SET~_~_|\"}},\"birthday\":{\"constraints\":{\"minLength\":null,\"maxLength\":null,\"uuid\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null},\"directives\":{\"md5\":false,\"now\":false,\"default\":411436800}},\"about\":{\"constraints\":{\"minLength\":null,\"maxLength\":\"255\",\"uuid\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null},\"directives\":{\"index\": true, \"md5\":false,\"now\":false,\"default\":\"\"}}}";

public function __construct(\Pho\Kernel\Kernel $kernel, \Pho\Lib\Graph\GraphInterface $graph , string $username, string $password, ?int $birthday = 411436800, ?string $about = "")
{
Expand Down

0 comments on commit 55a54c6

Please sign in to comment.