Skip to content

Commit

Permalink
added new signals
Browse files Browse the repository at this point in the history
  • Loading branch information
esokullu committed May 1, 2018
1 parent 1671431 commit 687346f
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Pho/Kernel/Foundation/AbstractActor.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function join(AbstractGraph $graph): void
throw new Exceptions\ExecutePermissionException($graph, $this);
$graph->add($this);
$this->memberships[] = (string) $graph->id();
$this->emit("joined", [$graph]);
$this->persist();
}

Expand All @@ -73,6 +74,7 @@ public function leave(AbstractGraph $graph): void
throw new \Exception(sprintf("No member with id %s", $this->id()->toString()));
$graph->remove($this->id());
unset($this->memberships[\array_search((string) $graph->id(), $this->memberships)]);
$this->emit("left", [$graph]);
$this->persist();
}

Expand Down
19 changes: 16 additions & 3 deletions src/Pho/Kernel/Graphsystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ public function warmUpCache(): void
$this->logger->info("Founder warmed up");
}

public function purge(ID $id): void
{
$id = (string) $id;
if(isset($this->node_cache[$id])) {
unset($this->node_cache[$id]);
}
elseif(isset($this->edge_cache[$id])) {
unset($this->edge_cache[$id]);
}
}

public function cache(EntityInterface $entity): EntityInterface
{
if($entity instanceof EdgeInterface) {
Expand Down Expand Up @@ -186,21 +197,23 @@ public function touch(EntityInterface $entity): void
//$this->index->index($entity);
}

public function delEdge(Graph\ID $id): void
public function delEdge(ID $id): void
{
$this->purge($id);
$this->database->del($id);
$this->events->emit("graphsystem.edge_deleted", [(string) $id]);
//$this->index->edgeDeleted((string) $id);
}

public function delNode(Graph\ID $id): void
public function delNode(ID $id): void
{
$this->purge($id);
$this->database->del($id);
$this->events->emit("graphsystem.node_deleted", [(string) $id]);
//$this->index->nodeDeleted((string) $id);
}

public function expire(Graph\ID $id, int $timeout = (60*60*24)): void
public function expire(ID $id, int $timeout = (60*60*24)): void
{
$this->database->expire((string) $id, $timeout);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Pho/Kernel/Traits/Node/PersistentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function destroy(): void
$edge->destroy();
}
$this->kernel->logger()->info("Node %s with label: %s has been called for deletion", $this->id(), $this->label());
$this->kernel->database()->del(sprintf("node:%s", $this->id()));
$this->kernel->gs()->delNode($this->id());
parent::destroy();
}

Expand Down
31 changes: 30 additions & 1 deletion tests/Pho/Kernel/SignalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/


namespace Pho\Kernel;

class SignalsTest extends TestCase
Expand Down Expand Up @@ -56,5 +55,35 @@ public function testNodeModifiedWithEdgeChange() {
$user->post("emre sokullu");
$this->assertEquals(1, $ref);
}

public function testJoin() {
$ref = 0;
$user = new \PhoNetworksAutogenerated\User($this->kernel, $this->graph, "123456");
$user2 = new \PhoNetworksAutogenerated\User($this->kernel, $this->graph, "123456");
$user2->on("joined", function() use (&$ref) {
$ref++;
});
//eval(\Psy\sh());
$group = new \PhoNetworksAutogenerated\Group($this->kernel, $user, $this->graph, "Title", "Desc");
$this->assertInstanceOf(\PhoNetworksAutogenerated\Group::class, $group);
$user2->join($group);
$this->assertEquals(1, $ref);
}

public function testLeft() {
$ref = 0;
$user = new \PhoNetworksAutogenerated\User($this->kernel, $this->graph, "123456");
$user2 = new \PhoNetworksAutogenerated\User($this->kernel, $this->graph, "123456");
$user2->on("left", function() use (&$ref) {
$ref++;
});
//eval(\Psy\sh());
$group = new \PhoNetworksAutogenerated\Group($this->kernel, $user, $this->graph, "Title", "Desc");
$this->assertInstanceOf(\PhoNetworksAutogenerated\Group::class, $group);
$user2->join($group);
$this->assertEquals(0, $ref);
$user2->leave($group);
$this->assertEquals(1, $ref);
}

}
3 changes: 3 additions & 0 deletions tests/Pho/Kernel/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
include("tests/assets/compiled/UserOut/Post.php");
include("tests/assets/compiled/UserOut/Consume.php");

include("tests/assets/group_upgrade/Group.php");
include("tests/assets/group_upgrade/UserOut/Create.php");

