PHP code example of delolmo / valinor-console
1. Go to this page and download the library: Download delolmo/valinor-console 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/ */
delolmo / valinor-console example snippets
use App\DTO\CustomObject;
use CuyZ\Valinor\Mapper\Source\Source;
use CuyZ\Valinor\MapperBuilder;
use DelOlmo\Valinor\Mapping\Source\InputSource;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
final class CustomCommand extends Command
{
public function execute(InputInterface $input, OutputInterface $output): int
{
// Create the Source using the new InputSource
$source = Source::iterable(new InputSource($input));
// Create the Mapper, using the desired configuration
$mapper = new MapperBuilder())
->allowSuperfluousKeys()
->enableFlexibleCasting()
->mapper();
// Map the source to whatever object makes sense
$mapped = $mapper->map(CustomObject::class, $source);
// Apply whatever business logic makes sense from here
// ...
}
}