Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix serializable interface depreciation warnings for php 8.1+ #14

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
build
docs
*.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
"require": {
"php":">=7.1",
"psr/log": "^1.0",
"psr/log": "^3.0",
"phonetworks/pho-lib-dht": "^1.0"
},
"require-dev": {
Expand Down
43 changes: 21 additions & 22 deletions src/Pho/Lib/Graph/Edge.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@

/**
* Atomic graph entity, Edge
*
*
* Edges (aka lines or arcs in graph theory) are used to
* represent the relationships between Nodes of a Graph
* therefore it is a fundamental unit of
* therefore it is a fundamental unit of
* which graphs are formed.
*
*
* Uses Observer Pattern to observe updates from its attribute bags,
* as well as tail nodes.
*
*
* @author Emre Sokullu <[email protected]>
*/
class Edge implements
EntityInterface,
class Edge implements
EntityInterface,
EntityWorkerInterface,
EdgeInterface,
EdgeInterface,
HookableInterface,
\Serializable,
Event\EmitterInterface
{

use SerializableTrait;
use Event\EmitterTrait;
use EntityTrait {
Expand All @@ -54,7 +53,7 @@ class Edge implements
* @var string
*/
protected $tail_id;

/**
* Head node. Where this is directed towards.
*
Expand Down Expand Up @@ -91,15 +90,15 @@ class Edge implements
* @param NodeInterface $tail The node where this edge originates from.
* @param ?NodeInterface $head The node where this edge is targeted at. Default: null.
* @param ?PredicateInterface $predicate The predicate of this edge. Default: null.
*
*
* @throws Exceptions\DuplicateEdgeException when it's not a multiplicable edge and there's an attempt to create multiple edges between a particular pair of head and tail nodes.
*/
public function __construct(NodeInterface $tail, ?NodeInterface $head = null, ?PredicateInterface $predicate = null)
public function __construct(NodeInterface $tail, ?NodeInterface $head = null, ?PredicateInterface $predicate = null)
{
$this->predicate = $this->resolvePredicate($predicate, Predicate::class);

if( !$this->predicate->multiplicable()
&& !is_null($head)
if( !$this->predicate->multiplicable()
&& !is_null($head)
&& $tail->edges()->to($head->id(), get_class($this))->count() != 0
) {
throw new Exceptions\DuplicateEdgeException($tail, $head, get_class($this));
Expand All @@ -121,7 +120,7 @@ public function __construct(NodeInterface $tail, ?NodeInterface $head = null, ?P
$this->head->edges()->addIncoming($this);
$this->tail->edges()->addOutgoing($this);
}

$this->predicate_label = (string) $this->predicate;
$this->tail->emit("edge.created", [$this]);
if(!is_null($head)) {
Expand All @@ -138,13 +137,13 @@ public function init(): void

/**
* Resolves the predicate of this class.
*
*
* The predicate may be given. Or it may be resolved by the name of this class. Or it may be given
* a fallback. As a last resort, it may use the Predicate class available in pho-lib-graph.
*
* @param PredicateInterface|null $predicate Predicate may be given.
* @param string $fallback or the fallback class may be given, asking the method find something more specific if available.
*
*
* @return PredicateInterface A predicate object.
*/
protected function resolvePredicate(?PredicateInterface $predicate, string $fallback): PredicateInterface
Expand Down Expand Up @@ -204,7 +203,7 @@ public function head(): NodeInterface

if(isset($this->head)) {
return $this->head;
}
}
return $this->hookable();
}

Expand All @@ -226,7 +225,7 @@ public function tail(): NodeInterface
{
if(isset($this->tail)) {
return $this->tail;
}
}
return $this->hookable();
}

Expand All @@ -245,7 +244,7 @@ public function predicate(): PredicateInterface
{
if(isset($this->predicate)) {
return $this->predicate;
}
}
return $this->hookable();
}

Expand All @@ -269,7 +268,7 @@ public function observeTailDestruction(): void
}
$this->destroy();
}


/**
* {@inheritdoc}
Expand Down Expand Up @@ -298,4 +297,4 @@ public function return(): EntityInterface
}
}

}
}
11 changes: 5 additions & 6 deletions src/Pho/Lib/Graph/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@

/**
* Graph contains nodes
*
*
* Graph contains objects that implement NodeInterface
* interface, such as Node and Subgraph objects, but not
* Edges.
*
*
* @author Emre Sokullu <[email protected]>
*/
class Graph implements
class Graph implements
GraphInterface,
HookableInterface,
\Serializable,
Event\EmitterInterface
{

Expand All @@ -45,7 +44,7 @@ class Graph implements
*/
public function __construct(bool $emit_node_add_signal = true)
{
$this->emit_node_add_signal = $emit_node_add_signal;
$this->emit_node_add_signal = $emit_node_add_signal;
$this->init();
}

Expand All @@ -56,7 +55,7 @@ public function id(): ID
{
return ID::root();
}

/**
* {@inheritDoc}
*/
Expand Down
33 changes: 16 additions & 17 deletions src/Pho/Lib/Graph/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,30 @@

/**
* Atomic graph entity, Node
*
* A graph is made up of nodes (aka. nodes, or points) which are connected by
* edges (aka arcs, or lines) therefore node is the fundamental unit of
*
* A graph is made up of nodes (aka. nodes, or points) which are connected by
* edges (aka arcs, or lines) therefore node is the fundamental unit of
* which graphs are formed.
*
*
* Nodes are indivisible, yet they share some common characteristics with edges.
* In Pho context, these commonalities are represented with the EntityInterface.
*
*
* Uses Observer Pattern to observe updates from its attribute bags.
*
*
* Last but not least, this class is declared \Serializable. While it does nothing
* special within this class, this declaration may be useful for subclasses to override
* and persist data.
*
*
* @see EdgeList
*
*
* @author Emre Sokullu <[email protected]>
*/
class Node implements
EntityInterface,
class Node implements
EntityInterface,
EntityWorkerInterface,
NodeInterface,
NodeInterface,
NodeWorkerInterface,
HookableInterface,
\Serializable,
Event\EmitterInterface
{

Expand Down Expand Up @@ -72,7 +71,7 @@ class Node implements
/**
* {@inheritdoc}
*/
public function __construct(GraphInterface $context)
public function __construct(GraphInterface $context)
{
$this->____construct();
$this->edge_list = new EdgeList($this);
Expand All @@ -88,7 +87,7 @@ public function __construct(GraphInterface $context)
* recursively to the list of observers for deletion.
*
* @param GraphInterface $context
*
*
* @return void
*/
/*private function attachGraphObservers(GraphInterface $context): void
Expand All @@ -108,7 +107,7 @@ public function context(): GraphInterface
{
if(isset($this->context)) {
return $this->context;
}
}
return $this->hookable();
}

Expand All @@ -123,7 +122,7 @@ public function changeContext(GraphInterface $context): void
$this->context->add($this);
$this->emit("modified");
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -151,4 +150,4 @@ public function edge(string $id): EdgeInterface
return $this->hookable();
}

}
}
42 changes: 18 additions & 24 deletions src/Pho/Lib/Graph/SerializableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,33 @@
/**
* This trait is used to add demonstrational serialization functionality
* to package elements.
*
*
* @author Emre Sokullu <[email protected]>
*/
trait SerializableTrait
{

/**
* @internal
*
* Used for serialization.
* Removes listeners.
*
* @return string in PHP serialized format.
*/
public function serialize(): string
* Used for serialization.
*
* @return array of values to serialize.
*/
public function __serialize(): array
{
$vars = get_object_vars($this);
return serialize($vars);
return get_object_vars($this);
}

/**
* @internal
*
* Used for deserialization. Calls ```init``` method.
*
* @param string $data
*
* @return void
*/
public function unserialize(/* mixed */ $data): void
* Used to rebuild object after deserialization.
*
* @param array $data
*
* @return void
*/
public function __unserialize(array $data): void
{
$values = unserialize($data);
foreach ($values as $key=>$value) {
$this->$key = $value;
foreach($data as $key => $value) {
$this->$key = $value;
}
}
}
}