Beispiel #1
0
 public static function decorate(MatcherInterface $matcher, $value)
 {
     $factory = new PluginFactory();
     $config = $matcher->getPlugins()->addendum->plugins->matcher;
     $decorators = $factory->instance($config, $matcher, [MatcherDecoratorInterface::class]);
     foreach ($decorators as $decorator) {
         /* @var $decorator MatcherDecoratorInterface  */
         $decorator->decorate($matcher, $value);
     }
     return $value;
 }
Beispiel #2
0
 public static function create(DocumentPropertyMeta $meta, DocumentTypeMeta $modelMeta, $transformatorClass)
 {
     $sanitizerClass = self::_resolve($meta, $modelMeta);
     // Remap sanitizer if needed
     $mapConfig = [];
     $map = Mangan::fly($modelMeta->connectionId)->sanitizersMap;
     if (isset($map[$transformatorClass]) && isset($map[$transformatorClass][$sanitizerClass])) {
         $mapConfig = $map[$transformatorClass][$sanitizerClass];
         if (is_string($mapConfig)) {
             $mapClass = $mapConfig;
             $mapConfig = ['class' => $mapClass];
         }
     }
     if (is_array($meta->sanitizer)) {
         $sanitizerConfig = $meta->sanitizer;
         $sanitizerConfig['class'] = $sanitizerClass;
     } else {
         $sanitizerConfig = [];
         $sanitizerConfig['class'] = $sanitizerClass;
     }
     if (!empty($mapConfig)) {
         $sanitizerConfig = array_merge($sanitizerConfig, $mapConfig);
     }
     // Sanitize as array
     if ($meta->sanitizeArray) {
         $sanitizerConfig = ['class' => ArraySanitizer::class, 'sanitizer' => $sanitizerConfig];
     }
     $config = [$transformatorClass => [$sanitizerConfig]];
     $sanitizer = PluginFactory::fly($modelMeta->connectionId)->instance($config, $transformatorClass)[0];
     return $sanitizer;
 }
Beispiel #3
0
 public static function toModel($transformerClass, AnnotatedInterface $model)
 {
     $plugins = PluginFactory::fly()->instance(Mangan::fromModel($model)->finalizers, $transformerClass, ModelFinalizerInterface::class);
     foreach ($plugins as $finalizer) {
         /* @var $finalizer ArrayFinalizerInterface */
         $finalizer->toModel($model);
     }
     return $model;
 }
Beispiel #4
0
 public function testIfWillConfigureModelsFromFlyWithClassNameParam()
 {
     $plugins = PluginFactory::fly()->instance($this->config, TestModel::class);
     $this->assertSame(3, count($plugins), 'Should create 3 plugin instances');
     // Now configure second instance
     $plugins2 = PluginFactory::fly()->instance($this->config, TestModel::class);
     $this->assertSame(3, count($plugins2), 'Should create 3 plugin instances');
     // Default config check
     $expectedCfg = $this->config[TestModel::class];
     $this->assertInstanceOf($expectedCfg[0], $plugins2[0]);
     $this->assertInstanceOf($expectedCfg[1]['class'], $plugins2[1]);
     $this->assertInstanceOf($expectedCfg[2], $plugins2[2]);
     $this->assertSame($expectedCfg[1]['options'], $plugins2[1]->options);
     // Check if same instances
     $this->assertSame($plugins[0], $plugins2[0]);
     $this->assertSame($plugins[1], $plugins2[1]);
 }