thephpleague / fractal

Output complex, flexible, AJAX/RESTful data structures.
fractal.thephpleague.com
MIT License
3.52k stars 352 forks source link

Optimizations for longrunning applications #569

Open gam6itko opened 2 months ago

gam6itko commented 2 months ago

I'm working on increasing fractal performance in lognrunning application.

Not to setCurrentScope

First step is to make Transformer immutable. We must not set current scope to Transformer. This will give us opportunity to store transformers in service container. Scope should be passed to each transform or includeSomething method as argument.

public function transform(array $data, ScopeInterface $scope): array
{
    // magic here      
}

public function includeSomethingarray $data, ParamBag $p, ScopeInterface $scope): array
{
    // magic here      
}

TransformerAbstract should be removed.

User must construct his own Transformer class.

Now TransformerAbstract looks like

abstract class TransformerAbstract implements HasIncludesInterface, ScopeAwareInterface
{
    use HasIncludesTrait;
    use IncludeMethodBuildTrait;
    use ResourceCreateTrait;
    use ScopeAwareTrait;
}

For example User can make he`s own lightweight Transformer without includes. It will be a little faster because we do not spend time on figure out what to include.

abstract class MyAbstracttransformer
{
    use IncludeMethodBuildTrait;
    use ResourceCreateTrait;
}

Any mention of TransformerAbstract has been removed from Scope.

Also