@@ -48,18 +48,18 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function __construct(SearchService $searchService, array $mapping = array()) { |
50 | 50 | $this->searchService = $searchService; |
51 | - foreach($mapping as $key => $config) { |
|
52 | - if(!isset($config['mappings'])) { |
|
53 | - throw new \InvalidArgumentException($key . ' has no mapping defined!'); |
|
51 | + foreach ($mapping as $key => $config) { |
|
52 | + if (!isset($config['mappings'])) { |
|
53 | + throw new \InvalidArgumentException($key.' has no mapping defined!'); |
|
54 | 54 | } |
55 | - if(!isset($config['persistence'])) { |
|
56 | - throw new \InvalidArgumentException($key . ' has no persistence defined!'); |
|
55 | + if (!isset($config['persistence'])) { |
|
56 | + throw new \InvalidArgumentException($key.' has no persistence defined!'); |
|
57 | 57 | } |
58 | - if(!isset($config['persistence']['model'])) { |
|
59 | - throw new \InvalidArgumentException($key . ' has no model defined!'); |
|
58 | + if (!isset($config['persistence']['model'])) { |
|
59 | + throw new \InvalidArgumentException($key.' has no model defined!'); |
|
60 | 60 | } |
61 | 61 | $map = array(); |
62 | - foreach($config['mappings'] as $fieldKey => $fieldConfig) { |
|
62 | + foreach ($config['mappings'] as $fieldKey => $fieldConfig) { |
|
63 | 63 | $map[$fieldKey] = isset($fieldConfig['propertyPath']) && $fieldConfig['propertyPath'] ? $fieldConfig['propertyPath'] : $fieldKey; |
64 | 64 | } |
65 | 65 | |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::isIndexable() |
75 | 75 | */ |
76 | 76 | public function isIndexable(object $object) : bool { |
77 | - if($object instanceof SearchableEntity) { |
|
77 | + if ($object instanceof SearchableEntity) { |
|
78 | 78 | return true; |
79 | 79 | } |
80 | - if(count($this->getMapping(get_class($object))) > 0) { |
|
80 | + if (count($this->getMapping(get_class($object))) > 0) { |
|
81 | 81 | return true; |
82 | 82 | } |
83 | 83 | return false; |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function isClassIndexable(string $clazz) : bool { |
94 | 94 | $reflectionClass = new \ReflectionClass($clazz); |
95 | - if(array_key_exists(SearchableEntity::class, $reflectionClass->getInterfaces())) { |
|
95 | + if (array_key_exists(SearchableEntity::class, $reflectionClass->getInterfaces())) { |
|
96 | 96 | return true; |
97 | 97 | } |
98 | - if(count($this->getMapping($clazz)) > 0) { |
|
98 | + if (count($this->getMapping($clazz)) > 0) { |
|
99 | 99 | return true; |
100 | 100 | } |
101 | 101 | return false; |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::createDocument() |
108 | 108 | */ |
109 | 109 | public function createDocument(ObjectManager $manager, object $object) : ?Document { |
110 | - if(!$this->isIndexable($object)) |
|
110 | + if (!$this->isIndexable($object)) |
|
111 | 111 | return null; |
112 | 112 | $document = $this->searchService->createEmptyDocumentFromEntity($object); |
113 | 113 | $index = $this->fillDocument($document, $object); |
114 | - if($index === false) |
|
114 | + if ($index === false) |
|
115 | 115 | return null; |
116 | 116 | |
117 | 117 | return $document; |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | * @return boolean |
126 | 126 | */ |
127 | 127 | protected function fillDocument(Document $document, object $object) : bool { |
128 | - if($object instanceof SearchableEntity) { |
|
128 | + if ($object instanceof SearchableEntity) { |
|
129 | 129 | return $object->indexEntity($document); |
130 | 130 | } |
131 | 131 | $mapping = $this->getMapping(\get_class($object)); |
132 | 132 | $accessor = PropertyAccess::createPropertyAccessor(); |
133 | - foreach($mapping as $fieldName => $propertyPath) { |
|
133 | + foreach ($mapping as $fieldName => $propertyPath) { |
|
134 | 134 | $document->addField($fieldName, $accessor->getValue($object, $propertyPath)); |
135 | 135 | } |
136 | 136 | return true; |
@@ -143,15 +143,15 @@ discard block |
||
143 | 143 | * @throws \ReflectionException |
144 | 144 | */ |
145 | 145 | protected function getMapping(string $clazz) : array { |
146 | - if(isset($this->cachedMapping[$clazz])) { |
|
146 | + if (isset($this->cachedMapping[$clazz])) { |
|
147 | 147 | return $this->cachedMapping[$clazz]; |
148 | 148 | } |
149 | 149 | $ref = new \ReflectionClass($clazz); |
150 | 150 | |
151 | 151 | $mapping = array(); |
152 | 152 | |
153 | - foreach($this->mapping as $className => $config) { |
|
154 | - if($clazz === $className || $ref->isSubclassOf($className)) { |
|
153 | + foreach ($this->mapping as $className => $config) { |
|
154 | + if ($clazz === $className || $ref->isSubclassOf($className)) { |
|
155 | 155 | $mapping = \array_merge($mapping, $config); |
156 | 156 | } |
157 | 157 | } |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function autocomplete(string $search, int $maxResults = 10): array { |
68 | 68 | $words = array(); |
69 | - foreach($this->index as $doc) { |
|
70 | - foreach($doc->getFields() as $content) { |
|
71 | - if(is_string($content)) { |
|
69 | + foreach ($this->index as $doc) { |
|
70 | + foreach ($doc->getFields() as $content) { |
|
71 | + if (is_string($content)) { |
|
72 | 72 | $words = array_merge($words, explode(' ', $content)); |
73 | 73 | } |
74 | 74 | } |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | $facets = new FacetSetAdapter(); |
93 | 93 | |
94 | 94 | $hits = array(); |
95 | - foreach($this->index as $key => $doc) { |
|
96 | - foreach($doc->getFields() as $content) { |
|
97 | - if(is_string($content) && stripos($content, $term) !== false) { |
|
98 | - if(!isset($hits[$key])) { |
|
95 | + foreach ($this->index as $key => $doc) { |
|
96 | + foreach ($doc->getFields() as $content) { |
|
97 | + if (is_string($content) && stripos($content, $term) !== false) { |
|
98 | + if (!isset($hits[$key])) { |
|
99 | 99 | $hits[$key] = 0; |
100 | 100 | } |
101 | 101 | $hits[$key] = $hits[$key] + 1; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | } |
105 | 105 | arsort($hits); |
106 | 106 | $results = array(); |
107 | - foreach(array_keys($hits) as $docId) { |
|
107 | + foreach (array_keys($hits) as $docId) { |
|
108 | 108 | $doc = $this->index[$docId]; |
109 | 109 | $facets->addFacetValue(FacetSet::FACET_ENTITY_TYPE, $doc->getEntityClass()); |
110 | 110 | $facets->addFacetValue(FacetSet::FACET_AUTHOR, (string)$doc->getFieldValue(Document::FIELD_AUTHOR)); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $id = $document->getEntityClass(); |
132 | 132 | $id .= '#'; |
133 | 133 | $entityId = $document->getEntityId(); |
134 | - if(is_scalar($entityId)) { |
|
134 | + if (is_scalar($entityId)) { |
|
135 | 135 | $id .= $entityId; |
136 | 136 | } else { |
137 | 137 | $id .= md5(serialize($entityId)); |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | * @return array |
93 | 93 | */ |
94 | 94 | public function __get($name) { |
95 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
95 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
96 | 96 | $facetname = substr($name, 6); |
97 | 97 | |
98 | - if(isset($this->facets[$facetname])) { |
|
98 | + if (isset($this->facets[$facetname])) { |
|
99 | 99 | return $this->facets[$facetname]; |
100 | 100 | } |
101 | 101 | return array(); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * The value of the property |
111 | 111 | */ |
112 | 112 | public function __set($name, $value): void { |
113 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
113 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
114 | 114 | $facetname = substr($name, 6); |
115 | 115 | $this->facets[$facetname] = $value; |
116 | 116 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @return boolean |
124 | 124 | */ |
125 | 125 | public function __isset($name): bool { |
126 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
126 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
127 | 127 | return true; |
128 | 128 | } |
129 | 129 |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function getFieldValue($fieldName) { |
86 | 86 | $value = $this->fields[$fieldName] ?? null; |
87 | - if(\in_array($fieldName, self::$forceSingleValueFields) && \is_array($value)) { |
|
87 | + if (\in_array($fieldName, self::$forceSingleValueFields) && \is_array($value)) { |
|
88 | 88 | return current($value); |
89 | 89 | } |
90 | 90 | return $value; |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | * @see \StingerSoft\EntitySearchBundle\Model\Document::addMultiValueField() |
98 | 98 | */ |
99 | 99 | public function addMultiValueField(string $fieldName, $value): void { |
100 | - if(!array_key_exists($fieldName, $this->fields)) { |
|
100 | + if (!array_key_exists($fieldName, $this->fields)) { |
|
101 | 101 | $this->fields[$fieldName] = array( |
102 | 102 | $value |
103 | 103 | ); |
104 | - } else if(!\is_array($this->fields[$fieldName])) { |
|
104 | + } else if (!\is_array($this->fields[$fieldName])) { |
|
105 | 105 | $this->fields[$fieldName] = array( |
106 | 106 | $value, $this->fields[$fieldName] |
107 | 107 | ); |
108 | - } else if(!\in_array($value, $this->fields[$fieldName])) { |
|
108 | + } else if (!\in_array($value, $this->fields[$fieldName])) { |
|
109 | 109 | $this->fields[$fieldName][] = $value; |
110 | 110 | } |
111 | 111 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function setEntityClass(string $clazz): void { |
130 | 130 | $this->entityClass = $clazz; |
131 | - if(!$this->entityType) { |
|
131 | + if (!$this->entityType) { |
|
132 | 132 | $this->entityType = $clazz; |
133 | 133 | } |
134 | 134 | } |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | |
34 | 34 | public function addFacetValue(string $key, string $label, $value = null, int $increaseCounterBy = 1) : void { |
35 | 35 | $value = $value ?? $label; |
36 | - if(!isset($this->facets[$key])) { |
|
36 | + if (!isset($this->facets[$key])) { |
|
37 | 37 | $this->facets[$key] = array(); |
38 | 38 | } |
39 | - if(!isset($this->facets[$key][$label])) { |
|
39 | + if (!isset($this->facets[$key][$label])) { |
|
40 | 40 | $this->facets[$key][$label] = array( |
41 | 41 | 'value' => $value, |
42 | 42 | 'count' => 0, |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @see \StingerSoft\EntitySearchBundle\Model\Result\FacetSet::getFacet() |
53 | 53 | */ |
54 | 54 | public function getFacet(string $key): ?array { |
55 | - if(isset($this->facets[$key])) { |
|
55 | + if (isset($this->facets[$key])) { |
|
56 | 56 | return $this->facets[$key]; |
57 | 57 | } |
58 | 58 | return null; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | private $facetFormatter; |
33 | 33 | |
34 | 34 | public function searchAction(Request $request, DocumentToEntityMapperInterface $mapper) { |
35 | - if($request->query->get('term', false) !== false) { |
|
35 | + if ($request->query->get('term', false) !== false) { |
|
36 | 36 | $this->setSearchTerm($request->getSession(), $request->query->get('term')); |
37 | 37 | return $this->redirectToRoute('stinger_soft_entity_search_search'); |
38 | 38 | } |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | )); |
49 | 49 | |
50 | 50 | $facetForm->handleRequest($request); |
51 | - if($facetForm->isSubmitted()) { |
|
52 | - if($facetForm->get('clear')->isClicked()) { |
|
51 | + if ($facetForm->isSubmitted()) { |
|
52 | + if ($facetForm->get('clear')->isClicked()) { |
|
53 | 53 | $query->setFacets($this->getDefaultFacets()); |
54 | 54 | } |
55 | 55 | $this->setSearchTerm($request->getSession(), $query->getSearchTerm()); |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | |
70 | 70 | $page = (int)$request->query->get('page', 1); |
71 | 71 | $results = null; |
72 | - if($result instanceof PaginatableResultSet) { |
|
72 | + if ($result instanceof PaginatableResultSet) { |
|
73 | 73 | $results = $result->paginate($page, $this->getResultsPerPage()); |
74 | - } elseif($result !== null) { |
|
74 | + } elseif ($result !== null) { |
|
75 | 75 | $results = $result->getResults(($page - 1) * $this->getResultsPerPage(), $this->getResultsPerPage()); |
76 | 76 | } |
77 | 77 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | 'mapper' => $mapper, |
83 | 83 | 'facetForm' => $facetForm->createView() |
84 | 84 | )); |
85 | - } catch(\Exception $exception) { |
|
85 | + } catch (\Exception $exception) { |
|
86 | 86 | $response = $this->render($this->getErrorTemplate(), array( |
87 | 87 | 'error' => $exception->getMessage(), |
88 | 88 | 'term' => $query->getSearchTerm() |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | protected function getConfiguredUsedFacets(array $queryUsedFacets) { |
127 | 127 | $availableFacets = $this->getAvailableFacets(); |
128 | 128 | $usedFacets = array(); |
129 | - foreach($queryUsedFacets as $queryUsedFacet) { |
|
129 | + foreach ($queryUsedFacets as $queryUsedFacet) { |
|
130 | 130 | $usedFacets[$queryUsedFacet] = $availableFacets[$queryUsedFacet]; |
131 | 131 | } |
132 | 132 | return $usedFacets; |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | } |
194 | 194 | |
195 | 195 | protected function initFacets() { |
196 | - if(!$this->availableFacets) { |
|
196 | + if (!$this->availableFacets) { |
|
197 | 197 | $this->availableFacets = array(); |
198 | 198 | $this->facetFormatter = array(); |
199 | 199 | |
200 | 200 | $facetServices = $this->getParameter('stinger_soft.entity_search.available_facets'); |
201 | - foreach($facetServices as $facetServiceId) { |
|
201 | + foreach ($facetServices as $facetServiceId) { |
|
202 | 202 | $facetService = $this->searchService->getFacet($facetServiceId); |
203 | 203 | $this->availableFacets[$facetService->getField()] = $facetService->getFormOptions(); |
204 | - if($facetService->getFacetFormatter()) { |
|
204 | + if ($facetService->getFacetFormatter()) { |
|
205 | 205 | $this->facetFormatter[$facetService->getField()] = $facetService->getFacetFormatter(); |
206 | 206 | } |
207 | 207 | } |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return string[string][] |
216 | 216 | */ |
217 | 217 | protected function getSearchFacets(SessionInterface $session) { |
218 | - $facets = $session->get($this->getSessionPrefix() . '_facets', false); |
|
218 | + $facets = $session->get($this->getSessionPrefix().'_facets', false); |
|
219 | 219 | return $facets ? \json_decode($facets, true) : $this->getDefaultFacets(); |
220 | 220 | } |
221 | 221 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @param string[string][] $facets |
227 | 227 | */ |
228 | 228 | protected function setSearchFacets(SessionInterface $session, $facets) { |
229 | - $session->set($this->getSessionPrefix() . '_facets', \json_encode($facets)); |
|
229 | + $session->set($this->getSessionPrefix().'_facets', \json_encode($facets)); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * @return mixed |
237 | 237 | */ |
238 | 238 | protected function getSearchTerm(SessionInterface $session) { |
239 | - return $session->get($this->getSessionPrefix() . '_term', false); |
|
239 | + return $session->get($this->getSessionPrefix().'_term', false); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @param string $term |
247 | 247 | */ |
248 | 248 | protected function setSearchTerm(SessionInterface $session, $term) { |
249 | - $session->set($this->getSessionPrefix() . '_term', $term); |
|
249 | + $session->set($this->getSessionPrefix().'_term', $term); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | } |
253 | 253 | \ No newline at end of file |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @param LifecycleEventArgs $args |
119 | 119 | */ |
120 | 120 | public function postPersist(LifecycleEventArgs $args): void { |
121 | - if(!$this->enableIndexing) { |
|
121 | + if (!$this->enableIndexing) { |
|
122 | 122 | return; |
123 | 123 | } |
124 | 124 | $this->updateEntity($args->getObject(), $args->getObjectManager()); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @throws \Doctrine\ORM\OptimisticLockException |
131 | 131 | */ |
132 | 132 | public function postFlush(PostFlushEventArgs $eventArgs): void { |
133 | - if($this->needsFlush) { |
|
133 | + if ($this->needsFlush) { |
|
134 | 134 | $this->needsFlush = false; |
135 | 135 | $eventArgs->getEntityManager()->flush(); |
136 | 136 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param LifecycleEventArgs $args |
143 | 143 | */ |
144 | 144 | public function preRemove(LifecycleEventArgs $args): void { |
145 | - if(!$this->enableIndexing) { |
|
145 | + if (!$this->enableIndexing) { |
|
146 | 146 | return; |
147 | 147 | } |
148 | 148 | $this->removeEntity($args->getObject(), $args->getObjectManager()); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param LifecycleEventArgs $args |
155 | 155 | */ |
156 | 156 | public function postUpdate(LifecycleEventArgs $args): void { |
157 | - if(!$this->enableIndexing) return; |
|
157 | + if (!$this->enableIndexing) return; |
|
158 | 158 | $this->updateEntity($args->getObject(), $args->getObjectManager()); |
159 | 159 | } |
160 | 160 | |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | * @param object $entity |
180 | 180 | */ |
181 | 181 | protected function updateEntity(object $entity, ObjectManager $manager): void { |
182 | - if($entity instanceof SearchableAlias) { |
|
182 | + if ($entity instanceof SearchableAlias) { |
|
183 | 183 | $entity = $entity->getEntityToIndex(); |
184 | 184 | } |
185 | 185 | $document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity); |
186 | - if($document !== null) { |
|
187 | - if($this->getEventDispatcher()) { |
|
186 | + if ($document !== null) { |
|
187 | + if ($this->getEventDispatcher()) { |
|
188 | 188 | $event = new DocumentPreSaveEvent($document); |
189 | 189 | $this->getEventDispatcher()->dispatch($event, DocumentPreSaveEvent::NAME); |
190 | 190 | } |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | * @param object $entity |
199 | 199 | */ |
200 | 200 | protected function removeEntity(object $entity, ObjectManager $manager): void { |
201 | - if($entity instanceof SearchableAlias) { |
|
201 | + if ($entity instanceof SearchableAlias) { |
|
202 | 202 | $entity = $entity->getEntityToIndex(); |
203 | 203 | } |
204 | 204 | $document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity); |
205 | - if($document !== null) { |
|
205 | + if ($document !== null) { |
|
206 | 206 | $this->getSearchService()->removeDocument($document); |
207 | 207 | $this->needsFlush = true; |
208 | 208 | } |
@@ -36,14 +36,14 @@ |
||
36 | 36 | public function getEntity(Document $document): ?object { |
37 | 37 | $clazz = $document->getEntityClass(); |
38 | 38 | |
39 | - if($clazz === null) { |
|
39 | + if ($clazz === null) { |
|
40 | 40 | return null; |
41 | 41 | } |
42 | - if(!$document->getEntityId()) { |
|
42 | + if (!$document->getEntityId()) { |
|
43 | 43 | return null; |
44 | 44 | } |
45 | 45 | $manager = $this->managerRegistry->getManagerForClass($clazz); |
46 | - if($manager === null) { |
|
46 | + if ($manager === null) { |
|
47 | 47 | return null; |
48 | 48 | } |
49 | 49 | return $manager->getRepository($clazz)->find($document->getEntityId()); |
@@ -53,7 +53,7 @@ |
||
53 | 53 | * @required |
54 | 54 | */ |
55 | 55 | public function setObjectManager(EntityManagerInterface $om): void { |
56 | - if($this->objectManager) |
|
56 | + if ($this->objectManager) |
|
57 | 57 | return; |
58 | 58 | $this->objectManager = $om; |
59 | 59 | } |