-
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.
- Loading branch information
Showing
24 changed files
with
407 additions
and
79 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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
/** | ||
* @see AcceptsDebugContext | ||
* @internal | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
trait AcceptDebugContext | ||
{ | ||
public ?Context $context = null; | ||
|
||
// public function context(callable $code): self | ||
// { | ||
// $this->context ??= new Context(); | ||
// $code($this->context, $this); | ||
// return $this; | ||
// } | ||
|
||
public function tag(string $key, mixed $value): self | ||
{ | ||
$this->context ??= new Context(); | ||
$this->context->tag($key, $value); | ||
return $this; | ||
} | ||
|
||
public function push(string $key, mixed $value): self | ||
{ | ||
$this->context ??= new Context(); | ||
$this->context->push($key, $value); | ||
return $this; | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
interface AcceptsDebugContext | ||
{ | ||
// public function context(callable $code): self; | ||
|
||
public function tag(string $key, mixed $value): self; | ||
|
||
public function push(string $key, mixed $value): self; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
/** | ||
* Thrown when a child node is being added with a key that would overwrite another child with the same key. | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
final class ChildKeyCollision extends RuntimeException implements FailsIntegrity, AcceptsDebugContext | ||
{ | ||
use AcceptDebugContext; | ||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
use LogicException; | ||
|
||
/** | ||
* ConfigurationIssue | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
final class ConfigurationIssue extends LogicException implements FailsIntegrity | ||
{ | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
/** | ||
* Context meant for debugging issues. | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
final class Context | ||
{ | ||
public array $bag = []; | ||
|
||
public function tag(string $key, mixed $value): self | ||
{ | ||
$this->bag[$key] = $value; | ||
return $this; | ||
} | ||
|
||
public function push(string $key, mixed $value): self | ||
{ | ||
if (!isset($this->bag[$key])) { | ||
$this->bag[$key] = []; | ||
} | ||
$this->bag[$key][] = $value; | ||
return $this; | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
use LogicException; | ||
|
||
/** | ||
* A problem with return value of an extractor. | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
final class ExtractorReturnValueIssue extends LogicException implements FailsIntegrity, AcceptsDebugContext | ||
{ | ||
use AcceptDebugContext; | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
/** | ||
* Base interface for exceptions indicating a problem on the integration side, | ||
* be it either a configuration issue or invalid source data. | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
interface FailsIntegrity extends IndicatesTreeIssue | ||
{ | ||
} |
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
/** | ||
* Indicates internal logic fault. | ||
* Implementors should never see these being thrown. | ||
* | ||
* @internal | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
interface IndicatesInternalFault extends IndicatesTreeIssue | ||
{ | ||
|
||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
/** | ||
* Base exception interface for Oliva-specific exceptions. | ||
* This can be used to catch all exceptions thrown by Oliva. | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
interface IndicatesTreeIssue | ||
{ | ||
|
||
} |
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
use LogicException; | ||
|
||
/** | ||
* Sorry. | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
final class InternalLogicException extends LogicException implements IndicatesInternalFault | ||
{ | ||
} |
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,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
use RuntimeException; | ||
|
||
/** | ||
* Indicates invalid input data or argument. | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
final class InvalidInputData extends RuntimeException implements FailsIntegrity, AcceptsDebugContext | ||
{ | ||
use AcceptDebugContext; | ||
} |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
use Dakujem\Oliva\MovableNodeContract; | ||
use LogicException; | ||
use Throwable; | ||
|
||
/** | ||
* Every node factory callable must return a movable node implementation instance, otherwise the builders can not work. | ||
* @see MovableNodeContract | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
final class InvalidNodeFactoryReturnValue extends LogicException implements FailsIntegrity, AcceptsDebugContext | ||
{ | ||
use AcceptDebugContext; | ||
|
||
public function __construct($message = null, $code = null, Throwable $previous = null) | ||
{ | ||
parent::__construct( | ||
$message ?? ('The node factory must return a movable node instance (' . MovableNodeContract::class . ').'), | ||
$code ?? 0, | ||
$previous, | ||
); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dakujem\Oliva\Exceptions; | ||
|
||
use Dakujem\Oliva\MovableNodeContract; | ||
use LogicException; | ||
use Throwable; | ||
|
||
/** | ||
* Builders can only work with movable nodes: | ||
* @see MovableNodeContract | ||
* | ||
* @author Andrej Rypak <xrypak@gmail.com> | ||
*/ | ||
final class NodeNotMovable extends LogicException implements IndicatesTreeIssue | ||
{ | ||
public mixed $node; | ||
|
||
public function __construct(mixed $node, $message = null, $code = null, Throwable $previous = null) | ||
{ | ||
$this->node = $node; | ||
parent::__construct($message ?? 'Encountered a non-movable node while manipulating a tree.', $code ?? 0, $previous); | ||
} | ||
} |
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
Oops, something went wrong.