forked from sstok/gush-experiments-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Searches.php
99 lines (93 loc) · 2.77 KB
/
Searches.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/*
* This file is part of the RollerworksSearch package.
*
* (c) Sebastiaan Stok <s.stok@rollerscapes.net>
*
* 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:
*
* <code>
* 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();
* </code>
*
* You can also add custom extensions to the search factory:
*
* <code>
* $searchFactory = Searches::createSearchFactoryBuilder();
* ->addExtension(new AcmeExtension())
* ->getSearchFactory();
* </code>
*
* 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:
*
* <code>
* use Rollerworks\Component\Search\Searches;
*
* $searchFactory = Searches::createSearchFactoryBuilder();
* ->addType(new PersonType())
* ->addType(new PhoneNumberType())
* ->addTypeExtension(new DoctrineDbalExtension())
* ->getSearchFactory();
* </code>
*
* Support for the Validator component is provided by ValidatorExtension.
* This extension needs a Validator object to function properly:
*
* <code>
* 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();
* </code>
*
* @author Sebastiaan Stok <s.stok@rollerscapes.net>
*/
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()
{
}
}