use Pho\Kernel\Kernel;
use Pho\Kernel\Standards\Space;

Expand Down
55 changes: 55 additions & 0 deletions tests/assets/group_upgrade/Group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace PhoNetworksAutogenerated;

use Pho\Framework;
use Pho\Kernel\Kernel;
use Pho\Kernel\Traits;
use Pho\Kernel\Foundation;




/*****************************************************
* This file was auto-generated by pho-compiler
* For more information, visit http://phonetworks.org
******************************************************/

class Group extends Foundation\AbstractGraphDP {

const T_EDITABLE = true;
const T_PERSISTENT = true;
const T_EXPIRATION = 0;
const T_VERSIONABLE = false;

const DEFAULT_MOD = 0x1f751;
const DEFAULT_MASK = 0xff999;

const FIELDS = "{\"title\":{\"constraints\":{\"minLength\":null,\"maxLength\":\"80\",\"id\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null,\"format\":null},\"directives\":{\"sha1\":false,\"md5\":false,\"now\":false,\"default\":\"|_~_~NO!-!VALUE!-!SET~_~_|\",\"unique\":false,\"index\":false}},\"description\":{\"constraints\":{\"minLength\":null,\"maxLength\":null,\"id\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null,\"format\":null},\"directives\":{\"sha1\":false,\"md5\":false,\"now\":false,\"default\":\"|_~_~NO!-!VALUE!-!SET~_~_|\",\"unique\":false,\"index\":false}},\"create_date\":{\"constraints\":{\"minLength\":null,\"maxLength\":null,\"id\":null,\"regex\":null,\"greaterThan\":null,\"lessThan\":null,\"format\":null},\"directives\":{\"sha1\":false,\"md5\":false,\"now\":true,\"default\":\"|_~_~NO!-!VALUE!-!SET~_~_|\",\"unique\":false,\"index\":false}}}";

const FEED_SIMPLE = "";
const FEED_AGGREGATED = "";

public function __construct(\Pho\Kernel\Kernel $kernel, \Pho\Kernel\Foundation\AbstractActor $actor, \Pho\Lib\Graph\GraphInterface $graph , string $title, string $description)
{
$this->registerIncomingEdges(UserOut\Create::class);
$this->registerIncomingEdges(UserOut\Consume::class);
parent::__construct($kernel, $actor, $graph);
$this->setTitle($title, true);

$this->setDescription($description, true);

$this->setCreateDate(time(), true);

$this->persist();
$this->context()->emit("particle.formed", [$this]);
}

}

/*****************************************************
* Timestamp: 1524372085
* Size (in bytes): 2374
* Compilation Time: 14
* fd96103a25fa02977d514448545be6d7
******************************************************/
1 change: 1 addition & 0 deletions tests/assets/group_upgrade/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Based on https://github.com/pho-recipes/Facebook/blob/master/.compiled/Group.php
67 changes: 67 additions & 0 deletions tests/assets/group_upgrade/UserOut/Create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace PhoNetworksAutogenerated\UserOut
{

use Pho\Kernel\Traits\Edge\PersistentTrait;
use Pho\Framework;
use Pho\Kernel\Foundation;



/*****************************************************
* This file was auto-generated by pho-compiler
* For more information, visit http://phonetworks.org
******************************************************/

class Create extends Foundation\ActorOut\Write {


use PersistentTrait;


const HEAD_LABEL = "creation";
const HEAD_LABELS = "creations";
const TAIL_LABEL = "creator";
const TAIL_LABELS = "creators";

const TAIL_CALLABLE_LABEL = "";
const TAIL_CALLABLE_LABELS = "";
const HEAD_CALLABLE_LABEL = "";
const HEAD_CALLABLE_LABELS = "";

const FEED_SIMPLE_LABEL = "";
const FEED_AGGREGATED_LABEL = "";


const FORMABLES = [\PhoNetworksAutogenerated\Group::class];



}

/* Predicate to load as a partial */
class CreatePredicate extends Foundation\ActorOut\WritePredicate
{
protected $binding = true;
protected $multiplicable = false;

const T_CONSUMER = true;
const T_NOTIFIER = false;
const T_SUBSCRIBER = false;
const T_FORMATIVE = true;
const T_PERSISTENT = true;
}
/* Notification to load if it's a subtype of write or mention. */
class CreateNotification extends Foundation\ActorOut\WriteNotification
{

}
}

/*****************************************************
* Timestamp:
* Size (in bytes): 1613
* Compilation Time: 8
* b34abb6f3aada3fe015e4f8d40f7a2b8
******************************************************/

0 comments on commit 687346f

Please sign in to comment.