Git Product home page Git Product logo

ltree-bundle's Introduction

Korben Dallas

Linkedin Mail

About me

I'm a senior software engineer. I like to work with Laravel, Vue and PHP. I love MacOs. I'm open-source development enthusiast.

I have experience in the development of payment gateways, integration with various payment systems, corporate accounting systems such as 1C, CRM, ERP, etc., Working with API Google, Yandex, various messengers, etc.

I love to move towards automating routine tasks, building the right architecture in development.

I have the strongest self-motivation. Resistant to stress.

Stack I work with

and others...

I can integrate with with

Interesting stats

Korben's stats

ltree-bundle's People

Contributors

anomality avatar pvsaintpe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ltree-bundle's Issues

Bundle breaks existing repositories

I have repository that extends ServiceEntityRepository (generated by maker bundle)

<?php

namespace App\Repository;

use App\Entity\ShortUrl;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method ShortUrl|null find($id, $lockMode = null, $lockVersion = null)
 * @method ShortUrl|null findOneBy(array $criteria, array $orderBy = null)
 * @method ShortUrl[]    findAll()
 * @method ShortUrl[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class ShortUrlRepository extends ServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, ShortUrl::class);
    }
}

When using this bundle I get an error:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to App\Repository\ShortUrlRepository::__construct() must implement interface Symfony\Bridge\Doctrine\RegistryInterface, instance of Doctrine\ORM\EntityManager given, called in /Users/arudnikov/Projects/ctv-api/vendor/pvsaintpe/ltree-bundle/Repository/RepositoryFactory.php on line 94 in /Users/arudnikov/Projects/ctv-api/src/Repository/ShortUrlRepository.php:17
Stack trace:
#0 /Users/arudnikov/Projects/ctv-api/vendor/pvsaintpe/ltree-bundle/Repository/RepositoryFactory.php(94): App\Repository\ShortUrlRepository->__construct(Object(Doctrine\ORM\EntityManager), Object(Doctrine\ORM\Mapping\ClassMetadata))
#1 /Users/arudnikov/Projects/ctv-api/vendor/pvsaintpe/ltree-bundle/Repository/RepositoryFactory.php(69): LTree\Repository\RepositoryFactory->createRepository(Object(Doctrine\ORM\EntityManager), 'App\\Entity\\Shor...')
#2 /Users/arudnikov/Projects/ctv-api/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(713): LTree\Repository\Re in /Users/arudnikov/Projects/ctv-api/src/Repository/ShortUrlRepository.php on line 17

The error happens, because this bundle replaces default repository factory with ltree_bundle.repository_factory

TestRepository is not created. createRepository() must be an instance of Doctrine\Common\Persistence\ObjectRepository

Hi,
I'd like to use your bundle v2.0.1 in my project (Symfony 5.3). But now I'm struggling to make it work by provided example.

I made all things as described in example of code.
I made entity and test repository. In entity class I changed namespace of repository that I've used. Your repository class is placed under Ltree/Entity/Repository.

Here is a part of the TestEntity class:

/**
 * Class TestEntity
 * @package LTree\Entity
 *
 * @Entity(repositoryClass="App\Infrastructure\Repository\TestRepository")
 * @LTreeEntity()
 */
class TestEntity implements LTreeEntityInterface
{ ...

TestRepository class is exactly the same as provided in the example, except using of my namespace

<?php

namespace App\Infrastructure\Repository;

use Doctrine\ORM\EntityManagerInterface;
use LTree\Repository\LTreeEntityRepository;
use App\Domain\Ltree\TestEntity;

/**
 * Class TestRepository
 *
 * @method TestEntity|null find($id, $lockMode = null, $lockVersion = null)
 * @method TestEntity|null findOneBy(array $criteria, array $orderBy = null)
 * @method TestEntity[]    findAll()
 * @method TestEntity[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 *
 * @package LTree\Entity
 */
class TestRepository extends LTreeEntityRepository
{
    /**
     * TestRepository constructor.
     * @param EntityManagerInterface $registry
     */
    public function __construct(EntityManagerInterface $registry)
    {
        parent::__construct($registry, $registry->getClassMetadata(TestEntity::class));
    }
}

My first test:

<?php
namespace App\Infrastructure\Repository;

use App\Infrastructure\TestCase\ContainerTestCase;
use App\Domain\Ltree\TestEntity;

/**
 * Class TestRepositoryTest
 * @package App\Infrastructure\Repository
 */
class TestRepositoryTest extends ContainerTestCase
{
    /**
     * @var TestRepository
     */
    private $repo;

    /**
     * @inheritdoc
     */
    protected function setUp(): void
    {
        parent::setUp();
        
        // it's the same as to call $this->getContainer()->get('doctrine')->getManager()->getRepository(...)
        $this->repo = $this->getRepository('Ltree:TestEntity');
    }

    /**
     * @return void
     */
    public function testGetSuccess()
    {
        $node = $this->repo->get(2);

        $this->assertInstanceOf(TestEntity::class, $node);
    }
}

Result of running of this test:

1) App\Infrastructure\Repository\TestRepositoryTest::testGetSuccess
TypeError: Return value of LTree\Repository\RepositoryFactory::createRepository() must be 
an instance of Doctrine\Common\Persistence\ObjectRepository, 
instance of App\Infrastructure\Repository\TestRepository returned

But TestRepository class extends LTreeEntityRepository one.
So, it doesn't work even with own types.

BTW I'm using custom doctrine mappings as follows:

doctrine:
    ...
    orm:
    ...
        auto_mapping: false
        mappings:
            ...
            Ltree:
                type: annotation
                prefix: 'App\Domain\Ltree'
                dir: '%kernel.project_dir%/src/Domain/Ltree'
                is_bundle: false

Please help me with this.
I'm able to provide any required details.

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.