Skip to content

Commit

Permalink
EZP-27743: Criterion should implement CriterionInterface (ezsystems#2330
Browse files Browse the repository at this point in the history
)
  • Loading branch information
natanael89 authored and alongosz committed Jun 15, 2018
1 parent bea2660 commit 37d41f6
Show file tree
Hide file tree
Showing 32 changed files with 203 additions and 94 deletions.
20 changes: 20 additions & 0 deletions doc/bc/changes-7.2.md
@@ -0,0 +1,20 @@
# Backwards compatibility changes

Changes affecting version compatibility with former or future versions.

## Changes

* The abstract class `eZ\Publish\API\Repository\Values\Content\Query\Criterion` now implements interface `eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface`.

* The interface `eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface` no longer specifies `createFromQueryBuilder` and `getSpecifications` methods. The former was already specified by `eZ\Publish\API\Repository\Values\Content\Query\Criterion` abstract class and the latter was moved there.

* Classes extending the abstract class `eZ\Publish\API\Repository\Values\Content\Query\Criterion` no longer directly implement interface `eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface`. This interface is still implemented in those classes via `eZ\Publish\API\Repository\Values\Content\Query\Criterion` abstract class.

* The abstract class `eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalOperator` now throws `eZ\Publish\API\Repository\Exceptions\NotImplementedException` for method `getSpecifications`. This method will be completely removed in 8.0 when `LogicalOperator` no longer extends `eZ\Publish\API\Repository\Values\Content\Query\Criterion`.

## Deprecations

* The method `createFromQueryBuilder` from the abstract class `eZ\Publish\API\Repository\Values\Content\Query\Criterion` is deprecated and will be removed in 8.0. All overrides of this method are also deprecated and will be removed in 8.0.
Call constructors directly instead.

## Removed features
39 changes: 38 additions & 1 deletion eZ/Publish/API/Repository/Values/Content/Query/Criterion.php
Expand Up @@ -13,7 +13,7 @@
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator;
use InvalidArgumentException;

abstract class Criterion
abstract class Criterion implements CriterionInterface
{
/**
* The operator used by the Criterion.
Expand Down Expand Up @@ -113,6 +113,38 @@ public function __construct($target, $operator, $value, Value $valueData = null)
$this->valueData = $valueData;
}

/**
* Criterion description function.
*
* Returns the combination of the Criterion's supported operator/value,
* as an array of eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications objects
* - Operator is one supported Operator, as an Operator::* constant
* - ValueType is the type of input value this operator requires, either array or single
* - SupportedTypes is an array of types the operator will accept
* - ValueCountLimitation is an integer saying how many values are expected.
*
* <code>
* // IN and EQ are supported
* return [
* // The EQ operator expects a single value, either as an integer or a string
* new Specifications(
* Operator::EQ,
* Specifications::INPUT_TYPE_SINGLE,
* [Specifications::INPUT_VALUE_INTEGER, Specifications::INPUT_VALUE_STRING],
* ),
* // The IN operator expects an array of values, of either integers or strings
* new Specifications(
* Operator::IN,
* Specifications::INPUT_TYPE_ARRAY,
* [Specifications::INPUT_VALUE_INTEGER, Specifications::INPUT_VALUE_STRING]
* )
* ]
* </code>
*
* @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications[]
*/
abstract public function getSpecifications();

/**
* Returns a callback that checks the values types depending on the operator specifications.
*
Expand Down Expand Up @@ -146,8 +178,13 @@ private function getValueTypeCheckCallback($valueTypes)
return $callback;
}

/**
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
*/
public static function createFromQueryBuilder($target, $operator, $value)
{
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);

return new static($target, $operator, $value);
}
}
Expand Up @@ -10,15 +10,14 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;
use InvalidArgumentException;

/**
* A criterion that matches content that is ancestor to the given Location path string.
*
* Content will be matched if it is part of at least one of the given subtree path strings.
*/
class Ancestor extends Criterion implements CriterionInterface
class Ancestor extends Criterion
{
/**
* Creates a new Ancestor criterion.
Expand Down Expand Up @@ -57,8 +56,13 @@ public function getSpecifications()
);
}

/**
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
*/
public static function createFromQueryBuilder($target, $operator, $value)
{
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);

return new self($value);
}
}
Expand Up @@ -10,7 +10,6 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;

/**
* A criterion that matches content based on its id.
Expand All @@ -19,7 +18,7 @@
* - IN: will match from a list of ContentId
* - EQ: will match against one ContentId
*/
class ContentId extends Criterion implements CriterionInterface
class ContentId extends Criterion
{
/**
* Creates a new ContentId criterion.
Expand All @@ -44,8 +43,13 @@ public function getSpecifications()
);
}

/**
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
*/
public static function createFromQueryBuilder($target, $operator, $value)
{
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);

return new self($value);
}
}
Expand Up @@ -10,7 +10,6 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;

