PHP code example of php-etl / sylius-plugin
1. Go to this page and download the library: Download php-etl/sylius-plugin 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' );
php-etl / sylius-plugin example snippets
iboko\Plugin\Sylius;
use PhpParser \Node ;
use PhpParser \PrettyPrinter ;
use Symfony \Component \Console ;
use Symfony \Component \Yaml ;
$input = new Console\Input\ArgvInput($argv);
$output = new Console\Output\ConsoleOutput();
class DefaultCommand extends Console \Command \Command
{
protected static $defaultName = 'test' ;
protected function configure ()
{
$this ->addArgument('file' , Console\Input\InputArgument::REQUIRED);
}
protected function execute (Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$factory = new Sylius\Service();
$style = new Console\Style\SymfonyStyle(
$input,
$output,
);
$config = Yaml\Yaml::parse(input: file_get_contents($input->getArgument('file' )));
$style->section('Validation' );
$style->writeln($factory->validate($config) ? '<info>ok</info>' : '<error>failed</error>' );
$style->section('Normalized Config' );
$style->writeln(\json_encode($config = $factory->normalize($config), JSON_PRETTY_PRINT));
$style->section('Generated code' );
$style->writeln((new PrettyPrinter\Standard())->prettyPrintFile([
new Node\Stmt\Return_($factory->compile($config)->getBuilder()->getNode()),
]));
return 0 ;
}
}
(new Console\Application())
->add(new DefaultCommand())
->run($input, $output)
;