Skip to content
Draft
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
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"packaged/config": "~1.5",
"packaged/context": "^1.11",
"packaged/context-i18n": "~1.0",
"packaged/di-container": "^1.7",
"packaged/di-container": "dev-multi-observer as 1.7",
"packaged/event": "~1.2",
"packaged/figlet": "~0.0",
"packaged/helpers": "^2.15",
Expand Down Expand Up @@ -51,5 +51,11 @@
"psr-4": {
"Cubex\\Tests\\": "tests/"
}
}
},
"repositories": [
{
"type": "git",
"url": "git@github.com:msievenpiper/di-container.git"
}
]
}
17 changes: 17 additions & 0 deletions src/Attributes/AttributeResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Cubex\Attributes;

use Packaged\Context\Context;

interface AttributeResult
{
/**
* Returns null or a value to be returned from the method
*
* @param Context $ctx
*
* @return mixed
*/
public function process(Context $ctx): mixed;
}
11 changes: 0 additions & 11 deletions src/Attributes/ConditionResult.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
<?php

namespace Cubex\Attributes;
namespace Cubex\Attributes\Conditional;

use Cubex\Attributes\AttributeResult;
use Cubex\Attributes\ReturnsAttributeResultInterface;
use Packaged\DiContainer\DependencyInjector;

abstract class AbstractConditionAttribute
abstract class AbstractConditionAttribute implements ReturnsAttributeResultInterface
{
protected string $_class = '';
protected array $_args = [];

public function __construct(string $class, array $args = [])
public function __construct(protected string $_class, protected array $_args = [])
{
$this->_class = $class;
$this->_args = $args;
}

public function getClass(): string
{
return $this->_class;
}

public function result(?DependencyInjector $di): ConditionResult
public function result(?DependencyInjector $di): AttributeResult
{
$obj = null;

Expand All @@ -33,7 +30,7 @@ public function result(?DependencyInjector $di): ConditionResult
$obj = new $this->_class(...$this->_args);
}

if($obj instanceof ConditionResult)
if($obj instanceof AttributeResult)
{
return $obj;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Cubex\Attributes;
namespace Cubex\Attributes\Conditional;

use Attribute;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Cubex\Attributes;
namespace Cubex\Attributes\Conditional;

use Attribute;

Expand Down
10 changes: 10 additions & 0 deletions src/Attributes/ReturnsAttributeResultInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Cubex\Attributes;

use Packaged\DiContainer\DependencyInjector;

interface ReturnsAttributeResultInterface
{
public function result(?DependencyInjector $di): AttributeResult;
}
10 changes: 6 additions & 4 deletions src/Routing/ConditionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Cubex\Routing;

use Cubex\Attributes\PreCondition;
use Cubex\Attributes\SkipCondition;
use Cubex\Attributes\Conditional\AbstractConditionAttribute;
use Cubex\Attributes\Conditional\PreCondition;
use Cubex\Attributes\Conditional\SkipCondition;
use Cubex\Attributes\ReturnsAttributeResultInterface;
use Cubex\Cubex;
use Cubex\CubexAwareTrait;
use Packaged\Context\ContextAwareTrait;
Expand All @@ -24,7 +26,7 @@ public function __construct(Cubex $cubex)
}

/**
* @var \Cubex\Attributes\PreCondition[]
* @var ReturnsAttributeResultInterface[]
*/
protected array $_conditions = [];
protected bool $_processed = false;
Expand All @@ -48,7 +50,7 @@ protected function _processAttributes()
}
if($attribute->getName() === PreCondition::class)
{
/** @var \Cubex\Attributes\AbstractConditionAttribute $condition */
/** @var AbstractConditionAttribute $condition */
$condition = $attribute->newInstance();
$this->_conditions[$condition->getClass()] = $condition;
}
Expand Down