Skip to content

Commit bb81b10

Browse files
committed
feat: Constructo page improvements
1 parent 3a13edf commit bb81b10

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

src/pages/Constructo.tsx

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -277,34 +277,58 @@ echo sprintf(" Data de Nascimento: %s\\n", $user->birthDate->format('Y-m-d'));
277277
<TabsContent value="serialization">
278278
<Card>
279279
<CardHeader>
280-
<CardTitle>Serialização de Classes</CardTitle>
280+
<CardTitle>Desserialização Eficiente</CardTitle>
281281
<CardDescription>
282-
Converta objetos para arrays/JSON automaticamente
282+
Passe uma instância de objeto e converta-a em um objeto facilmente convertível
283+
para em array associativo ou JSON
283284
</CardDescription>
284285
</CardHeader>
285286
<CardContent>
286287
<CodeBlock language="php">
287-
{`<?php
288-
use Devitools\\Constructo\\Serializable;
288+
{`
289+
use Constructo\\Core\\Deserialize\\Demolisher;
290+
use Constructo\\Support\\Set;
291+
use Constructo\\Type\\Timestamp;
289292
290-
class User extends Serializable
293+
// Defina sua entidade informando os valores das propriedades no construtor
294+
readonly class User
291295
{
292296
public function __construct(
297+
public int $id,
293298
public string $name,
294-
public string $email,
295-
public DateTime $createdAt
299+
public Timestamp $birthDate,
300+
public bool $isActive = true,
301+
public array $tags = [],
296302
) {}
297303
}
298304
299-
$user = new User('João Silva', '[email protected]', new DateTime());
300-
301-
// Serialização automática
302-
$array = $user->toArray();
303-
$json = $user->toJson();
305+
// Instancie o objeto que deseja destruir
306+
$user = new User(
307+
id: 1,
308+
name: 'João Silva',
309+
birthDate: new Timestamp('1981-08-13'),
310+
isActive: true,
311+
tags: ['nice', 'welcome'],
312+
);
313+
314+
// Crie um novo demolisher e use-o para destruir o objeto
315+
$object = (new Demolisher())->demolish($user);
316+
317+
$set = Set::createFrom((array) $object);
318+
echo "# Usuário: \\n";
319+
echo sprintf("# ID: %s\\n", $set->get('id'));
320+
echo sprintf("# Nome: %s\\n", $set->get('name'));
321+
echo sprintf("# Ativo: %s\\n", $set->get('is_active') ? 'Sim' : 'Não');
322+
echo sprintf("# Tags: %s\\n", implode(', ', $set->get('tags')));
323+
echo sprintf("# Data de Nascimento: %s\\n", $set->get('birth_date'));
304324
305-
// Deserialização
306-
$newUser = User::fromArray($array);
307-
$fromJson = User::fromJson($json);`}
325+
# Usuário:
326+
# ID: 1
327+
# Nome: João Silva
328+
# Ativo: Sim
329+
# Tags: nice, welcome
330+
# Data de Nascimento: 1981-08-13T00:00:00+00:00
331+
`}
308332
</CodeBlock>
309333
</CardContent>
310334
</Card>

0 commit comments

Comments
 (0)