Giter Site home page Giter Site logo

proxy-factory's People

Contributors

rauanmayemir avatar serafimarts avatar vvval avatar wolfy-j avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

proxy-factory's Issues

Namespace issue in generated proxy classes

Here's a reproduction case for the bug.

src/Entity.php

<?php
declare(strict_types=1);
namespace App;

use App\Entity\Child;

class Entity
{
    public function updateChild(Child $child): void {}
}

src/Entity/Child.php

<?php
declare(strict_types=1);
namespace App\Entity;

class Child {}

Materializing App\Entity proxy will give us the following code (truncated for clarity):

<?php
declare(strict_types=1);
namespace App;

use Cycle\ORM\Promise\PromiseInterface;
use Cycle\ORM\Promise\Resolver;
use Cycle\ORM\Promise\Exception\ProxyFactoryException;
use Cycle\ORM\ORMInterface;
class EntityProxy_075f7896d56248c10e30d6df26d213297e38b30cdafa676bc55cbbdb7c1804a5 extends Entity implements PromiseInterface
{
    public function updateChild(App\Entity\Child $child) : void
    {
        if ($this->resolver->__resolve() !== null) {
            $this->resolver->__resolve()->updateChild($child);
        } else {
            throw new ProxyFactoryException(sprintf('Method `%s()` not loaded for `%s`', 'updateChild', 'App\\Entity'));
        }
    }
}

As seen here, use of App\Entity\Child is incorrect because it should be \App\Entity\Child. Otherwise, it's being considered local, i.e \App\App\Entity\Child.

Incompatible method declarations in proxy classes

1). Methods with variadic arguments like public function hasRole(...$roles) are generated as public function hasRole($roles)
2). Arguments with default values like public function fill($attributes = []) are generated as public function fill($attributes)

[PHP8] Add support for union types in methods

I want to use in my entity classes methods smth like this:

public function setProperties(array|string $properties) : self
{
    $this->properties = is_string($properties) ? $properties : json_encode($properties);
    return $this;
}

When a model loaded directly (fetchOne(), findByPk() and etc) everything is fine.

But when I want to use lazy load of relations (it happens through promises classes) I receive a 500 error with the message

Call to undefined method ReflectionUnionType::getName() in ... /Promise/Declaration/Extractor/Methods.php at line 215

I also use union types in class properties, but with them all seems good.

Strange behaviour with repository method ->findByPK()

I have pretty common code, where I get Id in Controller action, and try to load entity:

public function store(int $id, ProfileQuestionAnswerRequest $request)
{
        if (!$request->isValid()) {
            return $this->response->validationError($request->getErrors());
        }
        /** @var ProfileQuestion $question */
        $question = $this->profileQuestionRepository->findByPK($request->questionId);
        return [
          'type' => $question->getType(),
        ];
}

Where profileQuestionRepository is class ProfileQuestionRepository extends Repository,
And $question is ProfileQuestion entity with annotation

  @Annotation\Entity(repository = "App\Repository\ProfileQuestionRepository")
  @Annotation\Table(
     indexes = {
          @Annotation\Table\Index(columns = {"profile_id"}),
          @Annotation\Table\Index(columns = {"sort_order"}),
          @Annotation\Table\Index(columns = {"active"})
      }
  )

findByPK() causes Fatal error:

