parent
8f4424ab81
commit
cc958bd72d
@ -0,0 +1,18 @@ |
||||
<?php |
||||
|
||||
namespace Rinsvent\TransformerBundle\Service\Transformer\Request; |
||||
|
||||
use Rinsvent\TransformerBundle\Service\AbstractTransformer; |
||||
use Symfony\Component\HttpFoundation\Request; |
||||
use Symfony\Component\HttpFoundation\RequestStack; |
||||
|
||||
abstract class AbstractRequest extends AbstractTransformer |
||||
{ |
||||
/** @var Request */ |
||||
protected $request; |
||||
|
||||
public function __construct(RequestStack $requestStack) |
||||
{ |
||||
$this->request = $requestStack->getCurrentRequest(); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace Rinsvent\Data2DTOBundle\Service\Transformer\Request\Headers; |
||||
|
||||
use Rinsvent\Transformer\Transformer\Meta; |
||||
|
||||
#[\Attribute] |
||||
class Header extends Meta |
||||
{ |
||||
public function __construct( |
||||
public string $property, |
||||
public ?string $default = null, |
||||
public array $tags = ['request_headers'] |
||||
) { |
||||
parent::__construct($tags); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace Rinsvent\Data2DTOBundle\Service\Transformer\Request\Headers; |
||||
|
||||
use Rinsvent\Transformer\Transformer\Meta; |
||||
use Rinsvent\TransformerBundle\Service\Transformer\Request\AbstractRequest; |
||||
|
||||
class HeaderTransformer extends AbstractRequest |
||||
{ |
||||
/** |
||||
* @param Header $meta |
||||
*/ |
||||
public function transform(mixed $data, Meta $meta): mixed |
||||
{ |
||||
return $this->request->headers->get($meta->property, $meta->default); |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
<?php |
||||
|
||||
namespace Rinsvent\Data2DTOBundle\Service\Transformer\Request\Headers; |
||||
|
||||
use Codeception\Step\Meta; |
||||
|
||||
#[\Attribute] |
||||
class UserAgent extends Meta |
||||
{ |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
<?php |
||||
|
||||
namespace Rinsvent\Data2DTOBundle\Service\Transformer\Request\Headers; |
||||
|
||||
use Rinsvent\Transformer\Transformer\Meta; |
||||
|
||||
class UserAgentTransformer extends HeaderTransformer |
||||
{ |
||||
/** |
||||
* @param UserAgent $meta |
||||
*/ |
||||
public function transform(mixed $data, Meta $meta): mixed |
||||
{ |
||||
return $this->request->headers->get('user_agent', $meta->default); |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
<?php |
||||
|
||||
namespace Rinsvent\Data2DTOBundle\Service\Transformer\Request\Server; |
||||
|
||||
use Rinsvent\Transformer\Transformer\Meta; |
||||
|
||||
#[\Attribute] |
||||
class Ip extends Meta |
||||
{ |
||||
|
||||
} |
@ -0,0 +1,16 @@ |
||||
<?php |
||||
|
||||
namespace Rinsvent\Data2DTOBundle\Service\Transformer\Request\Server; |
||||
|
||||
use Rinsvent\Transformer\Transformer\Meta; |
||||
|
||||
class IpTransformer extends ServerTransformer |
||||
{ |
||||
/** |
||||
* @param Ip $meta |
||||
*/ |
||||
public function transform(mixed $data, Meta $meta): mixed |
||||
{ |
||||
return $this->request->getClientIp(); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace Rinsvent\Data2DTOBundle\Service\Transformer\Request\Server; |
||||
|
||||
use Rinsvent\Transformer\Transformer\Meta; |
||||
|
||||
#[\Attribute] |
||||
class Server extends Meta |
||||
{ |
||||
public function __construct( |
||||
public string $property, |
||||
public ?string $default = null, |
||||
public array $tags = ['request_server'] |
||||
) { |
||||
parent::__construct($tags); |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
<?php |
||||
|
||||
namespace Rinsvent\Data2DTOBundle\Service\Transformer\Request\Server; |
||||
|
||||
use Rinsvent\Transformer\Transformer\Meta; |
||||
use Rinsvent\TransformerBundle\Service\Transformer\Request\AbstractRequest; |
||||
|
||||
class ServerTransformer extends AbstractRequest |
||||
{ |
||||
/** |
||||
* @param Server $meta |
||||
*/ |
||||
public function transform(mixed $data, Meta $meta): mixed |
||||
{ |
||||
return $this->request->server->get($meta->property, $meta->default); |
||||
} |
||||
} |
Loading…
Reference in new issue