diff --git a/.gush.yml b/.gush.yml deleted file mode 100644 index e9d596a..0000000 --- a/.gush.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Gush configuration file, any comments will be lost. -adapter: github -issue_tracker: github -table-pr: - fixed_tickets: ['Fixed Tickets', ''] - license: [License, MIT] -base: master -meta-header: "This file is part of Testing Sandbox package.\n\n(c) 1980-2015 Doctor Who \n\nThis source file is subject to the MIT license that is bundled\nwith this source code in the file LICENSE." -repo_adapter: github -repo_org: sstok -repo_name: gush-experiments-sandbox -issue_org: sstok -issue_repo_name: gush-experiments-sandbox diff --git a/.php_cs.cache b/.php_cs.cache deleted file mode 100644 index e4b14a3..0000000 --- a/.php_cs.cache +++ /dev/null @@ -1 +0,0 @@ -a:3:{s:7:"version";s:59:"2.0-DEV:dev-master#9e212ed7f598929d491563d01d221155e358a2a3";s:6:"fixers";a:20:{i:0;s:6:"braces";i:1;s:6:"elseif";i:2;s:8:"encoding";i:3;s:10:"eof_ending";i:4;s:19:"function_call_space";i:5;s:20:"function_declaration";i:6;s:11:"indentation";i:7;s:20:"line_after_namespace";i:8;s:8:"linefeed";i:9;s:19:"lowercase_constants";i:10;s:18:"lowercase_keywords";i:11;s:21:"method_argument_space";i:12;s:12:"multiple_use";i:13;s:11:"parenthesis";i:14;s:15:"php_closing_tag";i:15;s:4:"psr0";i:16;s:9:"short_tag";i:17;s:25:"single_line_after_imports";i:18;s:15:"trailing_spaces";i:19;s:10:"visibility";}s:6:"hashes";a:0:{}} \ No newline at end of file diff --git a/AbstractExtension.php b/AbstractExtension.php deleted file mode 100644 index 94d6dd6..0000000 --- a/AbstractExtension.php +++ /dev/null @@ -1,161 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\InvalidArgumentException; -use Rollerworks\Component\Search\Exception\UnexpectedTypeException; - -/** - * The AbstractExtension can be used as a base class for SearchExtensions. - * - * An added bonus for extending this class rather then the implementing the the - * {@link SearchExtensionInterface} is that any new methods added the - * SearchExtensionInterface will not break existing implementations. - * - * @author Sebastiaan Stok - */ -abstract class AbstractExtension implements SearchExtensionInterface -{ - /** - * The types provided by this extension. - * - * @var FieldTypeInterface[] - */ - private $types; - - /** - * The type extensions provided by this extension. - * - * Keeps an array of FieldTypeExtensionInterface objects per type-name. - * type-name => FieldTypeExtensionInterface[] - * - * @var array - */ - private $typeExtensions; - - /** - * {@inheritdoc} - */ - public function getType($name) - { - if (null === $this->types) { - $this->initTypes(); - } - - if (!isset($this->types[$name])) { - throw new InvalidArgumentException( - sprintf('The type "%s" can not be loaded by this extension', $name) - ); - } - - return $this->types[$name]; - } - - /** - * {@inheritdoc} - */ - public function hasType($name) - { - if (null === $this->types) { - $this->initTypes(); - } - - return isset($this->types[$name]); - } - - /** - * {@inheritdoc} - */ - public function getTypeExtensions($name) - { - if (null === $this->typeExtensions) { - $this->initTypeExtensions(); - } - - return isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : []; - } - - /** - * {@inheritdoc} - */ - public function hasTypeExtensions($name) - { - if (null === $this->typeExtensions) { - $this->initTypeExtensions(); - } - - return isset($this->typeExtensions[$name]) && count($this->typeExtensions[$name]) > 0; - } - - /** - * Registers the types. - * - * @return FieldTypeInterface[] an array of FormTypeInterface instances - */ - protected function loadTypes() - { - return []; - } - - /** - * Registers the type extensions. - * - * @return array an array of FieldTypeExtensionInterface instances - * per type name - */ - protected function loadTypeExtensions() - { - return []; - } - - /** - * Initializes the types. - * - * @throws UnexpectedTypeException if any registered type is not an instance of FormTypeInterface - */ - private function initTypes() - { - $this->types = []; - - foreach ($this->loadTypes() as $type) { - if (!$type instanceof FieldTypeInterface) { - throw new UnexpectedTypeException($type, 'Rollerworks\Component\Search\FieldTypeInterface'); - } - - $this->types[$type->getName()] = $type; - } - } - - /** - * Initializes the type extensions. - * - * @throws UnexpectedTypeException if any registered type extension is not - * an instance of FieldTypeExtensionInterface - */ - private function initTypeExtensions() - { - $this->typeExtensions = []; - - foreach ($this->loadTypeExtensions() as $extension) { - if (!$extension instanceof FieldTypeExtensionInterface) { - throw new UnexpectedTypeException( - $extension, - 'Rollerworks\Component\Search\FieldTypeExtensionInterface' - ); - } - - $type = $extension->getExtendedType(); - - $this->typeExtensions[$type][] = $extension; - } - } -} diff --git a/AbstractFieldType.php b/AbstractFieldType.php deleted file mode 100644 index c35a54c..0000000 --- a/AbstractFieldType.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Symfony\Component\OptionsResolver\OptionsResolver; - -/** - * The AbstractFieldType can be used as a base class implementation for FieldTypes. - * - * An added bonus for extending this class rather then the implementing the the - * {@link FieldTypeInterface} is that any new methods added the - * FieldTypeInterface will not break existing implementations. - * - * @author Sebastiaan Stok - */ -abstract class AbstractFieldType implements FieldTypeInterface -{ - /** - * {@inheritdoc} - */ - public function buildType(FieldConfigInterface $config, array $options) - { - } - - /** - * {@inheritdoc} - */ - public function buildView(SearchFieldView $view, FieldConfigInterface $config, array $options) - { - } - - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver) - { - } - - /** - * {@inheritdoc} - */ - public function getParent() - { - return 'field'; - } -} diff --git a/AbstractFieldTypeExtension.php b/AbstractFieldTypeExtension.php deleted file mode 100644 index e7c6768..0000000 --- a/AbstractFieldTypeExtension.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Symfony\Component\OptionsResolver\OptionsResolver; - -/** - * The AbstractFieldTypeExtension can be used as a base implementation - * for FieldTypeExtensions. - * - * An added bonus for extending this class rather then the implementing the the - * {@link FieldTypeExtensionInterface} is that any new methods added the - * FieldTypeExtensionInterface will not break existing implementations. - */ -abstract class AbstractFieldTypeExtension implements FieldTypeExtensionInterface -{ - /** - * {@inheritdoc} - */ - public function buildType(FieldConfigInterface $builder, array $options) - { - } - - /** - * {@inheritdoc} - */ - public function buildView(FieldConfigInterface $config, SearchFieldView $view) - { - } - - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver) - { - } -} diff --git a/DataTransformerInterface.php b/DataTransformerInterface.php deleted file mode 100644 index 8528809..0000000 --- a/DataTransformerInterface.php +++ /dev/null @@ -1,76 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\TransformationFailedException; - -/** - * Transforms a value between different representations. - * - * @author Sebastiaan Stok - */ -interface DataTransformerInterface -{ - /** - * Transforms a value from the original representation to a transformed representation. - * - * This method is called on two occasions: - * - * 1. When data from an input is submitted using to transform the new input data - * back into the renderable format. For example if you have a date field and submit '2009-10-10' - * you might accept this value because its easily parsed, but the transformer still writes back - * "2009/10/10" onto the display field (for further displaying or other purposes). - * - * This method must be able to deal with empty values. Usually this will - * be NULL, but depending on your implementation other empty values are - * possible as well (such as empty strings). The reasoning behind this is - * that value transformers must be chainable. If the transform() method - * of the first value transformer outputs NULL, the second value transformer - * must be able to process that value. - * - * By convention, transform() should return an empty string if NULL is - * passed. - * - * @param mixed $value The value in the original representation - * - * @throws TransformationFailedException When the transformation fails. - * - * @return mixed The value in the transformed representation - */ - public function transform($value); - - /** - * Transforms a value from the transformed representation to its original - * representation. - * - * This method is called to transform the requests tainted data - * into an acceptable format for your data processing layer. - * - * This method must be able to deal with empty values. Usually this will - * be an empty string, but depending on your implementation other empty - * values are possible as well (such as empty strings). The reasoning behind - * this is that value transformers must be chainable. If the - * reverseTransform() method of the first value transformer outputs an - * empty string, the second value transformer must be able to process that - * value. - * - * By convention, reverseTransform() should return NULL if an empty string - * is passed. - * - * @param mixed $value The value in the transformed representation - * - * @throws TransformationFailedException When the transformation fails. - * - * @return mixed The value in the original representation - */ - public function reverseTransform($value); -} diff --git a/ExporterInterface.php b/ExporterInterface.php deleted file mode 100644 index baf640e..0000000 --- a/ExporterInterface.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * ExporterInterface defines the interface for SearchCondition exporters. - * - * @author Sebastiaan Stok - */ -interface ExporterInterface -{ - /** - * Exports the SearchCondition to a portable format. - * - * The returned format can be anything, as long as it's possible - * to 're-import' the exported search condition with a compatible - * input processor. - * - * @param SearchConditionInterface $condition - * - * @return mixed - */ - public function exportCondition(SearchConditionInterface $condition); -} diff --git a/FieldAliasResolverInterface.php b/FieldAliasResolverInterface.php deleted file mode 100644 index 7ae3890..0000000 --- a/FieldAliasResolverInterface.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * FieldAliasResolverInterface must be implemented by every AliasResolver. - * - * @author Sebastiaan Stok - */ -interface FieldAliasResolverInterface -{ - /** - * Resolve a field's alias to a real field name. - * - * Note: When a field alias cannot be resolved the field $fieldAlias - * should be returned without any changes. - * - * @param FieldSet $fieldSet - * @param string $fieldAlias - * - * @return string The real field name - */ - public function resolveFieldName(FieldSet $fieldSet, $fieldAlias); -} diff --git a/FieldConfigInterface.php b/FieldConfigInterface.php deleted file mode 100644 index 231540e..0000000 --- a/FieldConfigInterface.php +++ /dev/null @@ -1,164 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * The configuration of a SearchField. - * - * @author Sebastiaan Stok - */ -interface FieldConfigInterface -{ - /** - * Returns the name of field. - * - * @return string the Field name - */ - public function getName(); - - /** - * Returns the field type used to construct the field. - * - * @return ResolvedFieldTypeInterface The field's type - */ - public function getType(); - - /** - * Returns whether value-type $type is accepted by the field. - * - * Value must be a constant of: - * - * * ValuesBag::VALUE_TYPE_RANGE - * * ValuesBag::VALUE_TYPE_COMPARISON - * * ValuesBag::VALUE_TYPE_PATTERN_MATCH - * - * @param string $type - * - * @return bool - */ - public function supportValueType($type); - - /** - * Set whether value-type $type is accepted by the field. - * - * * ValuesBag::VALUE_TYPE_RANGE - * * ValuesBag::VALUE_TYPE_COMPARISON - * * ValuesBag::VALUE_TYPE_PATTERN_MATCH - * - * @param string $type - * @param bool $enabled - */ - public function setValueTypeSupport($type, $enabled); - - /** - * Returns the configured Model's class-name. - * - * This is required for certain storage engines. - * - * @return string - */ - public function getModelRefClass(); - - /** - * Returns the configured Model's field property-name. - * - * This is required for certain storage engines. - * - * @return string - */ - public function getModelRefProperty(); - - /** - * Set the {@link ValueComparisonInterface} instance for optimizing - * and validation. - * - * @param ValueComparisonInterface $comparisonObj - */ - public function setValueComparison(ValueComparisonInterface $comparisonObj); - - /** - * Returns the configured {@link ValueComparisonInterface} instance. - * - * @return ValueComparisonInterface - */ - public function getValueComparison(); - - /** - * Appends / prepends a transformer to the view transformer chain. - * - * The transform method of the transformer is used to convert data from the - * normalized to the view format. - * The reverseTransform method of the transformer is used to convert from the - * view to the normalized format. - * - * @param DataTransformerInterface $viewTransformer - * @param bool $forcePrepend if set to true, prepend instead of appending - */ - public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false); - - /** - * Clears the view transformers of the field. - * - * @return self The configuration object. - */ - public function resetViewTransformers(); - - /** - * Returns the view transformers of the field. - * - * @return DataTransformerInterface[] An array of {@link DataTransformerInterface} instances - */ - public function getViewTransformers(); - - /** - * Returns whether the field's data is locked. - * - * A field with locked data is restricted to the data passed in - * this configuration. - * - * @return bool Whether the data is locked - */ - public function getDataLocked(); - - /** - * Returns all options passed during the construction of the field. - * - * @return array The passed options - */ - public function getOptions(); - - /** - * Returns whether a specific option exists. - * - * @param string $name The option name - * - * @return bool Whether the option exists - */ - public function hasOption($name); - - /** - * Returns the value of a specific option. - * - * @param string $name The option name - * @param mixed $default The value returned if the option does not exist - * - * @return mixed The option value - */ - public function getOption($name, $default = null); - - /** - * Returns a new SearchFieldView for the SearchField. - * - * @return SearchFieldView - */ - public function createView(); -} diff --git a/FieldLabelResolverInterface.php b/FieldLabelResolverInterface.php deleted file mode 100644 index afc7279..0000000 --- a/FieldLabelResolverInterface.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * Provide a field-label resolver. - * - * @author Sebastiaan Stok - */ -interface FieldLabelResolverInterface -{ - /** - * Resolve the field name to an localized field-alias (label). - * - * Note: If the field alias can not be resolved - * this should return the $fieldName unresolved. - * - * @param FieldSet $fieldSet - * @param string $fieldName - * - * @return string - */ - public function resolveFieldLabel(FieldSet $fieldSet, $fieldName); -} diff --git a/FieldRegistry.php b/FieldRegistry.php deleted file mode 100644 index 5c8682c..0000000 --- a/FieldRegistry.php +++ /dev/null @@ -1,151 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\ExceptionInterface; -use Rollerworks\Component\Search\Exception\InvalidArgumentException; -use Rollerworks\Component\Search\Exception\UnexpectedTypeException; - -/** - * @author Sebastiaan Stok - */ -class FieldRegistry implements FieldRegistryInterface -{ - /** - * Extensions. - * - * @var SearchExtensionInterface[] - */ - private $extensions = []; - - /** - * @var FieldTypeInterface[] - */ - private $types = []; - - /** - * @var ResolvedFieldTypeFactoryInterface - */ - private $resolvedTypeFactory; - - /** - * Constructor. - * - * @param SearchExtensionInterface[] $extensions An array of SearchExtensionInterface - * @param ResolvedFieldTypeFactoryInterface $resolvedTypeFactory The factory for resolved field types - * - * @throws UnexpectedTypeException if any extension does not implement SearchExtensionInterface - */ - public function __construct(array $extensions, ResolvedFieldTypeFactoryInterface $resolvedTypeFactory) - { - foreach ($extensions as $extension) { - if (!$extension instanceof SearchExtensionInterface) { - throw new UnexpectedTypeException($extension, 'Rollerworks\Component\Search\SearchExtensionInterface'); - } - } - - $this->extensions = $extensions; - $this->resolvedTypeFactory = $resolvedTypeFactory; - } - - /** - * {@inheritdoc} - */ - public function getType($name) - { - if (!is_string($name)) { - throw new UnexpectedTypeException($name, 'string'); - } - - if (!isset($this->types[$name])) { - $type = null; - - foreach ($this->extensions as $extension) { - if ($extension->hasType($name)) { - $type = $extension->getType($name); - - break; - } - } - - if (!$type) { - throw new InvalidArgumentException( - sprintf('Could not load type "%s"', $name) - ); - } - - $this->resolveAndAddType($type); - } - - return $this->types[$name]; - } - - /** - * {@inheritdoc} - */ - public function hasType($name) - { - if (isset($this->types[$name])) { - return true; - } - - try { - $this->getType($name); - } catch (ExceptionInterface $e) { - return false; - } - - return true; - } - - /** - * {@inheritdoc} - */ - public function getExtensions() - { - return $this->extensions; - } - - /** - * Wraps a type into a ResolvedFieldTypeInterface implementation and connects - * it with its parent type. - * - * @param FieldTypeInterface $type The type to resolve - * - * @return ResolvedFieldTypeInterface The resolved type - */ - private function resolveAndAddType(FieldTypeInterface $type) - { - $parentType = $type->getParent(); - - if ($parentType instanceof FieldTypeInterface) { - $this->resolveAndAddType($parentType); - - $parentType = $parentType->getName(); - } - - $typeExtensions = []; - - foreach ($this->extensions as $extension) { - $typeExtensions = array_merge( - $typeExtensions, - $extension->getTypeExtensions($type->getName()) - ); - } - - $this->types[$type->getName()] = $this->resolvedTypeFactory->createResolvedType( - $type, - $typeExtensions, - $parentType ? $this->getType($parentType) : null - ); - } -} diff --git a/FieldRegistryInterface.php b/FieldRegistryInterface.php deleted file mode 100644 index 4b16ade..0000000 --- a/FieldRegistryInterface.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * @author Sebastiaan Stok - */ -interface FieldRegistryInterface -{ - /** - * Returns a field type by name. - * - * This methods registers the type extensions from the search extensions. - * - * @param string $name The name of the type - * - * @throws Exception\UnexpectedTypeException if the passed name is not a string - * @throws Exception\InvalidArgumentException if the type cannot be retrieved from any extension - * - * @return ResolvedFieldTypeInterface The type - */ - public function getType($name); - - /** - * Returns whether the given field type is supported. - * - * @param string $name The name of the type - * - * @return bool Whether the type is supported - */ - public function hasType($name); - - /** - * Returns the extensions loaded on the registry. - * - * @return SearchExtensionInterface[] - */ - public function getExtensions(); -} diff --git a/FieldSet.php b/FieldSet.php deleted file mode 100644 index e42808e..0000000 --- a/FieldSet.php +++ /dev/null @@ -1,297 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\BadMethodCallException; -use Rollerworks\Component\Search\Exception\UnexpectedTypeException; - -/** - * A FieldSet holds all the search fields and there configuration. - * - * @author Sebastiaan Stok - */ -class FieldSet implements \Countable, \IteratorAggregate -{ - /** - * Search fields. - * - * @var FieldConfigInterface[] - */ - private $fields = []; - - /** - * Name of the FieldSet. - * - * @var string - */ - private $name; - - /** - * @var bool - */ - private $locked = false; - - /** - * Constructor. - * - * @param string|null $name FieldSet name, should start with a letter, digit or underscore - * and only contain letters, digits, numbers, underscores ("_") and - * hyphens ("-"). - * - * @throws UnexpectedTypeException If the name is not a string or an integer - * @throws \InvalidArgumentException If the name contains invalid characters - */ - public function __construct($name = null) - { - self::validateName($name); - - $this->name = $name; - } - - /** - * Returns a new FieldSet instance. - * - * @param string|null $name - * - * @return FieldSet - */ - public static function create($name = null) - { - return new static($name); - } - - /** - * Returns the name of the set. - * - * @return null|string - */ - public function getSetName() - { - return $this->name; - } - - /** - * Add/replace a search field on the set. - * - * Any existing field with the same name will be overwritten. - * - * @param string $name - * @param FieldConfigInterface $config - * - * @return self - */ - public function set($name, FieldConfigInterface $config) - { - if ($this->locked) { - $this->throwLocked(); - } - - self::validateName($name); - - $this->fields[$name] = $config; - - return $this; - } - - /** - * Replaces an existing search field on the set. - * - * Same as {@link FieldSet::set()}, but throws an exception when there is no - * field registered with that name. - * - * @param string $name - * @param FieldConfigInterface $config - * - * @throws \RuntimeException When the field is not registered at this fieldset - * - * @return self - */ - public function replace($name, FieldConfigInterface $config) - { - if ($this->locked) { - $this->throwLocked(); - } - - if (!isset($this->fields[$name])) { - throw new \RuntimeException( - sprintf('Unable to replace none existent field: %s', $name) - ); - } - - $this->fields[$name] = $config; - - return $this; - } - - /** - * Removes a field from the set. - * - * @param string $name - * - * @return self - */ - public function remove($name) - { - if ($this->locked) { - $this->throwLocked(); - } - - if (isset($this->fields[$name])) { - unset($this->fields[$name]); - } - - return $this; - } - - /** - * Returns the {@link FieldConfigInterface} object of the search field. - * - * @param string $name - * - * @throws \RuntimeException When the field is not registered at this Fieldset - * - * @return FieldConfigInterface - */ - public function get($name) - { - if (!isset($this->fields[$name])) { - throw new \RuntimeException( - sprintf('Unable to find none existent field: %s', $name) - ); - } - - return $this->fields[$name]; - } - - /** - * Returns all the registered fields in the set. - * - * @return FieldConfigInterface[] [name] => {FieldConfigInterface object}) - */ - public function all() - { - return $this->fields; - } - - /** - * Returns whether the field is registered in the set. - * - * @param string $name - * - * @return bool - */ - public function has($name) - { - return isset($this->fields[$name]); - } - - /** - * Returns the current FieldSet as an Iterator that includes all Fields. - * - * @see all() - * - * @return \ArrayIterator An \ArrayIterator object for iterating over fields - */ - public function getIterator() - { - return new \ArrayIterator($this->fields); - } - - /** - * Returns the number of fields in the set. - * - * @return int The number of fields - */ - public function count() - { - return count($this->fields); - } - - /** - * Validates whether the given name is a valid set name. - * - * @param string|null $name The tested FieldSet name - * - * @throws UnexpectedTypeException If the name is not a string - * @throws \InvalidArgumentException If the name contains invalid characters - */ - public static function validateName($name) - { - if (null !== $name && !is_string($name)) { - throw new UnexpectedTypeException($name, ['string', 'null']); - } - - if (!self::isValidName($name)) { - throw new \InvalidArgumentException( - sprintf( - 'The name "%s" contains illegal characters. Names should start with a letter, digit or underscore '. - 'and only contain letters, digits, numbers, underscores ("_") and hyphens ("-").', - $name - ) - ); - } - } - - /** - * Returns whether the given name is a valid set name. - * - * A name is accepted if it: - * - * * is empty - * * starts with a letter, digit or underscore - * * contains only letters, digits, numbers, underscores ("_") and hyphens ("-") - * - * @param string $name The tested name - * - * @return bool Whether the name is valid - */ - final public static function isValidName($name) - { - return '' === $name || null === $name || preg_match('/^[a-zA-Z0-9_][a-zA-Z0-9_\-]*$/D', $name); - } - - /** - * Sets the set's data is locked. - * - * After calling this method, setter methods can be no longer called. - * - * @throws BadMethodCallException when the data is locked - */ - public function lockConfig() - { - if ($this->locked) { - $this->throwLocked(); - } - - $this->locked = true; - } - - /** - * Returns whether the set's data is locked. - * - * A FieldSet with locked data is restricted to the data currently - * configured. - * - * @return bool Whether the data is locked. - */ - public function isConfigLocked() - { - return $this->locked; - } - - private function throwLocked() - { - throw new BadMethodCallException( - 'FieldSet setter methods cannot be accessed anymore once the data is locked.' - ); - } -} diff --git a/FieldSetBuilder.php b/FieldSetBuilder.php deleted file mode 100644 index 445827f..0000000 --- a/FieldSetBuilder.php +++ /dev/null @@ -1,271 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\BadMethodCallException; -use Rollerworks\Component\Search\Exception\InvalidArgumentException; -use Rollerworks\Component\Search\Exception\UnexpectedTypeException; -use Rollerworks\Component\Search\Metadata\MetadataReaderInterface; - -/** - * The FieldSetBuilder helps with building a {@link FieldSet}. - * - * @author Sebastiaan Stok - */ -class FieldSetBuilder implements FieldSetBuilderInterface -{ - /** - * @var bool - */ - private $locked; - - /** - * Name of the FieldSet. - * - * @var string - */ - private $name; - - /** - * @var FieldConfigInterface[] - */ - private $fields = []; - - /** - * @var array[] - */ - private $unresolvedFields = []; - - /** - * @var SearchFactoryInterface - */ - private $searchFactory; - - /** - * @var MetadataReaderInterface - */ - private $metadataReader; - - /** - * Constructor. - * - * @param string $name Name of the FieldSet - * @param SearchFactoryInterface $searchFactory Search factory for creating new search fields - * @param MetadataReaderInterface $metadataReader Optional metadata reader for loading field configuration - */ - public function __construct($name, SearchFactoryInterface $searchFactory, MetadataReaderInterface $metadataReader = null) - { - $this->name = $name; - $this->searchFactory = $searchFactory; - $this->metadataReader = $metadataReader; - } - - /** - * Get the configured name for the FieldSet. - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * {@inheritdoc} - */ - public function add($field, $type = null, array $options = [], $required = false, $modelClass = null, $modelProperty = null) - { - if ($this->locked) { - throw new BadMethodCallException( - 'FieldSetBuilder methods cannot be accessed anymore once the builder is turned into a FieldSet instance.' - ); - } - - if (!$field instanceof FieldConfigInterface && !is_string($field)) { - throw new UnexpectedTypeException($field, 'string or Rollerworks\Component\Search\FieldConfigInterface'); - } - - if ($field instanceof FieldConfigInterface) { - $this->fields[$field->getName()] = $field; - unset($this->unresolvedFields[$field->getName()]); - - return $this; - } - - if (!$type instanceof FieldTypeInterface && !is_string($type)) { - throw new UnexpectedTypeException($type, 'string or Rollerworks\Component\Search\FieldTypeInterface'); - } - - if (null !== $modelClass) { - $options = array_merge( - $options, - [ - 'model_class' => $modelClass, - 'model_property' => $modelProperty, - ] - ); - } - - $this->unresolvedFields[$field] = [ - 'type' => $type, - 'options' => $options, - ]; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function remove($name) - { - if ($this->locked) { - throw new BadMethodCallException( - 'FieldSetBuilder methods cannot be accessed anymore once the builder is turned into a FieldSet instance.' - ); - } - - unset($this->fields[$name], $this->unresolvedFields[$name]); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function has($name) - { - if ($this->locked) { - throw new BadMethodCallException( - 'FieldSetBuilder methods cannot be accessed anymore once the builder is turned into a FieldSet instance.' - ); - } - - if (isset($this->unresolvedFields[$name])) { - return true; - } - - if (isset($this->fields[$name])) { - return true; - } - - return false; - } - - /** - * {@inheritdoc} - */ - public function get($name) - { - if ($this->locked) { - throw new BadMethodCallException( - 'FieldSetBuilder methods cannot be accessed anymore once the builder is turned into a FieldSet instance.' - ); - } - - if (isset($this->unresolvedFields[$name])) { - $this->fields[$name] = $this->searchFactory->createField( - $name, - $this->unresolvedFields[$name]['type'], - $this->unresolvedFields[$name]['options'] - ); - - unset($this->unresolvedFields[$name]); - } - - if (isset($this->fields[$name])) { - return $this->fields[$name]; - } - - throw new InvalidArgumentException(sprintf('The field with the name "%s" does not exist.', $name)); - } - - /** - * Import the fields configuration using the metadata reader. - * - * @param string $class Model Class-name to load metadata from - * @param array $include List of field names to use, everything else is excluded - * @param array $exclude List of field names to exclude, everything else is included - * - * @throws BadMethodCallException When the FieldSet has been already turned into a FieldSet instance - * @throws BadMethodCallException When no metadata reader is configured - * - * @return self - */ - public function importFromClass($class, array $include = [], array $exclude = []) - { - if ($this->locked) { - throw new BadMethodCallException( - 'FieldSetBuilder methods cannot be accessed anymore once the builder is turned into a FieldSet instance.' - ); - } - - if (!$this->metadataReader) { - throw new BadMethodCallException( - 'FieldSetBuilder is unable to import configuration from class, no MetadataReader was set for the constructor.' - ); - } - - foreach ($this->metadataReader->getSearchFields($class) as $field) { - if (($include && !in_array($field->fieldName, $include, true)) xor ($exclude && in_array($field->fieldName, $exclude, true))) { - continue; - } - - $field->options = array_merge( - $field->options, - [ - 'model_class' => $field->class, - 'model_property' => $field->property, - ] - ); - - $this->unresolvedFields[$field->fieldName] = [ - 'type' => $field->type, - 'options' => $field->options, - ]; - } - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getFieldSet() - { - if ($this->locked) { - throw new BadMethodCallException( - 'FieldSetBuilder methods cannot be accessed anymore once the builder is turned into a FieldSet instance.' - ); - } - - foreach ($this->unresolvedFields as $name => $field) { - $this->fields[$name] = $this->searchFactory->createField( - $name, - $field['type'], - $field['options'] - ); - - unset($this->unresolvedFields[$name]); - } - - $fieldSet = new FieldSet($this->name); - - foreach ($this->fields as $name => $field) { - $fieldSet->set($name, $field); - } - - $this->locked = true; - - return $fieldSet; - } -} diff --git a/FieldSetBuilderInterface.php b/FieldSetBuilderInterface.php deleted file mode 100644 index 768aa46..0000000 --- a/FieldSetBuilderInterface.php +++ /dev/null @@ -1,81 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\BadMethodCallException; -use Rollerworks\Component\Search\Exception\UnexpectedTypeException; - -/** - * @author Sebastiaan Stok - */ -interface FieldSetBuilderInterface -{ - /** - * Add a field to the set-builder. - * - * Note. The possibility to pass a FieldTypeInterface as $type is deprecated - * since 1.0.0-beta5 and will be removed in 2.0 - * - * Its possible to also pass in a FieldTypeInterface - * - * @param string|FieldConfigInterface $field Name of search field or an actual search field - * object - * @param string $type Field type-name - * @param array $options Array of options for building the field - * @param bool $required Is the field required in a ValuesGroup and must it - * always have a value (default is false) - * @param string $modelClass Optional Model class-name reference - * @param string $modelProperty Model property reference - * - * @throws BadMethodCallException When the FieldSet has been already turned into a FieldSet instance - * @throws UnexpectedTypeException - * - * @return self - */ - public function add($field, $type = null, array $options = [], $required = false, $modelClass = null, $modelProperty = null); - - /** - * Remove a field from the set-builder. - * - * @param string $name - * - * @throws BadMethodCallException When the FieldSet has been already turned into a FieldSet instance - * - * @return FieldSetBuilderInterface - */ - public function remove($name); - - /** - * Returns whether the set-builder has a field with the name. - * - * @param string $name - * - * @return bool - */ - public function has($name); - - /** - * Get a previously registered field from the set. - * - * @param string $name - * - * @return FieldConfigInterface - */ - public function get($name); - - /** - * Create the FieldSet using the fields set on the builder. - * - * @return FieldSet - */ - public function getFieldSet(); -} diff --git a/FieldSetRegistry.php b/FieldSetRegistry.php deleted file mode 100644 index 2436ac9..0000000 --- a/FieldSetRegistry.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\InvalidArgumentException; - -final class FieldSetRegistry implements FieldSetRegistryInterface -{ - private $fieldSets = []; - - /** - * {@inheritdoc} - */ - public function has($name) - { - return isset($this->fieldSets[$name]); - } - - /** - * {@inheritdoc} - */ - public function get($name) - { - if (isset($this->fieldSets[$name])) { - return $this->fieldSets[$name]; - } - - throw new InvalidArgumentException(sprintf('Unable to get none registered FieldSet "%s".', $name)); - } - - /** - * {@inheritdoc} - */ - public function add(FieldSet $fieldSet) - { - $name = $fieldSet->getSetName(); - - if (isset($this->fieldSets[$name])) { - throw new InvalidArgumentException(sprintf('Unable to overwrite already registered FieldSet "%s".', $name)); - } - - if (!$fieldSet->isConfigLocked()) { - throw new InvalidArgumentException(sprintf('Unable to register unlocked FieldSet "%s".', $name)); - } - - $this->fieldSets[$name] = $fieldSet; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function all() - { - return $this->fieldSets; - } -} diff --git a/FieldSetRegistryInterface.php b/FieldSetRegistryInterface.php deleted file mode 100644 index 1269976..0000000 --- a/FieldSetRegistryInterface.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\InvalidArgumentException; - -interface FieldSetRegistryInterface -{ - /** - * Returns whether the registry has the requested FieldSet. - * - * @param string $name - * - * @return bool - */ - public function has($name); - - /** - * Get a FieldSet from the registry. - * - * @param string $name - * - * @throws InvalidArgumentException when the requested FieldSet - * is not registered - * - * @return FieldSet - */ - public function get($name); - - /** - * Set a FieldSet on the registry. - * - * @param FieldSet $fieldSet - * - * @throws InvalidArgumentException when the FieldSet is - * already registered - */ - public function add(FieldSet $fieldSet); - - /** - * Returns all the available FieldSet's. - * - * @return FieldSet[] as FieldSet-name => {FieldSet object} - */ - public function all(); -} diff --git a/FieldTypeExtensionInterface.php b/FieldTypeExtensionInterface.php deleted file mode 100644 index 071ba32..0000000 --- a/FieldTypeExtensionInterface.php +++ /dev/null @@ -1,58 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Symfony\Component\OptionsResolver\OptionsResolver; - -/** - * @author Sebastiaan Stok - */ -interface FieldTypeExtensionInterface -{ - /** - * Builds the type. - * - * This method is called after the extended type has built the type to - * further modify it. - * - * @see FieldTypeInterface::buildType() - * - * @param FieldConfigInterface $builder The config builder - * @param array $options The options - */ - public function buildType(FieldConfigInterface $builder, array $options); - - /** - * Builds the SearchFieldView. - * - * This method is called after the extended type has built the view to - * further modify it. - * - * @param FieldConfigInterface $config - * @param SearchFieldView $view - */ - public function buildView(FieldConfigInterface $config, SearchFieldView $view); - - /** - * Overrides the default options from the extended type. - * - * @param OptionsResolver $resolver The resolver for the options - */ - public function configureOptions(OptionsResolver $resolver); - - /** - * Returns the name of the type being extended. - * - * @return string The name of the type being extended - */ - public function getExtendedType(); -} diff --git a/FieldTypeInterface.php b/FieldTypeInterface.php deleted file mode 100644 index 74b378b..0000000 --- a/FieldTypeInterface.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Symfony\Component\OptionsResolver\OptionsResolver; - -/** - * @author Sebastiaan Stok - */ -interface FieldTypeInterface -{ - /** - * Returns the name of the type. - * - * @return string The type name. - */ - public function getName(); - - /** - * Returns the name of the parent type. - * - * @return string|null The name of the parent type if any, null otherwise - */ - public function getParent(); - - /** - * Sets the default options for this type. - * - * @param OptionsResolver $resolver The resolver for the options - * - * @return - */ - public function configureOptions(OptionsResolver $resolver); - - /** - * This configures the {@link FieldConfigInterface}. - * - * This method is called for each type in the hierarchy starting from the - * top most type. Type extensions can further modify the field. - * - * @param FieldConfigInterface $config - * @param array $options - */ - public function buildType(FieldConfigInterface $config, array $options); - - /** - * Configures the SearchFieldView instance. - * - * This method is called for each type in the hierarchy starting from the - * top most type. Type extensions can further modify the view. - * - * @see FieldTypeExtensionInterface::buildView() - * - * @param SearchFieldView $view - * @param FieldConfigInterface $config - * @param array $options - */ - public function buildView(SearchFieldView $view, FieldConfigInterface $config, array $options); -} diff --git a/InputProcessorInterface.php b/InputProcessorInterface.php deleted file mode 100644 index 95bf722..0000000 --- a/InputProcessorInterface.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Input\ProcessorConfig; - -/** - * The InputProcessorInterface must be implemented by all input-processor. - * - * @author Sebastiaan Stok - */ -interface InputProcessorInterface -{ - /** - * Process the input and returns the result. - * - * The processor should only handle fields that are registered in - * the FieldSet. - * - * @param ProcessorConfig $config Configuration for the processor - * @param mixed $input Input to process, actual format depends - * on the processor implementation - * - * @throws Exception\InvalidSearchConditionException When a search condition is created - * but it has errors - * @throws Exception\ValuesOverflowException When maximum values count is exceeded - * @throws Exception\FieldRequiredException When a field is required but missing - * @throws Exception\UnknownFieldException When an unknown field is provided in the input - * - * @return SearchConditionInterface|null Returns null on empty input - */ - public function process(ProcessorConfig $config, $input); -} diff --git a/PreloadedExtension.php b/PreloadedExtension.php deleted file mode 100644 index be4d1be..0000000 --- a/PreloadedExtension.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\InvalidArgumentException; - -class PreloadedExtension implements SearchExtensionInterface -{ - /** - * @var array - */ - private $types = []; - - /** - * @var array - */ - private $typeExtensions = []; - - /** - * Constructor. - * - * @param FieldTypeInterface[] $types The types that the extension should support - * @param FieldTypeExtensionInterface[] $typeExtensions The type extensions that the extension should support - */ - public function __construct(array $types, array $typeExtensions) - { - $this->types = $types; - $this->typeExtensions = $typeExtensions; - } - - /** - * {@inheritdoc} - */ - public function getType($name) - { - if (!isset($this->types[$name])) { - throw new InvalidArgumentException( - sprintf('The type "%s" can not be loaded by this extension', $name) - ); - } - - return $this->types[$name]; - } - - /** - * {@inheritdoc} - */ - public function hasType($name) - { - return isset($this->types[$name]); - } - - /** - * {@inheritdoc} - */ - public function getTypeExtensions($name) - { - return isset($this->typeExtensions[$name]) ? $this->typeExtensions[$name] : []; - } - - /** - * {@inheritdoc} - */ - public function hasTypeExtensions($name) - { - return !empty($this->typeExtensions[$name]); - } -} diff --git a/ResolvedFieldType.php b/ResolvedFieldType.php deleted file mode 100644 index 3121677..0000000 --- a/ResolvedFieldType.php +++ /dev/null @@ -1,221 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\InvalidArgumentException; -use Rollerworks\Component\Search\Exception\UnexpectedTypeException; -use Symfony\Component\OptionsResolver\OptionsResolver; - -/** - * @author Sebastiaan Stok - */ -class ResolvedFieldType implements ResolvedFieldTypeInterface -{ - /** - * @var FieldTypeInterface - */ - private $innerType; - - /** - * @var FieldTypeExtensionInterface[] - */ - private $typeExtensions; - - /** - * @var ResolvedFieldType - */ - private $parent; - - /** - * @var OptionsResolver - */ - private $optionsResolver; - - /** - * Constructor. - * - * @param FieldTypeInterface $innerType - * @param array $typeExtensions - * @param ResolvedFieldTypeInterface $parent - * - * @throws UnexpectedTypeException When at least one of the given extensions is not an FieldTypeExtensionInterface - * @throws InvalidArgumentException When the name of inner type is invalid - */ - public function __construct(FieldTypeInterface $innerType, array $typeExtensions = [], ResolvedFieldTypeInterface $parent = null) - { - if (!preg_match('/^[a-z0-9_]*$/i', $innerType->getName())) { - throw new InvalidArgumentException( - sprintf( - 'The "%s" field-type name ("%s") is not valid. Names must only contain letters, numbers, and "_".', - get_class($innerType), - $innerType->getName() - ) - ); - } - - foreach ($typeExtensions as $extension) { - if (!$extension instanceof FieldTypeExtensionInterface) { - throw new UnexpectedTypeException( - $extension, - 'Rollerworks\Component\Search\FieldTypeExtensionInterface' - ); - } - } - - $this->innerType = $innerType; - $this->typeExtensions = $typeExtensions; - $this->parent = $parent; - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return $this->innerType->getName(); - } - - /** - * {@inheritdoc} - */ - public function getParent() - { - return $this->parent; - } - - /** - * {@inheritdoc} - */ - public function getInnerType() - { - return $this->innerType; - } - - /** - * {@inheritdoc} - */ - public function getTypeExtensions() - { - return $this->typeExtensions; - } - - /** - * {@inheritdoc} - */ - public function createField($name, array $options = []) - { - $options = $this->getOptionsResolver()->resolve($options); - $builder = $this->newField($name, $options); - - return $builder; - } - - /** - * {@inheritdoc} - */ - public function buildType(FieldConfigInterface $config, array $options) - { - if (null !== $this->parent) { - $this->parent->buildType($config, $options); - } - - $this->innerType->buildType($config, $options); - - foreach ($this->typeExtensions as $extension) { - $extension->buildType($config, $options); - } - } - - /** - * {@inheritdoc} - */ - public function createFieldView(FieldConfigInterface $config) - { - $view = $this->newFieldView($config); - $view->vars = array_merge($view->vars, [ - 'name' => $config->getName(), - 'type' => $config->getType()->getName(), - 'accept_ranges' => $config->supportValueType(ValuesBag::VALUE_TYPE_RANGE), - 'accept_compares' => $config->supportValueType(ValuesBag::VALUE_TYPE_COMPARISON), - 'accept_pattern_matchers' => $config->supportValueType(ValuesBag::VALUE_TYPE_PATTERN_MATCH), - ]); - - return $view; - } - - /** - * {@inheritdoc} - */ - public function buildFieldView(SearchFieldView $view, FieldConfigInterface $config, array $options) - { - if (null !== $this->parent) { - $this->parent->buildFieldView($view, $config, $options); - } - - $this->innerType->buildView($view, $config, $options); - - foreach ($this->typeExtensions as $extension) { - $extension->buildView($config, $view); - } - } - - /** - * {@inheritdoc} - */ - public function getOptionsResolver() - { - if (null === $this->optionsResolver) { - if (null !== $this->parent) { - $this->optionsResolver = clone $this->parent->getOptionsResolver(); - } else { - $this->optionsResolver = new OptionsResolver(); - } - - $this->innerType->configureOptions($this->optionsResolver); - - foreach ($this->typeExtensions as $extension) { - $extension->configureOptions($this->optionsResolver); - } - } - - return $this->optionsResolver; - } - - /** - * Creates a new SearchField instance. - * - * Override this method if you want to customize the field class. - * - * @param string $name The name of the field - * @param array $options The builder options - * - * @return SearchField The new field instance - */ - protected function newField($name, array $options) - { - return new SearchField($name, $this, $options); - } - - /** - * Creates a new SearchFieldView instance. - * - * Override this method if you want to customize the view class. - * - * @param FieldConfigInterface $config The search field - * - * @return SearchFieldView The new view instance - */ - protected function newFieldView(FieldConfigInterface $config) - { - return new SearchFieldView($config); - } -} diff --git a/ResolvedFieldTypeFactory.php b/ResolvedFieldTypeFactory.php deleted file mode 100644 index 26e6373..0000000 --- a/ResolvedFieldTypeFactory.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -class ResolvedFieldTypeFactory implements ResolvedFieldTypeFactoryInterface -{ - /** - * {@inheritdoc} - */ - public function createResolvedType(FieldTypeInterface $type, array $typeExtensions, ResolvedFieldTypeInterface $parent = null) - { - return new ResolvedFieldType($type, $typeExtensions, $parent); - } -} diff --git a/ResolvedFieldTypeFactoryInterface.php b/ResolvedFieldTypeFactoryInterface.php deleted file mode 100644 index f77c3f9..0000000 --- a/ResolvedFieldTypeFactoryInterface.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * @author Sebastiaan Stok - */ -interface ResolvedFieldTypeFactoryInterface -{ - /** - * Resolves a field type. - * - * @param FieldTypeInterface $type - * @param array $typeExtensions - * @param ResolvedFieldTypeInterface $parent - * - * @throws Exception\UnexpectedTypeException if the types parent {@link FieldTypeInterface::getParent()} is not a string - * @throws Exception\InvalidArgumentException if the types parent cannot be retrieved from any extension - * - * @return ResolvedFieldTypeInterface - */ - public function createResolvedType(FieldTypeInterface $type, array $typeExtensions, ResolvedFieldTypeInterface $parent = null); -} diff --git a/ResolvedFieldTypeInterface.php b/ResolvedFieldTypeInterface.php deleted file mode 100644 index 275eac8..0000000 --- a/ResolvedFieldTypeInterface.php +++ /dev/null @@ -1,94 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Symfony\Component\OptionsResolver\OptionsResolver; - -/** - * A wrapper for a field type and its extensions. - */ -interface ResolvedFieldTypeInterface -{ - /** - * Returns the name of the type. - * - * @return string The type name. - */ - public function getName(); - - /** - * Returns the parent type. - * - * @return ResolvedFieldTypeInterface|null The parent type or null - */ - public function getParent(); - - /** - * Returns the wrapped field type. - * - * @return FieldTypeInterface The wrapped field type - */ - public function getInnerType(); - - /** - * Returns the extensions of the wrapped field type. - * - * @return FieldTypeExtensionInterface[] - */ - public function getTypeExtensions(); - - /** - * Returns a new FieldConfigInterface instance. - * - * @param string $name - * @param array $options - * - * @return FieldConfigInterface - */ - public function createField($name, array $options = []); - - /** - * This configures the {@link FieldConfigInterface}. - * - * This method is called for each type in the hierarchy starting from the - * top most type. Type extensions can further modify the field. - * - * @param FieldConfigInterface $config - * @param array $options - */ - public function buildType(FieldConfigInterface $config, array $options); - - /** - * Creates a new SearchFieldView for a field of this type. - * - * @param FieldConfigInterface $config - * - * @return SearchFieldView - */ - public function createFieldView(FieldConfigInterface $config); - - /** - * Configures a SearchFieldView for the type hierarchy. - * - * @param SearchFieldView $view - * @param FieldConfigInterface $config - * @param array $options - */ - public function buildFieldView(SearchFieldView $view, FieldConfigInterface $config, array $options); - - /** - * Returns the configured options resolver used for this type. - * - * @return OptionsResolver The options resolver - */ - public function getOptionsResolver(); -} diff --git a/SearchCondition.php b/SearchCondition.php deleted file mode 100644 index 5875abb..0000000 --- a/SearchCondition.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * SearchCondition contains the searching conditions and FieldSet. - */ -class SearchCondition implements SearchConditionInterface -{ - private $fieldSet; - private $values; - - /** - * @param FieldSet $fieldSet - * @param ValuesGroup $valuesGroup - */ - public function __construct(FieldSet $fieldSet, ValuesGroup $valuesGroup) - { - $this->fieldSet = $fieldSet; - $this->values = $valuesGroup; - } - - /** - * @return FieldSet - */ - public function getFieldSet() - { - return $this->fieldSet; - } - - /** - * @return ValuesGroup - */ - public function getValuesGroup() - { - return $this->values; - } -} diff --git a/SearchConditionBuilder.php b/SearchConditionBuilder.php deleted file mode 100644 index d7a2127..0000000 --- a/SearchConditionBuilder.php +++ /dev/null @@ -1,164 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\BadMethodCallException; - -/** - * @author Sebastiaan Stok - */ -class SearchConditionBuilder -{ - /** - * @var ValuesGroup - */ - protected $valuesGroup; - - /** - * @var SearchConditionBuilder - */ - protected $parent; - - /** - * @var FieldSet - */ - protected $fieldSet; - - /** - * Constructor. - * - * @param string $logical - * @param FieldSet $fieldSet - * @param SearchConditionBuilder $parent - * - * @internal Usage of this method is protected as of v1.0.0-beta5 and access will be changed to protected - * in 2.0. Use the static create() method instead. - * - * @throws BadMethodCallException when no FieldSet is provided - */ - public function __construct($logical = ValuesGroup::GROUP_LOGICAL_AND, FieldSet $fieldSet = null, SearchConditionBuilder $parent = null) - { - if (null === $fieldSet && null === $parent) { - throw new BadMethodCallException('Unable to create SearchCondition without FieldSet.'); - } - - $this->valuesGroup = new ValuesGroup($logical); - $this->parent = $parent; - $this->fieldSet = $fieldSet; - } - - /** - * Creates a new SearchConditionBuilder. - * - * @param FieldSet $fieldSet - * @param string $logical - * - * @return SearchConditionBuilder - */ - public static function create(FieldSet $fieldSet, $logical = ValuesGroup::GROUP_LOGICAL_AND) - { - return new self($logical, $fieldSet); - } - - /** - * Create a new ValuesGroup and returns the object instance. - * - * After creating the group it can be expended with fields or subgroups: - * - * ->group() - * ->field('name') - * ->... - * ->end() // return back to the ValuesGroup. - * ->end() // return back to the parent ValuesGroup - * - * @param string $logical eg. one of the following ValuesGroup class constants value: - * GROUP_LOGICAL_OR or GROUP_LOGICAL_AND - * - * @return SearchConditionBuilder - */ - public function group($logical = ValuesGroup::GROUP_LOGICAL_AND) - { - $builder = new self($logical, null, $this); - $this->valuesGroup->addGroup($builder->getGroup()); - - return $builder; - } - - /** - * Add/expend a field on this ValuesGroup and returns the object instance. - * - * The object instance is a ValuesBagBuilder (subset of ValuesBag), which - * allows to add extra values to the field: - * - * ->field('name') - * ->addSingleValue(new SingleValue('my value')) - * ->addSingleValue(new SingleValue('my value 2')) - * ->end() // return back to the ValuesGroup - * - * Tip! If the field already exists the existing is expended (values are added). - * To force an overwrite of the existing field use `->field('name', true)` instead. - * - * @param string $name - * @param bool $forceNew - * - * @return ValuesBagBuilder - */ - public function field($name, $forceNew = false) - { - if (!$forceNew && $this->valuesGroup->hasField($name)) { - $valuesBag = $this->valuesGroup->getField($name); - } else { - $valuesBag = new ValuesBagBuilder($this); - $this->valuesGroup->addField($name, $valuesBag); - } - - return $valuesBag; - } - - /** - * @return SearchConditionBuilder - */ - public function end() - { - return null !== $this->parent ? $this->parent : $this; - } - - /** - * @return ValuesGroup - */ - public function getGroup() - { - return $this->valuesGroup; - } - - /** - * Build the SearchCondition object using the groups and fields. - * - * @return SearchCondition - */ - public function getSearchCondition() - { - if ($this->parent) { - return $this->parent->getSearchCondition(); - } - - return new SearchCondition($this->fieldSet, $this->valuesGroup); - } - - /** - * @return FieldSet - */ - public function getFieldSet() - { - return $this->fieldSet; - } -} diff --git a/SearchConditionInterface.php b/SearchConditionInterface.php deleted file mode 100644 index 0027e74..0000000 --- a/SearchConditionInterface.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * SearchCondition contains the searching conditions and FieldSet. - */ -interface SearchConditionInterface -{ - /** - * Returns the configured FieldSet of the search condition. - * - * @return FieldSet - */ - public function getFieldSet(); - - /** - * Returns the root ValuesGroup of the search condition. - * - * @return ValuesGroup - */ - public function getValuesGroup(); -} diff --git a/SearchConditionOptimizerInterface.php b/SearchConditionOptimizerInterface.php deleted file mode 100644 index 5a3c3a9..0000000 --- a/SearchConditionOptimizerInterface.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * SearchCondition optimizer interface. - * - * This interface needs to be implemented by all search condition optimizers. - * - * @author Sebastiaan Stok - */ -interface SearchConditionOptimizerInterface -{ - /** - * Optimizes a {@link \Rollerworks\Component\Search\SearchConditionInterface} instance. - * - * Optimizing may remove duplicated values, normalize overlapping values, etc. - * - * If the search condition has errors the optimizer is should - * ignore the condition and do nothing. - * - * @param SearchConditionInterface $condition - */ - public function process(SearchConditionInterface $condition); - - /** - * Priority of the optimizer. - * - * Must return value between -10 and 10. - * - * @return int - */ - public function getPriority(); -} diff --git a/SearchConditionSerializer.php b/SearchConditionSerializer.php deleted file mode 100644 index a480904..0000000 --- a/SearchConditionSerializer.php +++ /dev/null @@ -1,99 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\InvalidArgumentException; - -/** - * SearchConditionSerializer, serializes a search condition for persistent storage. - * - * In practice this serializes the root ValuesGroup and of the condition - * and bundles it with the FieldSet-name for future unserializing. - * - * @author Sebastiaan Stok - */ -class SearchConditionSerializer -{ - /** - * @var FieldSetRegistry - */ - private $fieldSetRegistry; - - /** - * Constructor. - * - * @param FieldSetRegistryInterface $fieldSetRegistry A FieldSet registry for loading - * FieldSet configurations - */ - public function __construct(FieldSetRegistryInterface $fieldSetRegistry) - { - $this->fieldSetRegistry = $fieldSetRegistry; - } - - /** - * Serialize a search condition. - * - * The returned value is an array, you should serialize it yourself. - * This is not done already because storing a serialized SearchCondition - * in a php session would serialize the serialized result again. - * - * @param SearchConditionInterface $searchCondition - * - * @throws InvalidArgumentException when the FieldSet of the search condition - * is not registered in the FieldSetRegistry - * - * @return array [FieldSet-name, serialized ValuesGroup object] - */ - public function serialize(SearchConditionInterface $searchCondition) - { - $setName = $searchCondition->getFieldSet()->getSetName(); - - if (!$this->fieldSetRegistry->has($setName)) { - throw new InvalidArgumentException( - sprintf( - 'FieldSet "%s" is not registered in the FieldSetRegistry, '. - 'you should register the FieldSet before serializing the search condition.', - $setName - ) - ); - } - - return [$setName, serialize($searchCondition->getValuesGroup())]; - } - - /** - * Unserialize a serialized search condition. - * - * @param array $searchCondition [FieldSet-name, serialized ValuesGroup object] - * - * @throws InvalidArgumentException when serialized SearchCondition is invalid - * (invalid structure or failed to unserialize) - * - * @return SearchCondition - */ - public function unserialize($searchCondition) - { - if (2 !== count($searchCondition) || !isset($searchCondition[0], $searchCondition[1])) { - throw new InvalidArgumentException( - 'Serialized search condition must be exactly two values [FieldSet-name, serialized ValuesGroup].' - ); - } - - $fieldSet = $this->fieldSetRegistry->get($searchCondition[0]); - - if (false === $group = unserialize($searchCondition[1])) { - throw new InvalidArgumentException('Unable to unserialize invalid value.'); - } - - return new SearchCondition($fieldSet, $group); - } -} diff --git a/SearchExtensionInterface.php b/SearchExtensionInterface.php deleted file mode 100644 index 69467ef..0000000 --- a/SearchExtensionInterface.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * @author Sebastiaan Stok - */ -interface SearchExtensionInterface -{ - /** - * Returns a type by name. - * - * @param string $name The name of the type - * - * @throws Exception\InvalidArgumentException if the given type is not supported by this extension - * - * @return FieldTypeInterface The type - */ - public function getType($name); - - /** - * Returns whether the given type is supported. - * - * @param string $name The name of the type - * - * @return bool Whether the type is supported by this extension - */ - public function hasType($name); - - /** - * Returns the extensions for the given type. - * - * @param string $name The name of the type - * - * @return FieldTypeExtensionInterface[] An array of extensions as FieldTypeExtensionInterface instances - */ - public function getTypeExtensions($name); -} diff --git a/SearchFactory.php b/SearchFactory.php deleted file mode 100644 index c018f6f..0000000 --- a/SearchFactory.php +++ /dev/null @@ -1,158 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\UnexpectedTypeException; -use Rollerworks\Component\Search\Metadata\MetadataReaderInterface; - -/** - * @author Sebastiaan Stok - */ -class SearchFactory implements SearchFactoryInterface -{ - /** - * @var FieldRegistryInterface - */ - private $registry; - - /** - * @var MetadataReaderInterface - */ - private $metadataReader; - - /** - * @var ResolvedFieldTypeFactoryInterface - */ - private $resolvedTypeFactory; - - /** - * Constructor. - * - * @param FieldRegistryInterface $registry - * @param ResolvedFieldTypeFactoryInterface $resolvedTypeFactory - * @param MetadataReaderInterface $metadataReader - */ - public function __construct(FieldRegistryInterface $registry, ResolvedFieldTypeFactoryInterface $resolvedTypeFactory, MetadataReaderInterface $metadataReader = null) - { - $this->registry = $registry; - $this->resolvedTypeFactory = $resolvedTypeFactory; - $this->metadataReader = $metadataReader; - } - - /** - * {@inheritdoc} - */ - public function createField($name, $type, array $options = []) - { - $field = $this->createFieldBuilder($name, $type, $options); - - return $field; - } - - /** - * Create a new search field referenced by property. - * - - * @param string $class Model reference class-name - * @param string $property Model reference property-name - * @param string $name Name of the field - * @param string $type Type of the field - * @param array $options Array of options for building the field - * - * @return SearchField - * - * @deprecated Deprecated since version 1.0.0-beta5, to be removed in 2.0. - * Use createField() with the 'model_class' and 'model_property' - * options instead. - */ - public function createFieldForProperty($class, $property, $name, $type, array $options = []) - { - $field = $this->createFieldBuilder($name, $type, $options); - $field->setModelRef($class, $property); - - return $field; - } - - /** - * {@inheritdoc} - */ - public function createFieldSetBuilder($name) - { - $fieldSetBuilder = new FieldSetBuilder($name, $this, $this->metadataReader); - - return $fieldSetBuilder; - } - - /** - * Creates a new {@link SearchField} instance. - * - * @param string $name - * @param string|FieldTypeInterface $type - * @param array $options - * - * @throws UnexpectedTypeException - * - * @return SearchField - */ - private function createFieldBuilder($name, $type = 'field', array $options = []) - { - if ($type instanceof FieldTypeInterface) { - $type = $this->resolveType($type); - } elseif (is_string($type)) { - $type = $this->registry->getType($type); - } elseif (!$type instanceof ResolvedFieldTypeInterface) { - throw new UnexpectedTypeException( - $type, - [ - 'string', - 'Rollerworks\Component\Search\ResolvedFieldTypeInterface', - 'Rollerworks\Component\Search\FieldTypeInterface', - ] - ); - } - - $field = $type->createField($name, $options); - - // Explicitly call buildType() in order to be able to override either - // createField() or buildType() in the resolved field type - $type->buildType($field, $field->getOptions()); - - return $field; - } - - /** - * Wraps a type into a ResolvedFieldTypeInterface implementation and connects - * it with its parent type. - * - * @param FieldTypeInterface $type The type to resolve - * - * @return ResolvedFieldTypeInterface The resolved type - */ - private function resolveType(FieldTypeInterface $type) - { - $parentType = $type->getParent(); - - if ($parentType instanceof FieldTypeInterface) { - $parentType = $this->resolveType($parentType); - } elseif (null !== $parentType) { - $parentType = $this->registry->getType($parentType); - } - - return $this->resolvedTypeFactory->createResolvedType( - $type, // Type extensions are not supported for unregistered type instances, - // i.e. type instances that are passed to the SearchFactory directly, - // nor for their parents, if getParent() also returns a type instance. - [], - $parentType - ); - } -} diff --git a/SearchFactoryBuilder.php b/SearchFactoryBuilder.php deleted file mode 100644 index c213a7a..0000000 --- a/SearchFactoryBuilder.php +++ /dev/null @@ -1,149 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Metadata\MetadataReaderInterface; - -/** - * @author Sebastiaan Stok - */ -class SearchFactoryBuilder implements SearchFactoryBuilderInterface -{ - /** - * @var ResolvedFieldTypeFactoryInterface - */ - private $resolvedTypeFactory; - - /** - * @var SearchExtensionInterface[] - */ - private $extensions = []; - - /** - * @var FieldTypeInterface[] - */ - private $types = []; - - /** - * @var @var array - */ - private $typeExtensions = []; - - /** - * @var MetadataReaderInterface - */ - private $mappingReader; - - /** - * {@inheritdoc} - */ - public function setResolvedTypeFactory(ResolvedFieldTypeFactoryInterface $resolvedTypeFactory) - { - $this->resolvedTypeFactory = $resolvedTypeFactory; - - return $this; - } - /** - * {@inheritdoc} - */ - public function setMetaReader(MetadataReaderInterface $mappingReader) - { - $this->mappingReader = $mappingReader; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function addExtension(SearchExtensionInterface $extension) - { - $this->extensions[] = $extension; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function addExtensions(array $extensions) - { - $this->extensions = array_merge($this->extensions, $extensions); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function addType(FieldTypeInterface $type) - { - $this->types[$type->getName()] = $type; - - return $this; - } - - /** - * @param FieldTypeInterface[] $types - * - * @return $this - */ - public function addTypes(array $types) - { - foreach ($types as $type) { - $this->types[$type->getName()] = $type; - } - - return $this; - } - - /** - * {@inheritdoc} - */ - public function addTypeExtension(FieldTypeExtensionInterface $typeExtension) - { - $this->typeExtensions[$typeExtension->getExtendedType()][] = $typeExtension; - - return $this; - } - - /** - * @param FieldTypeExtensionInterface[] $typeExtensions - * - * @return $this - */ - public function addTypeExtensions(array $typeExtensions) - { - foreach ($typeExtensions as $typeExtension) { - $this->typeExtensions[$typeExtension->getExtendedType()][] = $typeExtension; - } - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getSearchFactory() - { - $extensions = $this->extensions; - - if (count($this->types) > 0 || count($this->typeExtensions) > 0) { - $extensions[] = new PreloadedExtension($this->types, $this->typeExtensions); - } - - $resolvedTypeFactory = $this->resolvedTypeFactory ?: new ResolvedFieldTypeFactory(); - $registry = new FieldRegistry($extensions, $resolvedTypeFactory); - - return new SearchFactory($registry, $resolvedTypeFactory, $this->mappingReader); - } -} diff --git a/SearchFactoryBuilderInterface.php b/SearchFactoryBuilderInterface.php deleted file mode 100644 index 2134bbb..0000000 --- a/SearchFactoryBuilderInterface.php +++ /dev/null @@ -1,79 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * @author Sebastiaan Stok - */ -interface SearchFactoryBuilderInterface -{ - /** - * Sets the factory for creating ResolvedFieldTypeInterface instances. - * - * @param ResolvedFieldTypeFactoryInterface $resolvedTypeFactory - * - * @return SearchFactoryBuilderInterface The builder - */ - public function setResolvedTypeFactory(ResolvedFieldTypeFactoryInterface $resolvedTypeFactory); - - /** - * Adds an extension to be loaded by the factory. - * - * @param SearchExtensionInterface $extension The extension. - * - * @return SearchFactoryBuilderInterface The builder - */ - public function addExtension(SearchExtensionInterface $extension); - - /** - * Adds a list of extensions to be loaded by the factory. - * - * @param SearchExtensionInterface[] $extensions The extensions. - * - * @return SearchFactoryBuilderInterface The builder - */ - public function addExtensions(array $extensions); - - /** - * Adds a field type to the factory. - * - * @param FieldTypeInterface $type The field type. - * - * @return SearchFactoryBuilderInterface The builder - */ - public function addType(FieldTypeInterface $type); - - /** - * Adds a list of field types to the factory. - * - * @param FieldTypeInterface[] $types The field types. - * - * @return SearchFactoryBuilderInterface The builder - */ - public function addTypes(array $types); - - /** - * Adds a field type extension to the factory. - * - * @param FieldTypeExtensionInterface $typeExtension The field type extension. - * - * @return SearchFactoryBuilderInterface The builder - */ - public function addTypeExtension(FieldTypeExtensionInterface $typeExtension); - - /** - * Builds and returns the factory. - * - * @return SearchFactoryInterface The search factory - */ - public function getSearchFactory(); -} diff --git a/SearchFactoryInterface.php b/SearchFactoryInterface.php deleted file mode 100644 index 6068623..0000000 --- a/SearchFactoryInterface.php +++ /dev/null @@ -1,38 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * @author Sebastiaan Stok - */ -interface SearchFactoryInterface -{ - /** - * Create a new search field. - * - * @param string $name Name of the field - * @param string $type Type of the field - * @param array $options Array of options for building the field - * - * @return FieldConfigInterface - */ - public function createField($name, $type, array $options = []); - - /** - * Create a new FieldsetBuilderInterface instance. - * - * @param string $name - * - * @return FieldsetBuilderInterface - */ - public function createFieldSetBuilder($name); -} diff --git a/SearchField.php b/SearchField.php deleted file mode 100644 index 4492dad..0000000 --- a/SearchField.php +++ /dev/null @@ -1,369 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\BadMethodCallException; - -/** - * SearchField. - * - * @author Sebastiaan Stok - */ -class SearchField implements FieldConfigInterface -{ - /** - * @var string - */ - private $name; - - /** - * @var ResolvedFieldTypeInterface - */ - private $type; - - /** - * @var array - */ - private $options; - - /** - * @var bool[] - */ - private $supportedValueTypes = [ - ValuesBag::VALUE_TYPE_RANGE => false, - ValuesBag::VALUE_TYPE_COMPARISON => false, - ValuesBag::VALUE_TYPE_PATTERN_MATCH => false, - ]; - - /** - * @var ValueComparisonInterface - */ - private $valueComparison; - - /** - * @var bool - */ - private $locked = false; - - /** - * @var array - */ - private $viewTransformers = []; - - /** - * Constructor. - * - * @param string $name - * @param ResolvedFieldTypeInterface $type - * @param array $options - * - * @throws \InvalidArgumentException When the name is invalid - */ - public function __construct($name, ResolvedFieldTypeInterface $type, array $options = []) - { - FieldSet::validateName($name); - - if ('' === $name) { - throw new \InvalidArgumentException( - sprintf( - 'The name "%s" contains illegal characters. Names should start with a letter, digit or underscore '. - 'and only contain letters, digits, numbers, underscores ("_") and hyphens ("-").', - $name - ) - ); - } - - $this->name = $name; - $this->type = $type; - $this->options = $options; - $this->locked = false; - } - - /** - * BC method, does nothing. - * - * @deprecated Deprecated since version 1.0.0-beta5, to be removed in 2.0. - * Use a custom validator instead. - */ - public function setRequired($required = true) - { - // noop - } - - /** - * {@inheritdoc} - * - * @throws BadMethodCallException - */ - public function supportValueType($type) - { - if (!isset($this->supportedValueTypes[$type])) { - throw new BadMethodCallException( - sprintf( - 'Unable to find configured-support for unknown value type "%s".', - $type - ) - ); - } - - return $this->supportedValueTypes[$type]; - } - - /** - * {@inheritdoc} - * - * @throws BadMethodCallException - */ - public function setValueTypeSupport($type, $enabled) - { - if ($this->locked) { - throw new BadMethodCallException( - 'SearchField setter methods cannot be accessed anymore once the data is locked.' - ); - } - - if (!isset($this->supportedValueTypes[$type])) { - throw new BadMethodCallException( - sprintf( - 'Unable to configure support for unknown value type "%s".', - $type - ) - ); - } - - $this->supportedValueTypes[$type] = (bool) $enabled; - - return $this; - } - - /** - * {@inheritdoc} - * - * @throws BadMethodCallException - */ - public function getName() - { - return $this->name; - } - - /** - * {@inheritdoc} - * - * @throws BadMethodCallException - */ - public function getType() - { - return $this->type; - } - - /** - * BC method. - * - * @deprecated Deprecated since version 1.0.0-beta5, to be removed in 2.0. - * Use a custom validator instead. - */ - public function isRequired() - { - return false; - } - - /** - * @param string $class - * @param string $property - * - * @throws BadMethodCallException when the data is locked - * - * @return self - * - * @deprecated Deprecated since version 1.0.0-beta5, to be removed in 2.0. - * Use the 'model_class' and 'model_property' options instead. - */ - public function setModelRef($class, $property) - { - if ($this->locked) { - throw new BadMethodCallException( - 'SearchField setter methods cannot be accessed anymore once the data is locked.' - ); - } - - $this->options['model_class'] = $class; - $this->options['model_property'] = $property; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getModelRefClass() - { - return $this->getOption('model_class'); - } - - /** - * {@inheritdoc} - */ - public function getModelRefProperty() - { - return $this->getOption('model_property'); - } - - /** - * {@inheritdoc} - * - * @throws BadMethodCallException when the data is locked - * - * @return self - */ - public function setValueComparison(ValueComparisonInterface $comparisonObj) - { - if ($this->locked) { - throw new BadMethodCallException( - 'SearchField setter methods cannot be accessed anymore once the data is locked.' - ); - } - - $this->valueComparison = $comparisonObj; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getValueComparison() - { - return $this->valueComparison; - } - - /** - * {@inheritdoc} - */ - public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false) - { - if ($this->locked) { - throw new BadMethodCallException( - 'SearchField setter methods cannot be accessed anymore once the data is locked.' - ); - } - - if ($forcePrepend) { - array_unshift($this->viewTransformers, $viewTransformer); - } else { - $this->viewTransformers[] = $viewTransformer; - } - - return $this; - } - - /** - * {@inheritdoc} - * - * @throws BadMethodCallException when the data is locked - * - * @return self - */ - public function resetViewTransformers() - { - if ($this->locked) { - throw new BadMethodCallException( - 'SearchField setter methods cannot be accessed anymore once the data is locked.' - ); - } - - $this->viewTransformers = []; - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getViewTransformers() - { - return $this->viewTransformers; - } - - /** - * Sets the field's data is locked. - * - * After calling this method, setter methods can be no longer called. - * - * @param bool $locked - * - * @throws BadMethodCallException when the data is locked - */ - public function setDataLocked($locked = true) - { - if ($this->locked) { - throw new BadMethodCallException( - 'SearchField setter methods cannot be accessed anymore once the data is locked.' - ); - } - - $this->locked = $locked; - } - - /** - * {@inheritdoc} - */ - public function getDataLocked() - { - return $this->locked; - } - - /** - * {@inheritdoc} - */ - public function getOptions() - { - return $this->options; - } - - /** - * {@inheritdoc} - */ - public function hasOption($name) - { - return array_key_exists($name, $this->options); - } - - /** - * {@inheritdoc} - */ - public function getOption($name, $default = null) - { - if (array_key_exists($name, $this->options)) { - return $this->options[$name]; - } - - return $default; - } - - /** - * {@inheritdoc} - */ - public function createView() - { - if (!$this->locked) { - throw new BadMethodCallException( - 'Unable to create SearchFieldView when configuration is not locked.' - ); - } - - $view = new SearchFieldView(); - - $this->type->buildFieldView($view, $this, $this->options); - - return $view; - } -} diff --git a/SearchFieldView.php b/SearchFieldView.php deleted file mode 100644 index cd8679f..0000000 --- a/SearchFieldView.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * @author Sebastiaan Stok - */ -class SearchFieldView -{ - /** - * The variables assigned to this view. - * - * @var array - */ - public $vars = [ - 'attr' => [], - ]; -} diff --git a/Searches.php b/Searches.php deleted file mode 100644 index 8ff5d12..0000000 --- a/Searches.php +++ /dev/null @@ -1,99 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Extension\Core\CoreExtension; - -/** - * Entry point of the Search system. - * - * Use this class to conveniently create new search factories: - * - * - * use Rollerworks\Component\Search\Searches; - * - * $searchFactory = Searches::cre ateSearchFactory(); - * - * $fieldSet = $searchFactory->createFieldSetBuilder('fieldset-name') - * ->add('firstName', 'text') - * ->add('lastName', 'text') - * ->add('age', 'integer') - * ->add('gender', 'choice', array( - * 'choices' => array('m' => 'Male', 'f' => 'Female'), - * )) - * ->getFieldSet(); - * - * - * You can also add custom extensions to the search factory: - * - * - * $searchFactory = Searches::createSearchFactoryBuilder(); - * ->addExtension(new AcmeExtension()) - * ->getSearchFactory(); - * - * - * If you create custom field types or type extensions, it is - * generally recommended to create your own extensions that lazily - * loads these types and type extensions. In projects where performance - * does not matter that much, you can also pass them directly to the - * search factory: - * - * - * use Rollerworks\Component\Search\Searches; - * - * $searchFactory = Searches::createSearchFactoryBuilder(); - * ->addType(new PersonType()) - * ->addType(new PhoneNumberType()) - * ->addTypeExtension(new DoctrineDbalExtension()) - * ->getSearchFactory(); - * - * - * Support for the Validator component is provided by ValidatorExtension. - * This extension needs a Validator object to function properly: - * - * - * use Rollerworks\Component\Search\Searches; - * use Rollerworks\Component\Search\Extension\Validator\ValidatorExtension; - * use Symfony\Component\Validator\Validation; - * - * $validatorBuilder = Validation::createValidatorBuilder(); - * $validator = $validatorBuilder->getValidator(); - * - * $searchFactory = Searches::createSearchFactoryBuilder(); - * ->addExtension(new ValidatorExtension($validator)) - * ->getSearchFactory(); - * - * - * @author Sebastiaan Stok - */ -final class Searches -{ - /** - * Creates a search factory builder with the default configuration. - * - * @return SearchFactoryBuilder The search factory builder. - */ - public static function createSearchFactoryBuilder() - { - $builder = new SearchFactoryBuilder(); - $builder->addExtension(new CoreExtension()); - - return $builder; - } - - /** - * This class cannot be instantiated. - */ - private function __construct() - { - } -} diff --git a/ValueComparisonInterface.php b/ValueComparisonInterface.php deleted file mode 100644 index fa261f8..0000000 --- a/ValueComparisonInterface.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * ValueComparisonInterface. - * - * Each ValueComparison class must implement this class. - * - * @author Sebastiaan Stok - */ -interface ValueComparisonInterface -{ - /** - * Returns whether the first value is higher then the second value. - * - * @param mixed $higher - * @param mixed $lower - * @param array $options - * - * @return bool - */ - public function isHigher($higher, $lower, array $options); - - /** - * Returns whether the first value is lower then the second value. - * - * @param mixed $lower - * @param mixed $higher - * @param array $options - * - * @return bool - */ - public function isLower($lower, $higher, $options); - - /** - * Returns whether the first value equals the second value. - * - * @param mixed $value - * @param mixed $nextValue - * @param array $options - * - * @return bool - */ - public function isEqual($value, $nextValue, $options); -} diff --git a/ValueIncrementerInterface.php b/ValueIncrementerInterface.php deleted file mode 100644 index 2cbd606..0000000 --- a/ValueIncrementerInterface.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * ValueIncrementerInterface allows for finding the incremented value. - * - * Increments can be used for optimizing eg. the ranges in a search - * condition. - * - * @author Sebastiaan Stok - */ -interface ValueIncrementerInterface extends ValueComparisonInterface -{ - /** - * Returns the incremented value of the value. - * - * The returned value must be returned in the "normalized" format, - * that is supported by the field type. - * - * @param mixed $value The value to increment - * @param array $options Array of options passed with the field - * @param int $increments Number of increments - * - * @return mixed - */ - public function getIncrementedValue($value, array $options, $increments = 1); -} diff --git a/ValuesBag.php b/ValuesBag.php deleted file mode 100644 index 57de312..0000000 --- a/ValuesBag.php +++ /dev/null @@ -1,492 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -use Rollerworks\Component\Search\Exception\BadMethodCallException; -use Rollerworks\Component\Search\Exception\ValuesStructureIsLocked; -use Rollerworks\Component\Search\Value\Compare; -use Rollerworks\Component\Search\Value\PatternMatch; -use Rollerworks\Component\Search\Value\Range; -use Rollerworks\Component\Search\Value\SingleValue; - -/** - * A ValuesBag holds all the values per type. - * - * @author Sebastiaan Stok - */ -class ValuesBag implements \Countable, \Serializable -{ - const VALUE_TYPE_RANGE = 'range'; - const VALUE_TYPE_COMPARISON = 'comparison'; - const VALUE_TYPE_PATTERN_MATCH = 'pattern-match'; - - private $excludedValues = []; - private $ranges = []; - private $excludedRanges = []; - private $comparisons = []; - private $singleValues = []; - private $patternMatchers = []; - private $valuesCount = 0; - private $errors = []; - private $locked = false; - - /** - * @return SingleValue[] - */ - public function getSingleValues() - { - return $this->singleValues; - } - - /** - * @param SingleValue $value - * - * @return static - */ - public function addSingleValue(SingleValue $value) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - $this->singleValues[] = $value; - ++$this->valuesCount; - - return $this; - } - - /** - * @return bool - */ - public function hasSingleValues() - { - return count($this->singleValues) > 0; - } - - /** - * @param int $index - * - * @return static - */ - public function removeSingleValue($index) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - if (isset($this->singleValues[$index])) { - unset($this->singleValues[$index]); - - --$this->valuesCount; - } - - return $this; - } - - /** - * @param SingleValue $value - * - * @return static - */ - public function addExcludedValue(SingleValue $value) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - $this->excludedValues[] = $value; - ++$this->valuesCount; - - return $this; - } - - /** - * @return bool - */ - public function hasExcludedValues() - { - return count($this->excludedValues) > 0; - } - - /** - * @return SingleValue[] - */ - public function getExcludedValues() - { - return $this->excludedValues; - } - - /** - * @param int $index - * - * @return static - */ - public function removeExcludedValue($index) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - if (isset($this->excludedValues[$index])) { - unset($this->excludedValues[$index]); - - --$this->valuesCount; - } - - return $this; - } - - /** - * @param Range $range - * - * @return static - */ - public function addRange(Range $range) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - $this->ranges[] = $range; - ++$this->valuesCount; - - return $this; - } - - /** - * @return bool - */ - public function hasRanges() - { - return count($this->ranges) > 0; - } - - /** - * @return Range[] - */ - public function getRanges() - { - return $this->ranges; - } - - /** - * @param int $index - * - * @return static - */ - public function removeRange($index) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - if (isset($this->ranges[$index])) { - unset($this->ranges[$index]); - - --$this->valuesCount; - } - - return $this; - } - - /** - * @param Range $range - * - * @return static - */ - public function addExcludedRange(Range $range) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - $this->excludedRanges[] = $range; - ++$this->valuesCount; - - return $this; - } - - /** - * @return bool - */ - public function hasExcludedRanges() - { - return count($this->excludedRanges) > 0; - } - - /** - * @return Range[] - */ - public function getExcludedRanges() - { - return $this->excludedRanges; - } - - /** - * @param int $index - * - * @return static - */ - public function removeExcludedRange($index) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - if (isset($this->excludedRanges[$index])) { - unset($this->excludedRanges[$index]); - - --$this->valuesCount; - } - - return $this; - } - - /** - * @param Compare $value - * - * @return static - */ - public function addComparison(Compare $value) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - $this->comparisons[] = $value; - ++$this->valuesCount; - - return $this; - } - - /** - * @return Compare[] - */ - public function getComparisons() - { - return $this->comparisons; - } - - /** - * @return bool - */ - public function hasComparisons() - { - return count($this->comparisons) > 0; - } - - /** - * @param int $index - * - * @return static - */ - public function removeComparison($index) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - if (isset($this->comparisons[$index])) { - unset($this->comparisons[$index]); - - --$this->valuesCount; - } - - return $this; - } - - /** - * @return PatternMatch[] - */ - public function getPatternMatchers() - { - return $this->patternMatchers; - } - - /** - * @param PatternMatch $value - * - * @return static - */ - public function addPatternMatch(PatternMatch $value) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - $this->patternMatchers[] = $value; - ++$this->valuesCount; - - return $this; - } - - /** - * @return bool - */ - public function hasPatternMatchers() - { - return count($this->patternMatchers) > 0; - } - - /** - * @param int $index - * - * @return static - */ - public function removePatternMatch($index) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - if (isset($this->patternMatchers[$index])) { - unset($this->patternMatchers[$index]); - - --$this->valuesCount; - } - - return $this; - } - - /** - * @param ValuesError $error - * - * @return static - */ - public function addError(ValuesError $error) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - $this->errors[$error->getHash()] = $error; - - return $this; - } - - /** - * @return bool - */ - public function hasErrors() - { - return count($this->errors) > 0; - } - - /** - * @return ValuesError[] - */ - public function getErrors() - { - return $this->errors; - } - - /** - * @param ValuesError $error - * - * @return bool - */ - public function hasError(ValuesError $error) - { - return isset($this->errors[$error->getHash()]); - } - - /** - * @param ValuesError $error - * - * @return static - */ - public function removeError(ValuesError $error) - { - if (isset($this->errors[$error->getHash()])) { - unset($this->errors[$error->getHash()]); - } - - return $this; - } - - /** - * @return int - */ - public function count() - { - return $this->valuesCount; - } - - /** - * {@inheritdoc} - */ - public function serialize() - { - return serialize([ - $this->excludedValues, - $this->ranges, - $this->excludedRanges, - $this->comparisons, - $this->singleValues, - $this->patternMatchers, - $this->valuesCount, - $this->errors, - $this->locked, - ]); - } - - /** - * {@inheritdoc} - */ - public function unserialize($serialized) - { - $data = unserialize($serialized); - - list( - $this->excludedValues, - $this->ranges, - $this->excludedRanges, - $this->comparisons, - $this->singleValues, - $this->patternMatchers, - $this->valuesCount, - $this->errors, - $this->locked - ) = $data; - } - - /** - * Sets the values data is locked. - * - * After calling this method, setter methods can be no longer called. - * - * @param bool $locked - * - * @throws BadMethodCallException when the data is locked - */ - public function setDataLocked($locked = true) - { - if ($this->locked) { - throw new ValuesStructureIsLocked(); - } - - $this->locked = $locked; - } - - /** - * Returns whether the field's data is locked. - * - * A field with locked data is restricted to the data passed in - * this configuration. - * - * @return bool Whether the data is locked. - */ - public function isDataLocked() - { - return $this->locked; - } -} diff --git a/ValuesBagBuilder.php b/ValuesBagBuilder.php deleted file mode 100644 index 8fb3c67..0000000 --- a/ValuesBagBuilder.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Rollerworks\Component\Search; - -/** - * Helper class for the SearchConditionBuilder. - * - * @author Sebastiaan Stok - */ -class ValuesBagBuilder extends ValuesBag -{ - /** - * @var SearchConditionBuilder - */ - protected $parent; - - /** - * Constructor. - * - * @param SearchConditionBuilder $parent - */ - public function __construct(SearchConditionBuilder $parent) - { - $this->parent = $parent; - } - - /** - * @return SearchConditionBuilder - */ - public function end() - { - return $this->parent; - } -}