1. Go to this page and download the library: Download cuyz/valinor-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use CuyZ\Valinor\Mapper\TreeMapper;
final class SomeAutowiredService
{
public function __construct(
private TreeMapper $mapper,
) {}
public function someMethod(): void
{
$this->mapper->map(SomeDto::class, /* … */);
// …
}
}
// config/services.php
use CuyZ\Valinor\Mapper\TreeMapper;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $container): void {
$container
->services()
->set(\Acme\SomeService::class)
->args([
service(TreeMapper::class),
]);
};
use CuyZ\Valinor\Mapper\MapperBuilder;
final class SomeAutowiredService
{
public function __construct(
private MapperBuilder $mapperBuilder,
) {}
public function someMethod(): void
{
$this->mapperBuilder
// …
// Some mapper configuration
// …
->mapper()
->map(SomeDto::class, /* … */);
// …
}
}
use CuyZ\Valinor\Normalizer\JsonNormalizer;
final class SomeAutowiredService
{
public function __construct(
private JsonNormalizer $jsonNormalizer,
) {}
public function someMethod(): void
{
// …
$this->jsonNormalizer->normalize($someObject);
// …
}
}
// config/services.php
use CuyZ\Valinor\Normalizer\JsonNormalizer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $container): void {
$container
->services()
->set(\Acme\SomeService::class)
->args([
service(JsonNormalizer::class),
]);
};
use CuyZ\Valinor\Normalizer\Format;
use CuyZ\Valinor\NormalizerBuilder;
final class SomeAutowiredService
{
public function __construct(
private NormalizerBuilder $normalizerBuilder,
) {}
public function someMethod(): void
{
$this->normalizerBuilder
// …
// Some normalizer configuration
// …
->normalizer(Format::array())
->normalize($someValue);
// …
}
}
// config/packages/valinor.php
return static function (Symfony\Config\ValinorConfig $config): void {
// Date formats that will be supported by the mapper by default.
$config->mapper()->dateFormatsSupported(['Y-m-d', 'Y-m-d H:i:s']);
// For security reasons, exceptions thrown in a constructor will not be
// caught by the mapper unless they are specifically allowed by giving their
// class names to the configuration below.
$config->mapper()->allowedExceptions([
\Webmozart\Assert\InvalidArgumentException::class,
\App\CustomException::class,
]);
// When a mapping error occurs during a console command, the output will
// automatically be enhanced to show information about errors. The maximum
// number of errors that will be displayed can be configured below, or set
// to 0 to disable this feature entirely.
$config->console()->mappingErrorsToOutput(15);
// By default, mapper cache entries are stored in the build directory of the
// application. This can be changed by setting a custom cache service.
$config->cache()->service('app.custom_cache');
// Cache entries representing class definitions won't be cleared when files
// are modified during development of the application. This can be changed
// by setting in which environments cache entries will be unvalidated.
$config->cache()->envWhereFilesAreWatched(['dev', 'custom_env']);
};
use CuyZ\Valinor\MapperBuilder;
use CuyZ\ValinorBundle\Configurator\MapperBuilderConfigurator
final class ConstructorRegistrationConfigurator implements MapperBuilderConfigurator
{
public function configureMapperBuilder(MapperBuilder $builder): MapperBuilder
{
return $builder
->registerConstructor(SomeDTO::create(...))
->registerConstructor(SomeOtherDTO::new(...));
}
}
final class DateFormatConfigurator implements MapperBuilderConfigurator
{
public function configureMapperBuilder(MapperBuilder $builder): MapperBuilder
{
return $builder
->supportDateFormats('Y/m/d', 'Y-m-d H:i:s');
}
}
use CuyZ\Valinor\NormalizerBuilder;
use CuyZ\ValinorBundle\Configurator\NormalizerBuilderConfigurator;
final class TransformerRegistrationConfigurator implements NormalizerBuilderConfigurator
{
public function configureNormalizerBuilder(NormalizerBuilder $builder): NormalizerBuilder
{
return $builder->registerTransformer(
fn (string $value): string => strtoupper($value),
);
}
}
#[\CuyZ\ValinorBundle\Cache\WarmupForMapper]
final readonly class ClassThatWillBeWarmedUp
{
public function __construct(
public string $foo,
public int $bar,
) {}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.