1. Go to this page and download the library: Download earc/parameter-transformer 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/ */
earc / parameter-transformer example snippets
use eArc\DI\DI;
DI::init();
use eArc\ParameterTransformer\Configuration;
use eArc\ParameterTransformer\ParameterTransformer;
$input = [
'parameterNameOne' => 'someValue',
'parameterNameTwo' => 'anotherValue',
//...
];
// $target has to be a callable a class string or an instance of \ReflectionFunctionAbstract
$target = [MyClass::class, 'myMethod'];
$argv = (new ParameterTransformer())->callableTransform($target, $input, new Configuration());
use eArc\ParameterTransformer\Configuration;
use eArc\ParameterTransformer\ParameterTransformer;
$input = [
'parameterNameOne' => 'someValue',
'parameterNameTwo' => 'anotherValue',
//...
];
$target = new MyClass();
$target = (new ParameterTransformer())->objectTransform($target, $input, new Configuration());
use eArc\ParameterTransformer\Configuration;
$config = (new Configuration())->setDefaultResource([new MyInputProvider(), 'getDefault']);
use eArc\ParameterTransformer\Configuration;
$mapping = [
'id' => 0,
'product' => 'productName',
'description' => 'text',
];
$config = (new Configuration())->setMapping($mapping);
use eArc\ParameterTransformer\Configuration;
$config = (new Configuration())->setNoInputIsAllowed(true);
use eArc\ParameterTransformer\Configuration;
$config = (new Configuration())->setPredefinedTypeHints([
MyServiceOne::class => new MyServiceOne(),
MyServiceTwo::class => new MyServiceTwo(),
//...
]);
use eArc\ParameterTransformer\Interfaces\ParameterTransformerFactoryInterface;
class MyClient implements ParameterTransformerFactoryInterface
{
//...
public function __construct(string $connectionConfigurationString)
{
//...
}
//...
public static function buildFromParameter($parameter) : static
{
return new MyClient((string) $parameter);
}
}
use eArc\Data\Entity\Interfaces\EntityInterface;
use eArc\ParameterTransformer\Interfaces\ParameterTransformerFactoryServiceInterface;
class MyEntityTypeHintingService implements ParameterTransformerFactoryServiceInterface
{
public function buildFromParameter(string $fQCN, $parameter) : object|null
{
if (is_subclass_of($fQCN, EntityInterface::class)) {
return data_load($fQCN, $parameter);
}
return di_get(EntityManagerInterface::class)
->getRepository($fQCN)
?->find($parameter);
}
}
di_tag(ParameterTransformerFactoryServiceInterface::class, MyEntityTypeHintingService::class);
use eArc\ParameterTransformer\Configuration;
$config = (new Configuration())->setNullIsAllowed(true);
use eArc\ParameterTransformer\Configuration;
$config = (new Configuration())->setMethodsFirst(false);
use eArc\ParameterTransformer\Configuration;
$config = (new Configuration())
->setFilterMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_PROTECTED)
->setMaxParameterCount(3)
->setNoInputIsAllowed(true);
use eArc\ParameterTransformer\Configuration;
$config = (new Configuration())
->setFilterProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
$config = (new Configuration())
->setUsePropertyTransformation(false);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.