-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Format-D/refactoring-multiservices
Refactoring multiservices
- Loading branch information
Showing
13 changed files
with
607 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
|
||
namespace FormatD\GeoIndexable\Aspect; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Aop\JoinPointInterface; | ||
|
||
/** | ||
* An aspect | ||
* | ||
* @Flow\Scope("singleton") | ||
* @Flow\Aspect | ||
*/ | ||
class LoggingAspect | ||
{ | ||
/** | ||
* | ||
* | ||
* @param JoinPointInterface $joinPoint | ||
* @Flow\Before("method(.*->indexByAddress(.*)) && within(FormatD\GeoIndexable\Domain\Service\AbstractGeoIndexingService)") | ||
* @return void | ||
*/ | ||
public function logIndexByAddress(JoinPointInterface $joinPoint) { | ||
$className = $joinPoint->getClassName(); | ||
// echo 'Indexing by address with class: '.$className."\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
|
||
namespace FormatD\GeoIndexable\Domain; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* @Flow\Scope("prototype") | ||
*/ | ||
class LocationData implements LocationDataDetails | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $details; | ||
|
||
/** | ||
* @param array $requiredDetails | ||
*/ | ||
public function __construct($requiredDetails) { | ||
$this->details = array_combine($requiredDetails, array_pad([], count($requiredDetails), '')); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getRequiredDetails(){ | ||
return array_keys($this->getDetails()); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getDetails(): array { | ||
return $this->details; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return bool | ||
*/ | ||
public function hasDetail($name){ | ||
return array_key_exists($name, $this->getDetails()); | ||
} | ||
|
||
/** | ||
* @param $name | ||
* @return mixed | ||
*/ | ||
public function getDetail($name){ | ||
if(!$this->hasDetail($name)){ | ||
return NULL; | ||
} | ||
return $this->details[$name]; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param mixed $value | ||
* @return bool (true if successful and false if no detail was found) | ||
*/ | ||
public function setDetail($name, $value){ | ||
if(!$this->hasDetail($name)){ | ||
return false; | ||
} | ||
$this->details[$name] = $value; | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace FormatD\GeoIndexable\Domain; | ||
|
||
/** | ||
* Supported Location Details | ||
*/ | ||
interface LocationDataDetails | ||
{ | ||
/** | ||
* Details | ||
*/ | ||
const LATITUDE = 'latitude'; | ||
const LONGITUDE = 'longitude'; | ||
const LABEL = 'label'; | ||
const CITY = 'city'; | ||
const COUNTRY = 'country'; | ||
const BOUNDINGBOX = 'boundingbox'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace FormatD\GeoIndexable\Domain\Model; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Neos\Flow\Annotations as Flow; | ||
use Flowpack\ElasticSearch\Annotations as ElasticSearch; | ||
use FormatD\GeoIndexable\Domain\LocationDataDetails; | ||
|
||
trait GeoIndexableElasticSearchTrait | ||
{ | ||
use GeoIndexableTrait; | ||
|
||
/** | ||
* Lat and Lon as array for elasticsearch indexing [lat => xx.xxx, lon => xx.xxx] | ||
* Be aware! After DB-Persist lat and lon are strings! | ||
* | ||
* @var array | ||
* @ElasticSearch\Indexable | ||
* @ElasticSearch\Mapping(type="geo_point") | ||
*/ | ||
protected $locationGeoPoint = []; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getLocationGeoPoint() { | ||
if (isset($this->locationGeoPoint['lat']) && $this->locationGeoPoint['lat']) { | ||
$this->locationGeoPoint['lat'] = (float) $this->locationGeoPoint['lat']; | ||
} | ||
if (isset($this->locationGeoPoint['lon']) && $this->locationGeoPoint['lon']) { | ||
$this->locationGeoPoint['lon'] = (float) $this->locationGeoPoint['lon']; | ||
} | ||
return $this->locationGeoPoint; | ||
} | ||
|
||
/** | ||
* @param string $locationAddress | ||
*/ | ||
protected function onLocationChange($locationAddress){ | ||
if (strlen($locationAddress) > 1) { | ||
$this->geoIndexService->indexByAddress($this->locationData, $locationAddress); | ||
if( | ||
$this->locationData->hasDetail(LocationDataDetails::LONGITUDE) | ||
&& $this->locationData->hasDetail(LocationDataDetails::LATITUDE) | ||
){ | ||
$this->locationGeoPoint['lat'] = $this->locationData->getDetail(LocationDataDetails::LATITUDE); | ||
$this->locationGeoPoint['lon'] = $this->locationData->getDetail(LocationDataDetails::LONGITUDE); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.