/**
* A criterion that will match content based on its ContentTypeGroup id.
Expand All @@ -20,7 +19,7 @@
* - IN: will match from a list of ContentTypeGroup id
* - EQ: will match against one ContentTypeGroup id
*/
class ContentTypeGroupId extends Criterion implements CriterionInterface
class ContentTypeGroupId extends Criterion
{
/**
* Creates a new ContentTypeGroup criterion.
Expand Down Expand Up @@ -54,8 +53,13 @@ public function getSpecifications()
);
}

/**
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
*/
public static function createFromQueryBuilder($target, $operator, $value)
{
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);

return new self($value);
}
}
Expand Up @@ -10,7 +10,6 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;

/**
* A criterion that matches content based on its ContentType id.
Expand All @@ -19,7 +18,7 @@
* - IN: will match from a list of ContentTypeId
* - EQ: will match against one ContentTypeId
*/
class ContentTypeId extends Criterion implements CriterionInterface
class ContentTypeId extends Criterion
{
/**
* Creates a new ContentType criterion.
Expand All @@ -46,8 +45,13 @@ public function getSpecifications()
);
}

/**
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
*/
public static function createFromQueryBuilder($target, $operator, $value)
{
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);

return new self($value);
}
}
Expand Up @@ -10,7 +10,6 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;

/**
* A criterion that matches content based on its ContentType Identifier.
Expand All @@ -19,7 +18,7 @@
* - IN: will match from a list of ContentTypeIdentifier
* - EQ: will match against one ContentTypeIdentifier
*/
class ContentTypeIdentifier extends Criterion implements CriterionInterface
class ContentTypeIdentifier extends Criterion
{
/**
* Creates a new ContentType criterion.
Expand Down Expand Up @@ -51,8 +50,13 @@ public function getSpecifications()
);
}

/**
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
*/
public static function createFromQueryBuilder($target, $operator, $value)
{
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);

return new self($value);
}
}
Expand Up @@ -10,14 +10,13 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;

/**
* The Field Criterion class.
*
* Provides content filtering based on Fields contents & values.
*/
class CustomField extends Criterion implements CriterionInterface
class CustomField extends Criterion
{
public function getSpecifications()
{
Expand Down
Expand Up @@ -10,7 +10,6 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;
use InvalidArgumentException;

/**
Expand All @@ -31,7 +30,7 @@
* );
* </code>
*/
class DateMetadata extends Criterion implements CriterionInterface
class DateMetadata extends Criterion
{
/**
* DateMetadata target: modification date.
Expand Down
Expand Up @@ -10,15 +10,14 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;
use eZ\Publish\API\Repository\Values\Content\Query\CustomFieldInterface;

/**
* The Field Criterion class.
*
* Provides content filtering based on Fields contents & values.
*/
class Field extends Criterion implements CriterionInterface, CustomFieldInterface
class Field extends Criterion implements CustomFieldInterface
{
/**
* Custom field definitions to query instead of default field.
Expand Down
Expand Up @@ -10,7 +10,6 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;

/**
* A criterion that matches Content based on the relations in relation field.
Expand All @@ -22,7 +21,7 @@
* - IN: will match if Content relates to one or more of the given ids through given relation field
* - CONTAINS: will match if Content relates to all of the given ids through given relation field
*/
class FieldRelation extends Criterion implements CriterionInterface
class FieldRelation extends Criterion
{
public function getSpecifications()
{
Expand All @@ -34,8 +33,13 @@ public function getSpecifications()
);
}

/**
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
*/
public static function createFromQueryBuilder($target, $operator, $value)
{
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);

return new self($target, $operator, $value);
}
}
Expand Up @@ -10,7 +10,6 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;
use eZ\Publish\API\Repository\Values\Content\Query\CustomFieldInterface;

/**
Expand Down Expand Up @@ -48,7 +47,7 @@
* - Simple stop word removal might be applied to the words provided in the
* query.
*/
class FullText extends Criterion implements CriterionInterface, CustomFieldInterface
class FullText extends Criterion implements CustomFieldInterface
{
/**
* Fuzziness of the fulltext search.
Expand Down Expand Up @@ -123,8 +122,13 @@ public function getSpecifications()
);
}

/**
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
*/
public static function createFromQueryBuilder($target, $operator, $value)
{
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);

return new self($value);
}

Expand Down
Expand Up @@ -10,7 +10,6 @@

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;
use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;

/**
Expand All @@ -20,7 +19,7 @@
* - IN: matches against a list of language codes
* - EQ: matches against one language code
*/
class LanguageCode extends Criterion implements CriterionInterface
class LanguageCode extends Criterion
{
/**
* Switch for matching Content that is always-available.
Expand Down Expand Up @@ -66,10 +65,12 @@ public function getSpecifications()
}

/**
* @todo needs to be updated for $matchAlwaysAvailable
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead.
*/
public static function createFromQueryBuilder($target, $operator, $value)
{
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED);

return new self($value);
}
}
Expand Up @@ -9,11 +9,10 @@
namespace eZ\Publish\API\Repository\Values\Content\Query\Criterion;

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\API\Repository\Values\Content\Query\CriterionInterface;

/**
* This is the base class for Location criterions.
*/
abstract class Location extends Criterion implements CriterionInterface
abstract class Location extends Criterion
{
}

0 comments on commit 37d41f6

Please sign in to comment.