-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a4a009
commit c57d350
Showing
19 changed files
with
1,375 additions
and
1 deletion.
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,41 @@ | ||
<?php | ||
|
||
namespace App\Helpers; | ||
|
||
use Betalabs\Engine\Requests\EndpointResolver; | ||
use Betalabs\Engine\Auth\Token; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class Engine | ||
{ | ||
/** | ||
* Authenticate tenant in Engine | ||
* | ||
* @param \Illuminate\Contracts\Auth\Authenticatable $tenant | ||
*/ | ||
public static function auth(Authenticatable $tenant): void | ||
{ | ||
/** @var \Betalabs\LaravelHelper\Models\Tenant $tenant */ | ||
$registry = $tenant->engineRegistry; | ||
$endpoint = rtrim($registry->api_base_uri, '/api'); | ||
|
||
EndpointResolver::setEndpoint($endpoint); | ||
resolve(Token::class)->informToken($registry->api_access_token); | ||
} | ||
|
||
/** | ||
* Make a valid Engine API URL | ||
* | ||
* @param null|string $endpoint | ||
* | ||
* @return string | ||
*/ | ||
public static function makeUrl(string $endpoint): string | ||
{ | ||
/** @var \Betalabs\LaravelHelper\Models\Tenant $registry */ | ||
$registry = Auth::user()->engineRegistry; | ||
|
||
return $registry->api_base_uri . '/' . trim($endpoint, '/'); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Genesis; | ||
|
||
use App\Helpers\Engine; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
use Laravel\Passport\Passport; | ||
|
||
abstract class Base | ||
{ | ||
|
||
/** | ||
* Authenticate tenant | ||
* | ||
* @param \Illuminate\Contracts\Auth\Authenticatable $authenticatable | ||
*/ | ||
protected function authenticate(Authenticatable $authenticatable) | ||
{ | ||
Passport::actingAs($authenticatable); | ||
Engine::auth($authenticatable); | ||
} | ||
|
||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Genesis; | ||
|
||
use Betalabs\LaravelHelper\Models\Tenant; | ||
|
||
class CreateExtraFields extends Base | ||
{ | ||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param \Betalabs\LaravelHelper\Models\Tenant $tenant | ||
*/ | ||
public function handle(Tenant $tenant) | ||
{ | ||
// Do not forget to authenticate | ||
$this->authenticate($tenant); | ||
|
||
// Here you can use API to add extra fields. | ||
} | ||
|
||
} |
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,48 @@ | ||
<?php | ||
|
||
namespace App\Listeners\Genesis; | ||
|
||
use App\Services\Genesis\Workflows\MultipleActionMenu; | ||
use App\Services\Genesis\Workflows\SingleActionMenu; | ||
use Betalabs\LaravelHelper\Models\Tenant; | ||
|
||
class CreateWorkflows extends Base | ||
{ | ||
|
||
/** @var \App\Services\Genesis\Workflows\SingleActionMenu */ | ||
private $singleActionMenu; | ||
|
||
/** @var \App\Services\Genesis\Workflows\MultipleActionMenu */ | ||
private $multipleActionMenu; | ||
|
||
/** | ||
* CreateWorkflows constructor. | ||
* | ||
* @param \App\Services\Genesis\Workflows\SingleActionMenu $singleActionMenu | ||
* @param \App\Services\Genesis\Workflows\MultipleActionMenu $multipleActionMenu | ||
*/ | ||
public function __construct( | ||
SingleActionMenu $singleActionMenu, | ||
MultipleActionMenu $multipleActionMenu | ||
) { | ||
$this->singleActionMenu = $singleActionMenu; | ||
$this->multipleActionMenu = $multipleActionMenu; | ||
} | ||
|
||
|
||
/** | ||
* Handle the event. | ||
* | ||
* @param \Betalabs\LaravelHelper\Models\Tenant $tenant | ||
*/ | ||
public function handle(Tenant $tenant) | ||
{ | ||
// Do not forget to authenticate | ||
$this->authenticate($tenant); | ||
|
||
// Services to create workflows | ||
$this->singleActionMenu->create(); | ||
$this->multipleActionMenu->create(); | ||
} | ||
|
||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace App\Models\Enums\Engine; | ||
|
||
use MyCLabs\Enum\Enum; | ||
|
||
class WorkflowConditionApproach extends Enum | ||
{ | ||
const AND = 'and'; | ||
const OR = 'or'; | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace App\Models\Enums\Engine; | ||
|
||
use MyCLabs\Enum\Enum; | ||
|
||
class WorkflowConditionOperator extends Enum | ||
{ | ||
const EQUAL = '='; | ||
const DIFFERENT = '!='; | ||
const GREATER_THAN = '>'; | ||
const GREATER_THAN_OR_EQUAL_TO = '>='; | ||
const LESS_THAN = '<'; | ||
const LESS_THAN_OR_EQUAL_TO = '<='; | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace App\Models\Enums\Engine; | ||
|
||
use MyCLabs\Enum\Enum; | ||
|
||
class WorkflowIdentification extends Enum | ||
{ | ||
const ML_AD_SINGLE_ACTION_MENU = 'ml-advertisements-single-action-menu'; | ||
const ML_AD_MULTIPLE_ACTION_MENU = 'ml-advertisements-multiple-action-menu'; | ||
const ML_AD_EXTRA_FORMS = 'ml-advertisements-extra-forms'; | ||
const ML_ORDER_SINGLE_ACTION_MENU = 'ml-orders-single-action-menu'; | ||
const ML_ORDER_MULTIPLE_ACTION_MENU = 'ml-orders-multiple-action-menu'; | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace App\Models\Enums\Engine; | ||
|
||
use MyCLabs\Enum\Enum; | ||
|
||
class WorkflowStepApproach extends Enum | ||
{ | ||
const SYNCHRONOUS = 'synchronous'; | ||
const ASYNCHRONOUS = 'asynchronous'; | ||
} |
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,96 @@ | ||
<?php | ||
|
||
namespace App\Services\Engine; | ||
|
||
use Betalabs\Engine\Request; | ||
use Illuminate\Support\Collection; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
abstract class AbstractIndexer | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $query = []; | ||
/** | ||
* @var int | ||
*/ | ||
private $limit = 10; | ||
/** | ||
* @var int | ||
*/ | ||
private $offset = 0; | ||
|
||
/** | ||
* Set the query property. | ||
* | ||
* @param array $query | ||
* | ||
* @return self | ||
*/ | ||
public function setQuery(array $query): self | ||
{ | ||
$this->query = $query; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Set the limit property. | ||
* | ||
* @param int $limit | ||
* | ||
* @return self | ||
*/ | ||
public function setLimit(int $limit): self | ||
{ | ||
$this->limit = $limit; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Set the offset property. | ||
* | ||
* @param int $offset | ||
* | ||
* @return self | ||
*/ | ||
public function setOffset(int $offset): self | ||
{ | ||
$this->offset = $offset; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Return Engine endpoint | ||
* | ||
* @return string | ||
*/ | ||
abstract protected function endpoint(): string; | ||
|
||
/** | ||
* Handle request response | ||
* | ||
* @param \Psr\Http\Message\ResponseInterface $response | ||
*/ | ||
abstract protected function handleResponse(ResponseInterface $response): void; | ||
|
||
/** | ||
* Retrieve a resource | ||
* | ||
* @return \Illuminate\Support\Collection | ||
*/ | ||
public function retrieve(): Collection | ||
{ | ||
$query = http_build_query(array_merge($this->query, [ | ||
'_limit' => $this->limit, | ||
'_offset' => $this->offset | ||
])); | ||
|
||
$request = Request::get(); | ||
$index = $request->send("{$this->endpoint()}?{$query}"); | ||
|
||
$this->handleResponse($request->getResponse()); | ||
|
||
return collect($index->data); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace App\Services\Engine\Event; | ||
|
||
use App\Services\Engine\AbstractIndexer; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class Indexer extends AbstractIndexer | ||
{ | ||
/** | ||
* Return Engine endpoint | ||
* | ||
* @return string | ||
*/ | ||
protected function endpoint(): string | ||
{ | ||
return 'events'; | ||
} | ||
|
||
/** | ||
* Handle request response | ||
* | ||
* @param \Psr\Http\Message\ResponseInterface $response | ||
*/ | ||
protected function handleResponse(ResponseInterface $response): void | ||
{ | ||
if ($response->getStatusCode() >= 300) { | ||
throw new \RuntimeException( | ||
'Engine Events could not be retrieved.' | ||
); | ||
} | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace App\Services\Engine\Listener; | ||
|
||
use App\Services\Engine\AbstractIndexer; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class Indexer extends AbstractIndexer | ||
{ | ||
/** | ||
* Return Engine endpoint | ||
* | ||
* @return string | ||
*/ | ||
protected function endpoint(): string | ||
{ | ||
return 'listeners'; | ||
} | ||
|
||
/** | ||
* Handle request response | ||
* | ||
* @param \Psr\Http\Message\ResponseInterface $response | ||
*/ | ||
protected function handleResponse(ResponseInterface $response): void | ||
{ | ||
if ($response->getStatusCode() >= 400) { | ||
throw new \RuntimeException('Unable to retrieve listeners'); | ||
} | ||
} | ||
} |
Oops, something went wrong.