Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Jan 20, 2025
1 parent c5fd2e8 commit 5c8a5d5
Show file tree
Hide file tree
Showing 68 changed files with 1,477 additions and 862 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- `DefaultProcessor` - automatic meta cache reset after main `process()` call (performance optimization)
- `Skipped` modifier and the related code - it was an undocumented feature that is no longer necessary
- `FieldContext` - `getType()` - unused and no longer necessary

## [0.2.0](https://github.com/orisai/object-mapper/compare/0.1.0...0.2.0) - 2024-06-22

Expand Down
10 changes: 3 additions & 7 deletions src/Callbacks/BaseCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Orisai\ObjectMapper\Args\Args;
use Orisai\ObjectMapper\Args\ArgsChecker;
use Orisai\ObjectMapper\Context\ArgsContext;
use Orisai\ObjectMapper\Context\BaseFieldContext;
use Orisai\ObjectMapper\Context\FieldContext;
use Orisai\ObjectMapper\Context\MappedObjectContext;
use Orisai\ObjectMapper\Context\CallbackBaseContext;
use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Processing\ObjectHolder;
use ReflectionClass;
Expand Down Expand Up @@ -317,16 +315,14 @@ public static function getArgsType(): string
}

/**
* @param mixed $data
* @param BaseCallbackArgs $args
* @param FieldContext|MappedObjectContext $context
* @param BaseCallbackArgs $args
* @return mixed
*/
public static function invoke(
$data,
Args $args,
ObjectHolder $holder,
BaseFieldContext $context,
CallbackBaseContext $context,
ReflectionClass $declaringClass
)
{
Expand Down
20 changes: 10 additions & 10 deletions src/Callbacks/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Orisai\ObjectMapper\Args\Args;
use Orisai\ObjectMapper\Context\ArgsContext;
use Orisai\ObjectMapper\Context\BaseFieldContext;
use Orisai\ObjectMapper\Context\FieldContext;
use Orisai\ObjectMapper\Context\MappedObjectContext;
use Orisai\ObjectMapper\Context\CallbackBaseContext;
use Orisai\ObjectMapper\Context\CallbackObjectContext;
use Orisai\ObjectMapper\Context\CallbackPropertyContext;
use Orisai\ObjectMapper\Exception\InvalidData;
use Orisai\ObjectMapper\Exception\ValueDoesNotMatch;
use Orisai\ObjectMapper\MappedObject;
Expand All @@ -22,7 +22,7 @@ interface Callback
{

/**
* @param array<int|string, mixed> $args
* @param array<int|string, mixed> $args
* @param ReflectionClass<MappedObject>|ReflectionProperty $reflector
* @return T_ARGS
*/
Expand All @@ -34,11 +34,11 @@ public static function resolveArgs(array $args, ArgsContext $context, Reflector
public static function getArgsType(): string;

/**
* @param mixed $data
* @param T_ARGS $args
* @param FieldContext|MappedObjectContext $context
* @param ObjectHolder<MappedObject> $holder
* @param ReflectionClass<MappedObject> $declaringClass
* @param mixed $data
* @param T_ARGS $args
* @param CallbackObjectContext|CallbackPropertyContext $context
* @param ObjectHolder<MappedObject> $holder
* @param ReflectionClass<MappedObject> $declaringClass
* @return mixed
* @throws ValueDoesNotMatch
* @throws InvalidData
Expand All @@ -47,7 +47,7 @@ public static function invoke(
$data,
Args $args,
ObjectHolder $holder,
BaseFieldContext $context,
CallbackBaseContext $context,
ReflectionClass $declaringClass
);

Expand Down
40 changes: 0 additions & 40 deletions src/Context/BaseFieldContext.php

This file was deleted.

8 changes: 8 additions & 0 deletions src/Context/CallbackBaseContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types = 1);

namespace Orisai\ObjectMapper\Context;

abstract class CallbackBaseContext
{

}
9 changes: 9 additions & 0 deletions src/Context/CallbackObjectContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types = 1);

namespace Orisai\ObjectMapper\Context;

//TODO
final class CallbackObjectContext extends CallbackBaseContext
{

}
9 changes: 9 additions & 0 deletions src/Context/CallbackPropertyContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types = 1);

namespace Orisai\ObjectMapper\Context;

//TODO
final class CallbackPropertyContext extends CallbackBaseContext
{

}
54 changes: 17 additions & 37 deletions src/Context/TypeContext.php → src/Context/DynamicContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,44 @@
namespace Orisai\ObjectMapper\Context;

use Orisai\ObjectMapper\MappedObject;
use Orisai\ObjectMapper\Meta\MetaLoader;
use Orisai\ObjectMapper\Meta\Runtime\RuntimeMeta;
use Orisai\ObjectMapper\Processing\Options;
use Orisai\ObjectMapper\Rules\Rule;
use Orisai\ObjectMapper\Rules\RuleManager;
use function array_keys;

class TypeContext
final class DynamicContext
{

private MetaLoader $metaLoader;

private RuleManager $ruleManager;

private Options $options;

private bool $initializeObjects;

/** @var array<class-string<MappedObject>, true> */
private array $processedClasses = [];

public function __construct(MetaLoader $metaLoader, RuleManager $ruleManager, Options $options)
public function __construct(Options $options, bool $initializeObjects)
{
$this->metaLoader = $metaLoader;
$this->ruleManager = $ruleManager;
$this->options = $options;
$this->initializeObjects = $initializeObjects;
}

public function getOptions(): Options
/**
* @return static
*/
public function createClone(): self
{
return $this->options;
$clone = clone $this;
$clone->options = $this->options->createClone();

return $clone;
}

/**
* @param class-string<MappedObject> $class
*/
public function getMeta(string $class): RuntimeMeta
public function getOptions(): Options
{
return $this->metaLoader->load($class);
return $this->options;
}

/**
* @template T of Rule
* @param class-string<T> $rule
* @return T
*/
public function getRule(string $rule): Rule
public function shouldInitializeObjects(): bool
{
return $this->ruleManager->getRule($rule);
return $this->initializeObjects;
}

/**
Expand All @@ -72,15 +63,4 @@ public function getProcessedClasses(): array
return array_keys($this->processedClasses);
}

/**
* @return static
*/
public function createClone(): self
{
$clone = clone $this;
$clone->options = $this->options->createClone();

return $clone;
}

}
90 changes: 0 additions & 90 deletions src/Context/FieldContext.php

This file was deleted.

53 changes: 0 additions & 53 deletions src/Context/MappedObjectContext.php

This file was deleted.

Loading

0 comments on commit 5c8a5d5

Please sign in to comment.