Skip to content

Commit

Permalink
IBX-4918: Moved Specification abstraction from AdminUi to Core (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattfarinn authored Jan 26, 2023
1 parent caa5d24 commit 962b0fc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 109 deletions.
41 changes: 6 additions & 35 deletions src/lib/Specification/AbstractSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,13 @@

namespace Ibexa\AdminUi\Specification;

abstract class AbstractSpecification implements SpecificationInterface
{
/**
* @param $item
*
* @return bool
*/
abstract public function isSatisfiedBy($item): bool;

/**
* @param SpecificationInterface $other
*
* @return SpecificationInterface
*/
public function and(SpecificationInterface $other): SpecificationInterface
{
return new AndSpecification($this, $other);
}

/**
* @param SpecificationInterface $other
*
* @return SpecificationInterface
*/
public function or(SpecificationInterface $other): SpecificationInterface
{
return new OrSpecification($this, $other);
}
use Ibexa\Contracts\Core\Specification\AbstractSpecification as BaseAbstractSpecification;

/**
* @return SpecificationInterface
*/
public function not(): SpecificationInterface
{
return new NotSpecification($this);
}
/**
* @deprecated 4.4.0 Use \Ibexa\Contracts\Core\Specification\AbstractSpecification
*/
abstract class AbstractSpecification extends BaseAbstractSpecification
{
}

class_alias(AbstractSpecification::class, 'EzSystems\EzPlatformAdminUi\Specification\AbstractSpecification');
26 changes: 9 additions & 17 deletions src/lib/Specification/AndSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,24 @@

namespace Ibexa\AdminUi\Specification;

use Ibexa\Contracts\Core\Specification\AndSpecification as BaseAndSpecification;
use Ibexa\Contracts\Core\Specification\SpecificationInterface;

/**
* @deprecated 4.4.0 Use \Ibexa\Contracts\Core\Specification\AndSpecification
*/
class AndSpecification extends AbstractSpecification
{
/** @var SpecificationInterface */
private $one;

/** @var SpecificationInterface */
private $two;
private SpecificationInterface $baseSpecification;

/**
* @param SpecificationInterface $one
* @param SpecificationInterface $two
*/
public function __construct(SpecificationInterface $one, SpecificationInterface $two)
{
$this->one = $one;
$this->two = $two;
$this->baseSpecification = new BaseAndSpecification($one, $two);
}

/**
* @param $item
*
* @return bool
*/
public function isSatisfiedBy($item): bool
{
return $this->one->isSatisfiedBy($item) && $this->two->isSatisfiedBy($item);
return $this->baseSpecification->isSatisfiedBy($item);
}
}

Expand Down
23 changes: 9 additions & 14 deletions src/lib/Specification/NotSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,24 @@

namespace Ibexa\AdminUi\Specification;

use Ibexa\Contracts\Core\Specification\NotSpecification as BaseNotSpecification;
use Ibexa\Contracts\Core\Specification\SpecificationInterface;

/**
* @deprecated 4.4.0 Use \Ibexa\Contracts\Core\Specification\NotSpecification
*/
class NotSpecification extends AbstractSpecification
{
/**
* @var SpecificationInterface
*/
private $specification;
private SpecificationInterface $baseSpecification;

/**
* @param SpecificationInterface $specification
*/
public function __construct(SpecificationInterface $specification)
{
$this->specification = $specification;
$this->baseSpecification = new BaseNotSpecification($specification);
}

/**
* @param $item
*
* @return bool
*/
public function isSatisfiedBy($item): bool
{
return !$this->specification->isSatisfiedBy($item);
return $this->baseSpecification->isSatisfiedBy($item);
}
}

Expand Down
26 changes: 9 additions & 17 deletions src/lib/Specification/OrSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,24 @@

namespace Ibexa\AdminUi\Specification;

use Ibexa\Contracts\Core\Specification\OrSpecification as BaseOrSpecification;
use Ibexa\Contracts\Core\Specification\SpecificationInterface;

/**
* @deprecated 4.4.0 Use \Ibexa\Contracts\Core\Specification\OrSpecification
*/
class OrSpecification extends AbstractSpecification
{
/** @var SpecificationInterface */
private $one;

/** @var SpecificationInterface */
private $two;
private SpecificationInterface $baseSpecification;

/**
* @param SpecificationInterface $one
* @param SpecificationInterface $two
*/
public function __construct(SpecificationInterface $one, SpecificationInterface $two)
{
$this->one = $one;
$this->two = $two;
$this->baseSpecification = new BaseOrSpecification($one, $two);
}

/**
* @param $item
*
* @return bool
*/
public function isSatisfiedBy($item): bool
{
return $this->one->isSatisfiedBy($item) || $this->two->isSatisfiedBy($item);
return $this->baseSpecification->isSatisfiedBy($item);
}
}

Expand Down
32 changes: 6 additions & 26 deletions src/lib/Specification/SpecificationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,13 @@

namespace Ibexa\AdminUi\Specification;

interface SpecificationInterface
{
/**
* @param $item
*
* @return bool
*/
public function isSatisfiedBy($item): bool;

/**
* @param SpecificationInterface $other
*
* @return SpecificationInterface
*/
public function and(SpecificationInterface $other): SpecificationInterface;

/**
* @param SpecificationInterface $other
*
* @return SpecificationInterface
*/
public function or(SpecificationInterface $other): SpecificationInterface;
use Ibexa\Contracts\Core\Specification\SpecificationInterface as BaseSpecificationInterface;

/**
* @return SpecificationInterface
*/
public function not(): SpecificationInterface;
/**
* @deprecated 4.4.0 Use \Ibexa\Contracts\Core\Specification\SpecificationInterface
*/
interface SpecificationInterface extends BaseSpecificationInterface
{
}

class_alias(SpecificationInterface::class, 'EzSystems\EzPlatformAdminUi\Specification\SpecificationInterface');

0 comments on commit 962b0fc

Please sign in to comment.