-
-
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 #9 from phonetworks/plus
Plus
- Loading branch information
Showing
23 changed files
with
649 additions
and
54 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
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,99 @@ | ||
<?php | ||
|
||
namespace Pho\Framework; | ||
|
||
use Pho\Lib\Graph\EdgeInterface; | ||
use Pho\Lib\Graph\SerializableTrait; | ||
|
||
abstract class AbstractNotification implements \Serializable | ||
{ | ||
|
||
use SerializableTrait; | ||
|
||
const MSG = ""; | ||
|
||
/** | ||
* The edge | ||
* | ||
* Where this notification originates from. | ||
* | ||
* @var \Pho\Lib\Graph\EdgeInterface | ||
*/ | ||
protected $edge; | ||
|
||
/** | ||
* The edge id. | ||
* | ||
* Kept in records for hydration/dehydration. | ||
* | ||
* @var [type] | ||
*/ | ||
protected $edge_id; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \Pho\Lib\Graph\EdgeInterface $edge | ||
*/ | ||
public function __construct(EdgeInterface $edge) | ||
{ | ||
$this->edge = $edge; | ||
$this->edge_id = $edge->id(); | ||
} | ||
|
||
public function __invoke() //: mixed | ||
{ | ||
return $this->edge(); | ||
} | ||
|
||
public function edge(): EdgeInterface | ||
{ | ||
if(isset($this->edge)) | ||
return $this->edge; | ||
else | ||
return $this->hydratedEdge(); | ||
} | ||
|
||
protected function hydratedEdge(): EdgeInterface | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Turns the notification into a string | ||
* | ||
* @return string | ||
*/ | ||
abstract public function __toString(): string; | ||
/*{ | ||
$params = $this->params; | ||
array_unshift($params, $this->actor); | ||
return sprintf(static::MSG, ...$params); | ||
}*/ | ||
|
||
/** | ||
* Dumps the object in an array | ||
* | ||
* Useful for serialization | ||
* | ||
* @return array | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return array( | ||
"edge" => $this->edge_id | ||
); | ||
} | ||
|
||
/* | ||
public function serialize(): string | ||
{ | ||
return serialize($this->toArray()); | ||
} | ||
public function unserialize(string $data) //: mixed | ||
{ | ||
$this->edge = | ||
} | ||
*/ | ||
} |
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,53 @@ | ||
<?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; | ||
|
||
abstract class AbstractPredicate extends \Pho\Lib\Graph\Predicate | ||
{ | ||
/** | ||
* methods that would be available in this class | ||
* | ||
* @var array | ||
*/ | ||
public $_methods; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
$oClass = new \ReflectionObject($this); | ||
$this->_methods = array_map(function(string $name) { | ||
return substr(strtolower($name),2); | ||
}, array_filter( | ||
array_keys( | ||
$oClass->getConstants()), | ||
function(string $name) { | ||
return substr($name,0,2) == "T_"; | ||
} | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* {@internal} | ||
* | ||
* Used to call predicate traits. | ||
*/ | ||
public function __call(string $name, array $args)//: mixed | ||
{ | ||
if(in_array($name, $this->_methods)) { | ||
$const = sprintf("static::T_%s", strtoupper($name)); | ||
return constant($const); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
* | ||
* @author Emre Sokullu <[email protected]> | ||
*/ | ||
class Actor extends \Pho\Lib\Graph\Node implements ParticleInterface | ||
class Actor extends \Pho\Lib\Graph\Node implements ParticleInterface, \SplObserver, \SplSubject | ||
{ | ||
|
||
use ParticleTrait { | ||
|
@@ -37,11 +37,19 @@ class Actor extends \Pho\Lib\Graph\Node implements ParticleInterface | |
*/ | ||
protected $current_context; | ||
|
||
/** | ||
* Notifications | ||
* | ||
* @var NotificationList | ||
*/ | ||
protected $notifications; | ||
|
||
public function __construct(ContextInterface $context) | ||
{ | ||
parent::__construct($context); | ||
$this->creator = $this; | ||
$this->creator_id = (string) $this->id(); | ||
$this->notifications = new NotificationList($this); | ||
$this->enter($context); | ||
$this->particleConstructor(); | ||
} | ||
|
@@ -111,4 +119,31 @@ public function pwd(): ContextInterface | |
return $this->where(); | ||
} | ||
|
||
|
||
|
||
public function update(\SplSubject $subject): void | ||
{ | ||
if($subject instanceof NotificationList) { | ||
$this->observeNotificationListUpdate($subject); | ||
} | ||
else { | ||
parent::update($subject); | ||
} | ||
} | ||
|
||
protected function observeNotificationListUpdate(): void | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Gives access to the actor's notifications list | ||
* | ||
* @return NotificationList | ||
*/ | ||
public function notifications(): NotificationList | ||
{ | ||
return $this->notifications; | ||
} | ||
|
||
} |
Oops, something went wrong.