cycle / proxy-factory

Proxy Factory implementation for cycle ORM
MIT License
7 stars 5 forks source link

Strange behaviour with repository method ->findByPK() #4

Closed alexndr-novikov closed 5 years ago

alexndr-novikov commented 5 years ago

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
alexndr-novikov commented 5 years ago

Original entity

public function setDisplayName(string $displayName): self
    {
        $this->displayName = $displayName;

        return $this;
    }

    public function setSortOrder(int $sortOrder): \stdClass
    {
        $this->sortOrder = $sortOrder;

        return $this;
    }

    public function setPayout(int $payout): Profile
    {
        $this->payout = $payout;

        return $this;
    }

Generated file

/**
     * {@inheritdoc}
     */
    public function setDisplayName(string $displayName) : \self
    {
        if ($this->__resolver->__resolve() !== null) {
            return $this->__resolver->__resolve()->setDisplayName($displayName);
        } else {
            throw new ProxyFactoryException('Promise not loaded');
        }
    }
    /**
     * {@inheritdoc}
     */
    public function setSortOrder(int $sortOrder) : \stdClass
    {
        if ($this->__resolver->__resolve() !== null) {
            return $this->__resolver->__resolve()->setSortOrder($sortOrder);
        } else {
            throw new ProxyFactoryException('Promise not loaded');
        }
    }
    /**
     * {@inheritdoc}
     */
    public function setPayout(int $payout) : \App\Entity\Profile
    {
        if ($this->__resolver->__resolve() !== null) {
            return $this->__resolver->__resolve()->setPayout($payout);
        } else {
            throw new ProxyFactoryException('Promise not loaded');
        }
    }
vvval commented 5 years ago

Fixed.