-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from phonetworks/with_acl
Introduction of ACL
- Loading branch information
Showing
7 changed files
with
198 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Pho\Framework; | ||
|
||
use Pho\Lib\Graph; | ||
|
||
class Acl { | ||
|
||
protected $creator; | ||
protected $context; | ||
|
||
public function __construct(Actor $creator, Graph\GraphInterface $context) { | ||
$this->creator = $creator; | ||
$this->context = $context; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
//eval(\Psy\sh()); | ||
return [ | ||
"creator" => (string) $this->creator->id(), | ||
"context" => ($this->context instanceof Graph\Graph) ? Graph\Graph::class : (string) $this->context->id() | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
namespace Pho\Framework; | ||
|
||
use Pho\Lib\Graph; | ||
|
||
/** | ||
* The Actor Particle | ||
* | ||
|
@@ -23,7 +25,7 @@ | |
* | ||
* @author Emre Sokullu <[email protected]> | ||
*/ | ||
class Actor extends \Pho\Lib\Graph\Node implements ParticleInterface { | ||
class Actor extends Graph\Node implements ParticleInterface { | ||
|
||
use ParticleTrait; | ||
|
||
|
@@ -36,4 +38,10 @@ class Actor extends \Pho\Lib\Graph\Node implements ParticleInterface { | |
*/ | ||
const EDGES_IN = [ActorOut\Reads::class, ActorOut\Subscribes::class, ObjectOut\Transmits::class]; | ||
|
||
public function __construct(Graph\GraphInterface $context) { | ||
parent::__construct($context); | ||
$this->acl = new Acl($this, $context); | ||
$this->setupEdges(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
namespace Pho\Framework; | ||
|
||
use Pho\Lib\Graph\SubGraph; | ||
use Pho\Lib\Graph; | ||
|
||
/** | ||
* The Frame Particle | ||
|
@@ -31,7 +31,7 @@ | |
* | ||
* @author Emre Sokullu <[email protected]> | ||
*/ | ||
class Frame extends \Pho\Lib\Graph\SubGraph implements ParticleInterface { | ||
class Frame extends Graph\SubGraph implements ParticleInterface { | ||
|
||
use ParticleTrait; | ||
|
||
|
@@ -44,4 +44,10 @@ class Frame extends \Pho\Lib\Graph\SubGraph implements ParticleInterface { | |
*/ | ||
const EDGES_IN = [ActorOut\Reads::class, ActorOut\Subscribes::class, ActorOut\Writes::class, ObjectOut\Transmits::class]; | ||
|
||
public function __construct(Actor $creator, Graph\GraphInterface $context) { | ||
parent::__construct($context); | ||
$this->acl = new Acl($creator, $context); | ||
$this->setupEdges(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Pho package. | ||
* | ||
* (c) Emre Sokullu <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Pho\Framework; | ||
|
||
use Pho\Lib\Graph; | ||
|
||
class SimpleTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
private $graph; | ||
|
||
public function setUp() { | ||
$this->graph = new Graph\Graph(); | ||
} | ||
|
||
public function tearDown() { | ||
unset($this->graph); | ||
} | ||
|
||
public function testActor() { | ||
$node = new Actor($this->graph); | ||
$node_expected_to_be_identical = $this->graph->get($node->id()); | ||
$this->assertEquals($node->id(), $node_expected_to_be_identical->id()); | ||
} | ||
|
||
public function testActorEdge() { | ||
$actor = new Actor($this->graph); | ||
$object = new Object($actor, $this->graph); | ||
$edge = $actor->writes($object); | ||
$this->assertInstanceOf(ActorOut\Writes::class, $edge); | ||
$this->assertInstanceOf(Graph\Predicate::class, $edge->predicate()); | ||
} | ||
|
||
public function testActorPredicate() { | ||
$actor = new Actor($this->graph); | ||
$object = new Object($actor, $this->graph); | ||
$edge = $actor->subscribes($object); | ||
$this->assertInstanceOf(ActorOut\SubscribesPredicate::class, $edge->predicate()); | ||
} | ||
|
||
public function testObjectGetter() { | ||
$actor = new Actor($this->graph); | ||
$object = new Object($actor, $this->graph); | ||
$edge = $actor->writes($object); | ||
$this->assertInstanceOf(ActorOut\Writes::class, $object->getWriters()[0]); | ||
$this->assertCount(1, $object->getWriters()); | ||
$this->assertCount(1, $actor->getWrites()); | ||
$this->assertInstanceOf(ActorOut\Writes::class, $actor->getWrites()[0]); | ||
} | ||
|
||
public function testFiltering() { | ||
$actor = new Actor($this->graph); | ||
$object = new Object($actor, $this->graph); | ||
$edge = $actor->writes($object); | ||
$edge = $actor->reads($object); | ||
$this->assertCount(1, $actor->getWrites()); | ||
} | ||
|
||
/** | ||
* Since write extends subscribes | ||
*/ | ||
public function testEdgeInheritance() { | ||
$actor = new Actor($this->graph); | ||
$object = new Object($actor, $this->graph); | ||
$edge = $actor->writes($object); | ||
$this->assertCount(1, $actor->getSubscriptions()); | ||
$this->assertCount(0, $actor->getReads()); | ||
} | ||
|
||
/** | ||
* @expectedException Pho\Framework\Exceptions\InvalidEdgeHeadTypeException | ||
*/ | ||
public function testImpossibleEdge() { | ||
$actor1 = new Actor($this->graph); | ||
$actor2 = new Actor($this->graph); | ||
$edge = $actor1->writes($actor2); | ||
} | ||
|
||
public function testEdgeInvoke() { | ||
$actor = new Actor($this->graph); | ||
$object = new Object($actor, $this->graph); | ||
$edge = $actor->writes($object); | ||
$this->assertInstanceOf(Object::class, $edge()); | ||
$this->assertEquals($object->id(), $edge()->id()); | ||
} | ||
|
||
|
||
public function testActorToArray() { | ||
$actor = new Actor($this->graph); | ||
$array = $actor->toArray(); | ||
$faker = \Faker\Factory::create(); | ||
$this->assertArrayHasKey("id", $array); | ||
$this->assertArrayHasKey("attributes", $array); | ||
$this->assertCount(0, $array["attributes"]); | ||
$actor->attributes()->username = $faker->username; | ||
$this->assertCount(1, $actor->toArray()["attributes"]); | ||
$this->assertArrayHasKey("edge_list", $array); | ||
$this->assertArrayHasKey("acl", $array); | ||
$this->assertCount(2, $array["acl"]); | ||
$this->assertArrayHasKey("context", $array["acl"]); | ||
$this->assertArrayHasKey("creator", $array["acl"]); | ||
} | ||
|
||
public function testFrameToArray() { | ||
$faker = \Faker\Factory::create(); | ||
$actor = new Actor($this->graph); | ||
$frame = new Frame($actor, $this->graph); | ||
$edge = $actor->writes($frame); | ||
$array = $frame->toArray(); | ||
$this->assertArrayHasKey("id", $array); | ||
$this->assertArrayHasKey("attributes", $array); | ||
$this->assertCount(0, $array["attributes"]); | ||
$actor->attributes()->username = $faker->username; | ||
$this->assertCount(1, $actor->toArray()["attributes"]); | ||
$this->assertArrayHasKey("edge_list", $array); | ||
$this->assertArrayHasKey("acl", $array); | ||
$this->assertCount(2, $array["acl"]); | ||
$this->assertArrayHasKey("context", $array["acl"]); | ||
$this->assertArrayHasKey("creator", $array["acl"]); | ||
$this->assertEquals($actor->id(), $array["acl"]["creator"]); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.