-
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.
Merge pull request #20 from smartbooster/common_entity_trait_interface
Common entity trait interface + new ProcessMonitor feature
- Loading branch information
Showing
30 changed files
with
1,009 additions
and
3 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
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,57 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Command; | ||
|
||
use Smart\CoreBundle\Utils\ArrayUtils; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
class CommandPoolHelper | ||
{ | ||
public function __construct(private readonly KernelInterface $kernel) | ||
{ | ||
} | ||
|
||
/** | ||
* Return all commands indexed by a given type | ||
* @return Command[] | ||
*/ | ||
public function getCommands(string $type): array | ||
{ | ||
$application = new Application($this->kernel); | ||
|
||
return array_filter($application->all(), function ($key) use ($type) { | ||
return str_starts_with($key, "$type:"); | ||
}, ARRAY_FILTER_USE_KEY); | ||
} | ||
|
||
/** | ||
* Parse commands from a given type and return an associative array that can be used in form choice type | ||
* @return array | ||
* [ | ||
* 'app.my_command.label' => 'my-command', | ||
* 'app.my_other_command.label' => 'my-other-command', | ||
* ] | ||
*/ | ||
public function getCommandsChoices(string $type): array | ||
{ | ||
return ArrayUtils::flatToMap( | ||
array_keys($this->getCommands($type)), | ||
function ($key) { | ||
return str_replace([':', '-'], ['.', '_'], $key) . '.label'; | ||
}, | ||
function ($value) use ($type) { | ||
return str_replace("$type:", '', $value); | ||
} | ||
); | ||
} | ||
|
||
public function getCronChoices(): array | ||
{ | ||
return $this->getCommandsChoices('cron'); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
interface AddressInterface | ||
{ | ||
public function getAddress(): ?string; | ||
|
||
public function getAdditionalAddress(): ?string; | ||
|
||
public function getPostalCode(): ?string; | ||
|
||
public function getCity(): ?string; | ||
} |
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,76 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
trait AddressTrait | ||
{ | ||
#[ORM\Column(length: 255, nullable: true)] | ||
#[Assert\Length(max: 255)] | ||
private ?string $address = null; | ||
|
||
#[ORM\Column(length: 255, nullable: true)] | ||
#[Assert\Length(max: 255)] | ||
private ?string $additionalAddress = null; | ||
|
||
#[ORM\Column(length: 10, nullable: true)] | ||
#[Assert\Length(max: 10)] | ||
private ?string $postalCode = null; | ||
|
||
#[ORM\Column(length: 255, nullable: true)] | ||
#[Assert\Length(max: 255)] | ||
private ?string $city = null; | ||
|
||
public function getAddress(): ?string | ||
{ | ||
return $this->address; | ||
} | ||
|
||
public function setAddress(?string $address): self | ||
{ | ||
$this->address = $address; | ||
|
||
return $this; | ||
} | ||
|
||
public function getAdditionalAddress(): ?string | ||
{ | ||
return $this->additionalAddress; | ||
} | ||
|
||
public function setAdditionalAddress(?string $additionalAddress): self | ||
{ | ||
$this->additionalAddress = $additionalAddress; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPostalCode(): ?string | ||
{ | ||
return $this->postalCode; | ||
} | ||
|
||
public function setPostalCode(?string $postalCode): self | ||
{ | ||
if (strlen($postalCode) === 4) { | ||
$postalCode = '0' . $postalCode; | ||
} | ||
$this->postalCode = $postalCode; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCity(): ?string | ||
{ | ||
return $this->city; | ||
} | ||
|
||
public function setCity(?string $city): self | ||
{ | ||
$this->city = $city; | ||
|
||
return $this; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
interface ApiCallInterface extends ProcessInterface | ||
{ | ||
public function getOrigin(): ?string; | ||
|
||
public function setOrigin(string $origin): static; | ||
|
||
public function getStatusCode(): ?int; | ||
|
||
public function setStatusCode(int $statusCode): static; | ||
|
||
public function getMethod(): ?string; | ||
|
||
public function setMethod(string $method): static; | ||
|
||
public function getRouteUrl(): ?string; | ||
|
||
public function setRouteUrl(string $routeUrl): static; | ||
|
||
public function getInputData(): ?array; | ||
|
||
public function setInputData(?array $inputData): static; | ||
|
||
public function getOutputResponse(): array|string|null; | ||
|
||
public function setOutputResponse(array|string|null $outputResponse): static; | ||
} |
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,116 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
trait ApiCallTrait | ||
{ | ||
use ProcessTrait; | ||
|
||
#[ORM\Column(length: 20)] | ||
private ?string $origin = null; | ||
|
||
#[ORM\Column] | ||
private ?int $statusCode = null; | ||
|
||
#[ORM\Column(length: 10)] | ||
private ?string $method = null; | ||
|
||
/** | ||
* The routeUrl property contains the full url used to call the API | ||
* On other hand, the route alias will be stored in the type property from the ProcessTrait. Storing the route alias this way can help you build | ||
* api stats call on top this trait/interface. | ||
*/ | ||
#[ORM\Column(type: Types::TEXT)] | ||
private ?string $routeUrl = null; | ||
|
||
#[ORM\Column(nullable: true)] | ||
private ?array $inputData = null; | ||
|
||
#[ORM\Column(type: Types::JSON, nullable: true)] | ||
private array|string|null $outputResponse = null; | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->statusCode . ' - ' . $this->getRouteUrl(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getOrigin(): ?string | ||
{ | ||
return $this->origin; | ||
} | ||
|
||
public function setOrigin(string $origin): static | ||
{ | ||
$this->origin = $origin; | ||
|
||
return $this; | ||
} | ||
|
||
public function getStatusCode(): ?int | ||
{ | ||
return $this->statusCode; | ||
} | ||
|
||
public function setStatusCode(int $statusCode): static | ||
{ | ||
$this->statusCode = $statusCode; | ||
|
||
return $this; | ||
} | ||
|
||
public function getMethod(): ?string | ||
{ | ||
return $this->method; | ||
} | ||
|
||
public function setMethod(string $method): static | ||
{ | ||
$this->method = $method; | ||
|
||
return $this; | ||
} | ||
|
||
public function getRouteUrl(): ?string | ||
{ | ||
return $this->routeUrl; | ||
} | ||
|
||
public function setRouteUrl(string $routeUrl): static | ||
{ | ||
$this->routeUrl = $routeUrl; | ||
|
||
return $this; | ||
} | ||
|
||
public function getInputData(): ?array | ||
{ | ||
return $this->inputData; | ||
} | ||
|
||
public function setInputData(?array $inputData): static | ||
{ | ||
$this->inputData = $inputData; | ||
|
||
return $this; | ||
} | ||
|
||
public function getOutputResponse(): array|string|null | ||
{ | ||
return $this->outputResponse; | ||
} | ||
|
||
public function setOutputResponse(array|string|null $outputResponse): static | ||
{ | ||
$this->outputResponse = $outputResponse; | ||
|
||
return $this; | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
interface EmailInterface | ||
{ | ||
public function getEmail(): ?string; | ||
|
||
public function setEmail(?string $email): self; | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace Smart\CoreBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
trait EmailTrait | ||
{ | ||
#[ORM\Column(length: 255, nullable: true)] | ||
#[Assert\Length(max: 255)] | ||
#[Assert\Email] | ||
private ?string $email = null; | ||
|
||
public function getEmail(): ?string | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function setEmail(?string $email): self | ||
{ | ||
$email = strtolower($email); | ||
if ($email === '') { | ||
$email = null; | ||
} | ||
$this->email = $email; | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.