-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Showing
21 changed files
with
776 additions
and
0 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,19 @@ | ||
# routes.yml | ||
|
||
prestasafe_prettyblocks_zone_list: | ||
path: /prettyblocks/api/zones | ||
methods: [ GET ] | ||
defaults: | ||
_controller: 'prestasafe.prettyblocks.controller.zone_controller:listZones' | ||
|
||
prestasafe_prettyblocks_zone_get: | ||
path: /prettyblocks/api/zones/{id} | ||
methods: [ GET ] | ||
defaults: | ||
_controller: 'prestasafe.prettyblocks.controller.zone_controller:getZone' | ||
|
||
prestasafe_prettyblocks_zone_update: | ||
path: /prettyblocks/api/zones/{id} | ||
methods: [ PUT ] | ||
defaults: | ||
_controller: 'prestasafe.prettyblocks.controller.zone_controller:updateZone' |
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,49 @@ | ||
# config.yml | ||
|
||
services: | ||
default: | ||
public: true | ||
autoconfigure: true | ||
autowire: true | ||
|
||
# Registry pour enregistrer dynamiquement les types d'entités | ||
prestasafe.prettyblocks.registry.entity_registry: | ||
class: PrestaSafe\PrettyBlocks\Registry\EntityRegistry | ||
|
||
# Factory pour la création dynamique des entités | ||
prestasafe.prettyblocks.factory.entity_factory: | ||
class: PrestaSafe\PrettyBlocks\Factory\EntityFactory | ||
arguments: | ||
- '@prestasafe.prettyblocks.registry.entity_registry' | ||
|
||
# Repositories Doctrine | ||
prestasafe.prettyblocks.repository.block_repository: | ||
class: PrestaSafe\PrettyBlocks\Repository\BlockRepository | ||
factory: [ '@doctrine', getRepository ] | ||
|
||
prestasafe.prettyblocks.repository.component_repository: | ||
class: PrestaSafe\PrettyBlocks\Repository\ComponentRepository | ||
factory: [ '@doctrine', getRepository ] | ||
|
||
prestasafe.prettyblocks.repository.primitive_field_repository: | ||
class: PrestaSafe\PrettyBlocks\Repository\PrimitiveFieldRepository | ||
factory: [ '@doctrine', getRepository ] | ||
|
||
prestasafe.prettyblocks.repository.zone_repository: | ||
class: PrestaSafe\PrettyBlocks\Repository\ZoneRepository | ||
factory: [ '@doctrine', getRepository ] | ||
|
||
# Service principal pour la gestion des zones | ||
prestasafe.prettyblocks.service.zone_service: | ||
class: PrestaSafe\PrettyBlocks\Service\ZoneService | ||
arguments: | ||
- '@prestasafe.prettyblocks.repository.zone_repository' | ||
- '@prestasafe.prettyblocks.factory.entity_factory' | ||
|
||
# Contrôleurs API | ||
prestasafe.prettyblocks.controller.zone_controller: | ||
class: PrestaSafe\PrettyBlocks\Controller\Api\ZoneController | ||
arguments: | ||
- '@prestasafe.prettyblocks.service.zone_service' | ||
tags: | ||
- { name: controller.service_arguments } |
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,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaSafe\PrettyBlocks\Controller\Api; | ||
|
||
use PrestaSafe\PrettyBlocks\Service\ZoneService; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class ZoneController extends AbstractController | ||
{ | ||
private $zoneService; | ||
|
||
public function __construct(ZoneService $zoneService) | ||
{ | ||
$this->zoneService = $zoneService; | ||
} | ||
|
||
/** | ||
* Endpoint to list all available zones | ||
*/ | ||
public function listZones(): JsonResponse | ||
{ | ||
$zones = $this->zoneService->getAllZones(); | ||
$data = []; | ||
|
||
foreach ($zones as $zone) { | ||
$data[] = [ | ||
'id' => $zone->getId(), | ||
'label' => $zone->getLabel(), | ||
// You can add more details if needed | ||
]; | ||
} | ||
|
||
return new JsonResponse($data); | ||
} | ||
|
||
/** | ||
* Endpoint to get a specific zone by ID | ||
*/ | ||
public function getZone(string $id): JsonResponse | ||
{ | ||
$zone = $this->zoneService->getZoneById($id); | ||
|
||
if (!$zone) { | ||
return new JsonResponse(['error' => 'Zone not found'], JsonResponse::HTTP_NOT_FOUND); | ||
} | ||
|
||
$data = [ | ||
'id' => $zone->getId(), | ||
'label' => $zone->getLabel(), | ||
'blocks' => [], | ||
]; | ||
|
||
foreach ($zone->getBlocks() as $block) { | ||
$data['blocks'][] = [ | ||
'id' => $block->getId(), | ||
'label' => $block->getLabel(), | ||
'fields' => $block->getFields(), | ||
// Include more block details if necessary | ||
]; | ||
} | ||
|
||
return new JsonResponse($data); | ||
} | ||
|
||
/** | ||
* Endpoint to update a specific zone by ID with edited blocks | ||
*/ | ||
public function updateZone(Request $request, string $id): JsonResponse | ||
{ | ||
$zone = $this->zoneService->getZoneById($id); | ||
|
||
if (!$zone) { | ||
return new JsonResponse(['error' => 'Zone not found'], JsonResponse::HTTP_NOT_FOUND); | ||
} | ||
|
||
$data = json_decode($request->getContent(), true, 512, JSON_THROW_ON_ERROR); | ||
|
||
if (!isset($data['blocks'])) { | ||
return new JsonResponse(['error' => 'Invalid data'], JsonResponse::HTTP_BAD_REQUEST); | ||
} | ||
|
||
try { | ||
$this->zoneService->updateZone($zone, $data['blocks']); | ||
} catch (\Exception $e) { | ||
return new JsonResponse(['error' => $e->getMessage()], JsonResponse::HTTP_INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
return new JsonResponse(['status' => 'Zone updated successfully']); | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaSafe\PrettyBlocks\Entity\Block; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\MappedSuperclass | ||
*/ | ||
abstract class AbstractBlock implements BlockInterface | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="string") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @ORM\Column(type="string") | ||
*/ | ||
protected $label; | ||
|
||
/** | ||
* @ORM\Column(type="json") | ||
*/ | ||
protected $fields = []; | ||
|
||
public function __construct(string $id, string $label) | ||
{ | ||
$this->id = $id; | ||
$this->label = $label; | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getLabel(): string | ||
{ | ||
return $this->label; | ||
} | ||
|
||
public function getFields(): array | ||
{ | ||
return $this->fields; | ||
} | ||
|
||
public function addField($field): void | ||
{ | ||
$this->fields[] = $field; | ||
} | ||
|
||
abstract public function validate(): bool; | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaSafe\PrettyBlocks\Entity\Block; | ||
|
||
interface BlockInterface | ||
{ | ||
public function getId(): string; | ||
|
||
public function getLabel(): string; | ||
|
||
public function getFields(): array; | ||
|
||
public function addField($field): void; | ||
|
||
public function validate(): bool; | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaSafe\PrettyBlocks\Entity\Block; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity(repositoryClass="PrestaSafe\PrettyBlocks\Repository\BlockRepository") | ||
* @ORM\Table(name="text_blocks") | ||
*/ | ||
class TextBlock extends AbstractBlock | ||
{ | ||
public function validate(): bool | ||
{ | ||
// Validation spécifique pour le TextBlock | ||
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaSafe\PrettyBlocks\Entity\Component; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\MappedSuperclass | ||
*/ | ||
abstract class AbstractComponent implements ComponentInterface | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="string") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @ORM\Column(type="string") | ||
*/ | ||
protected $label; | ||
|
||
/** | ||
* @ORM\Column(type="string") | ||
*/ | ||
protected $type; | ||
|
||
public function __construct(string $id, string $label, string $type) | ||
{ | ||
$this->id = $id; | ||
$this->label = $label; | ||
$this->type = $type; | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getLabel(): string | ||
{ | ||
return $this->label; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
|
||
abstract public function validate(): bool; | ||
} |
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 PrestaSafe\PrettyBlocks\Entity\Component; | ||
|
||
interface ComponentInterface | ||
{ | ||
public function getId(): string; | ||
|
||
public function getLabel(): string; | ||
|
||
public function getType(): string; | ||
|
||
public function validate(): bool; | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaSafe\PrettyBlocks\Entity\Component; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity(repositoryClass="PrestaSafe\PrettyBlocks\Repository\ComponentRepository") | ||
* @ORM\Table(name="text_components") | ||
*/ | ||
class TextComponent extends AbstractComponent | ||
{ | ||
public function validate(): bool | ||
{ | ||
// Validation spécifique pour le TextComponent | ||
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PrestaSafe\PrettyBlocks\Entity\PrimitiveField; | ||
|
||
abstract class AbstractPrimitiveField implements PrimitiveFieldInterface | ||
{ | ||
protected string $id; | ||
protected string $label; | ||
protected mixed $value; | ||
|
||
public function __construct(string $id, string $label) | ||
{ | ||
$this->id = $id; | ||
$this->label = $label; | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getLabel(): string | ||
{ | ||
return $this->label; | ||
} | ||
|
||
public function getValue(): mixed | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function setValue($value): void | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
abstract public function validate(): bool; | ||
} |
Oops, something went wrong.