Fatal error: '\self' is an invalid class name in /var/www/core/vendor/cycle/proxy-factory/src/Materizalizer/EvalMaterializer.php(16) : eval()'d code on line 86
Call Stack:
    0.0003     394448   1. {main}() /var/www/core/app.php:0
    0.1466    4222104   2. App\App->serve() /var/www/core/app.php:21
    0.1467    4222480   3. Spiral\Core\ContainerScope::runScope() /var/www/core/vendor/spiral/boot/src/AbstractKernel.php:100
    0.1467    4222480   4. Spiral\Http\RrDispacher->serve() /var/www/core/vendor/spiral/core/src/ContainerScope.php:48
  111.9680    4711552   5. Spiral\Http\Http->handle() /var/www/core/vendor/spiral/framework/src/Http/RrDispacher.php:75
  111.9681    4711664   6. Spiral\Http\Pipeline->handle() /var/www/core/vendor/spiral/http/src/Http.php:98
  111.9681    4711664   7. App\Middleware\ParseJsonMiddleware->process() /var/www/core/vendor/spiral/http/src/Pipeline.php:80
  111.9683    4712376   8. Spiral\Http\Pipeline->handle() /var/www/core/app/src/Middleware/ParseJsonMiddleware.php:27
  111.9684    4713448   9. Spiral\Core\Container->runScope() /var/www/core/vendor/spiral/http/src/Pipeline.php:85
  111.9685    4713824  10. Spiral\Http\Pipeline->Spiral\Http\{closure:/var/www/core/vendor/spiral/http/src/Pipeline.php:83-85}() /var/www/core/vendor/spiral/core/src/Container.php:264
  111.9686    4713824  11. Spiral\Router\Router->handle() /var/www/core/vendor/spiral/http/src/Pipeline.php:84
  111.9696    4716072  12. Spiral\Core\Container->runScope() /var/www/core/vendor/spiral/router/src/Router.php:76
  111.9696    4716448  13. Spiral\Router\Router->Spiral\Router\{closure:/var/www/core/vendor/spiral/router/src/Router.php:74-76}() /var/www/core/vendor/spiral/core/src/Container.php:264
  111.9696    4716448  14. Spiral\Router\Route->handle() /var/www/core/vendor/spiral/router/src/Router.php:75
  111.9731    4836456  15. Spiral\Http\Pipeline->process() /var/www/core/vendor/spiral/router/src/Route.php:118
  111.9732    4836568  16. Spiral\Http\Pipeline->handle() /var/www/core/vendor/spiral/http/src/Pipeline.php:66
  111.9732    4837640  17. Spiral\Core\Container->runScope() /var/www/core/vendor/spiral/http/src/Pipeline.php:85
  111.9732    4838016  18. Spiral\Http\Pipeline->Spiral\Http\{closure:/var/www/core/vendor/spiral/http/src/Pipeline.php:83-85}() /var/www/core/vendor/spiral/core/src/Container.php:264
  111.9732    4838016  19. Spiral\Router\CoreHandler->handle() /var/www/core/vendor/spiral/http/src/Pipeline.php:84
  111.9739    4876304  20. Spiral\Core\Core->callAction() /var/www/core/vendor/spiral/router/src/CoreHandler.php:107
  111.9845    4891104  21. Spiral\Core\Container->runScope() /var/www/core/vendor/spiral/hmvc/src/AbstractCore.php:69
  111.9846    4891856  22. Spiral\Core\Core->Spiral\Core\{closure:/var/www/core/vendor/spiral/hmvc/src/AbstractCore.php:51-69}() /var/www/core/vendor/spiral/core/src/Container.php:264
  112.1378    9609152  23. Spiral\Core\ContainerScope::runScope() /var/www/core/vendor/spiral/hmvc/src/AbstractCore.php:68
  112.1378    9609152  24. Spiral\Core\Core->Spiral\Core\{closure:/var/www/core/vendor/spiral/hmvc/src/AbstractCore.php:57-68}() /var/www/core/vendor/spiral/core/src/ContainerScope.php:48
  112.1379    9609152  25. Spiral\Core\Core->callMethod() /var/www/core/vendor/spiral/hmvc/src/AbstractCore.php:63
  112.1593    9976616  26. ReflectionMethod->invokeArgs() /var/www/core/vendor/spiral/hmvc/src/AbstractCore.php:115
  112.1593    9976648  27. App\Controller\ProfileAnswerController->store() /var/www/core/vendor/spiral/hmvc/src/AbstractCore.php:115
  112.1625   10044592  28. App\Repository\ProfileQuestionRepository->findByPK() /var/www/core/app/src/Controller/ProfileAnswerController.php:130
  112.1633   10061752  29. Cycle\ORM\Select->fetchOne() /var/www/core/vendor/cycle/orm/src/Select/Repository.php:38
  112.1810   10233040  30. Cycle\ORM\ORM->make() /var/www/core/vendor/cycle/orm/src/Select.php:350
  112.1878   10507856  31. Cycle\ORM\RelationMap->init() /var/www/core/vendor/cycle/orm/src/ORM.php:146
  112.1878   10507856  32. Cycle\ORM\Relation\BelongsTo->initPromise() /var/www/core/vendor/cycle/orm/src/RelationMap.php:65
  112.1878   10508232  33. Cycle\ORM\ORM->promise() /var/www/core/vendor/cycle/orm/src/Relation/Traits/PromiseOneTrait.php:25
  112.1879   10508232  34. Cycle\ORM\Promise\ProxyFactory->promise() /var/www/core/vendor/cycle/orm/src/ORM.php:303
  112.2537   11461504  35. Cycle\ORM\Promise\Materizalizer\EvalMaterializer->materialize() /var/www/core/vendor/cycle/proxy-factory/src/ProxyFactory.php:94

Documentation?

Is there any documentation on this library? It is mentioned here: https://cycle-orm.dev/docs/advanced-promise that you can use it for resolving relation references, but what's not mentioned is that you cannot create a new object like new \Cycle\ORM\Promise\ProxyFactory(), because there a few required arguments in the constructor. I found no info regarding how exactly this library is supposed to be used.

Perhaps unnecessary entity parsing during proxy instantiation

Looks like every proxy object instantiation leads to parsing original object.

Here it is call extract method from in instantiate():

$structure = $this->extractor->extract($reflection);

which internaly calls getExtendedMethodNodes() which perform file read and parse:

private function getExtendedMethodNodes(array $reflections): array

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.