-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRequestDataTransformer.php
More file actions
67 lines (57 loc) · 1.94 KB
/
Copy pathRequestDataTransformer.php
File metadata and controls
67 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
/*
* UserFrosting Framework (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/framework
* @copyright Copyright (c) 2013-2024 Alexander Weissman, Louis Charette, Jordan Mele
* @license https://github.com/userfrosting/framework/blob/master/LICENSE.md (MIT License)
*/
namespace UserFrosting\Fortress;
use UserFrosting\Fortress\RequestSchema\RequestSchemaInterface;
use UserFrosting\Fortress\Transformer\RequestDataTransformer as DataTransformer;
/**
* Perform a series of transformations on a set of data fields, as specified by
* a RequestSchemaInterface.
*
* @deprecated 5.1 Use `\UserFrosting\Fortress\Transformer\RequestDataTransformer` instead
*/
class RequestDataTransformer implements RequestDataTransformerInterface
{
protected DataTransformer $transformer;
/**
* Create a new data transformer.
*
* @param RequestSchemaInterface $schema A RequestSchemaInterface object, containing the transformation rules.
*/
public function __construct(protected RequestSchemaInterface $schema)
{
$this->transformer = new DataTransformer();
}
/**
* Set the schema for this transformer, as a valid RequestSchemaInterface object.
*
* @param RequestSchemaInterface $schema A RequestSchemaInterface object, containing the transformation rules.
*
* @return $this
*/
public function setSchema(RequestSchemaInterface $schema): static
{
$this->schema = $schema;
return $this;
}
/**
* {@inheritdoc}
*/
public function transform(array $data, string $onUnexpectedVar = 'skip'): array
{
return $this->transformer->transform($this->schema, $data, $onUnexpectedVar);
}
/**
* {@inheritdoc}
*/
public function transformField(string $name, array|string $value): array|string
{
return $this->transformer->transformField($this->schema, $name, $value);
}
}