@@ -137,7 +137,7 @@ |
||
137 | 137 | /** |
138 | 138 | * Fetches the mapping for the given object including the mapping of superclasses |
139 | 139 | * |
140 | - * @param object $object |
|
140 | + * @param string $clazz |
|
141 | 141 | * @return \StingerSoft\EntitySearchBundle\Services\string[string] |
142 | 142 | */ |
143 | 143 | protected function getMapping($clazz) { |
@@ -47,18 +47,18 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct(SearchService $searchService, array $mapping = array()) { |
49 | 49 | $this->searchService = $searchService; |
50 | - foreach($mapping as $key => $config) { |
|
51 | - if(!isset($config['mappings'])) { |
|
52 | - throw new \InvalidArgumentException($key . ' has no mapping defined!'); |
|
50 | + foreach ($mapping as $key => $config) { |
|
51 | + if (!isset($config['mappings'])) { |
|
52 | + throw new \InvalidArgumentException($key.' has no mapping defined!'); |
|
53 | 53 | } |
54 | - if(!isset($config['persistence'])) { |
|
55 | - throw new \InvalidArgumentException($key . ' has no persistence defined!'); |
|
54 | + if (!isset($config['persistence'])) { |
|
55 | + throw new \InvalidArgumentException($key.' has no persistence defined!'); |
|
56 | 56 | } |
57 | - if(!isset($config['persistence']['model'])) { |
|
58 | - throw new \InvalidArgumentException($key . ' has no model defined!'); |
|
57 | + if (!isset($config['persistence']['model'])) { |
|
58 | + throw new \InvalidArgumentException($key.' has no model defined!'); |
|
59 | 59 | } |
60 | 60 | $map = array(); |
61 | - foreach($config['mappings'] as $fieldKey => $fieldConfig) { |
|
61 | + foreach ($config['mappings'] as $fieldKey => $fieldConfig) { |
|
62 | 62 | $map[$fieldKey] = isset($fieldConfig['propertyPath']) && $fieldConfig['propertyPath'] ? $fieldConfig['propertyPath'] : $fieldKey; |
63 | 63 | } |
64 | 64 | |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::isIndexable() |
74 | 74 | */ |
75 | 75 | public function isIndexable($object) { |
76 | - if($object instanceof SearchableEntity) { |
|
76 | + if ($object instanceof SearchableEntity) { |
|
77 | 77 | return true; |
78 | 78 | } |
79 | - if(count($this->getMapping(get_class($object))) > 0) { |
|
79 | + if (count($this->getMapping(get_class($object))) > 0) { |
|
80 | 80 | return true; |
81 | 81 | } |
82 | 82 | return false; |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function isClassIndexable($clazz) { |
92 | 92 | $reflectionClass = new \ReflectionClass($clazz); |
93 | - if(array_key_exists(SearchableEntity::class, $reflectionClass->getInterfaces())) { |
|
93 | + if (array_key_exists(SearchableEntity::class, $reflectionClass->getInterfaces())) { |
|
94 | 94 | return true; |
95 | 95 | } |
96 | - if(count($this->getMapping($clazz)) > 0) { |
|
96 | + if (count($this->getMapping($clazz)) > 0) { |
|
97 | 97 | return true; |
98 | 98 | } |
99 | 99 | return false; |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::createDocument() |
106 | 106 | */ |
107 | 107 | public function createDocument(ObjectManager $manager, $object) { |
108 | - if(!$this->isIndexable($object)) |
|
108 | + if (!$this->isIndexable($object)) |
|
109 | 109 | return false; |
110 | 110 | $document = $this->getSearchService($manager)->createEmptyDocumentFromEntity($object); |
111 | 111 | $index = $this->fillDocument($document, $object); |
112 | - if($index == false) |
|
112 | + if ($index == false) |
|
113 | 113 | return false; |
114 | 114 | |
115 | 115 | return $document; |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | * @param object $object |
123 | 123 | * @return boolean |
124 | 124 | */ |
125 | - protected function fillDocument(Document &$document, $object) { |
|
126 | - if($object instanceof SearchableEntity) { |
|
125 | + protected function fillDocument(Document&$document, $object) { |
|
126 | + if ($object instanceof SearchableEntity) { |
|
127 | 127 | return $object->indexEntity($document); |
128 | 128 | } |
129 | 129 | $mapping = $this->getMapping(get_class($object)); |
130 | 130 | $accessor = PropertyAccess::createPropertyAccessor(); |
131 | - foreach($mapping as $fieldName => $propertyPath) { |
|
131 | + foreach ($mapping as $fieldName => $propertyPath) { |
|
132 | 132 | $document->addField($fieldName, $accessor->getValue($object, $propertyPath)); |
133 | 133 | } |
134 | 134 | return true; |
@@ -141,15 +141,15 @@ discard block |
||
141 | 141 | * @return \StingerSoft\EntitySearchBundle\Services\string[string] |
142 | 142 | */ |
143 | 143 | protected function getMapping($clazz) { |
144 | - if(isset($this->cachedMapping[$clazz])) { |
|
144 | + if (isset($this->cachedMapping[$clazz])) { |
|
145 | 145 | return $this->cachedMapping[$clazz]; |
146 | 146 | } |
147 | 147 | $ref = new \ReflectionClass($clazz); |
148 | 148 | |
149 | 149 | $mapping = array(); |
150 | 150 | |
151 | - foreach($this->mapping as $className => $config) { |
|
152 | - if($clazz == $className || $ref->isSubclassOf($className)) { |
|
151 | + foreach ($this->mapping as $className => $config) { |
|
152 | + if ($clazz == $className || $ref->isSubclassOf($className)) { |
|
153 | 153 | $mapping = array_merge($mapping, $config); |
154 | 154 | } |
155 | 155 | } |
@@ -105,12 +105,14 @@ |
||
105 | 105 | * @see \StingerSoft\EntitySearchBundle\Services\Mapping\EntityToDocumentMapperInterface::createDocument() |
106 | 106 | */ |
107 | 107 | public function createDocument(ObjectManager $manager, $object) { |
108 | - if(!$this->isIndexable($object)) |
|
109 | - return false; |
|
108 | + if(!$this->isIndexable($object)) { |
|
109 | + return false; |
|
110 | + } |
|
110 | 111 | $document = $this->getSearchService($manager)->createEmptyDocumentFromEntity($object); |
111 | 112 | $index = $this->fillDocument($document, $object); |
112 | - if($index == false) |
|
113 | - return false; |
|
113 | + if($index == false) { |
|
114 | + return false; |
|
115 | + } |
|
114 | 116 | |
115 | 117 | return $document; |
116 | 118 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | private $searchService; |
56 | 56 | |
57 | 57 | public function searchAction(Request $request) { |
58 | - if($request->query->get('term', false) !== false) { |
|
58 | + if ($request->query->get('term', false) !== false) { |
|
59 | 59 | $this->setSearchTerm($request->getSession(), $request->query->get('term')); |
60 | 60 | return $this->redirectToRoute('stinger_soft_entity_search_search'); |
61 | 61 | } |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | )); |
71 | 71 | |
72 | 72 | $facetForm->handleRequest($request); |
73 | - if($facetForm->isSubmitted()) { |
|
74 | - if($facetForm->get('clear')->isClicked()) { |
|
73 | + if ($facetForm->isSubmitted()) { |
|
74 | + if ($facetForm->get('clear')->isClicked()) { |
|
75 | 75 | $query->setFacets($this->getDefaultFacets()); |
76 | 76 | } |
77 | 77 | $this->setSearchTerm($request->getSession(), $query->getSearchTerm()); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | $page = $request->query->get('page', 1); |
89 | 89 | $results = array(); |
90 | - if($result instanceof PaginatableResultSet) { |
|
90 | + if ($result instanceof PaginatableResultSet) { |
|
91 | 91 | $results = $result->paginate($page, self::RESULTS_PER_PAGE); |
92 | 92 | } else { |
93 | 93 | $results = $result->getResults(($page - 1) * self::RESULTS_PER_PAGE, self::RESULTS_PER_PAGE); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @return string[string][] |
137 | 137 | */ |
138 | 138 | protected function getSearchFacets(SessionInterface $session) { |
139 | - $facets = $session()->get(self::SESSION_PREFIX . '_facets', false); |
|
139 | + $facets = $session()->get(self::SESSION_PREFIX.'_facets', false); |
|
140 | 140 | return $facets ? json_decode($facets, true) : $this->getDefaultFacets(); |
141 | 141 | } |
142 | 142 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @param string[string][] $facets |
148 | 148 | */ |
149 | 149 | protected function setSearchFacets(SessionInterface $session, $facets) { |
150 | - $session->set(self::SESSION_PREFIX . '_facets', json_encode($facets)); |
|
150 | + $session->set(self::SESSION_PREFIX.'_facets', json_encode($facets)); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @return mixed |
158 | 158 | */ |
159 | 159 | protected function getSearchTerm(SessionInterface $session) { |
160 | - return $session->get(self::SESSION_PREFIX . '_term', false); |
|
160 | + return $session->get(self::SESSION_PREFIX.'_term', false); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param string $term |
168 | 168 | */ |
169 | 169 | protected function setSearchTerm(SessionInterface $session, $term) { |
170 | - $session->set(self::SESSION_PREFIX . '_term', $term); |
|
170 | + $session->set(self::SESSION_PREFIX.'_term', $term); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | */ |
68 | 68 | protected function execute(InputInterface $input, OutputInterface $output) { |
69 | 69 | // Detect upload path |
70 | - if(!self::$defaultUploadPath) { |
|
70 | + if (!self::$defaultUploadPath) { |
|
71 | 71 | $root = $this->getContainer()->get('kernel')->getRootDir(); |
72 | - self::$defaultUploadPath = $root . '/../web/uploads'; |
|
72 | + self::$defaultUploadPath = $root.'/../web/uploads'; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | // Get the entity argument |
76 | 76 | $entity = $input->getArgument('entity'); |
77 | 77 | |
78 | - if($entity == 'all') { |
|
78 | + if ($entity == 'all') { |
|
79 | 79 | /** |
80 | 80 | * @var EntityManager $entityManager |
81 | 81 | */ |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | /** |
92 | 92 | * @var ClassMetadata $m |
93 | 93 | */ |
94 | - foreach($meta as $m) { |
|
95 | - if($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { |
|
94 | + foreach ($meta as $m) { |
|
95 | + if ($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { |
|
96 | 96 | continue; |
97 | 97 | } |
98 | - if(!$mapper->isClassIndexable($m->getReflectionClass()->getName())) { |
|
98 | + if (!$mapper->isClassIndexable($m->getReflectionClass()->getName())) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | 101 | $this->indexEntity($input, $output, $m->getReflectionClass()->getName()); |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | try { |
116 | 116 | // Get repository for the given entity type |
117 | 117 | $repository = $entityManager->getRepository($entity); |
118 | - } catch(\Exception $e) { |
|
118 | + } catch (\Exception $e) { |
|
119 | 119 | $output->writeln(sprintf('<error>No repository found for "%s", check your input</error>', $entity)); |
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | 123 | // Get all entities |
124 | 124 | $entities = $repository->findAll(); |
125 | - if(count($entities) == 0) { |
|
125 | + if (count($entities) == 0) { |
|
126 | 126 | $output->writeln('<comment>No entities found for indexing</comment>'); |
127 | 127 | return; |
128 | 128 | } |
@@ -130,14 +130,14 @@ discard block |
||
130 | 130 | $entitiesIndexed = 0; |
131 | 131 | |
132 | 132 | // Index each entity seperate |
133 | - foreach($entities as $entity) { |
|
134 | - if($this->getEntityToDocumentMapper()->isIndexable($entity)) { |
|
133 | + foreach ($entities as $entity) { |
|
134 | + if ($this->getEntityToDocumentMapper()->isIndexable($entity)) { |
|
135 | 135 | $document = $this->getEntityToDocumentMapper()->createDocument($entityManager, $entity); |
136 | 136 | $this->getSearchService($entityManager)->saveDocument($document); |
137 | 137 | $entitiesIndexed++; |
138 | 138 | } |
139 | 139 | } |
140 | - $output->writeln('<comment>Indexed ' . $entitiesIndexed . ' entities</comment>'); |
|
140 | + $output->writeln('<comment>Indexed '.$entitiesIndexed.' entities</comment>'); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @return EntityToDocumentMapperInterface |
146 | 146 | */ |
147 | 147 | protected function getEntityToDocumentMapper() { |
148 | - if(!$this->entityToDocumentMapper) { |
|
148 | + if (!$this->entityToDocumentMapper) { |
|
149 | 149 | $this->entityToDocumentMapper = $this->getContainer()->get(EntityToDocumentMapperInterface::SERVICE_ID); |
150 | 150 | } |
151 | 151 | return $this->entityToDocumentMapper; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @return SearchService |
157 | 157 | */ |
158 | 158 | protected function getSearchService(ObjectManager $manager) { |
159 | - if(!$this->searchService) { |
|
159 | + if (!$this->searchService) { |
|
160 | 160 | $this->searchService = $this->getContainer()->get(SearchService::SERVICE_ID); |
161 | 161 | } |
162 | 162 | $this->searchService->setObjectManager($manager); |